命令ls按文件大小来排序

有时候我们想按照文件的大小来排序,一直忘记,为此特记下如下操作

按照文件所占的大小从大开始排列
# ls -lS
total 64
-rw-r--r--  1 root root 55895 Nov  5 22:01 all.log
-rw-r--r--  1 root root  6356 Nov  5 22:35 all.tar.gz
drwx------. 3 root root    17 Oct 25 16:22 systemd-private-27df22a4d93a4d489d3ac1494f38a459-httpd.service-MZGAp4
drwx------. 3 root root    17 Oct 25 16:07 systemd-private-27df22a4d93a4d489d3ac1494f38a459-mariadb.service-WL8NGJ
drwx------  3 root root    17 Nov  5 08:50 systemd-private-5cba973031874b1cac7c3ed4293a8422-httpd.service-CqimqR
drwx------  3 root root    17 Nov  5 08:50 systemd-private-5cba973031874b1cac7c3ed4293a8422-mariadb.service-sED24g
drwx------. 2 root root     6 Oct 21 11:58 vmware-root
drwx------. 2 root root     6 Oct 25 15:56 vmware-root_15442-2958697629
drwx------. 2 root root     6 Oct 25 15:56 vmware-root_15461-4256151916
drwx------  2 root root     6 Nov  5 08:50 vmware-root_557-4282236562
drwx------  2 root root     6 Nov  4 19:39 vmware-root_561-4290035465
drwx------  2 root root     6 Oct 28 14:10 vmware-root_562-2965513557

#按文件的大小从小到大来排列
# ls -lSr
total 64
drwx------  2 root root     6 Oct 28 14:10 vmware-root_562-2965513557
drwx------  2 root root     6 Nov  4 19:39 vmware-root_561-4290035465
drwx------  2 root root     6 Nov  5 08:50 vmware-root_557-4282236562
drwx------. 2 root root     6 Oct 25 15:56 vmware-root_15461-4256151916
drwx------. 2 root root     6 Oct 25 15:56 vmware-root_15442-2958697629
drwx------. 2 root root     6 Oct 21 11:58 vmware-root
drwx------  3 root root    17 Nov  5 08:50 systemd-private-5cba973031874b1cac7c3ed4293a8422-mariadb.service-sED24g
drwx------  3 root root    17 Nov  5 08:50 systemd-private-5cba973031874b1cac7c3ed4293a8422-httpd.service-CqimqR
drwx------. 3 root root    17 Oct 25 16:07 systemd-private-27df22a4d93a4d489d3ac1494f38a459-mariadb.service-WL8NGJ
drwx------. 3 root root    17 Oct 25 16:22 systemd-private-27df22a4d93a4d489d3ac1494f38a459-httpd.service-MZGAp4
-rw-r--r--  1 root root  6356 Nov  5 22:35 all.tar.gz
-rw-r--r--  1 root root 55895 Nov  5 22:01 all.log

同时这里也记录一下按修改时间来排列

#按文件修改的日期从新到旧来排序 
# ls -lt
total 64
-rw-r--r--  1 root root  6356 Nov  5 22:35 all.tar.gz
-rw-r--r--  1 root root 55895 Nov  5 22:01 all.log
drwx------  3 root root    17 Nov  5 08:50 systemd-private-5cba973031874b1cac7c3ed4293a8422-mariadb.service-sED24g
drwx------  3 root root    17 Nov  5 08:50 systemd-private-5cba973031874b1cac7c3ed4293a8422-httpd.service-CqimqR
drwx------  2 root root     6 Nov  5 08:50 vmware-root_557-4282236562
drwx------  2 root root     6 Nov  4 19:39 vmware-root_561-4290035465
drwx------  2 root root     6 Oct 28 14:10 vmware-root_562-2965513557
drwx------. 3 root root    17 Oct 25 16:22 systemd-private-27df22a4d93a4d489d3ac1494f38a459-httpd.service-MZGAp4
drwx------. 3 root root    17 Oct 25 16:07 systemd-private-27df22a4d93a4d489d3ac1494f38a459-mariadb.service-WL8NGJ
drwx------. 2 root root     6 Oct 25 15:56 vmware-root_15461-4256151916
drwx------. 2 root root     6 Oct 25 15:56 vmware-root_15442-2958697629
drwx------. 2 root root     6 Oct 21 11:58 vmware-root

##按文件修改的日期从旧到新来排序 ,-r就是倒序
# ls -lrt
total 64
drwx------. 2 root root     6 Oct 21 11:58 vmware-root
drwx------. 2 root root     6 Oct 25 15:56 vmware-root_15442-2958697629
drwx------. 2 root root     6 Oct 25 15:56 vmware-root_15461-4256151916
drwx------. 3 root root    17 Oct 25 16:07 systemd-private-27df22a4d93a4d489d3ac1494f38a459-mariadb.service-WL8NGJ
drwx------. 3 root root    17 Oct 25 16:22 systemd-private-27df22a4d93a4d489d3ac1494f38a459-httpd.service-MZGAp4
drwx------  2 root root     6 Oct 28 14:10 vmware-root_562-2965513557
drwx------  2 root root     6 Nov  4 19:39 vmware-root_561-4290035465
drwx------  2 root root     6 Nov  5 08:50 vmware-root_557-4282236562
drwx------  3 root root    17 Nov  5 08:50 systemd-private-5cba973031874b1cac7c3ed4293a8422-httpd.service-CqimqR
drwx------  3 root root    17 Nov  5 08:50 systemd-private-5cba973031874b1cac7c3ed4293a8422-mariadb.service-sED24g
-rw-r--r--  1 root root 55895 Nov  5 22:01 all.log
-rw-r--r--  1 root root  6356 Nov  5 22:35 all.tar.gz
#统计此目录下的文件夹的数量
# ls -l|grep ^d|wc -l
10
#统计此目录下的文件的数量
# ls -l|grep ^-|wc -l
2

有时候,这些ls命令的用处体现在工作中,有时候忘记,到处找,现在记录下来,方便查看

posted @ 2019-11-05 22:51  wang509020  阅读(1858)  评论(0编辑  收藏  举报