Linux ENOENTMedium

The 'File Not Found' Error in Linux: Causes and Solutions

This article explains why the 'File not found' error occurs in Linux and offers practical solutions, from simple path checks to data recovery.

Updated at February 16, 2026
5-15 minutes
Easy
FixPedia Team
Применимо к:Ubuntu 20.04 and aboveCentOS 7 and aboveDebian 10 and aboveAll Linux distributions

What the 'File Not Found' Error Means

In Linux, the "File not found" error (English: "No such file or directory") is a system message that appears when the operating system cannot locate the specified file or directory at the given path. The error is typically accompanied by text such as bash: /home/user/file.txt: No such file or directory or ls: cannot access 'file': No such file or directory. It occurs when executing various commands like cat, ls, rm, or when running scripts and programs.

This error corresponds to the system error code ENOENT (Error NO ENTry). It does not necessarily mean the file has been deleted—it may simply be in a different location, or the path may be incorrect. Often, the issue stems from human error, but it can sometimes be caused by filesystem failures or data corruption.

Common Causes

Specific reasons why this error occurs:

  1. Incorrect file path: A typo in the file or directory name, using a relative path instead of an absolute one, or missing a leading slash (e.g., file.txt instead of /home/user/file.txt).
  2. File was moved or deleted: The file existed previously but was deleted or moved to another location, while a command or script still references the old location.
  3. File is in a different directory: You are looking for the file in the wrong directory. For example, you expect the file in /var/log, but it is actually in /home/user.
  4. Issues with symbolic links: A symbolic link (symlink) points to a file that no longer exists. When attempting to access the link, the system tries to find the target file and fails.
  5. Filesystem not mounted: The file is on a separate partition or external storage (e.g., a USB drive) that has not been mounted into the system, making the path inaccessible.
  6. Case sensitivity: In Linux, filenames are case-sensitive. A file named Document.txt will not be found if you request document.txt.
  7. Special characters in filename: The filename contains spaces, quotes, or other special characters that must be escaped or enclosed in quotes. For example, file name.txt should be specified as file\ name.txt or "file name.txt".
  8. Script or program error: A script or application may have a programming error that constructs an invalid path, for example, due to incorrect string concatenation.

Solutions

Solution 1: Verify and Correct the File Path

The simplest step is to double-check that the file path is specified correctly.

  1. Ensure you are using an absolute path (starting with /), especially in scripts and configuration files. For example, use /home/user/file.txt instead of file.txt.
  2. Check the spelling of the filename and directories for typos. Remember that Linux is case-sensitive: File.txt and file.txt are different files.
  3. If the path contains spaces or special characters (e.g., $, *, ?), enclose the entire path in quotes or escape the characters with a backslash. For example: "/home/user/my file.txt" or /home/user/my\ file.txt.
  4. Use tab autocompletion: start typing the path in the terminal and press Tab to let the system suggest possible variants and verify existence.
  5. If the path contains environment variables (e.g., $HOME), ensure they are correctly defined. Check their values with commands like echo $HOME or env.

After correcting the path, repeat the command. If the error disappears, the issue was with the path.

Solution 2: Search for the File in the System

If you are unsure where the file is located, use search commands to determine its location.

  1. To search for a file by name across the entire filesystem (may require superuser privileges for some directories):
    sudo find / -name "filename" 2>/dev/null
    

    The 2>/dev/null option suppresses access error messages, leaving only found files.
  2. To search in the current directory and all subdirectories:
    find . -name "filename"
    
  3. If you have the locate utility installed, which uses a pre-built database, the search will be much faster:
    locate filename
    

    Note: The locate database may be outdated. Update it with sudo updatedb (requires sudo and may take time).
  4. If you are searching for a file by a partial name, use wildcards. For example, to find all .txt files:
    find / -name "*.txt" 2>/dev/null
    

After locating the file, use the full path provided by the command or copy the file to the expected location.

