No such file or directory
This error occurs when a command or application attempts to access a file or folder path that does not exist.
Usually happens because:
- ☑ Target file path spelling typo or case mismatch
- ☑ Terminal pwd does not contain the relative path
- ☑ Shell script has Windows carriage return CRLF line endings
🔍 Quick Checklist:
What is No such file or directory?
The 'No such file or directory' error is a standard POSIX system error associated with the error code ENOENT (Error No Entity). It indicates that the operating system kernel failed to locate a file or directory at the specified path. This commonly happens due to typos in command paths, executing commands in the wrong directory, shell scripts using Windows carriage return endings, or missing mount points.
Common Causes
- Spelling typo in target path: A simple spelling or capitalization typo in the file or directory name.
- Wrong working directory context: The active terminal session is in a different directory than the file's relative path destination.
- Windows CRLF script shebangs: Shell scripts edited on Windows containing carriage returns (\r) causing the interpreter to search for a binary like '/bin/sh\r' which does not exist.
| Cause | Frequency |
|---|---|
| Spelling typo in file or directory path | ⭐⭐⭐⭐⭐ |
| Incorrect terminal working directory (pwd) | ⭐⭐⭐⭐ |
| Windows CRLF shebang line corruption | ⭐⭐⭐ |
Common Mistakes
- Assuming directory casing does not matter (Linux file systems like ext4 are strictly case-sensitive, meaning `Config.json` and `config.json` are different files).
- Running commands that expect a file path to exist in `~/.bashrc` or initialization scripts without verifying their presence.
How to Fix
Linux Operations & Verification
Locate files in directory listings or absolute search queries before accessing them.
# 1. Check current folder files
$ ls -la
# 2. Search for config files system-wide
$ find / -name "config.json" 2>/dev/null
/etc/app/config.json
# 3. Read using absolute path
$ cat /etc/app/config.jsonPlatform Specific Fixes
Verify current folder path location and check files present.
pwd
ls -lhBest Practices
- Always use absolute paths inside automated scripts or cron jobs to eliminate relative directory dependency bugs.
- Utilize shell path autocompletes (Tab completion) to confirm folder routes interactively.
Frequently Asked Questions (FAQ)
Q: What is ENOENT?
ENOENT stands for 'Error No Entry' (specifically, 'No such file or directory'). It is the low-level operating system code for file missing exceptions.
Q: Why does my script say 'no such file' when the file is clearly there?
This usually happens if the script has Windows-style CRLF line endings. The shell reads the shebang line as '#!/bin/bash\r' and fails because the command '/bin/bash\r' (with a carriage return) does not exist.
Q: How do I find a missing file on my system?
Use the find utility: 'find / -name "filename.txt" 2>/dev/null' to search the entire system.
Q: How do I change carriage returns to Unix format?
Install and run 'dos2unix filename.sh' to automatically strip Windows line endings.