Skip to Content

4 ways to fix cd: no such file or directory

“cd: no such file or directory” is an error message that is displayed when the command line interpreter (CLI) is unable to find the directory that the user is trying to navigate to using the “cd” command.

This error can occur if the directory name is spelled incorrectly, if the directory does not exist, or if the user is in the wrong location within the file system.

In this article, we will dive into this error and explore how to fix it.

Check the spelling of the directory name

One way to fix the “cd: no such file or directory” error is to check the spelling of the directory name and try again.

Make sure that the directory name is typed correctly, including proper capitalization and any special characters.

If the directory does not exist, you may need to create it or navigate to a different location.

Check File Path in Linux

There are two main categories of file system paths: absolute paths and relative paths.

An absolute path is a full path to a file or directory from the root directory of a file system. It starts with the top-most directory and includes every subdirectory and file needed to reach the destination.

Absolute paths include the full URL or drive letter, for example, C:\Users\John\Documents\file.txt.

A relative path, on the other hand, is a path that is relative to the current directory. It does not include the full URL or drive letter, but instead, it only includes the necessary subdirectories and files needed to reach the destination.

For example, if the current directory is C:\Users\John\Documents and the file we want to access is called file.txt, the relative path would simply be “file.txt” because it’s in the same directory.

It is important to note that relative path is relative to the current working directory, the path you are currently on, and can change depending on the location you are working on. While absolute path is fixed and doesn’t change.

Verify directory exists with ls command

Another way to fix the “cd: no such file or directory” error is to verify that the directory exists by using the ls command.

You can list the contents of the current directory by typing “ls” and pressing enter.

If the directory you are trying to navigate to is in the current directory, it will be listed.

You can also use the “ls” command followed by the path to the directory you want to check. For example, if you want to check if the directory called “example” exists in the “Documents” folder, you would type “ls ~/Documents/example” and press enter.

If the directory does not exist, you will get an error message similar to “ls: cannot access ‘/path/to/directory’: No such file or directory”. This means that the directory you’re trying to navigate to doesn’t exist and you may need to create it or navigate to a different location.

Verify file path with pwd command

Another way to fix the “cd: no such file or directory” error is to use the “pwd” command to check your current working directory and make sure you are in the correct location.

The “pwd” command stands for “print working directory” and it will display the path of the current directory you are in.

If you’re not in the correct location, you can use the “cd” command to navigate to the desired directory. Make sure to give the correct path to the directory if the directory you want to navigate to is not in the current working directory.

For example, if you want to navigate to the “example” directory which is located in the “Documents” folder, you would type “cd ~/Documents/example” and press enter.

Keep in mind that, depending on the operating system, the path to the directory may be different.