A simple command

A simple command

In the terminal window, enter "ls" and press Enter. You should see something like this (the actual contents may vary):

sandbox@laptop:~ > ls
KDesktop  public_html  snapshot1.png
sandbox@laptop:~ >

The "ls" (list) command lists the contents of the current directory. When used from a terminal, it generally uses colours to differentiate between directories, images, executable files etc. As you can see, the prompt reappears at the end.

Adding options

Like practically all commands in Linux, you can add options to the "ls" command to alter its output or influence its behaviour. An option is preceded by a dash (eg, "ls -a"). Try out the following variations of the ls command, to see different forms of output:

ls -l
Produces a "long format" directory listing. For each file or directory, it also shows the owner, group, size, date modified and permissions
ls -a
Lists all the files in the directory, including hidden ones. In Linux, files that start with a period (.) are usually not shown.
ls -R
Lists the contents of each subdirectory, their subdirectories etc (recursive).

When you want to give more than one option, you can group them together with a single dash. For example, the command "ls -al
" is the same as "ls -a -l"

Some options consist of a word (or words) instead of a letter, and have two dashes instead of one. For example, the command "ls -l --full-time" displays the date and time of modification in full.

Finally, some options may also have a value. For example, "ls -l --sort=size
" sorts the listing by size.

Adding parameters

Apart from options (which are preceded by one or two dashes), you can also specify
parameters, such as filenames, directory names and so on.

For example with the "ls" command, if you don’t specify any parameter, it will list the contents of the current directory. However, you could instead give it a parameter specifying what to list. For example if you type in "ls /usr", it will list the contents of the "/usr" directory. You can specify more than one parameter, but we’ll see more about that later.