cd command in Linux with Examples
cd command in linux known as change directory command. It is used to change current working directory.
$ cd [directory]
To move inside a subdirectory : to move inside a subdirectory in linux we use
$ cd [directory_name]
In the above example, we have checked number of directories in our home directory and moved inside the Documents directory by using cd Documents command.
Different functionalities of cd command :
- cd /: this command is used to change directory to the root directory, The root directory is the first directory in your filesystem hierarchy.
$ cd /
- Above, / represents the root directory.
- cd dir_1/dir_2/dir_3: This command is used to move inside a directory from a directory
$ cd dir_1/dir_2/dir_3
- In above example, we have the document directory and inside the document directory we have a directory named geeksforgeeks and inside that directory we have example directory. To navigate example directory we have used command cd Documents/geeksforgeeks/example.
- cd ~ : this command is used to change directory to the home directory.
$ cd ~
- cd : this command also work same as cd ~ command.
- cd .. : this command is used to move to the parent directory of current directory, or the directory one level up from the current directory. “..” represents parent directory.
$ cd ..
- cd “dir name”: This command is used to navigate to a directory with white spaces.Instead of using double quotes we can use single quotes then also this command will work.
$ cd "dir name"
- In above example, we have navigated the My songs directory by using cd “My songs” command.
$ cd dir\ name :
- this command work same as cd “dir name” command.