Linux Working Directory and Paths
How it works
Every shell has a working directory: the starting point for ordinary relative paths. pwd displays it; cd DIRECTORY changes it in the current shell. A path beginning with / starts at the root of the process filesystem view; a path such as notes/hello.txt starts at the working directory. . means the current directory, .. its parent, and unquoted ~ at the start of a shell word expands to the home directory. / is not the root user’s home. A directory tree can be pictured as the lab root containing notes, archive and empty, with hello.txt inside notes. The same file can be reached by different paths.
Prepare a safe practice environment
Use GNU/Linux and Bash as a normal user. From the extracted package root run bash lab-fixtures/files/setup.sh. It prints a fresh private directory under /tmp. Copy that path and enter it with cd (quote the path if needed); check pwd. Each code example below starts in a new lab with the same fixture: notes/hello.txt, notes/daily report.txt, notes/-draft, notes/.hidden, and empty directories archive and empty. Set export LC_ALL=C for the shown ordering and English diagnostics. Never run the modifying examples on your own files.
Navigate and return
Both reads print hello. Moving back to the parent changes which relative path is correct.
Remember an absolute location
The first line is the generated lab root; the next two add /notes and /archive. The exact prefix varies.
Read through a parent path
Prints hello: the parent contains the sibling directory notes.
Starting in archive, the first component .. selects the lab root. The next component notes selects a sibling directory, and hello.txt selects its file. The command reads the file without changing the working directory.
Common mistakes and safe habits
A failed cd does not move you to the requested directory. Stop and inspect the error and pwd before running a modifying command. Do not confuse a relative path with a path starting at /. In Bash, pwd -P shows the physical path rather than a logical path through symbolic links (covered later).
Try it yourself
From notes, reach archive, then read the sibling file notes/hello.txt without returning to the lab root. Explain each path component.
Use a fresh lab for the practice. When finished, return to the lab root if you are in a subdirectory, then leave it with cd ... Remove only the identified temporary lab folder using your file manager if desired. Never remove an unrelated path.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Working directory and paths — Knowledge Check
Apply filesystem concepts in a fresh disposable Linux lab.
Which path is absolute?
From archive, how do you read the sibling notes/hello.txt?
What does pwd report?
What should you do after cd fails?
What does .. normally refer to?