Enhance your Career in Networking With IPinBits!!!​

Linux for network engineers – cd command

Taking further our Linux for network engineers, today we will study about the cd command. cd stands for change directory and as its name suggests it is used for changing directories (or we can say changing folders in windows terms). The “pwd” command allows you to find out what directory you are currently in.

The syntax for the cd command is as follows:

cd [OPTIONS] directory

The most basic use of “cd” command is without any options. It will take us to our current user root directory.

ipinbits@ubuntu:~/Documents/personal$ pwd
ipinbits@ubuntu:~/Documents/personal$ cd
ipinbits@ubuntu:~$ pwd

 Now how do we change directories, please have a look on below example:- 

ipinbits@ubuntu:~$ pwd
ipinbits@ubuntu:~$ ls
Desktop  Documents  Downloads  examples.desktop  Music  Pictures  Public  Templates  Videos
ipinbits@ubuntu:~$ cd Documents/
ipinbits@ubuntu:~/Documents$ pwd

In the above example we went to Documents directory. Now “cd” command will not work if you do not have execute permission for the directory.

ipinbits@ubuntu:~/Documents/personal$ ls -l
total 4
d--------- 2 ipinbits ipinbits 4096 Apr 24 06:10 bank
ipinbits@ubuntu:~/Documents/personal$ cd bank/
bash: cd: bank/: Permission denied

Now here we have a bank directory without any permissions to current user. When we tried to change directory to bank, it gets rejected. How to overcome this issue – simply change permissions

ipinbits@ubuntu:~/Documents/personal$ chmod 777 bank
ipinbits@ubuntu:~/Documents/personal$ cd bank
ipinbits@ubuntu:~/Documents/personal/bank$ pwd

How to go 1 step back using cd command

ipinbits@ubuntu:~/Documents/personal/bank$ cd ..

 Some more useful cd commands :-
1. cd folder- if “folder” is in the current directory.
2. cd .. – goes 1 step back from current directory
3. cd . – does nothing, remains in same directory
4. cd /dir1/folder1/ – gave absolute path from any directory. Notice for going to another directory we used “/” before dir15. cd ../src – Let’s say you are in the /usr/local/share directory, and you want to switch to the /usr/local/src.

Related blog posts