How to use the cd command in Linux


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.

cd /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/

The syntax for the cd command is as follows:

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

Follow symbolic links . By default, cd behaves as if the -L option is specified.
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#