A Linux administrator is currently working in the /var/log directory. They previously navigated from their home directory, /home/admin. The administrator needs to quickly switch back to their previous working directory, /home/admin. Which of the following commands will achieve this?
The correct command to switch to the previous working directory is cd -. In the Bash shell, the hyphen (-) is a special relative path shortcut that refers to the directory stored in the $OLDPWD environment variable, which is updated every time the cd command is successfully executed. The cd .. command would change the directory to the parent directory of /var/log, which is /var. The cd . command would change the directory to the current directory (/var/log), effectively doing nothing. The cd ~ command would change to the current user's home directory, /home/admin, which happens to be the correct destination in this specific scenario, but it does not accomplish the task of switching to the previous directory. The cd - command is the most accurate and direct method for returning to the last directory, regardless of what that directory was.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the `$OLDPWD` environment variable?
Open an interactive chat with Bash
What is the difference between the commands `cd -` and `cd ..`?
Open an interactive chat with Bash
How does the shell determine the current directory?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
System Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access