How to change directory in linux

How to change directory in linux

  • Linux
  • 745 Views

The cd Command

The cd command is used to navigate between directories, "cd" stands for "change directory" .

1. Navigate to root directory

to navigate to root directory  just type the ls command

cd / 

 

2. Navigate to home directory

to navigate to root directory  just type the ls command

cd 

OR

cd ~

 

 

3. Navigate to new directory using absolute path

to navigate to a directory using absolute path mention the whole path starting from the root

cd /var/www/html/

 

4. Navigate to new directory using relative path

to navigate to a directory using relative path mention the path relative to the current directory,

e.g here we navigate from www root to html using relative path

cd html             ---(navigation using relative path)


cd /var/www/html    --- (navigation using absolute path)

 

 

5. Navigate to parent directory

to navigate to parent directory use the following command

cd ..         (one level up)

cd ../..      (two levels up)

cd ../../..   (three levels up)

 

 

6. Navigate to previous working directory

to navigate to previous working directory use the following command

cd - 

 

7. Directories with spaces in their names

to navigate to a directory that contain space in their names, you can use quotes or backslash to escape the space. 

for example to navigate to a folder with name "MY PORTFOLIO" from current directory type the following command

cd 'MY PORTFOLIO'

OR

cd  MY\ PORTFOLIO

 

Conclusion

There are tons of other commands and combinations you can explore.

you can run cd --help to explore more of cd command: