linux 中实现将指定目录中的所有文件从大到小或者从小到大排列

 

001、

[root@pc1 test]# ls                  ## 测试文件
a.txt  b.txt  c.txt  d.txt  e.txt
[root@pc1 test]# ll -h
total 250M
-rw-r--r--. 1 root root 100M Oct 28 16:06 a.txt
-rw-r--r--. 1 root root  10M Oct 28 16:06 b.txt
-rw-r--r--. 1 root root  50M Oct 28 16:06 c.txt
-rw-r--r--. 1 root root  30M Oct 28 16:06 d.txt
-rw-r--r--. 1 root root  60M Oct 28 16:06 e.txt
[root@pc1 test]# ls -S | xargs -n 1 du -sh     ## 从大到小的顺序排列
100M    a.txt
60M     e.txt
50M     c.txt
30M     d.txt
10M     b.txt
[root@pc1 test]# ls -S | xargs -n 1 du -sh | tac     ## 从小到大的顺序排列
10M     b.txt
30M     d.txt
50M     c.txt
60M     e.txt
100M    a.txt
[root@pc1 test]# ls -S          ## 从大到小排列
a.txt  e.txt  c.txt  d.txt  b.txt

 

posted @ 2022-10-28 16:15  小鲨鱼2018  阅读(132)  评论(0编辑  收藏  举报