linux中计算管道左侧传递的一类文件总的大小

 

001、

[root@PC1 test]# ls
a.txt  b.txt  c.txt  x.ped  y.ped  z.ped
[root@PC1 test]# du -sh *                                   ## 显示每个文件的大小
30M     a.txt
60M     b.txt
200M    c.txt
20M     x.ped
100M    y.ped
50M     z.ped
[root@PC1 test]# find *.txt | xargs du -ch                 ## 输出文件的大小以及总的大小
30M     a.txt
60M     b.txt
200M    c.txt
290M    total
[root@PC1 test]# find *.txt | xargs du -ch | tail -n 1     ## 输出所有txt文件总的大小
290M    total
[root@PC1 test]# find *.ped | xargs du -ch | tail -n 1     ## 输出所有ped文件总的大小
170M    total

 

002、在指定目录可以不用管道

[root@PC1 test]# ls                        ## 测试文件
a.txt  b.txt  c.txt  x.ped  y.ped  z.ped
[root@PC1 test]# du -sh *                  ## 输出每个文件的大小
30M     a.txt
60M     b.txt
200M    c.txt
20M     x.ped
100M    y.ped
50M     z.ped
[root@PC1 test]# du -ch *.txt
30M     a.txt
60M     b.txt
200M    c.txt
290M    total
[root@PC1 test]# du -ch *.txt | tail -n 1     ## 输出当前目录下所有txt文件总的大小
290M    total
[root@PC1 test]# du -ch *.ped | tail -n 1     ## 输出当前目录下所有ped文件总的大小
170M    total

 。

 

posted @ 2024-02-09 18:37  小鲨鱼2018  阅读(9)  评论(0编辑  收藏  举报