cd
cd
: change directory.
The cd
command is used to change the current working directory in the command line environment. This command allows you to navigate the file system of your computer. Changing the current working directory is a fundamental operation when managing files or running programs from the terminal.
Note that if the path contains spaces, you need to enclose it in quotes so that the cd
command treats it as a single argument.
For example, if the path is /home/alex/my documents
, you would run the command cd "/home/alex/my documents"
. You can use both single '
and double quotes "
, but always use the same pair of quotes.
Also, note that on every operating system (except Windows), paths and commands are case-sensitive. For example, /home/Alex
and /home/alex
are two different paths.
Examples
Linux/macOS
Change to a specific directory:
cd /path/to/directory
Go up one directory level:
cd ..
Go up two directory levels:
cd ../..
Go back to the previously visited directory:
cd -
Change to the home directory:
cd ~
Windows (PowerShell)
PowerShell supports cd
as an alias for its Set-Location
cmdlet. The behavior and options are similar to Unix systems.
For a long time, Windows used backslashes (\
) as directory separators, while Unix systems used forward slashes (/
). However, modern versions of Windows support both types of separators. In my opinion, it's better to use forward slashes in PowerShell, as they're more compatible with Unix systems.
Change to a specific directory:
cd C:/path/to/directory
Go up one directory level:
cd ..
Go up two directory levels:
cd ../..
Go back to the previously visited directory:
cd -
Change to the home directory:
cd ~