Thursday, August 9, 2007

Unix command `ls`

Linux,Unix command.
`ls` : list contents of directory
feature : [ -aAbcCdfFgilLmnopqrRstux1 ] [ file ... ]
For each file that is a directory, ls lists the contents of the directory; for each file that is an ordinary file, ls repeats its name and any other information requested. The output is sorted alphabetically by default. When no argument is given, the current directory is listed. When several arguments are given, the arguments are first sorted appropriately, but file arguments appear before directories and their contents.
How to use the features
[root@server tmp]# ls -l
-rw------- 1 apache apache 92 Aug 1 10:08 sess_276
-rw------- 1 apache apache 450 Aug 2 11:29 ess_730701

Features means
-a Lists all entries, including those that begin with a dot (.), which are normally not listed.
-A Lists all entries, including those that begin with a dot (.), with the exception of the working directory (.) and the parent directory (..).
-b Forces printing of non-printable characters to be in the octal \ddd notation.
-c Uses time of last modification of the i-node (file created, mode changed, and so forth) for sorting (-t) or printing (-l or -n).
-C Multi-column output with entries sorted down the columns. This is the default output format.
-d If an argument is a directory, lists only its name (not its contents); often used with -l to get the status of a directory.
-f Forces 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.
-F Marks 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 sock- ets with a trailing equals sign (=).
-g The same as -l, except that the owner is not printed.
-i For each file, prints the i-node number in the first column of the report.
-l Lists in long format, giving mode, ACL indication, number of links, owner, group, size in bytes, and time of last modification for each file (see above). If the file is a special file, the size field instead con- tains the major and minor device numbers. If the time of last modification is greater than six months ago, it is shown in the format `month date year' for the POSIX locale. When the LC_TIME locale category is not set to the POSIX locale, a different format of the time field may be used. Files modified within six months show `month date time'. If the file is a sym- bolic link, the filename is printed followed by "->" and the path name of the referenced file.
-L If an argument is a symbolic link, lists the file or directory the link references rather than the link itself.
-m Streams output format; files are listed across the page, separated by commas.
-n The same as -l, except that the owner's UID and group's GID numbers are printed, rather than the asso- ciated character strings.
-o The same as -l, except that the group is not printed.
-p Puts a slash (/) after each filename if the file is a directory.
-q Forces printing of non-printable characters in file names as the character question mark (?).
-r Reverses the order of sort to get reverse alphabetic
-R Recursively lists subdirectories encountered.
-s Gives size in blocks, including indirect blocks, for each entry.
-t Sorts by time stamp (latest first) instead of by name. The default is the last modification time. (See -u and -c.)
-u Uses time of last access instead of last modification for sorting (with the -t option) or printing (with the -l option).
-x Multi-column output with entries sorted across rather than down the page.
-1 Prints one entry per line of output.


No comments: