Examples
cd - is the most common trick: hopping between two directories (it prints
where it went).
Moving around the filesystem: cd, cd -, cd ~, cd .., pushd/popd, CDPATH.
cd dir
go into a directory
cd ..
one level up
cd ~
home
cd -
back to the previous directory
pushd dir
go there, remembering the old directory on a stack
popd
go back to the previous one from the stack
dirs -v
show the directory stack
cd "path with space"
a path with a space — always quote it
cd (change directory) is a shell builtin: it changes the current working
directory. It is not a separate program but a builtin of bash itself (which
is why there's no man cd — use help cd).
pwd shows where you are now; cd with no arguments takes you home.
Paths: . is the current directory, .. is the parent, ~ is home
(/home/user), / is root, - is the previous directory.
cd has few flags — it's a builtin, not a separate program with a large --help.
| Option | What it does | Example |
|---|---|---|
- |
Go to the previous working directory ($OLDPWD) and print it. | cd - |
-L |
Follow symlinks logically (honor `..` along the symlink's path). The default behavior. | cd -L /var/www/current |
-P |
Resolve symlinks physically — go to the real directory; `pwd` shows the actual path. | cd -P /var/www/current |
-e |
With -P, exit with an error if the resulting directory could not be determined. | cd -Pe /var/www/current |
Nothing found. Try a shorter query.
cd - is the most common trick: hopping between two directories (it prints
where it went).
In bash you can turn on shopt -s autocd — then typing a bare path without
cd goes there directly. And cd supports Tab completion for names.
cd: too many argumentscd takes one path. If the directory name has a space, quote it:
cd "My Folder", or escape it: cd My\ Folder.
cd: not a directoryThe target path is a file, not a directory. Check with ls -ld path.
cd: permission deniedNo x (enter) permission on the directory. You need the execute bit — see
chmod-chown.
Every process/script has its own working directory. cd inside a bash script
does not change the parent shell's directory — that is expected.
Found an inaccuracy? Report an error in the article