How to Change Current Working Directory in Ubuntu Terminal
Answer: Use the
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:
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.
Similarly, to change the current working directory to
html you can use:
If your current working directory is
www then to change it to
html, 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
html and you want to change it to
www you can type:
For changing the current working directory from
var, 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
ls command 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
pwd command (pwd stands for "print working directory").
Here are some more FAQ related to this topic: