theme: ricetheme
New palette
New palette

File No Such File or Directory Errors, Explained

No such file or directory means the path didn’t resolve. Trace typos, broken symlinks, script interpreters, and container or NixOS path mismatches.

A dark terminal shows a file error while a magnifying glass searches for a missing document icon near an empty folder slot.

tl;dr the short answer

“No such file or directory” means a program could not find the exact path it tried to use, including a folder, script interpreter, or binary loader. Check the path from left to right, confirm the working directory and environment, and look for typos, missing parent folders, broken symlinks, hidden characters, or unavailable dependencies. The fix is usually to correct the path or make the missing file available where the program runs.

Ever give directions to your place, only to hear back that the street doesn’t exist? Usually the street is real, and the address just has a typo.

That’s the heart of No such file or directory: the system looked for the exact path you gave it and came up empty.

Under the hood, the message comes from ENOENT, the system’s error code for a missing path.

In this post, we’ll cover the path, script, and container causes behind it, then dig into dotfile-specific cases like broken symlinks, bootstrap scripts, and NixOS interpreter paths that generic guides tend to skip.

What ‘No Such File or Directory’ Actually Means

Ever typed a command you were sure was right, only to get that message back? It’s more precise than it sounds.

Where the ENOENT code comes from

That text is a readable form of ENOENT, the code the kernel (Linux’s core) returns for a missing path (errno 2, the number programs read). The kernel walks each path component, the folders and filename in turn, and stops at the first missing one.

Every syscall (system call, a program’s request to the kernel) that hits that gap returns the same code.

Consider a Hyprland user who runs cp hyprland.conf ~/.config/hypr/ on a fresh install. The hypr folder doesn’t exist yet, so the kernel stops there. One mkdir -p ~/.config/hypr clears it.

Spotting the error in shells and logs

Look for it in four places:

  • Shell messages: bash: ./setup.sh: No such file or directory names the script bash couldn’t run.
  • strace output: strace, a tool that logs system calls, shows the raw request: openat(AT_FDCWD, "/home/you/.config/kitty/kitty.conf", O_RDONLY) = -1 ENOENT. The quoted path is where it failed.
  • Bad interpreter: A script’s shebang (its first line, naming the program that runs it) points at a program that’s missing, so you see bad interpreter: No such file or directory.
  • Application logs: Apps wrap the same words in their own text, so look at the path they name.

When the error points at the wrong path

Sometimes the file is right there and the error persists, because the program resolved a different path than you typed. Other times the message names a location you never set. Either way, where the lookup failed matters more than what you meant.

The missing piece is often a middle folder, not the file. Let’s check each level from the left: ls ~/.config, then ls ~/.config/hypr. The first failure is the one to fix.

Causes Tied to Paths and Filenames

Most of these errors come from the path itself, so that’s where we’ll look: a missing file, a missing folder, or a name the shell reads differently.

The file is missing or misspelled

The simplest cause: the file was never created, or something deleted it. A typo in the path does the same. On Linux, case sensitivity makes Config and config two different folders. An unmounted drive leaves an empty folder where your files should be.

Hidden characters hide in plain sight: a trailing space is invisible, and a script saved with Windows line endings ends its first line with a \r, so the interpreter path becomes /bin/bash\r, which doesn’t exist.

When the starting directory is wrong

Relative paths depend on where you are, while absolute paths don’t. A relative path like ./config/nvim starts from your current directory, so run pwd before you blame the file. An absolute path starts at / and works anywhere.

Cron (the job scheduler) usually starts in your home directory, and a systemd service ignores your shell’s directory, so set WorkingDirectory= in its unit file.

Bootstrap scripts trip on this too. Say Maya, a Debian user, clones her dotfiles to ~/code/dotfiles and runs bash ~/code/dotfiles/install.sh from home. The script copies ./zsh/zshrc, which resolves against home, so the copy fails.

Adding cd "$(dirname "$0")" at the top lets her install finish from any folder.

A parent folder that doesn’t exist