If the error occurs when using a symbolic link (symlink), check whether the target file the link points to exists.

  1. View what the symbolic link points to:
    ls -l /path/to/link
    

    The output will look like: link -> /target/path/file.
  2. Check if the target file exists at the specified path:
    ls -l /target/path/file
    

    If the command outputs "No such file or directory", the target file is missing.
  3. If the target file was moved or deleted, point the link to a new path:
    ln -sf /new/path/file /path/to/link
    

    The -f option forces replacement of an existing link.
  4. If the link is no longer needed, remove it:
    rm /path/to/link
    

    (Ensure you are removing the link itself, not the target file).

Solution 4: Recover a Deleted File

If a file was accidentally deleted and you have no backup, you can attempt to recover it using specialized utilities. Success depends on how long ago the file was deleted and how actively the disk is used.

  1. Immediately stop using the filesystem where the file was located to minimize the risk of data overwrite. If it is a system disk, consider booting from a LiveCD.
  2. Identify the partition (device) on which the file was located. For example, /home might be on /dev/sda3. Use the df -h command to view mount points.
  3. Use recovery utilities. For ext3/ext4 filesystems:
    • extundelete:
      sudo extundelete /dev/sdX --restore-file /path/to/file
      
      Replace /dev/sdX with your partition (e.g., /dev/sda3). Recovered files will be placed in the current directory under a folder named RECOVERED_FILES.
    • testdisk (interactive) or photorec (works with any filesystem but does not preserve filenames or structure).
  4. For XFS filesystems, use xfs_undelete (if available) or testdisk.
  5. After recovery, check the file's integrity. Recovery is not guaranteed, especially if the file was deleted long ago or the disk is actively used.

Solution 5: Check Filesystem Mounting

If the file should be on a separate partition, external drive (USB, SSD), or network filesystem (NFS, Samba), ensure it is properly mounted.

  1. Check if the filesystem containing the file is mounted:
    mount | grep /path/to/file
    

    Or use:
    df -h /path/to/file
    

    If the command outputs nothing or shows an error, the filesystem is not mounted.
  2. Identify the device corresponding to the filesystem. For a USB drive:
    lsblk
    

    Find the device (e.g., /dev/sdb1) and its mount point.
  3. Mount the filesystem. For a regular disk:
    sudo mount /dev/sdb1 /mnt/usb
    

    For network resources (NFS):
    sudo mount -t nfs server:/share /mnt/nfs
    

    Ensure you have permissions to mount and access the device.
  4. After mounting, repeat the command that caused the error. If the file is now accessible, the issue is resolved.
  5. For automatic mounting at boot, add an entry to /etc/fstab. For example:
    /dev/sdb1  /mnt/usb  ext4  defaults  0  2
    

    Be cautious: an incorrect entry can prevent the system from booting.

Prevention

To avoid the "File not found" error in the future, follow these practices:

  • Always use absolute paths in scripts, configuration files, and cron jobs. This eliminates confusion with the current working directory. For example, write /home/user/script.sh instead of ./script.sh.
  • Check for file existence before performing operations that require them. In bash scripts, use conditional constructs:
    if [ -f "/path/to/file" ]; then
        # file exists, perform actions
    else
        echo "Error: file not found" >&2
        exit 1
    fi
    
    Use -d for directories, -L for links.
  • Maintain backups of important files and directories. Use tools like rsync, tar, or cloud services (e.g., Dropbox, Google Drive). Set up regular automated backups with cron.
  • Use version control (e.g., Git) for configuration files, scripts, and source code. This allows tracking changes and restoring previous file versions.
  • Be careful with symbolic links: when moving or deleting a target file, update or remove corresponding links. Regularly check their integrity with find / -xtype l 2>/dev/null (finds broken links).
  • Regularly update the locate database with sudo updatedb for fast filename searches.
  • When working with external media, always safely eject devices (via umount or a graphical interface) before unplugging to avoid filesystem corruption.
  • Write scripts with error handling: use set -e to exit on error or explicitly check command return codes.

Following these guidelines will significantly reduce the likelihood of encountering the "File not found" error and simplify troubleshooting if it does occur.

F.A.Q.

What does the 'No such file or directory' error mean in Linux?
How to check if a file exists before running a command?
Can this error occur due to permissions?
How to find a file that has been moved or deleted?

Hints

Check the file path correctness
Use the `ls` command to check file existence
Search for the file in other directories
Restore the file from a backup
Check symbolic links
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community