cd: No Such File or Directory? Fix It in 5 Steps
The “cd: no such file or directory” error in Linux means the shell cannot find the path you typed. This usually happens because of a typo, a missing space, or because the directory doesn’t exist in your current location. The fix is to check your current directory, verify the exact name, and use the correct absolute or relative path.
What the Error Actually Means
When you run cd (change directory), the shell looks for the exact path you gave it. If it can’t find it, it prints bash: cd: /some/path: No such file or directory (or similar, depending on your shell). This is not a permission problem or a broken system—it simply means the path you typed doesn’t match any existing directory.
The most common cause is a simple typo: a wrong letter, a missing slash, or an extra space. Linux paths are case-sensitive, so Documents and documents are different. Another frequent issue is trying to cd into a file instead of a directory—cd only works on directories, not regular files.
Check Your Current Directory First
Before you can fix the error, you need to know where you are. Run pwd (print working directory) to see your current location. Then think about whether the path you typed is relative (starting from where you are) or absolute (starting from the root /).
- Relative path:
cd Documentslooks forDocumentsinside your current directory. - Absolute path:
cd /home/username/Documentsstarts from the root and works no matter where you are.
A common mistake is assuming you’re in your home directory when you’re actually somewhere else. If you just opened a terminal, you’re usually in /home/username, but if you’ve been navigating, you might be in /var/log or another folder. Use pwd to confirm.
How to Find the Correct Path
Instead of guessing, use commands to see what’s actually there. The ls command lists files and directories in the current folder. Run ls -la to see hidden files (those starting with a dot) and permissions. If you don’t see the directory you expected, it’s not there—or it has a different name.
To search more broadly, use find or locate:
find / -type d -name "documents" 2>/dev/null
This searches the whole system for a directory named documents (case-sensitive). The 2>/dev/null suppresses permission errors. If you know the directory is under your home, use find ~ -type d -name "documents".
Common Causes and Fixes
1. Typo or Wrong Case
Linux is case-sensitive. cd Desktop is different from cd desktop. Use ls to see the exact capitalization. Also check for spaces—if a directory is named My Documents, you must quote it: cd "My Documents" or escape the space: cd My\ Documents.
2. Trailing Slash on a File
If you type cd file.txt/, the trailing slash tells the shell to treat it as a directory. If file.txt is a regular file, you’ll get the error. Remove the slash.
3. Directory Doesn’t Exist
Maybe you never created it, or it was deleted. Use ls to confirm. If it’s missing, you can create it with mkdir directoryname.
4. Symbolic Links Broken
If the path contains a symlink that points to a non-existent location, cd will fail. Check with ls -l to see if any component is a link. Use readlink -f path to resolve the real path.
5. Permissions
If you don’t have execute permission on a directory in the path, you’ll get a “Permission denied” error, not “No such file or directory.” But if the directory itself is missing, it’s not a permission issue.
Using Tab Completion to Avoid Errors
The easiest way to avoid this error is to use the Tab key. Type cd Doc and press Tab—the shell will autocomplete to the correct name, including proper capitalization. If there are multiple matches, press Tab twice to see all options. This eliminates typos and case mistakes.
Tab completion also handles spaces automatically. If you type cd My and press Tab, it will become cd My\ Documents with the space escaped correctly.
What to Do When the Fix Doesn’t Work
If you’ve checked the path and it still fails, try these steps:
- Run
pwdto confirm your current directory. - Run
ls -lato see all files, including hidden ones. - Use
find ~ -type d -name "*partialname*"to search for a directory with a similar name. - Check if you’re in a chroot or container that has a different filesystem.
- If you’re using a network mount, the directory might not be mounted—check with
mount.
If you’re trying to cd into a directory that exists but you still get the error, it might be a Unicode issue—the directory name contains a non-ASCII character that looks like a regular letter. Use ls | cat -A to see hidden characters, or use the find command with the exact name from ls output.
Frequently Asked Questions
Why does cd fail when I copy-paste a path from a file manager?
File managers often show paths with a tilde (~) or with spaces that get copied with invisible characters. When you paste into the terminal, the shell might interpret the tilde literally if it’s not at the start, or the spaces might not be escaped. Try typing the path manually or use cd with quotes around the entire path.
Is “No such file or directory” the same as “Permission denied”?
No. “Permission denied” means the directory exists but you don’t have the right to access it. “No such file or directory” means the path doesn’t exist at all. If you see “Permission denied” when using cd, check the directory’s permissions with ls -ld and consider using sudo if appropriate.
Can I cd into a directory with a hyphen at the beginning?
Yes, but you need to use cd -- -directory or cd ./-directory. A leading hyphen is interpreted as an option by many commands. The -- tells the shell to stop parsing options.
Why does cd work in one terminal but not another?
Each terminal session has its own current working directory. If you opened a new terminal, it starts in your home directory by default. If you’re in a different location, the relative path might not exist. Use absolute paths or check pwd in each session.
Does the error appear if the directory is on a mounted drive that’s not mounted?
Yes. If you have a USB drive or network share that isn’t mounted, the mount point directory exists but is empty, so cd into a subdirectory will fail. Mount the drive first with mount or use your file manager to mount it.
What if I get “cd: not a directory” instead?
This error means the path exists but is a regular file, not a directory. You can’t cd into a file. Use ls -l to confirm, and if you need to work with that file, use cat, less, or an editor instead.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.