Quiz: File Operations and Manipulation
Test your understanding of creating, copying, moving, and deleting files and directories.
1. What command creates a new empty file?
- create
- new
- touch
- make
Show Answer
The correct answer is C. The touch command creates a new empty file if it doesn't exist, or updates the modification timestamp if it does. For example, touch myfile.txt creates an empty file named myfile.txt.
Concept Tested: Touch Command
2. What command creates a new directory?
- md
- mkdir
- newdir
- create
Show Answer
The correct answer is B. The mkdir (make directory) command creates new directories. Use mkdir -p to create nested directories in one command (e.g., mkdir -p projects/2024/january).
Concept Tested: Mkdir Command
3. What does cp -r source/ destination/ do?
- Copies only the empty directory
- Copies the directory and all its contents recursively
- Creates a symbolic link
- Renames the directory
Show Answer
The correct answer is B. The -r (recursive) flag tells cp to copy a directory and all its contents, including subdirectories and files. Without -r, cp cannot copy directories.
Concept Tested: Cp Command, Recursive Copy
4. What is the difference between mv and cp?
- There is no difference
mvmoves/renames files;cpcopies filescpmoves files;mvcopies files- Both delete the original file
Show Answer
The correct answer is B. The mv (move) command moves files to a new location OR renames them—the original is removed. The cp (copy) command creates a duplicate, leaving the original in place.
Concept Tested: Mv Command, Cp Command
5. How do you rename a file in Linux?
- rename oldname newname
- rn oldname newname
- mv oldname newname
- cp oldname newname
Show Answer
The correct answer is C. In Linux, you use mv to rename files. When the source and destination are in the same directory, mv effectively renames the file. For example, mv report.txt final_report.txt renames the file.
Concept Tested: Mv Command
6. What does rm -rf directory/ do?
- Removes only empty directories
- Creates a backup before removing
- Recursively removes directory and contents without prompts
- Moves directory to trash
Show Answer
The correct answer is C. The rm -rf command recursively (-r) removes a directory and all contents, forcing (-f) deletion without confirmation prompts. This is dangerous—it permanently deletes files without sending them to trash. Use with extreme caution!
Concept Tested: Rm Command
7. What does cat file.txt do?
- Displays cat pictures
- Displays the entire file contents
- Creates a new file
- Compresses the file
Show Answer
The correct answer is B. The cat (concatenate) command displays the entire contents of a file to the terminal. It can also combine multiple files: cat file1.txt file2.txt displays both files' contents sequentially.
Concept Tested: Cat Command
8. Which commands show only the beginning or end of a file?
- top and bottom
- head and tail
- start and end
- first and last
Show Answer
The correct answer is B. The head command shows the first 10 lines of a file (or specify with -n), and tail shows the last 10 lines. Use tail -f to follow a file as it grows—perfect for watching log files in real-time.
Concept Tested: Head Command, Tail Command
9. What command counts lines, words, and characters in a file?
- count
- stats
- wc
- measure
Show Answer
The correct answer is C. The wc (word count) command counts lines, words, and characters. By default it shows all three; use -l for lines only, -w for words, or -c for characters.
Concept Tested: Wc Command
10. What does rmdir do differently than rm -r?
- It's faster
- It only removes empty directories
- It creates backups
- It moves to trash
Show Answer
The correct answer is B. The rmdir command only removes empty directories—it fails if the directory contains anything. This is a safety feature. Use rm -r when you need to remove a directory with contents.
Concept Tested: Rmdir Command