Directories

Listing files and directories

ls (list)

When you first login, your current working directory is your home directory. Your home directory has the same name as your user-name, also know as $HOME and it is where your personal files and subdirectories are saved.

$HOME $> ls

ls list the files in your home directory. Files beginning with a dotare known as hidden files and usually contain important program configuration information. 

To list all files in your home directory including those whose names begin with a dot, type

$HOME $> ls -a

Directories

mkdir (make directory) and rmdir (remove directory)

To make a subdirectory called red in your current working directory type

$HOME $> mkdir red

To see the directory you have just created, type

$HOME $> ls

To remove a subdirectory called red in your current working directory type

$HOME $> rmdir red

Note: rmdir will remove only empty directories.

Changing to a different directory

cd (change directory)

The command cd directory means change the current working directory to "directory".  To change to the directory you have just made, type:

$HOME $> cd red

$HOME/red $>

Exercise

Make another directory inside the red directory called backups

The directories . and ..

As you can see, in the stuff directory (and in all other directories), there are two directories called . and .. in every directory.

In UNIX, . means the current directory, so typing: 

$HOME/red $> cd .

This may not seem very useful at first, but using . as the name of the current directory will save a lot of typing. .. means the parent of the current directory, so typing

$HOME/red $> cd ..

will take you one directory up the hierarchy (back to your home directory).

Note: typing cd with no argument always returns you to your home directory $HOME. This is very useful if you are lost in the file system.

Pathnames

pwd (print working directory)

Pathnames enable you to work out where you are in relation to the whole file-system. For example, to find out the absolute pathname of your current-directory type:

$HOME $> pwd

The full pathname will look something like this:

/ichec/home/users/your_user_name/

Note: This path is called $HOME. You can also go to your home directory typing cd $HOME or simply cd + enter.

Exercise

Use the commands lspwd and cd to explore the file system.

More about home directories and pathnames

Useful tips: 

First type cd to get back to your home-directory, then type

$HOME $> ls red

to list the contents of your red directory. But if you type ls blue you will get a message like: blue: No such file or directory

The reason is that blue is not in your current working directory. 

~ (your home directory)

Home directories $HOME can also be referred to by the tilde ~ character. It can be used to specify paths starting at your home directory. So typing

$HOME $> ls ~/red

will list the contents of your red directory, no matter where you currently are in the file system.

Supported By

File Browser Reference
Department FHERIS
University of Galway
HEA Logo