Linux File System Navigation 2 — Questions and Answers
Question 1: Which command displays the full path of the current working directory?
- pwd (Correct answer)
- cwd
- dir
- path
Correct answer: pwd
The `pwd` (print working directory) command outputs the absolute path of the current directory.
Question 2: What does the `cd -` command do in Linux?
- Switches to the previous working directory (Correct answer)
- Moves up one directory level
- Goes to the root directory
- Lists hidden directories
Correct answer: Switches to the previous working directory
`cd -` switches to the previous working directory stored in the $OLDPWD variable.
Question 3: Which command lists directory contents sorted by modification time, newest first?
- ls -lt (Correct answer)
- ls -la
- ls -lr
- ls -lS
Correct answer: ls -lt
`ls -lt` sorts output by modification time with the newest files listed first.
Question 4: What is the absolute path of the home directory for the root user on most Linux systems?
- /root (Correct answer)
- /home/root
- /usr/root
- /var/root
Correct answer: /root
The root user's home directory is `/root`, not under `/home` like regular users.
Question 5: Which `find` command option limits the search depth to 2 directory levels?
- -maxdepth 2 (Correct answer)
- -depth 2
- -level 2
- -recurse 2
Correct answer: -maxdepth 2
The `-maxdepth 2` option tells `find` to descend at most 2 levels below the starting point.
Question 6: What does `ls -d */` display?
- Only directories in the current location (Correct answer)
- All files including hidden ones
- Symbolic links only
- Files sorted by directory
Correct answer: Only directories in the current location
`ls -d */` matches and lists only directories (the trailing slash selects directories, `-d` prevents recursion).
Question 7: Which variable stores the path to the current user's home directory?
- $HOME (Correct answer)
- $USER
- $PATH
- $PWD
Correct answer: $HOME
The `$HOME` environment variable holds the absolute path of the current user's home directory.
Which command displays the full path of the current working directory?