Working Directory
The working directory is the location a shell uses when resolving ordinary relative file paths.
Understand the idea
A shell session has a working directory. It is the starting point for ordinary relative path arguments in the examples here. Opening another terminal tab can give you a different session with a different working directory, so check the current location instead of assuming it matches another tab.
In the simple POSIX-shell example, cd ./notes changes the shell’s working directory to an existing notes subfolder. The ./ prefix explicitly starts from the current directory. It changes the shell’s location; it is not a command to move the folder or delete its contents. pwd shows the resulting location.
The example assumes a human-lab folder with a notes subfolder already inside it. If the target folder does not exist or is inaccessible, cd can fail; the example does not create it for you. Before running a script by filename, check that you are in the folder containing it or supply the appropriate path.
Key points
- 01 The working directory belongs to the current shell session.
- 02 Ordinary relative paths are interpreted from that location.
- 03 pwd shows the current location in the illustrated POSIX shell.
- 04 cd ./notes selects an existing notes subfolder relative to the current folder.
- 05 A failed directory change is different from successfully entering a folder.
Worked example
Change the base for relative paths
A worked example using sample data. Nothing here runs on your computer.
pwd
cd ./notes
pwd/home/learner/human-lab
/home/learner/human-lab/notesIllustrative POSIX-shell output. The notes folder must already exist beneath the initial human-lab folder. cd normally produces no output here; the two displayed paths come from the two pwd commands.
Visual
flowchart LR A["Working directory: human-lab"] -->|"cd ./notes"| B["Working directory: human-lab/notes"]
Follow the primary sources
An original HWTL explanation, prepared and independently checked with AI against the sources below. This lesson has not yet been tested with human learners.
Source review completed 2026-10-07.
- POSIX.1-2024: cd
cd changes the current shell execution environment’s working directory; relative-path resolution and failure behavior are specified.
- POSIX.1-2024: pwd
pwd reports the current working directory, with logical/physical path distinctions beyond this simple no-symlink example.
Practice · predict the result
Track the working directory through a failed change
A small test from your robot instructors. Hints are welcome.
What you will practice: Predict how a successful directory change alters a relative-path base, and how a failed change leaves that base unchanged.
Sample scenario. Synthetic POSIX shell. Only the listed folders exist and are accessible; no symbolic links or CDPATH lookup apply. Steps continue after the failed cd. Predict stdout from pwd only; the failed cd has a diagnostic whose exact wording is outside this model.
- Initial working directory
/human-lab- Existing accessible folder
/human-lab- Existing accessible folder
/human-lab/notes- Step 1
cd ./notes- Step 2
pwd- Step 3
cd ./missing- Step 4
pwd- Resolve after the steps
plan.txt
Follow the four steps. What is the final working directory, where does plan.txt point, and what are the two pwd output lines?
Attempts stay on this browser and are kept separate from lesson views and your self-reported knowledge.
Sources and exercise scope
- POSIX.1-2024: cd
cd changes the current shell working directory; an unsuccessful change leaves that directory unchanged.
- POSIX.1-2024: pwd
Plain pwd reports the current working directory as an absolute path, followed by a newline.
Original synthetic exercise, checked with AI against primary documentation on 2026-10-08. Human learner validation is pending. A result here records this attempt; it does not establish mastery.
Make this lesson yours
Save it for later, or tell your robot what would help.
This correction stays on this browser. Browse all concepts if the topic is missing.
Familiarity is your own assessment. To use it in your coding tool, download your updated learning profile.
Choices are saved on this browser. They do not sync to your account or coding tool.
Lesson diagnostics
Download the public lesson material, resource choices, and robot text selected for this page. The file does not include your chat, code, or saved profile. Nothing from the trace is uploaded.
It records the page’s selections, not video playback or proof of learning. A link from your coding tool does not supply its original recommendation trace.
Enable JavaScript to create a trace on this device.