Error message
No such file or directory
The path you gave does not resolve — but often the missing part is not the one you think.
Quick diagnosis
Start here. This one command usually tells you which of the causes below you are dealing with:
$ ls -la "$(dirname the/path)" && pwd Lists what actually exists in the parent directory and confirms where you are standing. Nine times out of ten the answer is visible right there.
Causes, ordered by how often they are the culprit
1 You are not where you think you are
Relative paths resolve from the current directory. This is by far the most common cause, especially in scripts and cron jobs, which start in a different directory than your interactive shell.
$ pwd && ls $ cd /the/right/place # or use an absolute path 2 A typo, or the wrong capitalisation
Linux filesystems are case sensitive: Documents and documents are different directories. People coming from Windows or macOS hit this constantly.
$ ls -la | grep -i thename $ cat Notes.txt # match the real capitalisation exactly Use Tab completion instead of typing names: it cannot get the case wrong.
3 A parent directory does not exist
Writing to logs/app/today.log fails if logs/app was never created. The error points at the whole path, not at the missing part.
$ ls -la logs/ $ mkdir -p logs/app 4 A broken symbolic link
The link exists but what it points at is gone or moved. ls shows the name, opening it fails — a confusing combination the first time you meet it.
$ ls -la thelink && readlink -f thelink $ ln -sfn /the/correct/target thelink 5 The script has Windows line endings
A file edited on Windows ends its lines with CR+LF. The shebang line then reads as "/bin/bash\r", which does not exist — and the error names a path that looks perfectly correct.
$ file script.sh && head -1 script.sh | cat -A $ sed -i "s/\r$//" script.sh If cat -A shows ^M at the end of lines, this is your cause. See also the dedicated page on "bad interpreter".
6 Unquoted spaces in the path
Without quotes, the shell splits on spaces and the command receives several arguments instead of one path.
$ ls -la $ cat "My Documents/notes.txt" 7 The binary exists but a library it needs does not
A subtle case: running a program returns "No such file or directory" even though you can see the file. What is missing is its dynamic loader or a shared library.
$ file ./theprogram && ldd ./theprogram $ sudo apt install the-missing-library How to stop it happening again
- Use Tab completion for every path. It cannot misspell, cannot get the case wrong, and escapes spaces for you.
- In scripts, use absolute paths, or set the working directory explicitly: cd "$(dirname "$0")".
- Create parent directories with mkdir -p before writing into them — it never fails when they already exist.
- If you edit files on Windows, configure your editor to save with LF line endings.
Frequently asked questions
The file is right there in ls — why does it say it does not exist?
Three usual suspects: capitalisation differs, the name contains an invisible character (check with ls | cat -A), or it is a broken symlink pointing at something that is gone.
Why does my script fail from cron but works when I run it?
Cron starts in the user's home directory with a minimal environment, so every relative path in your script resolves somewhere else. Use absolute paths.
What is the difference between this and "Permission denied"?
This one means the path does not resolve. "Permission denied" means it resolves fine but you are not allowed to use it — a completely different fix.
Commands involved
List the contents of a directory, with options for hidden files, long format, sorting and more.
cdMove between directories: absolute and relative paths, home shortcut, and jumping back.
pwdShow the absolute path of the directory you are currently in.
findLocate files anywhere in a directory tree by name, type, size, date — and act on them.
lnMake one file reachable from several paths — and understand symlinks vs hard links.
Concepts behind this error: Absolute vs relative path · Working directory · Symbolic link (symlink)
Other errors
SSH rejected your login because no key you offered was accepted by the server.
bash: command: command not foundThe shell searched every directory in your PATH and found no executable with that name.
Permission deniedThe path resolves fine — the system simply will not let you do that with it.
No space left on deviceA filesystem is full — confirm which one, and whether you ran out of bytes or inodes.