Cd Command in Linux (Change Directory)

The cd (“change directory”) command is used to change the current working directory in Linux and other Unix-like operating systems. It is one of the most basic and frequently used commands when working on the Linux terminal.
The current working directory is the directory (folder) in which the user is currently working. Each time you interact with your command prompt, you are working within a directory.
This article will show you how to use the cd command to navigate your system’s directory tree.
cd Command
cd is a shell built-in, and its behavior may slightly differ from shell to shell. It uses the shell environment variables
to determine necessary information for its execution.
We will cover the Bash-builtin version of cd.
The syntax for the cd command is as follows:
cd [OPTIONS] directoryThe command accepts two options that are rarely used.
-L, Follow symbolic links . By default,cdbehaves as if the-Loption is specified.-P, Don’t follow symbolic links. When this option is specified,cdresolves the symlink and sets your working directory to the physical (real) path rather than the symbolic path.
In its simplest form, when used without any argument, cd will take you to your home directory.
When navigating through the file system, you can use the Tab key to autocomplete the names of directories. Adding a slash at the end of the directory name is optional.
To switch to a directory, you must have executable permissions for that directory.
The pwd
command allows you to find out what directory you are currently in.
Absolute and Relative Path Names
When specifying a directory to change to, you can use either absolute or relative path names. The absolute or full path starts from the system root /, and the relative path starts from your current directory.
By default, when you log into your Linux system, your current working directory is set to your home directory. Assuming that the Downloads directory exists in your home directory, you can navigate to it by using the relative path to the directory:
cd DownloadsYou can also navigate to the same directory by using its absolute path:
cd /home/username/DownloadsIn short, if the path starts with a slash (/), it is the absolute path to the directory.
The Parent Directory
On Unix-like operating systems, the current working directory is represented by a single dot (.). Two dots (..), one after the other, represent the parent directory or the directory immediately above the current one.
If you type cd ., you will change into the current directory or, in other words, the command will do nothing.
Suppose you are currently in the /usr/local/share directory. To switch to the /usr/local directory (one level up from the current directory), you would type:
cd ../To move two levels up to the /usr directory (the parent’s parent), you could run the following:
cd ../../Here is another example. Let’s say you are in the /usr/local/share directory, and you want to switch to /usr/local/src. You can do that by typing:
cd ../srcNavigate to the Previous Directory
To change back to the previous working directory, pass the dash (-) character as an argument to the cd command:
cd -Navigate to the Home Directory
To navigate to your home directory, simply type cd. Another way to return directly to your home directory is to use the tilde (~) character, as shown below:
cd ~For example, if you want to navigate to the Downloads directory, which is inside your home directory, you would type:
cd ~/DownloadsYou can also navigate to another user’s home directory using the following syntax:
cd ~usernameDirectories with Space in Their Names
If the directory you want to change to has spaces in its name, you should either surround the path with quotes or use the backslash (\) character to escape the space:
cd 'Dir name with space'cd Dir\ name\ with\ spaceUsing CDPATH
CDPATH lets you define a set of base directories that cd will search when you use a relative path. For example:
export CDPATH=.:~/projects:/optWith this set, cd myapp will try ./myapp, ~/projects/myapp, and /opt/myapp in that order.
Quick Reference
| Task | Command |
|---|---|
| Go to home directory | cd or cd ~ |
| Go to previous directory | cd - |
| Go to parent directory | cd .. |
| Go up two levels | cd ../../ |
| Use an absolute path | cd /path/to/dir |
| Use a relative path | cd path/to/dir |
FAQ
Why does cd say “Permission denied”?
You need execute (x) permission on the target directory to enter it.
What does cd - do?
It switches to the previous working directory and prints its path.
What is the difference between cd .. and cd ../?
They are equivalent; both move you to the parent directory.
Conclusion
By now, you should have a good understanding of what the current working directory is and how to use the cd command to navigate through your system’s directory structure.
If you have any questions or feedback, feel free to leave a comment.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page