Listing Files

We'll start by using the ls (short for list) command to list the contents of the current directory:

$ ls

The output will be similar to the following:

Desktop         Icon            Music           Sites
Documents       Library         Pictures        Temporary Items
Downloads       Movies          Public

We can tell that several items are in the current directory, but this output does not tell us whether these items are files or directories. To find out which of the items are files and which are directories, we can specify the -F option to ls. An option is an argument that starts with the hyphen or dash character, '-'.

The following example illustrates the use of the -F option of ls:

$ ls -F

Now the output for the directory is slightly different:

 Desktop/ Icon Music/ Sites/ Documents/ ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.