How to use the cd command in Linux

Created

The cd command, also known as chdir (change directory), is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files.

Change from current directory to /usr/local/bin.

Change
cd /usr/local/bin
pwd
/usr/local/bin

Switch back to previous directory where you working earlier

Switch back
cd -
Change Current directory to parent directory.
cd ..
Show last working directory from where we moved (use ‘–‘ switch) as shown.
cd --
Move to users home directory from anywhere.
cd ~
Change to a directory containing white spaces.
cd test\ installmd/
/root

The syntax for the cd command is as follows:

Usage: 
  cd [-L|[-P [-e]]] [dir]

OPTIONS:
-L
Follow symbolic links . By default, cd behaves as if the -L option is specified.
-P
Don’t follow symbolic links. In other words, when this option is specified, and you try to navigate to a symlink that points to a directory, the cd will change into the directory.

Related Tags

#Linux# #cd#