A Quick Introduction to Unix/Listing Files and Directories

From Wikibooks, open books for an open world
Jump to: navigation, search

Listing files and directories[edit]

ls (list)

When you login you are in your home directory. This directory is associated with your userid, for example, ccaajim, and it is where your personal files and subdirectories are stored.

To find out what is in a directory you can type

% ls

The ls command lists the contents of your current working directory.

A file listing in a Socrates shell at UCL

There may be no files visible in your home directory, in which case you will return to the Unix prompt but some files will usually have been created by the System Administrator when your account was created.

ls does not list quite all the files in your home directory but only those ones whose name does not begin with a dot (.) Files beginning with a dot are hidden files and usually contain important program configuration information. They are hidden because you should not change them unless you are very familiar with Unix.

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

% ls -a

A listing from ls-l in a Socrates shell at UCL.

As you can see, ls -a lists files that are normally hidden.

ls can take options, for example -a is an example of an option. Options change the behaviour of commands. Test the output of ls -l and of ls -la.

Another very useful option is -t which displays the directory contents newest first by timestamp.