Site Logo
Back to Articles

How to Fix 'No Such File or Directory' in Linux

ZS
ZekByte Systems

Watch the full tutorial on YouTube

If you’ve ever run a Linux command and received:

No such file or directory

you’re not alone.

This is one of the most common Linux errors and usually means Linux cannot find the file, directory or path you specified.

This is what the error typically looks like:

Linux No Such File or Directory error in terminal

The video below demonstrates the fix in under 30 seconds, but this article explains why the error occurs and how to troubleshoot it properly. Whether you’re using Ubuntu, Debian, CentOS, Rocky Linux, Fedora or another Linux distribution, the troubleshooting steps are essentially the same. This error commonly appears when using commands such as cat, cp, mv, rm and shell scripts.

What Causes “No Such File or Directory”?

The error typically occurs when:

  • The file does not exist.
  • The filename is misspelled.
  • The path is incorrect.
  • You are in the wrong directory.
  • The file was moved or deleted.

Check Your Current Directory

The best thing to do is to start by checking where you are using the following command:

pwd

The output may look similar to:

/home/user/documents

That’s how you find your current working directory.

List Available Files

Next, verify the file exists:


ls -la

This command displays all files in the current directory. If the file is not listed, it’s usually because:

  • you’re in the wrong directory
  • the filename is incorrect
  • the file no longer exists

Verify the File Path

If the file is stored elsewhere, specify the full path:


cat /home/user/documents/report.txt

Using absolute paths often eliminates confusion.

Common Mistakes

Typographical Errors

Linux filenames are case-sensitive. These are different files:

report.txt
Report.txt
REPORT.txt

Wrong Directory

Check where you are:

pwd

Navigate if necessary:

cd /path/to/directory

File Deleted

Search for the file:

find /home -name "report.txt" 2>/dev/null

Example Fix

Before:

cat reports.txt

Result:

cat: reports.txt: No such file or directory

After correcting the filename:

cat report.txt

The file opens successfully.

Conclusion

The “No Such File or Directory” error almost always comes down to an incorrect path, filename or missing file.

Use the following commands to quickly identify the issue and verify that the file actually exists:

pwd
ls -la
find

Once you understand how Linux paths work, this becomes one of the easiest errors to fix.

More troubleshooting articles will be added here as the Linux knowledge base grows.

Enjoyed this article?

Subscribe to my YouTube channel for more content like this

Subscribe on YouTube

Share this article