The current working directory is the directory or folder where you are currently working.
You can use the cd (change directory) command to change the current working directory or move around the file system. This command will work in all Linux distribution.
For a moment let's consider the following directory structure:
/
|—— var/
| |—— www/
| |—— html
| ...
| ...
...
Now, for example, if your current working directory is the root directory (i.e. /), then to change the current working directory to www you can use the command:
cd var/www
However, to change the current working directory to www regardless of where you are, you can use the absolute path. Any path that starts with a forward slash / is an absolute path.
cd /var/www
Similarly, to change the current working directory to html you can use:
cd /var/www/html
If your current working directory is www then to change it to html, you can simply type:
cd html
To navigate up one directory level, you can simply use "cd ..", there's no need to type directory name, e.g., if your current working directory is html and you want to change it to www you can type:
cd ..
For changing the current working directory from html to var, you can type:
cd ../../
Move to root directory from anywhere, you can simply type:
cd /
Switch back to previous directory where you were working earlier, you can type:
cd -
To navigate to user's home directory from anywhere, you can type:
cd ~
Moreover, you can use the ls command to list the files in your current directory.
ls
Tip: By default, when you first login, your current working directory is set to your home directory. Alternatively, to find out the current working directory, you can use the pwd command (pwd stands for "print working directory").
Use the
cdCommandThe current working directory is the directory or folder where you are currently working.
You can use the
cd(change directory) command to change the current working directory or move around the file system. This command will work in all Linux distribution.For a moment let's consider the following directory structure:
Now, for example, if your current working directory is the root directory (i.e.
/), then to change the current working directory towwwyou can use the command:However, to change the current working directory to
wwwregardless of where you are, you can use the absolute path. Any path that starts with a forward slash / is an absolute path.Similarly, to change the current working directory to
htmlyou can use:If your current working directory is
wwwthen to change it tohtml, you can simply type:To navigate up one directory level, you can simply use "cd ..", there's no need to type directory name, e.g., if your current working directory is
htmland you want to change it towwwyou can type:For changing the current working directory from
htmltovar, you can type:Move to root directory from anywhere, you can simply type:
Switch back to previous directory where you were working earlier, you can type:
To navigate to user's home directory from anywhere, you can type:
Moreover, you can use the
lscommand to list the files in your current directory.Tip: By default, when you first login, your current working directory is set to your home directory. Alternatively, to find out the current working directory, you can use the
pwdcommand (pwd stands for "print working directory").