010-160 Linux Filesystem & File Management 3 — Questions and Answers
Question 1: What is the difference between a hard link and a symbolic link?
- Hard links can span filesystems; symbolic links cannot
- Symbolic links point to the inode directly; hard links use a path
- Hard links share the same inode as the original; symbolic links store a path to the target (Correct answer)
- There is no difference — they are aliases for the same feature
Correct answer: Hard links share the same inode as the original; symbolic links store a path to the target
Hard links reference the same inode as the original file, while symbolic links store a path string pointing to the target.
Question 2: Which command removes an empty directory?
- rm -d
- rmdir (Correct answer)
- del
- remove
Correct answer: rmdir
`rmdir` removes empty directories; it fails if the directory contains any files.
Question 3: What does `ls -la` show that `ls` alone does not?
- Only symbolic links
- Long format details and hidden files (Correct answer)
- File sizes in bytes only
- Sorted output by modification time
Correct answer: Long format details and hidden files
`-l` enables long format (permissions, owner, size, date) and `-a` shows hidden files starting with a dot.
Question 4: In Linux, what character is used to separate directories in a file path?
- \
- / (Correct answer)
- :
- ;
Correct answer: /
Linux uses the forward slash `/` as the directory separator in file paths.
Question 5: Which command copies a directory and all its contents recursively?
- cp dir1 dir2
- cp -r dir1 dir2 (Correct answer)
- mv dir1 dir2
- cp -a dir1
Correct answer: cp -r dir1 dir2
`cp -r` (or `cp -R`) copies a directory and all its subdirectories and files recursively.
Question 6: What does the `wc -l` command count?
- Words in a file
- Lines in a file (Correct answer)
- Characters in a file
- Files in a directory
Correct answer: Lines in a file
`wc -l` counts the number of lines in a file or from standard input.
Question 7: Which command is used to view the contents of a text file one screen at a time?
- cat
- head
- less (Correct answer)
- grep
Correct answer: less
`less` allows you to scroll through file contents one screen at a time, both forward and backward.
What is the difference between a hard link and a symbolic link?