cd

file managementlinux
The cd command is one of the most frequently used commands in Linux/Unix-like operating systems. cd The cd command is used to change the current working directory in Linux/Unix systems. cd stands for "change directory" and it's one of the most essential commands for navigating the filesystem.

Quick Reference

Command Name:

cd

Category:

file management

Platform:

linux

Basic Usage:

cd /path/to/directory

Common Use Cases

  • 1

    Directory navigation

    Change the current working directory

  • 2

    Path traversal

    Navigate through the filesystem hierarchy

  • 3

    Scripting

    Use in shell scripts to change directories programmatically

  • 4

    File management

    Easily access and manipulate files in different directories

Syntax

cd [OPTION] [DIRECTORY]

Options

Option Description
-L Follow symbolic links (default behavior)
-P Use the physical directory structure without following symbolic links
-e If the -P option is supplied, and the current working directory cannot be determined successfully, exit with a non-zero status
-@ On systems that support it, present a file with extended attributes as a directory containing the file attributes

Examples

How to Use These Examples

The examples below show common ways to use the cd command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

#

Basic Examples:

# Change to the home directory
cd 
# Change to a specific directory cd /var/log
# Change to a subdirectory cd Documents
# Go up one directory level cd ..
# Go to the previous directory cd -

Advanced Examples:

# Change to the root directory
cd /
# Use a relative path with parent directory cd ../../another_directory # Change to a directory with spaces in its name cd "My Documents" # Change to a directory with environment variable cd $HOME/projects # Change to a user's home directory cd ~username

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

Common Use Cases:

  • Navigating the file system
  • Moving between project directories
  • Accessing configuration files in specific locations
  • Returning to previous locations
  • Moving to a user's home directory

Special Directory Shortcuts:

  • cd or cd ~ - Change to your home directory
  • cd - - Change to the previous directory you were in
  • cd .. - Move up one directory level
  • cd . - Stay in the current directory (rarely used)
  • cd / - Change to the root directory

Tips:

  • Use tab completion to avoid typing full directory names
  • Remember that Linux is case-sensitive for directory and file names
  • The cd command doesn't work on files, only directories
  • Use quotes for directory names containing spaces or special characters
  • You can create aliases for frequently accessed directories in your shell configuration file

Related Commands:

  • pwd - Print working directory
  • ls - List directory contents
  • mkdir - Create directories
  • rmdir - Remove empty directories
  • pushd/popd - Maintain a directory stack for navigation

Tips & Tricks

1

Use the - option to change to the previous directory

2

Use the ~ option to change to the home directory

3

Use the .. option to change to the parent directory

4

Use the -L option to follow symbolic links

5

Use the -P option to not follow symbolic links

Common Use Cases

Directory navigation

Change the current working directory

Path traversal

Navigate through the filesystem hierarchy

Scripting

Use in shell scripts to change directories programmatically

File management

Easily access and manipulate files in different directories

Command execution

Execute commands in specific directories

Related Commands

These commands are frequently used alongside cd or serve similar purposes:

Use Cases

1

Directory navigation

Change the current working directory

2

Path traversal

Navigate through the filesystem hierarchy

3

Scripting

Use in shell scripts to change directories programmatically

4

File management

Easily access and manipulate files in different directories

5

Command execution

Execute commands in specific directories

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the cd command works in different scenarios.

$ cd
View All Commands