O'Reilly logo

Linux Pocket Guide, 2nd Edition by Daniel J. Barrett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

ls — stdin  stdout  - file  -- opt  --help  --version

Synopsis

ls [options] [files]

The ls command (pronounced as it is spelled, ell ess) lists attributes of files and directories. You can list files in the current directory:

$ ls

in given directories:

$ ls dir1 dir2 dir3

or individually:

$ ls file1 file2 file3

The most important options are -a, -l, and -d. By default, ls hides files whose names begin with a dot, as explained in the sidebar Dot Files. The -a option displays all files.

$ ls
myfile1   myfile2
$ ls -a
.hidden_file   myfile1   myfile2

The -l option produces a long listing:

-rw-r--r--    1 smith users       149 Oct 28  2011 my.data

that includes, from left to right: the file’s permissions (-rw-r--r--), owner (smith), group (users), size (149 bytes), last modification date (Oct 28 2011) and name. See File Protections for more information on permissions.

The -d option lists information about a directory itself, rather than descending into the directory to list its files.

$ ls -ld my.dir
drwxr-xr-x    1 smith users      4096 Oct 29  2011 my.dir

Useful options

-a

List all files, including those whose names begin with a dot.

-l

Long listing, including file attributes. Add the -h option (human-readable) to print file sizes in kilobytes, megabytes, and gigabytes, instead of bytes.

-F

Decorate certain filenames with meaningful symbols, indicating their types. Appends “/” to directories, “*” to executables, “@” to symbolic links, “|” to named pipes, and “=” to sockets. These are just visual indicators ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required