Best practice to use the cd command in Linux and ubuntu

Hello Penguins, Welcome to the Next article on the Linux command line tutorial for beginners in this article we see the Best practice to use the cd command in Linux and ubuntu. 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. we will learn. How we can use the CD command in Linux. CD command we can use to change the current working directory and Linux. So let’s see how we can use it so first of all to use the cd command. We have to open the terminal. So press CTRL+alt+t to open the terminal.

The syntax for the cd command

cd [directory path]

You can just use the cd as it is and it can be used with the directory name also. So first of all whenever, you’ll give the cd command without any directory name. So it is going to land you in the current home directory. Whatever you open whenever you open the terminal

Change directory to the root directory

cd /

The root directory is denoted by a forward slash. So to go root directory type cd / (forward slash) and then press Enter. Now we are in the root directory.

Change directory to the current user home directory

cd ~

This cd tilde command is used to go current user home directory. We can type cd ~ to any location this command will take you on current user home directory.

To go one directory back

cd ..

There is a command something like cd .. It means we want to go to the parent directory of the current working directory. For instance. Our working directory in /home/logan/Desktop. Where logan is my username. So when I give a cd .. Then we will go one directory cack or parent the current folder.

Navigate to a directory with white spaces

cd “Directory name”

So how you can now go inside the folder which has space between. There are 3 options so you can use to navigate such kind of Folder.

The first option is you can just write a cd and then type backlash between the space of the directory name.

The second option is that instead of using this backslash you can just try to double quote. Then you can just write the directory name. The third option is to use a single quote. Like cd ‘directory name’ and it will work.

Conclusion

So what are the commands we have used in this article? cd command without any option. Then you will go to your home directory. In order to navigate to a particular directory. I need to give its absolute path or related path. we learn how to go one directory back with the cd .. command. Then we see how can we avoid spaces to go on that directory. Which name has space on their name?