WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to Change Current Working Directory in Ubuntu Terminal

Topic: Ubuntu / LinuxPrev|Next

Answer: Use the cd Command

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").


Related FAQ

Here are some more FAQ related to this topic:

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties