- 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
| Job | Linux | Windows Command Prompt |
|---|---|---|
| Show the current folder | pwd | cd (with nothing after it) |
| List files in a folder | ls | dir |
| Change folder | cd foldername | cd foldername |
| Make a folder | mkdir name | md name or mkdir name |
| Copy a file | cp source target | copy source target |
| Move or rename a file | mv old new | move or ren |
| Delete a file | rm name | del name |
| Show the contents of a text file | cat name | type name |
| Clear the screen | clear | cls |
| Create an empty file | touch 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. Which Linux command lists the files in a folder?
- pwd
- cat
- ls
- mv
Show answer
Answer: C. ls lists files and folders. Its Windows partner is dir.
-
2. Which Windows command clears the Command Prompt screen?
- md
- del
- dir
- cls
Show answer
Answer: D. cls clears the screen; the Linux equivalent is clear.
-
3. You are in /home/asha/work and type cd .. . Which folder are you in now?
- /home/asha/work
- /work
- /home
- /home/asha
Show answer
Answer: D. Two dots mean the parent folder, so you move from /home/asha/work up to /home/asha.
-
4. Which Linux command displays the contents of a text file on the screen?
- touch
- cat
- cp
- pwd
Show answer
Answer: B. cat prints a text file's contents. The Windows partner is type.
-
5. What does mv notes.txt study.txt do if both are in the same folder?
- Renames notes.txt to study.txt
- Deletes study.txt
- Moves it to another drive
- 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.
Sign in to keep track of the lessons you finish.