An explanation of LS command in Linux

Source: Internet
Author: User
Tags sorts

The s command can be said to be one of the most commonly used commands under Linux.


-A lists all files under the directory, including the. The implied file at the beginning.
-B lists the characters that are not output in the file name in the form of a backslash and a character number (as in the C language).
-C The modified time of the I node of the output file and sorted by this.
-D Displays the directory as if it were a file, rather than displaying the file below it.
-e outputs the full information of the time, not the output of the brief information.
-f-u the output file is not sorted.
-G useless.
-I index information for the I node of the output file.
-K represents the size of a file in the form of a byte.
-l lists the file details.
-m output file name horizontally and "," as a separator.
-N replaces the name with the uid,gid of the number.
-O Displays detailed information about the file in addition to the group information.
-p-f a character appended to each file name to indicate the type of the file, "*" indicates an executable normal
file; "/" means directory; "@" means symbolic link; "|" Represents a fifos; "=" represents a set of
Socket (sockets).
-Q replaces non-output characters.
-R sorts the directory backwards.
-S prints the size of the file after each file name.
-T is sorted by time.
-U sorts the time the file was last accessed.
-X output by column, sorted horizontally.
-a displays except for "." and ".." All files outside the file.
-B does not output backup files ending with "~".
-C output By column, sorted vertically.
-G output file for the group information.
-l lists the link file name instead of the file that is linked to.
-N does not limit file length.
-Q Enclose the file name of the output in double quotation marks.
-r lists all the files under subdirectories.
-S is sorted by file size.
-X sorts with the file's extension (the last character after the.).
-11 lines output only one file.

--color=no do not display color file names
The--HELP displays help information on the standard output.
The--version outputs the version information on the standard output and exits.

List subdirectories only
1. Ls-f | grep/$ or alias sub = "Ls-f | grep/$ "(Linux)
2. Ls-l | grep "^d" or Ls-ll | grep "^d" (Solaris)

Calculate the number of files and directories in the current directory
The following command can calculate the number of files and directories in the current directory, respectively:
# ls-l * |grep "^-" |wc-l----to count files
# ls-l * |grep "^d" |wc-l-----to Count dir

Display a list of color catalogs
Open/ETC/BASHRC and add the following line:
Alias ls= "LS--color"
The next time you start bash, you'll be able to display a list of colored catalogs as you would in Slackware, where the meanings of colors are as follows:
1. Blue---Directory
2. Green---executable file
3. Red--Compress files
4. Light blue--linked files
5. Gray--Other files

LS-TL--time-style=full-iso sshd
Ls-ctl--time-style=long-iso

The ls command means that the list displays the name of the file in the current directory. Note that it displays the names of all files and directories except hidden files, without parameters.

1)ls–a displays all files in the current directory, including hidden files

]# Ls–a

. . gnome2. Nautilus

.. . gnome2_private oracle_rpm

. bash_profile. Gtkrc-1.2-gnome2 Tnsnames.ora

. bashrc. Iceauthority Types.h

Note that hidden files are in the file name with "." The file that begins with the (English period).

2)ls–l Display the file and its details.

]# ls–l

Total 5

-rw-r--r--1 root root 1668 Oct 3-anaconda-ks.cfg

Drwxr-xr-x 2 root root 4096 Nov 6 00:04 AA

What does the file details display represent? Take the blue section above as an example.

Total 5 represents the sum of the file sizes in the current directory as 5K(the size of each directory is calculated as 4K )

Drwxr-xr-x The first character has 3 cases: "-" For ordinary files, "D" for the Directory, "l" for the connection file, "b" Represents a device file.

Each of the following 9 characters is a group of 3 , each representing the file owner, the user group where the file owner resides, and other users ' permissions to the file. The 3 characters in each group represent read, write, and execute permissions, which are represented by "-" If none of the permissions are available. The permission to execute has two characters optional "x" for executable, "s" for the socket interface file.

The following number 2 represents the number of directory files in the directory "AA" (This number = number of hidden directories + normal directory). We enter the "AA" directory with the command Ls–al (in order to see the hidden file we add-a parameter)

]# Ls-al

Total 8

Drwxr-xr-x 2 root root 4096 Nov 6 00:04.

Drwxr-x---root root 4096 Nov 6 00:04.

(The 2 in line 3 above indicates that there are 2 subdirectories in the current directory, i.e. . ) and ..

The above line 4 indicates that the previous level of the directory has a. subdirectories. )

The next root represents the owner of the file (directory) as the user root .

The next root represents the group root of the user group to which the file (directory) belongs.

4096 represents the size of the file (in bytes), and the directory size is always 4096 bytes.

6 00:04 represents the modified time of the file (directory).

AA represents the file (directory) in the name.

3) Meaning of the file name color

The default color represents normal files. Example:install.log

Green represents the executable file. Example:rc.news

Red represents the tar package file. Example:vim-7.1.tar.bz2

Blue represents the catalog file. Example:AA

Shuihong represents an image file. Example:sunset.jpg

Cyan represents the linked file. Example:rc4.d (This type of file is equivalent to a shortcut)

Yellow represents the device file. Example:fd0

4) A few more commonly used parameters.

- t sorts by last modified time.

- s sorts by file size. ( Sin uppercase)

- R Sort when in reverse order.

- h increase readability when displaying file size (example:1K 234M 2G)

If this AA is an ordinary file, 2 means that the file has 2 aliases (this file has been created by someone to create a hard-link file)

     

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.