Name

ls — List files in a directory.

Synopsis

ls [-l] [-a] [directory]

Options

-l

Long listing giving more information.

-a

Listing includes all files.

directory

Directory to list.

Description

This command produces a list of all the files in a given directory, if no directory is specified then the present working directory is shown. Example 12.1, “Using the cd and ls commands to navigate a filesystem” shows the listing of the PWD.

Listing the “root” directory (ls /) lists all the available filesystems.

Example 12.2. Using the ls command

This shows a simple directory listing of the first hard disc partition with a filesystem.

>ls (hd0)
lost+found
etc
media
var
usr
bin
boot
dev
home
lib
mnt
proc
root
sbin
tmp
sys
srv
opt
>

This shows a detailed directory listing of the first hard disc partition with a filesystem.

>ls -l -a (hd0)
drwxr-xr-x   22 0 0     4096 .
drwxr-xr-x   22 0 0     4096 ..
drwxr-xr-x    2 0 0    49152 lost+found
drwxr-xr-x   73 0 0     4096 etc
drwxr-xr-x    2 0 0     4096 media
drwxr-xr-x   13 0 0     4096 var
drwxr-xr-x   12 0 0     4096 usr
drwxr-xr-x    2 0 0     4096 bin
drwxr-xr-x    2 0 0     4096 boot
drwxr-xr-x    7 0 0    24576 dev
drwxrwxr-x    5 0 50    4096 home
drwxr-xr-x    9 0 0     4096 lib
drwxr-xr-x    2 0 0     4096 mnt
drwxr-xr-x    2 0 0     4096 proc
drwxr-xr-x    5 0 0     4096 root
drwxr-xr-x    2 0 0     4096 sbin
drwxrwxrwx    4 0 0     4096 tmp
drwxr-xr-x    2 0 0     4096 sys
drwxr-xr-x    2 0 0     4096 srv
drwxr-xr-x    2 0 0     4096 opt
>

This shows the PWD being changed and the ls command used to display the directory contents.

>cd (hd0)
>ls -l -a
drwxr-xr-x   22 0 0     4096 .
drwxr-xr-x   22 0 0     4096 ..
drwxr-xr-x    2 0 0    49152 lost+found
drwxr-xr-x   73 0 0     4096 etc
drwxr-xr-x    2 0 0     4096 media
drwxr-xr-x   13 0 0     4096 var
drwxr-xr-x   12 0 0     4096 usr
drwxr-xr-x    2 0 0     4096 bin
drwxr-xr-x    2 0 0     4096 boot
drwxr-xr-x    7 0 0    24576 dev
drwxrwxr-x    5 0 50    4096 home
drwxr-xr-x    9 0 0     4096 lib
drwxr-xr-x    2 0 0     4096 mnt
drwxr-xr-x    2 0 0     4096 proc
drwxr-xr-x    5 0 0     4096 root
drwxr-xr-x    2 0 0     4096 sbin
drwxrwxrwx    4 0 0     4096 tmp
drwxr-xr-x    2 0 0     4096 sys
drwxr-xr-x    2 0 0     4096 srv
drwxr-xr-x    2 0 0     4096 opt
>