Writing into a missing folder fails even when the file name is right. Say you redirect output into ~/.config/newtool/aliases before that folder exists. Create it with mkdir -p ~/.config/newtool, where -p also builds any missing parents.

The error names the full path, so read it left to right to find the gap. The file name was fine. The room just wasn’t built.

A symlink (symbolic link) points to another path. If the target is deleted or moved, the link survives but opening it fails. ls -l still shows the arrow, so it looks healthy. Check with readlink -e, which prints nothing for a broken link.

Package upgrades can trigger this by replacing a versioned file a link points at.

Dotfile links are the quietest case. Move ~/dotfiles to ~/code/dotfiles, and every link in ~/.config still aims at the old spot. Find them with find ~/.config -xtype l, then rerun your install script or recreate each with ln -sfn.

A diagram showing config files failing to link to an empty folder, with a warning icon and a terminal command.

Spaces, odd characters, and variables

Unquoted spaces split arguments: cp My Notes.txt ~/backup/ treats My and Notes.txt as two separate files, so quote the name as "My Notes.txt". Names with & or ( need quotes too.

An unset variable fails quietly, since "$CONFIG_DIR/nvim" becomes /nvim when the variable is empty. Give it a fallback with "${CONFIG_DIR:-$HOME/.config}/nvim".

A trailing newline is invisible on screen, so check with printf '%q\n' "$path", which exposes it. Finally, a tilde inside quotes doesn’t expand, so "~/.config" looks for a folder literally named ~. Use "$HOME/.config" instead.

Problems Running Scripts and Binaries

The file is usually there, so the question is less about where it is and more about what it needs.

Windows line endings that break the shebang

Files saved on Windows end lines with CRLF (carriage return plus line feed). A stray return on your shebang (the #! line naming the interpreter) makes the kernel hunt for an interpreter with an invisible character in its name:

bash: ./setup.sh: /bin/bash^M: bad interpreter: No such file or directory

Spot it with cat -A (line ends show ^M$) and fix it with dos2unix.

Shebang line points to a missing interpreter

If the interpreter isn’t installed at all, install it. Otherwise the path has to match: a #!/usr/local/bin/python3 line fails on a system that keeps Python in /usr/bin, so run which python3 and copy its output.

#!/usr/bin/env python3 sidesteps hardcoding altogether.

Arguments break it too. Linux passes everything after the interpreter name as one argument, so #!/usr/bin/env python3 -u makes env hunt for a program named python3 -u. Most Linux env commands accept -S to split them.

NixOS doesn’t ship /bin/bash. Say you’re rebuilding your laptop from your dotfiles: the bootstrap script dies on line one, and changing it to #!/usr/bin/env bash gets it running again.

Binaries that exist but won’t launch

An ELF (Executable and Linkable Format, the standard Linux binary format) names a dynamic loader, the helper that loads shared libraries. If that loader is missing, you get this error even though the binary exists. Its loader is what’s gone.

Most distributions use glibc (the standard C library on most distros) with a loader at /lib64/ld-linux-x86-64.so.2. musl (a smaller C library used by Alpine) has its own loader, so a glibc binary copied there fails this way.

A missing library reports cannot open shared object file instead, and ldd ./tool shows which one. A 32-bit binary on a 64-bit system fails the same way without its 32-bit loader, and file ./tool shows which kind you have.

NixOS prebuilt binaries hit this hardest, since the standard loader path doesn’t exist there. Rewrite the loader path with patchelf --set-interpreter, or enable the nix-ld module.

Commands missing from your PATH

Type a bare name like mytool and the shell searches each folder in your PATH (the list of directories it checks for commands). If none holds it, you’ll usually see command not found, though tools like env print this error instead.

Run type -a mytool to see where it lives. If it reports not found, the tool isn’t installed or its folder was never added.

The dotfiles trap: ~/.local/bin in .zshrc doesn’t reach cron jobs or systemd services. Set PATH in that script or unit, or use the full path.

Missing execute or read permissions

Permission problems usually say Permission denied instead of No such file or directory, so check these after the path checks come up empty.

  • File not executable. Running ./deploy.sh needs the execute bit, so chmod +x deploy.sh fixes it.
  • Parent directory. A folder without execute permission blocks access to everything inside. Find the gap with namei -l /path/to/script.
  • Read permission. Scripts need it too, since the interpreter has to open the file: chmod u+r script.sh.

Causes That Depend on the Environment

A command that works in your terminal can fail inside a container, a service, or a cron job. Each one sees files differently, so let’s check where the gaps hide.

Container and chroot path mismatches

Containers and chroot (a process’s own root folder) give programs a private view of your disk. Ask where a program looks, not just whether the file exists.

  • Host-only path. The file exists on your machine, not in the container.
  • Missing bind mount. The host folder was never mapped in.
  • Layer not in image. The file never made it into an image layer.
  • Dockerfile COPY mismatch. COPY resolves paths from the build context, not your shell’s folder.

Flatpak and Snap apps are sandboxed too. An editor from Flatpak can’t reach ~/.config/nvim unless you grant access.

Why systemd services hit this error

A systemd service skips your shell, so your shell’s habits don’t follow it.

  • Wrong WorkingDirectory. Relative paths resolve from WorkingDirectory=, not your project folder.
  • Unexpanded variable in ExecStart. ~ and shell variables may reach the program as literal text.
  • Use absolute ExecStart paths. Write ExecStart=/home/you/dotfiles/sync.sh instead.

A student’s user timer runs ExecStart=~/dotfiles/sync.sh. It works in their terminal, but the service can’t find a literal ~ folder. Switch to the absolute path and the timer finally syncs.

Cron jobs with a minimal environment

Cron runs jobs with a minimal environment: a short PATH, few variables, and a start directory that’s usually your home folder.

  • Short PATH. Commands your shell finds easily may not be found.
  • Different start directory. Relative paths resolve from wherever cron starts.
  • Use absolute paths. Write /usr/bin/rsync and /home/you/dotfiles/backup.sh.

A self-hoster’s crontab runs ./backup.sh. It works from the dotfiles folder, but cron starts in home, so the job fails overnight. Same script, different starting point.

Diagram contrasting a failed relative path backup with a successful absolute path using the dotfiles directory.

How to Track Down the Cause

The error names a path but rarely says why it’s missing, so work outward from the failing command.

Check the path piece by piece

Every directory along the way has to exist, so check each one. One gap is enough.

  • ls -la the parent directory: Shows whether the file is there, hidden files included.
  • pwd to confirm location: Relative paths often resolve from the wrong folder.
  • realpath and readlink -f: Print the fully resolved path, following every symlink.
  • Check for dangling symlinks: A dangling symlink points at a moved or deleted target, and test -e on it returns false.

Follow the failing system calls with strace

strace logs every system call (a program’s request to the kernel), so you see the exact file that failed.

  • Filter for ENOENT: strace -e trace=file yourcommand 2>&1 | grep ENOENT keeps only failed lookups. ENOENT means “error, no entry.”
  • Follow forks with -f: Catches failures in child processes.
  • ltrace for library calls: Logs calls into shared libraries instead of the kernel.
  • nsenter into containers: Joins a running container’s namespace, its isolated view of files and processes.

Look over the binary and its libraries

Sometimes the file is fine, but something it depends on isn’t.

  • file and readelf -l: file reports the binary’s type. readelf -l prints the headers of the ELF (Executable and Linkable Format) binary, including the loader path in INTERP. A missing loader causes this same error.
  • ldd for missing libraries: Any line marked not found is your culprit.
  • command -v and which: Show which copy your shell runs, which matters more than whether one exists.

Debugging a shell script step by step

A Linux user clones their dotfiles to a fresh Arch install and runs ./bootstrap.sh, which fails with /bin/bash^M: bad interpreter: No such file or directory. Both files exist.

  • set -x tracing: bash -x script.sh prints each command before it runs, so the last one shown marks the failure.
  • cat -A and hexdump: cat -A reveals the ^M, a carriage return from a Windows-style line ending. hexdump -C shows raw bytes.
  • Check for a BOM and hidden characters: A BOM (byte order mark) is an invisible marker some editors add. Before the #! line, it breaks the script.
  • Path verification functions: A helper like need() { [ -e "$1" ] || { echo "missing: $1" >&2; exit 1; }; } fails fast on missing files.

Stripping the carriage returns with sed -i 's/\r$//' bootstrap.sh fixes the example.

Debugging flowchart, in order:

  1. Interpreter named in the error: check the #! line with cat -A.
  2. File it opens: ls -la the parent, then readlink -f the path.
  3. Command it calls: run command -v on it.
  4. Still stuck: run bash -x and find the last line printed.

Recreate the problem inside a container

Containers are minimal, so host tools may be missing from the image.

  • List image contents: docker run --rm your-image ls -l /usr/bin shows what’s really inside.
  • Test with a bind mount: -v "$HOME/dotfiles:/dotfiles" mounts your folder into the container, so you can check the path from its side.

How to Fix the Error

Most fixes come down to one question: does the path your program uses actually exist?

Correcting paths and filenames

Confirm where you are with pwd, then cd to the folder your script expects. Filenames are case-sensitive on Linux, so match capitalization exactly and quote any path with spaces. mkdir -p creates missing folders, parents included.

A symlink (a shortcut) breaks when its target moves. Recreate it with ln -sfn ~/dotfiles/nvim ~/.config/nvim: -f replaces the old link, and -n stops ln from nesting it inside a linked folder.

Repairing line endings and interpreter paths

Scripts copied from Windows often carry hidden carriage returns, which break the shebang (the #! line naming the interpreter). Fix them with dos2unix setup.sh, or sed -i 's/\r$//' setup.sh if dos2unix isn’t installed.

A NixOS user copying a script from Ubuntu hits this error because /bin/bash isn’t there. Switch the shebang to #!/usr/bin/env bash, which finds bash on your PATH, so the script runs. Missing interpreters need installing, like sudo apt install python3.

Compiled binaries fail the same way when their interpreter path (the dynamic loader that starts them) is wrong. Check it with patchelf --print-interpreter ./tool, then set it with patchelf --set-interpreter <path> ./tool.

If ldd ./tool marks a library as not found, install it, then run sudo ldconfig to refresh the linker cache.

A split illustration showing a broken bash script on the left and a fixed version on the right, connected by a green arrow.

Walking through a Docker COPY fix

A Go service runs locally but fails in Docker. Its Dockerfile has COPY main.go /app/, but main.go lives in cmd/server/. COPY sources resolve relative to the build context (the folder you pass to docker build), not the Dockerfile’s folder.

Change the line to COPY cmd/server/main.go /app/, then rebuild from the project root with docker build -t my-go-service .

Check the path first.

Habits That Prevent the Error

Most of these errors are preventable, and we’ll stop them early with a few steady habits.

Write paths that always resolve

A relative path like ./themes depends on where you run the command, and that’s fragile. Use an absolute path (starting from / or ~) for files that must always resolve.

Better yet, compute the script’s own directory with SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)".

Consider a linux user whose installer hunted for ./themes in her home folder. Computing the script directory fixed it.

Tab completion shows whether a path exists before you run anything. Always quote variables, since an unquoted $file with a space splits into two arguments.

Guard your scripts against bad paths

Add an existence guard before first use, such as [ -f "$CONFIG" ] || { echo "missing: $CONFIG" >&2; exit 1; }, and wrap repeated checks in a require_file helper function.

Add set -euo pipefail near the top: -e stops on the first failed command, -u flags unset variables, and pipefail catches failures inside pipelines. Start with #!/usr/bin/env bash, the shebang line, so bash is found on your PATH wherever it lives.

Log the full resolved path on failure so the message shows where it looked. A loud failure beats a silent one.

Keep line endings consistent across machines

Line endings differ: Unix uses a line feed (LF), while Windows uses a carriage return plus line feed (CRLF). A CRLF shebang fails with env: 'bash\r': No such file or directory. Control it three ways:

  • Editor saves LF. Set your editor to save LF endings.
  • git autocrlf setting. On Linux and macOS, set core.autocrlf to input so git converts CRLF to LF on commit.
  • .gitattributes eol rules. An end-of-line (eol) rule like *.sh text eol=lf pins endings per file type.

Catch broken paths in CI and images

Continuous integration (CI) checks are the cheapest place to catch these.

  • Validate symlinks. A broken symlink points at nothing, so fail the build if find . -xtype l prints anything.
  • Run ldd and readelf. ldd flags missing libraries, while readelf -l shows the dynamic linker a binary loads at launch.
  • Smoke-test config paths. Launch each tool once with its config to confirm it starts.

Minimal images need that linker too. One homelab tinkerer’s tiny tmux container lacked it, so every launch failed with ‘No such file or directory’ even though the binary was right there. One readelf check in CI would have flagged the gap first.

Similar Errors and Handy Cheat Sheets

Many errors look like this one but mean something else.

Telling similar errors apart

  • Permission denied: The file exists, but you can’t read or run it. It’s about access, not location.
  • command not found: The shell can’t find the program on your PATH.
  • bad interpreter: A script’s shebang (its first line) names a missing program, often because of Windows-style line endings.
  • Is a directory: You passed a folder where a file belongs.
  • library not found: A shared library is missing, so the program won’t launch. Same wording, different file.

Quick references and common questions

Message Cause Fix
No such file or directory Typo or missing file Check the path
Permission denied Missing read or execute bit Fix permissions or ownership
command not found Not on PATH or misspelled Add its folder to PATH
bad interpreter Shebang path missing Fix the shebang or line endings
Is a directory Folder, not a file Point at a file inside
library not found Missing shared library Install the package providing it

Keep these handy:

  • ls -l: does the file exist, and who can touch it?
  • command -v: can your shell find this program?
  • head -1: which interpreter does it ask for?
  • ldd: which shared libraries are missing?

Why does ls show the file, yet the command says it’s missing? Usually it’s a broken symlink, a shortcut whose target was moved or deleted. It’s a classic after moving a dotfiles repo. Run ls -l and look for an arrow pointing at a missing target.

Why does a command work in your terminal but fail in cron? Cron runs with a much shorter PATH and none of your shell profile. Picture a self-hoster whose backup script runs fine by hand but silently fails overnight.

Switching to absolute paths like /usr/bin/rsync means it finally runs every night.

Most of the time, this error is just a path that’s a little off: a typo, a missing folder, a symlink pointing nowhere, or a script hunting for a file in the wrong spot.

Once you know to check the path the system actually sees, the fix usually takes minutes.

Keep the prevention habits in mind and this error will show up far less often. When it does, read the path the way the system reads it, and the mystery usually ends right there.

Questions

How to fix no such file or directory error?

Check the exact path the program is trying to open, then verify each folder and filename with `ls -la` and confirm your current directory with `pwd`. Correct typos and capitalization, create missing parent folders with `mkdir -p`, or repair broken symlinks. If the path exists, check for a missing script interpreter, Windows line endings, a missing binary loader, or a different environment such as cron or a container.

Why do I get no such file or directory?

You get this error when the system cannot find a path component the program requested. Common causes include a misspelled or missing file, a missing parent directory, a broken symlink, an unexpected working directory, or a script or binary that refers to a missing interpreter or loader. Containers, cron jobs, and services can also look in different locations or use a different environment than your terminal.

What does "no such file or directory" mean?

“No such file or directory” is the system’s readable form of ENOENT, an error indicating that a requested path or one of its components could not be found. It can refer to a missing file or folder, but it may also appear when a script’s interpreter or a binary’s dynamic loader is missing.