• Practice
  • About 13 min
  • 5 practice questions

Command-line questions: Linux and Windows commands

Match common Linux and Windows commands to their jobs and predict what a short sequence of commands does.

If something looks wrong, please tell us.

A command-line interface (CLI) accepts typed commands. Exams ask for the command that does a given job, or the result of a short sequence. The commands are few, so learn them as pairs: the Linux command and its Windows (Command Prompt) partner.

Commands in pairs

Common commands
JobLinuxWindows Command Prompt
Show the current folderpwdcd (with nothing after it)
List files in a folderlsdir
Change foldercd foldernamecd foldername
Make a foldermkdir namemd name or mkdir name
Copy a filecp source targetcopy source target
Move or rename a filemv old newmove or ren
Delete a filerm namedel name
Show the contents of a text filecat nametype name
Clear the screenclearcls
Create an empty filetouch name(no direct short form)

Two shortcuts help in paths: .. means the parent folder (one level up) and . means the current folder. A path that begins from the top, such as /home/asha/work on Linux or C:\Users\Asha on Windows, is absolute. A path that starts from where you are, such as work/a.txt, is relative. Linux uses forward slashes in paths and treats capital and small letters as different; Windows uses backslashes and ignores the case.

Worked example 1: follow the commands

You start in /home/asha. The commands are: mkdir work, cd work, touch a.txt, ls, pwd. Step by step: a folder named work is created inside /home/asha; cd work moves into it; touch a.txt creates an empty file; ls lists a.txt; pwd prints /home/asha/work.

Worked example 2: going back up

From /home/asha/work you type cd .. and then pwd. The two dots mean the parent folder, so you move up one level and pwd prints /home/asha. Typing cd ../.. instead would move up two levels, to /home.

Worked example 3: copy, then rename

In a folder holding report.txt you run cp report.txt backup.txt and then mv backup.txt old.txt. The first command makes a duplicate named backup.txt; the second renames the duplicate to old.txt. The folder now holds report.txt and old.txt, and no backup.txt.

Wildcards and options

A wildcard stands for unknown characters in a name. The star matches any number of characters and the question mark ? matches exactly one. So .txt means every file whose name ends in .txt. Many commands also take options that change their behaviour; for example rm -r removes a folder together with everything in it, so it must be used with great care. On Windows, rmdir or rd removes an empty folder, and del removes files.

Worked example 4: wildcard

A folder holds a.txt, b.txt, c.doc and d.txt. The command ls *.txt lists only a.txt, b.txt and d.txt, which is 3 files. The file c.doc is left out because its name does not end in .txt.

Linux ls = Windows dir; cp = copy; mv = move or rename; rm = del; cat = type; clear = cls; two dots mean one folder up.

Common traps

  • Confusing rm (delete a file) with rmdir (remove an empty folder).
  • Forgetting that cp keeps the original and mv does not.
  • Reading cd .. as 'close' rather than 'go up one level'.
  • Assuming file names in Linux ignore capital letters; Report.txt and report.txt are different.

Check your understanding

  1. 1. Which Linux command lists the files in a folder?

    1. pwd
    2. cat
    3. ls
    4. mv
    Show answer

    Answer: C. ls lists files and folders. Its Windows partner is dir.

  2. 2. Which Windows command clears the Command Prompt screen?

    1. md
    2. del
    3. dir
    4. cls
    Show answer

    Answer: D. cls clears the screen; the Linux equivalent is clear.

  3. 3. You are in /home/asha/work and type cd .. . Which folder are you in now?

    1. /home/asha/work
    2. /work
    3. /home
    4. /home/asha
    Show answer

    Answer: D. Two dots mean the parent folder, so you move from /home/asha/work up to /home/asha.

  4. 4. Which Linux command displays the contents of a text file on the screen?

    1. touch
    2. cat
    3. cp
    4. pwd
    Show answer

    Answer: B. cat prints a text file's contents. The Windows partner is type.

  5. 5. What does mv notes.txt study.txt do if both are in the same folder?

    1. Renames notes.txt to study.txt
    2. Deletes study.txt
    3. Moves it to another drive
    4. Copies notes.txt to study.txt
    Show answer

    Answer: A. With both names in the same folder, mv simply renames the file. No second copy is created.

Privacy · Terms · Refunds · Delivery