ls command options | Linux

by Ramakanta · Published November 26, 2012 · Updated November 21, 2016

ls is probably the most used command and for good reason. With it, we can see directory contents and determine a variety of important file and directory attributes. As we have seen, we can simply enter ls to see a list of files and subdirectories contained in the current working directory:

By adding -l to the command, we changed the output to the long format.

Options and Arguments

This brings us to a very important point about how most commands work. Commands are often followed by one or more options that modify their behavior and, further, by one or more arguments, the items upon which the command acts. So most commands look something like this:

command -options arguments

Most commands use options consisting of a single character preceded by a dash, such as -l. But many commands, including those from the GNU Project, also support long options, consisting of a word preceded by two dashes.

Also, many commands allow multiple short options to be strung together. In this example, the ls command is given two options, the l option to produce long format output, and the t option to sort the result by the file’s modification time:

The ls command has a large number of possible options and most commonly used commands are listed below:

Option

Long Option

Description

-a

–all

List all files, even those with names that begin with a period, which are normally not listed (i.e., hidden).

-d

–directory

Ordinarily, if a directory is specified, ls will list the contents of the directory, not the directory itself. Use this option in conjunction with the -l option to see details about the directory rather than its contents.

-F

–classify

This option will append an indicator character to the end of each listed name (for example, a forward slash if the name is a directory).

-h

–human-readable

In long format listings, display file sizes in human-readable format rather than in bytes.

-l

Display results in long format.

-r

–reverse

Display the results in reverse order. Normally,

ls

Displays its results in ascending alphabetical order.

-S

-t

Sort by modification time.

A Longer Look at Long Format

As we saw before, the -l option causes ls to display its results in long format.

This format contains a great deal of useful information. Here is the Examples

directory from an Ubuntu system:

-rw-r–r– 1 root root 3576296 2012-04-03 11:05 Experience ubuntu.ogg

-rw-r–r– 1 root root 1186219 2012-04-03 11:05 kubuntu-leaflet.png

-rw-r–r– 1 root root 47584 2012-04-03 11:05 logo-Edubuntu.png

-rw-r–r– 1 root root 44355 2012-04-03 11:05 logo-Kubuntu.png

-rw-r–r– 1 root root 34391 2012-04-03 11:05 logo-Ubuntu.png

-rw-r–r– 1 root root 32059 2012-04-03 11:05 oo-cd-cover.odf

-rw-r–r– 1 root root 159744 2012-04-03 11:05 oo-derivatives.doc

-rw-r–r– 1 root root 27837 2012-04-03 11:05 oo-maxwell.odt

-rw-r–r– 1 root root 98816 2012-04-03 11:05 oo-cd-cover.odf

ls Long Listing Fields Field Meaning

-rw-r—r– Access rights to the file. The first character indicates the type of file. Among the different types, a leading dash means a regular file, while a d indicates a directory. The next three characters are the access rights for the file’s owner, the next three are for members of the file’s group, and the final three are for everyone else.