File and Directory Commands

cd

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. Examples:

  • To navigate into the root directory, type:

    cd /

  • To navigate to your home directory, type:

    cd

    or

    cd ~

  • To navigate up one directory level, type:

    cd ..

  • To navigate to the previous directory (or back), type:

    cd -

  • To navigate through multiple levels of directory 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.

pwd

pwd: The pwd command will show you which directory you're located in (pwd stands for “print working directory”). For example, typing

pwd

in the Desktop directory, will show ~/Desktop.

[Note]

GNOME Terminal also displays this information in the title bar of it's window.

ls

The ls command shows you the files in your current directory. Used with certain options, you can see sizes of files, when files where made, and permissions of files. For example, typing

ls ~

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

cp

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

cp file foo

to make a exact copy of file and name it foo, but the file file will still be there.

mv

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

mv file foo

will rename the file file to foo.

mv foo ~/Desktop

will move the file foo to your Desktop directory but will not rename it. You must specify a new file name to rename a file.

[Note]

If you are using mv with sudo you will not be able to use the ~ shortcut, but will have to use the full pathnames to your files. This is because when you are working as root, ~ will refer to the root account's home directory, not your own.

rm

Use the rm command to remove or delete a file in your directory. It will not work on directories which have files in them.

mkdir

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

mkdir music

will create a music directory in the current directory.