010-160 - LPI Linux Essentials Command Line Navigation Questions and Answers — Questions and Answers
Question 1: A user is currently in the `/home/user/documents` directory. Which of the following commands will change the current directory to the `/home/user` directory?
- cd .. (Correct answer)
- cd /
- cd ~/
- cd documents
Correct answer: cd ..
The `..` represents the parent directory. From `/home/user/documents`, the parent directory is `/home/user`. Therefore, `cd ..` will navigate one level up to the desired directory.
Question 2: Which command is used to display the full path of the current working directory?
- path
- whereami
- pwd (Correct answer)
- dir
Correct answer: pwd
The `pwd` command stands for 'print working directory' and its function is to display the absolute path of the directory you are currently in.
Question 3: A user wants to navigate to their home directory, regardless of their current location in the filesystem. Which is the most efficient command to achieve this?
- cd /home/[username]
- cd (Correct answer)
- cd ../..
- cd root
Correct answer: cd
Typing `cd` without any arguments, or using `cd ~`, will always take you to your home directory. This is the most direct and universally applicable method.
Question 4: What is the key difference between an absolute path and a relative path?
- An absolute path is shorter than a relative path.
- A relative path always starts from the user's home directory.
- An absolute path is valid from anywhere in the filesystem, while a relative path depends on the current directory. (Correct answer)
- Relative paths can only be used to navigate to subdirectories.
Correct answer: An absolute path is valid from anywhere in the filesystem, while a relative path depends on the current directory.
An absolute path specifies a location from the root directory (`/`) and is unambiguous. A relative path specifies a location starting from the current directory, so its meaning changes depending on where you are.
Question 5: After navigating from `/usr/share` to `/etc/systemd`, which command will take you back to `/usr/share`?
- cd last
- cd ..
- cd back
- cd - (Correct answer)
Correct answer: cd -
The `cd -` command is a special shortcut that changes the current directory to the previous working directory. It effectively toggles between the two most recent directories.
Question 6: You are in a directory `/var/log`. You want to list the contents of the `apt` subdirectory within `/var/log`. Which command, using a relative path, would you use?
- ls /var/log/apt
- list apt
- ls apt (Correct answer)
- dir apt
Correct answer: ls apt
Since you are already in `/var/log`, you can use a relative path. The command `ls apt` will list the contents of the `apt` directory, which is located within your current directory.
A user is currently in the `/home/user/documents` directory.
Which of the following commands will change the current directory to the `/home/user` directory?