Linux cd command

Linux cd command

 Linux cd command


The cd command stands for “change directory”. This command is used to leave the current directory and navigate to another directory on the system.

Syntax:

cd <Path to new dir>

Change to a New Directory

After login to the system, the user gets the home directory. Now you can navigate to another directory for example /home/rahul/Workspace where my present directory is /home/rahul

cd Workspace

Use pwd to check your present working directory.

pwd

/home/rahul/Workspace

There are two ways to navigate between directories is the absolute path and the relative path.

The Absolute Path vs Relative Path

Absolute Path:

An absolute path is a complete path to the directory from the root directory (/). In simple terms, all the path started with a slash (/) are an absolute path. For example:

  • /var
  • /var/www/html
  • /home/rahul/Workspace
  • /backup/db/daily

You can see all the above paths are started with a slash (/).

Relativ Path:

Any path which is not started with a slash (/) is a relative path. For example:

  • Documents
  • www/html
  • Workspace/Linux/Guides
  • www/tecadmin.net/

Change Directory with Absolute Path

Changing to directory /home/rahul/Workspace with absolute directory using the cd command.

cd /home/rahul/Workspace

Change Directory with Relative Path

Changing to the directory Linux/Guides with a relative path using the cd command.

cd Linux/Guides

The cd Options

Use the below options to understand the uses of the cd command.

 Option
 Description
cd .
The single dot (.) denotes to current directory. This will keep you in current directory.
cd ..
Change to parent directory.
cd ~
Change to home directory. As ~ denotes to home directory.
cd –
Change to previos directory
cd /path/to/dir
Change to specified directory
Reactions

Post a Comment

0 Comments

close