Linux and Command-Line Basics
The directory /home/alice/data exists, and the current directory is /home/alice/work. Which of the following is the directory shown when "cd ../data" is run and then "pwd"?
- A/data
- B/home/alice/data
- C/home/alice/work/data
Show answer and explanation
Answer: B. /home/alice/data
A path that does not start with "/" is a relative path and is interpreted starting from the current directory. ".." means the parent directory, so .. moves from /home/alice/work to /home/alice, and data then leads into /home/alice/data. pwd prints the current directory as an absolute path starting with "/". An absolute path starting with "/" always refers to the same place regardless of the current directory.
- A. /data is the data directory directly under the root directory. A relative path is interpreted from the current directory, not from "/".
- B. Correct. .. moves to /home/alice, and from there into data.
- C. /home/alice/work/data is where "cd data" would go. ".." means going back to the parent directory.