Thursday, January 6, 2011

ls command

List information about the FILEs (the current directory by default).

Syntax
ls [OPTION]... [FILE]... 
Options
-a    Shows you all files, even files that are hidden (these files begin with a . dot.)
-A    List all files including the hidden files. However, does not display the working directory (.) or the parent directory (..).
-b    Force printing of non-printable characters to be in octal \ddd notation.
-c    Use 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. Generally this is the default option.
-d    If an argument is a directory it only lists its name not its contents.
-f   Force 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    Mark 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 (=).
-g    Same as -l except the owner is not printed.
-h     print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
-i    For each file, print the i-node number in the first column of the report.
-l    long listing of a file or a directory contents (permissions, owners, size, and when last modified.)
-L    If an argument is a symbolic link, list the file or directory the link references rather than the link itself.
-m    Stream 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 associated character strings.
-o    The same as -l, except that the group is not printed.
-p    Displays a slash ( / ) in front of all directories.
-q    Force printing of non-printable characters in file names as the character question mark (?).
-r    Reverses the order of how the files are displayed.
-R    Includes the contents of subdirectories.
-s    Give size in blocks, including indirect blocks, for each entry.
-S   Sort by file size
-t    Shows you the files in modification time.
-u    Use time of last access instead of last modification for sorting (with the -t option) or printing (with the -l option).
-x    Displays files in columns.
-Z  Print any SELinux security context of each file
-1   Print one entry per line of output.
pathnames    File or directory to list.

Examples

ls -l
-rw-r----- 1 lalit admin 7277202 Jan 06 14:29 go2linuxworld.txt
1st CharacterFile Type: First character specifies the type of the file. 
In the example above the hyphen (-) in the 1st character indicates that this is a normal file. Following are the possible file type options in the 1st character of the ls -l output.
          - normal file
          d directory
          s socket file
          l link file 
Field 1 – File Permissions: Next 9 character specifies the files permission. Each 3 characters refers to the read, write, execute permissions for user, group and world In this example, -rw-r—– indicates read-write permission for user, read permission for group, and no permission for others.
Field 2 – Number of links: Second field specifies the number of links for that file. In this example, 1 indicates only one link to this file. 
Field 3 – Owner: Third field specifies owner of the file. In this example, this file is owned by username ‘lalit’.
Field 4 – Group: Fourth field specifies the group of the file. In this example, this file belongs to 'admin’ group.
Field 5 – Size: Fifth field specifies the size of file. In this example, ’7277202′ indicates the file size.
Field 6 – Last modified date & time: Sixth field specifies the date and time of the last modification of the file. In this example, ‘Jan 06 14:29′ specifies the last modification time of the file.
Field 7 – File name: The last field is the name of the file. In this example, the file name is go2linuxworld.txt

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.

No comments:

Post a Comment

There was an error in this gadget