Navigation and files

Command cd

Go to another directory

Linux · Bash examples · commands run on the selected server

When to use cd

Use cd to change the working directory of the current shell before inspecting logs or editing a project. Relative paths start from your current location; absolute paths start at the filesystem root.

Syntax

cd [DIRECTORY]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

PATH
Absolute or relative path to the directory.
..
Go to parent directory.
-
Return to the previous working directory.

Usage examples

Go to logs

cd /var/log

The next relative command runs inside the log directory; cd itself normally prints nothing.

Go to home directory

cd ~

The tilde selects your home directory, independently of where the shell started.

Return to previous directory

cd -

The shell returns to its previous directory and normally prints that directory.

Notes and limitations

  • This shell builtin changes the working directory of the current session.
  • Quote paths containing spaces. Directory traversal requires execute (x) permission.

Common questions and troubleshooting

Why does cd report Permission denied?

You need search permission on each directory in the path. Check the path and directory permissions rather than changing all permissions recursively.

Why does a script not change my terminal directory?

A child shell cannot change its parent directory. Run cd in the interactive shell; sourcing a trusted script executes it in that same shell.

Further help

Options vary by version and distribution. Check the installed documentation with this command: help cd.