Roshan Book

My Tech Notebook

File and Directory Commands – Ubuntu


The cd command changes directories. When you open a terminal you will be in your home directory. To move around the file system you will use cd.

    • To navigate into the root directory, type:
cd /
    • To navigate to your home directory, type:


cd ~


The ~ character represents the current user’s home directory. As seen above, cd ~ is equivalent to cd /home/username/. However, when running a command as root (usingsudo, for example), ~ points instead to /root. When running a command with sudo, the full path to your home directory must be given.
    • To navigate up one directory level, type:
cd ..
    • To navigate to the previous directory (or back), type:
cd -
  • To navigate through multiple levels of directories at once, specify the full directory path that you want to go to. For example, type:
cd /var/www

to go directly to the /www subdirectory of /var/. As another example, type:

cd ~/Desktop

to move you to the Desktop subdirectory inside your home directory.


The pwd command outputs which directory you are currently located in (pwd stands for “print working directory”). For example, typing


in the Desktop directory, will show /home/username/Desktop.


GNOME Terminal also displays this information in the title bar of its window.


The ls command outputs a list of the files in the current directory. For example, typing

ls ~

will show you the files that are in your home directory.

Used with the -l options, ls outputs various other information alongside the filename, such as the current permissions on the file, and the file’s owner.


The cp command makes a copy of a file. For example, type:

cp foo bar

to make an exact copy of foo and name it bar. foo will be unchanged.


The mv command moves a file to a different location or will rename a file. Examples are as follows:

mv foo bar

will rename the file foo to bar.

mv foo ~/Desktop

will move the file foo to your Desktop directory but will not rename it.


rm is used to delete files.

rm foo

deletes the file foo from the current directory.

By default, rm will not remove directories. To remove a directory, you must use the -R option. For example,

rm -R foobar

will remove the directory foobar, and all of its contents!


The mkdir command allows you to create directories. For example, typing:

mkdir music

will create a directory named music in the current directory.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: