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.

Check
$ pwd && ls
Fix
$ 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.

Check
$ ls -la | grep -i thename
Fix
$ 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.

Check
$ ls -la logs/
Fix
$ 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.

Check
$ ls -la thelink && readlink -f thelink
Fix
$ 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.

Check
$ file script.sh && head -1 script.sh | cat -A
Fix
$ 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.

Check
$ ls -la
Fix
$ 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.

Check
$ file ./theprogram && ldd ./theprogram
Fix
$ sudo apt install the-missing-library

How to stop it happening again

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

ls

List the contents of a directory, with options for hidden files, long format, sorting and more.

cd

Move between directories: absolute and relative paths, home shortcut, and jumping back.

pwd

Show the absolute path of the directory you are currently in.

find

Locate files anywhere in a directory tree by name, type, size, date — and act on them.

ln

Make 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

Permission denied (publickey)

SSH rejected your login because no key you offered was accepted by the server.

bash: command: command not found

The shell searched every directory in your PATH and found no executable with that name.

Permission denied

The path resolves fine — the system simply will not let you do that with it.

No space left on device

A filesystem is full — confirm which one, and whether you ran out of bytes or inodes.