010-160 Linux Filesystem & File Management 5 — Questions and Answers
Question 1: Which command shows the current working directory?
- cwd
- pwd (Correct answer)
- dir
- where
Correct answer: pwd
`pwd` (print working directory) outputs the absolute path of the current directory.
Question 2: What does `rm -rf /tmp/testdir` do?
- Removes /tmp/testdir only if it is empty
- Recursively and forcefully removes /tmp/testdir and all its contents (Correct answer)
- Renames /tmp/testdir to a backup
- Removes only regular files inside /tmp/testdir
Correct answer: Recursively and forcefully removes /tmp/testdir and all its contents
`rm -r` removes directories recursively and `-f` suppresses prompts and ignores nonexistent files.
Question 3: What type of file does `ls -l` show when the first character of the permissions field is 'l'?
- Hard link
- Symbolic link (Correct answer)
- Log file
- Locked file
Correct answer: Symbolic link
In `ls -l` output, 'l' as the first character of the permissions string indicates a symbolic (soft) link.
Question 4: Which command can be used to display the last 20 lines of a file?
- head -20 file
- tail -20 file (Correct answer)
- less -20 file
- cat -20 file
Correct answer: tail -20 file
`tail -20 file` (or `tail -n 20 file`) displays the last 20 lines of the specified file.
Question 5: What is the purpose of the `/var` directory in the Linux filesystem hierarchy?
- Stores variable-length user configuration files
- Contains variable data that changes during system operation, like logs and spool files (Correct answer)
- Holds virtual filesystem interfaces to the kernel
- Stores volatile RAM-based temporary files
Correct answer: Contains variable data that changes during system operation, like logs and spool files
/var holds variable data that grows and changes during normal system operation, including log files, mail spools, and databases.
Question 6: How do you search for the string 'error' in all `.log` files in the current directory?
- find . -name error *.log
- grep 'error' *.log (Correct answer)
- search 'error' *.log
- cat *.log | find error
Correct answer: grep 'error' *.log
`grep 'error' *.log` searches for the pattern 'error' across all files matching *.log in the current directory.
Question 7: What does the `chmod 755 script.sh` command do?
- Sets read-only permissions for all users
- Gives the owner full permissions and others read+execute permissions (Correct answer)
- Removes execute permission from the file
- Sets the sticky bit on the file
Correct answer: Gives the owner full permissions and others read+execute permissions
755 means owner gets rwx (7), group gets r-x (5), and others get r-x (5) — full control for owner, read+execute for everyone else.
Which command shows the current working directory?