File and Directory Commands

cd

The cd command will allow you to change the directory you are in (cd stands simply for "change directory"). When you open a terminal you will be in your home directory. 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

The pwd command will allow you to know in which directory you're located (pwd stands for "print working directory"). For example, typing

pwd

in the Desktop directory, will show ~/Desktop.

[Note]

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

ls

The ls command will allow you to see the files in the directory you are in (ls stands simply for "list"). 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. Examples:

  • To list all the files (including hidden files), type:

    ls -a
  • To list information in a long format, type:

    ls -l

    . This will include information about permissions, owner, and last modification time.

  • To list your root patition, type:

    ls /
  • To list one time per line, type:

    ls -1

cp

The cp command will make a copy of a file for you (cp stands simply for "copy"). 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

mv: The mv command will move a file to a different location or will rename a file (mv stands simply for "move"). Examples:

  • To rename a file named file to foo, type:

    mv file foo

    .

  • To move the file foo to your Desktop, type:

    mv foo ~/Desktop

    . This will move foo 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

The rm will remove or delete a file in your directory (rm stands simply for "remove"). It will not work on directories which have files in them. To remove directories, you can use rm -r. The r stands for recursive. For example:

rm -r foo

will remove the directory named foo and all of its contents.

[Warning]

Using rm -r will delete a complete directory and everything in it without further questions, so be careful with this command.

mkdir

The mkdir command will allow you to create directories (mkdir stands simply for "make directory"). For example, typing:

mkdir music

will create a music directory in the current directory.