Use of cd command in Linux with Examples – Easy Guide 2021

What is use of cd command in Linux

cd command is used to change into different directory of file system from current working directory. cd is short to refers to change directory. Directories are found in file hierarchy system in all Computer operating systems. Root (represented by /) is at top of Linux file hierarchy. All directories are above root in Linux. By default when you log into your Linux system your home directory is presented to you. From home directory you can use cd command to change directory in Linux Operating system.

Use of cd command in Linux with Examples

Change directory using cd command

First basic usage cd command is to change into different directories.

Syntax

cd /[absolute path to directory]
cd [relative path to directory] 

You can use either relative path or absolute path to change to other directories. Absolute path is path where directory position is mentioned in reference to root.

Example

cd /var/vnc                             [this is absolute path]
cd new/xyz                             [this is relative path]

Root as already discussed is represented by “/“. In order to change to root directory use command.

cd /

Change to parent directory of current directory using cd command

To change to parent directory or one level above current directoy used “cd..” command.

Syntax

cd ..

This command will move you one directory above your current working directory

Return to your home directory

Simply use cd / cd~ command and you will return to your home directory

Syntax

cd

OR

cd~

Use of cd command in Linux to change to directory with space in its name

In order to change to directory with space in its name use double quotes or single quote to enclose name.

Syntax

cd "name of directory"
cd 'name of directory'

Example

cd "new directory"
cd 'new directory'

Change to other user to access directories for that user

Other user can be accessed by root user. To change to other user use command su followed by user name

Syntax

su [user name]

Example

su test