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 levelcd ~
: Change to the home directorycd -
: Switch to the previous directorycd /
: 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