Yesterday cd logs worked; today it says the directory does not exist. Before retrying or adding sudo, run pwd. The folder may be fine—you may simply be looking from a different working directory. A path is determined by both its name and where the lookup starts.
Where does a relative path start?
The working directory is the starting point
The shell keeps a current working directory, and pwd prints it. In this example, user is a placeholder account name:
$ pwd
/home/user/projectLinux paths form a tree rooted at /. A leading slash means start from the root. Without one, as in logs, the lookup starts at the current working directory.
From /home/user/project, logs resolves below project; /logs starts at the root and names a different location. An absolute path is not guaranteed to exist merely because its starting point is fixed.
/
└── home
└── user
└── project ← current directory: /home/user/project
└── logsHere logs refers to /home/user/project/logs. If you move to /home/user, the same word refers to /home/user/logs instead.
cd logs and cd /logs have different origins
| Working directory | Command | Resolved target |
|---|---|---|
/home/user/project | cd logs | /home/user/project/logs |
/home/user/project | cd ./logs | /home/user/project/logs |
/home/user/project | cd /logs | /logs |
./ explicitly means “from this directory,” so the first two commands are equivalent here. cd /logs ignores the current directory. If /logs does not exist, it fails with “No such file or directory.” An absolute path fixes the origin; it does not guarantee success.
Where are you after cd fails?
Start in project, enter its logs child, and use cd - to return to the previous location:
pwd
cd logs
pwd
cd -
pwdAn illustrative run ends each line with these path components. The temporary parent prefix may differ by machine:
.../project
.../project/logs
.../project
.../projectIf cd /logs then fails, pwd still shows .../project. The failed cd has not moved the shell. In a deployment script, stop before later commands run from the wrong directory:
cd "$target_dir" || exit 1This assumes target_dir was set earlier. Pasting it into an interactive shell can exit that session on failure; while exploring by hand, inspect pwd after cd instead.
.., ~, and - are different destinations
| Command | Meaning | Example from /home/user/project/logs |
|---|---|---|
cd .. | Parent directory | /home/user/project |
cd ~ or bare cd | User's home directory | /home/user, if that is the home |
cd - | Previous working directory | Depends on the preceding move |
.. expresses a filesystem relationship. - refers to shell history for the previous working directory. ~ is expanded to the user's home. They may happen to produce the same path, but they are not the same rule. Repeating cd - can toggle between two locations.
What should you check after a path error?
- Run
pwdto see the current working directory. - Check whether the input starts with
/. That decides whether lookup starts at root or here. - Use
lsorls -ldto check whether the target directory exists. - Quote names with spaces, for example
cd "project files". - In scripts, test whether
cdsucceeded before continuing.
“No such file or directory” and “Permission denied” point to different investigations. If a path does not exist, elevated privileges do not create it. If it exists but traversal is denied, inspect the current user and directory permissions.
Key takeaways
pwd tells you where relative lookup begins. cd logs begins there; cd /logs begins at the root. After a failed cd, check pwd rather than assuming the shell moved. In scripts, stop on a failed directory change before subsequent commands run in the wrong place.

