010-160 Command Line Navigation 2 — Questions and Answers
Question 1: Which command displays the full path of the current working directory?
- cwd
- pwd (Correct answer)
- dir
- path
Correct answer: pwd
The `pwd` (print working directory) command outputs the absolute path of the current directory.
Question 2: What does the tilde (~) represent in a Linux shell?
- The root directory
- The parent directory
- The current user's home directory (Correct answer)
- The last visited directory
Correct answer: The current user's home directory
In bash and most Linux shells, `~` expands to the current user's home directory (e.g., /home/alice).
Question 3: Which command would change to the previous working directory you were in?
- cd ..
- cd - (Correct answer)
- cd ~
- cd /
Correct answer: cd -
`cd -` switches back to the previously visited directory, equivalent to `cd $OLDPWD`.
Question 4: What is the absolute path of the root directory in Linux?
- /root
- /home
- / (Correct answer)
- //
Correct answer: /
The root directory is represented by a single forward slash `/`, which is the top of the filesystem hierarchy.
Question 5: If you are in /home/user/docs and type 'cd ../..', where will you end up?
- /home/user
- /home (Correct answer)
- /
- /home/user/docs/..
Correct answer: /home
Each `..` moves one level up: from docs to user, then from user to home, landing at /home.
Question 6: Which environment variable stores the path to the current user's home directory?
- $PATH
- $USER
- $HOME (Correct answer)
- $PWD
Correct answer: $HOME
The `$HOME` environment variable contains the absolute path to the current user's home directory.
Question 7: What does 'cd' with no arguments do in bash?
- Displays the current directory
- Changes to the root directory
- Changes to the home directory (Correct answer)
- Returns an error
Correct answer: Changes to the home directory
Running `cd` without arguments is equivalent to `cd ~` and takes you to the current user's home directory.
Which command displays the full path of the current working directory?