
Fix "No such file or directory" Error on Linux — Troubleshooting Guide
Practical fixes for the "No such file or directory" error on Linux. Covers typos, spaces, case sensitivity, absolute vs relative paths, permissions, and executable scripts.
What Does "No such file or directory" Mean?
The "No such file or directory" error indicates the system cannot find the file or folder at the path you provided. This is usually due to:
- A typo in the filename or path
- Incorrect directory navigation
- Incorrect file permissions
- Using absolute paths (
/) when you meant relative paths - Files on different filesystems or moved locations
Immediate Fixes to Try
1. Verify Your Current Location
pwd
This prints your current working directory. Confirm you're in the right folder before trying to access a file.
2. List Files in the Current Folder
ls
This shows all files and folders in your current location so you can spot typos in filenames.
Handle Spaces in Filenames
If the file name has spaces, you must wrap it in quotes or escape the spaces:
Option 1 — Wrap in quotes:
cat "my file.txt"
Option 2 — Use backslashes:
cat my file.txt
Without quotes or escapes, my file.txt is interpreted as two separate arguments, and the system looks for a file named my.
Check Case Sensitivity
Linux and macOS are case-sensitive. Ensure capitalization matches exactly:
Documents≠documentsMyFile.txt≠myfile.txt
If you're unsure, use:
ls -i
This lists files with their inode numbers, helping you identify exact filenames.
Use Absolute Paths When Unsure
If you're not sure of your relative location, use the full path starting from root:
cat /home/user/Documents/file.txt
Tip: If running a program and it can't find files, try changing into its directory first:
cd /path/to/program
./program
Running it from within the folder eliminates path confusion.
Check File Permissions
Ensure you have permission to access the file:
ls -l filename
This shows permissions. If you see -rw-r--r--, you can read it. If you can't, you may need to adjust permissions.
Scripts Not Executable
If running a script and get "No such file or directory":
chmod +x script.sh
./script.sh
The chmod +x command makes the script executable.
Windows to Linux Issues
If a file was created on Windows and moved to Linux, it might contain hidden carriage return characters that break execution. Fix it with:
dos2unix filename.sh
Then try running it again:
./filename.sh
Quick Troubleshooting Checklist
| Issue | Fix |
|---|---|
| Typo in filename | Run ls to verify exact spelling |
| File has spaces | Wrap in quotes: "file name.txt" |
| Wrong case | Check exact capitalization with ls |
| Script not executable | chmod +x script.sh |
| Windows carriage returns | dos2unix filename.sh |
| Lost in directories | Run pwd to see current location |
| Can't read file | Run ls -l to check permissions |
Example Workflow
You see the error:
bash: ./myscript.sh: No such file or directory
Step 1 — Check where you are:
pwd
Step 2 — List files to verify script exists:
ls
Step 3 — Make it executable:
chmod +x myscript.sh
Step 4 — Run it:
./myscript.sh
Most "No such file or directory" errors are resolved by one of these simple steps.
Derrk Samuel
Web3, crypto, and Linux PC insights — practical guides, security tips, mining setups, blockchain tools, and decentralized tech strategies for techs.
Related Articles

Symbolic Links vs Hard Links in Linux — Inodes, /etc/fstab, and the Windows mklink Difference

Docker Ate 40GB of My Disk — Here's How to Take It Back in 5 Minutes
How to View Docker Container Logs on Linux — Complete Guide
Discussion
Leave a comment
No comments yet. Be the first to start the discussion!