Skip to content

Instantly share code, notes, and snippets.

@devinschumacher
Last active July 22, 2025 16:41
Show Gist options
  • Save devinschumacher/e636af1041094e43b23932ea610e92a6 to your computer and use it in GitHub Desktop.
Save devinschumacher/e636af1041094e43b23932ea610e92a6 to your computer and use it in GitHub Desktop.
cd: `cd` Command Description, Explanation, Reference & Examples | Learn Command Line
title tags
The `cd` terminal command - Definition, Explanation & Examples
cd
linux
command line
shell
terminal

cd

"How do I get out of here?"

The cd command changes the current working directory (folder), allowing you to move between directories (folders) on the filesystem.

Click to watch the video πŸ‘‡

Name

cd - change directory

Mnemonic

cd stands for change directory.

Options

  • cd -: Change to the previous working directory

Examples

Move up one directory

cd ..

Moving up one directory with cd ..

Move up two directories

cd ../..

Moving up two directories with cd ../..

Move to parent folder's sibling directory

cd ../another-directory

Moving to parent folder's sibling directory with cd ../another-directory

Switch back to previous directory

cd -

Switching back to previous directory with cd -

Move the user's home directory

cd
cd ~
cd /Users/<username>
cd $HOME

Moving to user's home directory with cd

Move directly to the filesystem's root directory

cd /

Moving to filesystem's root directory with cd /

Move to a specific directory

cd ~/Desktop
cd [directoryName]
cd [directoryName/subDirectoryName]

Moving to specific directory with cd ~/Desktop

Command Quick Reference

Command What It Does Example
cd Go to home directory cd β†’ /Users/<username>
cd ~ Go to home directory cd ~ β†’ /Users/<username>
cd .. Go up one level From current directory to parent
cd ../.. Go up two levels From current directory up two levels
cd - Go back to previous directory Switches between last two directories
cd / Go to root directory cd / β†’ /
cd ~/Desktop Go to Desktop cd ~/Desktop β†’ ~/Desktop
cd ../another-directory Go to sibling directory From one folder to its sibling

Tips

How to Handle Spaces in Directory Names

cd "My Documents"
# or
cd My\ Documents

How to Handle Spaces in Directory Names with cd command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment