Linux ls sorting and linuxls sorting

Source: Internet
Author: User

Linux ls sorting and linuxls sorting

To view files in Linux, you sometimes need to sort the files.

The weblogic and Oracle directories are used as examples. By default, they are not sorted by creation time or file size.

[Web @ localhost Oracle] $ ls-l
Total 184
Drwxr-xr-x 6 web weblogic 4096 07-02 coherence_3.7
-Rw ---- 1 web weblogic 426 07-02 domain-registry.xml
Drwxr-xr-x 2 web weblogic 4096 07-11 logs
Drwxr-xr-x 7 web weblogic 36864 07-02 modules
-Rw-r -- 1 web weblogic 849 07-02 ocm. rsp
-Rw-r -- 1 web weblogic 108849 07-02 registry. dat
-Rw-r -- 2 web weblogic 1908 07-02 registry. xml
-Rw-r -- 1 web weblogic 1908 07-11 registry. xml --
Drwxr-x --- 3 web weblogic 4096 07-02 user_projects
Drwxr-xr-x 8 web weblogic 4096 07-02 utils
Drwxr-xr-x 8 web weblogic 4096 07-02 wlserver_10.3

1. sort by creation time. The default value is the last time.

[Web @ localhost Oracle] $ ls-lt
Total 184
Drwxr-xr-x 2 web weblogic 4096 07-11 logs
-Rw-r -- 1 web weblogic 1908 07-11 registry. xml --
-Rw ---- 1 web weblogic 426 07-02 domain-registry.xml
Drwxr-x --- 3 web weblogic 4096 07-02 user_projects
Drwxr-xr-x 6 web weblogic 4096 07-02 coherence_3.7
Drwxr-xr-x 8 web weblogic 4096 07-02 wlserver_10.3
-Rw-r -- 2 web weblogic 1908 07-02 registry. xml
-Rw-r -- 1 web weblogic 108849 07-02 registry. dat
-Rw-r -- 1 web weblogic 849 07-02 ocm. rsp
Drwxr-xr-x 8 web weblogic 4096 07-02 utils
Drwxr-xr-x 7 web weblogic 36864 07-02 modules

2. sort by file size. Note that the parameter is in uppercase S. The default value is before the maximum file sorting.

[Web @ localhost Oracle] $ ls-lS
Total 184
-Rw-r -- 1 web weblogic 108849 07-02 registry. dat
Drwxr-xr-x 7 web weblogic 36864 07-02 modules
Drwxr-xr-x 6 web weblogic 4096 07-02 coherence_3.7
Drwxr-xr-x 2 web weblogic 4096 07-11 logs
Drwxr-x --- 3 web weblogic 4096 07-02 user_projects
Drwxr-xr-x 8 web weblogic 4096 07-02 utils
Drwxr-xr-x 8 web weblogic 4096 07-02 wlserver_10.3
-Rw-r -- 2 web weblogic 1908 07-02 registry. xml
-Rw-r -- 1 web weblogic 1908 07-11 registry. xml --
-Rw-r -- 1 web weblogic 849 07-02 ocm. rsp
-Rw ---- 1 web weblogic 426 07-02 domain-registry.xml

Column 5th is the file size, and the largest file is registry. dat.

3. Reverse Order (inverted), using the-r parameter

[Web @ localhost Oracle] $ ls-lSr
Total 184
-Rw ---- 1 web weblogic 426 07-02 domain-registry.xml
-Rw-r -- 1 web weblogic 849 07-02 ocm. rsp
-Rw-r -- 1 web weblogic 1908 07-11 registry. xml --
-Rw-r -- 2 web weblogic 1908 07-02 registry. xml
Drwxr-xr-x 8 web weblogic 4096 07-02 wlserver_10.3
Drwxr-xr-x 8 web weblogic 4096 07-02 utils
Drwxr-x --- 3 web weblogic 4096 07-02 user_projects
Drwxr-xr-x 2 web weblogic 4096 07-11 logs
Drwxr-xr-x 6 web weblogic 4096 07-02 coherence_3.7
Drwxr-xr-x 7 web weblogic 36864 07-02 modules
-Rw-r -- 1 web weblogic 108849 07-02 registry. dat


Note: Column 2nd indicatesNumber of hard links or subdirectories of FilesThe number of hard links for files and the number of subdirectories for folders


In linux, the ls-t command is used to sort the files based on the change time, but how can we sort the latest documents first, not later?

Ls-tr

-R sorts directories in reverse order.

In linux, how does one sort by file type under the ls command?

No sort by type
Only by file size
Ls-S

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.