linux系统中统计指定文件类型的文件大小

 

1、测试数据

[root@centos7 test2]# ls
a.map  a.ped  b.map  b.ped  c.ped  result.map
[root@centos7 test2]# ll -h
total 1.4G
-rw-r--r--. 1 root root  41M Apr 15 09:47 a.map
-rw-r--r--. 1 root root 204M Apr 15 09:47 a.ped
-rw-r--r--. 1 root root  61M Apr 15 09:48 b.map
-rw-r--r--. 1 root root 407M Apr 15 09:47 b.ped
-rw-r--r--. 1 root root 611M Apr 15 09:47 c.ped
-rw-r--r--. 1 root root  21M Apr 15 09:44 result.map

 

2、统计map文件的大小

[root@centos7 test2]# ll -h *.map
-rw-r--r--. 1 root root 41M Apr 15 09:47 a.map
-rw-r--r--. 1 root root 61M Apr 15 09:48 b.map
-rw-r--r--. 1 root root 21M Apr 15 09:44 result.map

 

简化

[root@centos7 test2]# ls *.map | xargs du -h
41M     a.map
61M     b.map
21M     result.map

 

排序,从大致小

[root@centos7 test2]# ls -S *.map | xargs du -h
61M     b.map
41M     a.map
21M     result.map

 

排序,从小至大

[root@centos7 test2]# ls -S *.map | tac | xargs du -h
21M     result.map
41M     a.map
61M     b.map

 

计算某一类文件总的大小

[root@centos7 test]# ll -h
total 413M
-rw-r--r--. 1 root root  76M Apr 16 08:34 b.map
-rw-r--r--. 1 root root 151M Apr 16 08:34 c.ped
-rw-r--r--. 1 root root  30M Apr 16 08:34 d.map
-rw-r--r--. 1 root root 6.6M Apr 16 08:35 e.ped
-rw-r--r--. 1 root root 100M Apr 16 08:35 x.map
-rw-r--r--. 1 root root  51M Apr 16 08:35 y.ped
[root@centos7 test]# ls *.map | xargs du -ch
76M     b.map
30M     d.map
100M    x.map
205M    total
[root@centos7 test]# ls *.map | xargs du -ch | tail -n 1
205M    total

 

posted @ 2021-04-15 09:57  小鲨鱼2018  阅读(1239)  评论(0编辑  收藏  举报