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