Saturday, July 17, 2010

ls Command

Lists the contents of a directory.

Syntax

ls [-a] [-A] [-b] [-c] [-C] [-d] [-f] [-F] [-g] [-i] [-l] [-L] [-m] [-o]
[-p] [-q] [-r] [-R] [-s] [-t] [-u] [-x] [pathnames]


-aShows you all files, including hidden files (Note :
hidden files begin with a dot.)
-AList all files including the hidden files. but not
displays the working directory (.) and parent directory (..).
-bForce printing of non-printable characters to be in
octal notation.
-cUse time of last modification of the i-node (file
created, mode changed, e.t.c)
-CMulti-column output with entries sorted down the
columns. Generally the default one.
-dIf an argument is a directory it only lists its name
not its contents.
-fForce each argument to be interpreted as a directory
and list the name found in each slot. This option turns off -l, -t, -s,
and -r, and turns on -a; the order is the order in which entries appear
in the directory.
-FMark directories with a trailing slash (/), doors with
a trailing greater-than sign (>), executable files with a trailing
asterisk (*), FIFOs with a trailing vertical bar (|), symbolic links
with a trailing at-sign (@), and AF_Unix address family sockets with a
trailing equals sign (=).
-gSame as -l except the owner is not printed.
-iFor each file, print the i-node number in the first
column of the report.
-lShows you informations such as permissions, owners,
size, and when last modified e.t.c.
-LIf an argument is a symbolic link, list the file or
directory the link references rather than the link itself.
-mStream output format; files are listed across the page,
separated by commas.
-nThe same as -l, except that the owner's UID and group's
GID numbers are printed, rather than the associated character strings.
-oThe same as -l, except that the group is not printed.
-pDisplays a slash ( / ) in front of all directories.
-qForce printing of non-printable characters in file
names as the character question mark (?).
-rReverses the order of how the files are displayed.
-RIncludes the contents of subdirectories.
-sGive size in blocks, including indirect blocks, for
each entry.
-tShows you the files in modification time.
-uUse time of last access instead of last modification
for sorting (with the -t option) or printing (with the -l option).
-xDisplays files in columns.
-1Print one entry per line of output.
pathnamesFile or directory to list.

Examples

ls -l

In the above example this command would list each of the files in the current
directory and the files permissions, the size of the file, date of the last
modification, and the file name or directory. Below is additional information
about each of the fields this command lists.

PermissionsDirGroupSizeDateDirectory/file
drwx------3www4096Nov 1 19:50usr/
drwxr-s---32system32768Jan 20 20:30etc/
-rw-------1user3Nov 25 07:58first.c

Below is brief description of each of the above categories shown
when using the ls -l command.

Permissions - The permissions of the directory or file.

Directories - The amount of links or directories within the directory.

The default amount of directories is going to always be 2 because of the . and
.. directories.

Group - The group assigned to the file or directory

Size - Size of the file or directory.

Date - Date of last modification.

Directory of file - The name of the file or file.


ls ~

List the contents of your home directory by adding a tilde after the ls
command.

ls /

List the contents of your root directory.

ls ../

List the contents of the parent directory.

ls */

List the contents of all sub directories.

ls -d */

Only list the directories in the current directory.

1 comment:

  1. For more help refer manual page i.e. type "man ls" without quotes in terminal..

    ReplyDelete