• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

Cd Command in Linux

Written by Admin, Updated On December 20, 2019
bash, terminal
Cd Command in Linux

You can use cd (“change directory”) command to switch the current working directory in Linux and other Unix-like operating systems. This command is used frequently and it’s basic command to work with Linux terminal. In this guide, we will show you how to use the cd command to navigate your system’s directory tree.

cd Command (Change Directory)#

cd is a builtin command and following is the syntax for the cd command:

cd [OPTIONS] directory

You can pass options which are not mostly used.

  • −L, By passing it follow symbolic links. By default, cd behaves as if -L option is specified.
  • −P, It will not follow symbolic links. In simple words, when you try to navigate symlink it will change to directory which is pointed to it.

If you will not pass any argument cd command will navigate to home directory.

To switch to a directory, you must have executable permissions for that directory it. The pwd command allows you to find out current directory.

Absolute and Relative Path#

You can change directory using either absolute (full path) or relative path. Full path starts from the root of system / and relative path starts from your working directory. In short, if the path starts with a slash (/) it is the absolute path to the directory.

By default your working directory is home directory. If you would like to navigate to Documents directory you can do it by simple relative path:

cd Documents

Also, you can use absolute path to navigate same directory:

cd /home/tecnstuff/Documents

The Parent Directory#

In the Unix distro single dot (.) represents the current directory. Two dots (..) represents the parent directory or in other words the directory immediately above the current one.

For example currently you are in /var/www/html directory and you would like to switch to /var/www directory, you can using:

cd ../

To go to two level up means to parent’s parent you have to type:

cd ../../

Another example, you are in /var/www/html directory and you would like to switch to /var/www/log. You can do it by simply typing:

 cd ../log

Navigate to the Previous Directory#

To switch to previous working directory, just pass dash - character as an argument along with cd command:

cd -

Navigate to the Home Directory#

You can directly land to home directory using cd command. Alternate way is to pass tilde ~ character as an argument.

cd ~

For example, if you would like to navigate to Documents directory you can use below command:

cd ~/Documents

Same as you can navigate to another user directory using following command:

cd ~username

Directories with Space in Their Names#

If the directory name contains space then you should enclose the name with quotes. Either you can use backslash (\) character to escape the space.

cd 'Test Folder'
cd Test\ Folder

Conclusion#

Now you successfully learnt how to use cd command in Linux. We also show you how to navigate to parent directory and working directory.

If you have any query or suggestion, you can comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article Current Working Directory (Pwd Command in Linux)
Next Article   How to Install GO on Debian 10 Linux

Related Posts

  • How to Install SSH Keys on Ubuntu 22.04

    How to Set up SSH Keys on Ubuntu 22.04

    January 7, 2023
  • How to Install Fail2ban on Ubuntu 22.04

    How to Install and Configure Fail2ban on Ubuntu 22.04

    December 5, 2022
  • How to Enable SSH on Ubuntu 22.04

    How to Enable SSH on Ubuntu 22.04

    December 1, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook