linux sorted by file size and sorted by time to view the file command

1. View files by file size

a descending order:. ls -lsh

moudaen@morton:~$ ls -lsh
total 20M
20M -rw-r–r– 1 moudaen 65536 20M Nov 11 17:44 Gender.war
4.0K drwxr-xr-x 2 moudaen 65536 4.0K Nov 11 17:44 test
8.0K -rw-r–r– 1 moudaen 65536 5.2K Nov 11 11:44 MyApp.java

Command interpreter:

Ls behind the three parameters:

-l shows a display in long format, i.e. as described above are listed in the file format details.

-s represents sort in descending order by default.

-H indicate the size of the file size into our habit of M, K and other units

b ascending order:. ls -lrsh

Command interpreter:

About -l, -s, -h meaning as above

-r Indicates reverse mean, this is reverse order reverse order, the default is descending order, plus the reverse is the case -r on the ascending.

moudaen@morton:~$ ls -lrsh
total 20M
8.0K -rw-r–r– 1 moudaen 65536 5.2K Nov 11 11:44 MyApp.java
4.0K drwxr-xr-x 2 moudaen 65536 4.0K Nov 11 17:44 test
20M -rw-r–r– 1 moudaen 65536 20M Nov 11 17:44 Gender.war

2. View files by file modification time

a. descending, that recent changes ls -lt

moudaen@morton:~$ ls -lt
total 19836
-rw-r–r– 1 moudaen 65536 7 Nov 13 15:30 test.txt
-rw-r–r– 1 moudaen 65536 20267062 Nov 11 17:44 Gender.war
drwxr-xr-x 2 moudaen 65536 4096 Nov 11 17:44 test
-rw-r–r– 1 moudaen 65536 5258 Nov 11 11:44 MyApp.java

Command interpreter:

In fact, we use man ls -t command you can see the usage of the ls command with the parameter, -t sort by modification time, newest first push-modified sort files, the default is the most recently modified first.

b. Then we want to reverse ascending just under it, so the -r switch

ls -lrt

moudaen@morton:~$ ls -lrt
total 19836
-rw-r–r– 1 moudaen 65536 5258 Nov 11 11:44 MyApp.java
drwxr-xr-x 2 moudaen 65536 4096 Nov 11 17:44 test
-rw-r–r– 1 moudaen 65536 20267062 Nov 11 17:44 Gender.war
-rw-r–r– 1 moudaen 65536 7 Nov 13 15:30 test.txt

发布了218 篇原创文章 · 获赞 165 · 访问量 103万+

Guess you like

Origin blog.csdn.net/x_i_y_u_e/article/details/81476210