Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH

Bash cd - Change Directory

Using the cd Command

The cd command is used to change the current working directory in the terminal.


Basic Usage

To change to a specific directory, use cd directory_name:

Example

cd my_directory

Options Overview

The cd command supports several useful options for navigating directories:

  • cd ..: Move up one directory level
  • cd ~: Change to the home directory
  • cd -: Switch to the previous directory
  • cd /: Change to the root directory

cd .. Option: Move Up One Directory Level

The cd .. command lets you go to the folder above your current one.

It's useful when you need to go to the parent folder.

Example

cd ..

cd ~ Option: Change to Home Directory

The cd ~ command takes you to your home directory, which is the default directory for your user account.

This option is useful when you need to return to your starting point after navigating through various directories.

Example

cd ~

cd - Option: Switch to Previous Directory

The cd - command switches your working directory to the previous one you were in.

This option is useful for toggling between two directories without needing to type their full paths repeatedly.

Example

cd -

cd / Option: Change to Root Directory

The cd / command takes you to the root directory of the file system.

This option is useful when you need to access system-wide files or directories.

Example

cd /

Combining Options

The cd command itself does not support combining options, but you can use it in conjunction with other commands to enhance navigation efficiency.

For example, using cd with ls can quickly show you the contents of a directory you navigate to:

Example: Change and List

cd my_directory && ls
copy_of_my_file.txt  Cosmere_RPG_Beta_Rules_Preview.pdf
images/  my_file.txt  myfolder/  report.csv  voiceover.wav


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.