cd – change directory

cd changes your current working directory. It’s one of the most fundamental commands for navigating the filesystem.
Synopsis
cd [DIRECTORY]
Common Usage
| Command | Effect |
|---|---|
cd /path/to/dir | Go to absolute path |
cd dirname | Go to relative path |
cd or cd ~ | Go to home directory |
cd .. | Go up one level (parent directory) |
cd - | Go to previous directory |
cd ~/Documents | Go to Documents in home |
Examples
Navigate to absolute path
$ pwd
/home/greys
$ cd /etc
$ pwd
/etc
Navigate to relative path
$ pwd
/home/greys
$ cd projects/ansible
$ pwd
/home/greys/projects/ansible
Go to home directory
$ cd
$ pwd
/home/greys
# Or explicitly
$ cd ~
$ pwd
/home/greys
Go up one level
$ pwd
/home/greys/projects
$ cd ..
$ pwd
/home/greys
Go up multiple levels
$ pwd
/home/greys/projects/ansible/roles
$ cd ../../..
$ pwd
/home/greys
Return to previous directory
$ pwd
/home/greys
$ cd /var/log
$ pwd
/var/log
$ cd -
/home/greys
$ pwd
/home/greys
Use tilde for other users’ homes
$ cd ~admin
$ pwd
/home/admin
Special Directory Entries
Every directory contains two special entries:
| Entry | Meaning |
|---|---|
. | Current directory |
.. | Parent directory |
$ ls -la
drwxr-xr-x 5 greys staff 4096 Jan 15 10:00 .
drwxr-xr-x 3 greys staff 4096 Jan 15 09:00 ..
Permission Denied
If you can’t access a directory, you’ll see an error:
$ cd /root
bash: cd: /root: Permission denied
To enter a directory, you need execute permission (x) on it:
$ ls -ld /root
drwx------ 4 root root 4096 Jan 15 10:00 /root
Tips
- Tab completion: Type
cd pro<TAB>to autocomplete directory names - Case sensitive:
cd Documents≠cd documentson Linux - Spaces in names: Use quotes
cd "My Documents"or escapecd My\ Documents - Use pushd/popd: For navigating between multiple directories
- CDPATH variable: Set common parent directories for quick access
Set up CDPATH
# Add to ~/.bashrc
export CDPATH=.:~:~/projects
# Now you can cd to any project from anywhere
$ cd ansible # Goes to ~/projects/ansible
See Also
Related Commands
- pwd — Print current working directory
- ls — List directory contents
- pushd/popd — Directory stack navigation






