linux 中 查找指定目录下的最大文件及最小文件

 

001、

复制代码
[root@pc1 test01]# ls                              ## 测试文件
a.txt  test01  test02  test03
[root@pc1 test01]# find ./ -type f -exec ls -l {} \;         ## 列出文件大小
-rw-r--r--. 1 root root 21 Sep 11 10:57 ./test01/a.txt
-rw-r--r--. 1 root root 104857600 Sep 11 11:00 ./test02/test01/b.txt
-rw-r--r--. 1 root root 20971520 Sep 11 11:01 ./test02/test01/c.txt
-rw-r--r--. 1 root root 48894 Sep 11 10:58 ./test03/test01/a.txt
-rw-r--r--. 1 root root 108894 Sep 11 10:58 ./test03/test01/b.txt
-rw-r--r--. 1 root root 588895 Sep 11 10:58 ./test03/test01/test01/a.txt
-rw-r--r--. 1 root root 1288895 Sep 11 10:58 ./test03/test01/test01/c.txt
-rw-r--r--. 1 root root 3145728 Sep 11 11:00 ./a.txt
[root@pc1 test01]# find ./ -type f -exec ls -l {} +
-rw-r--r--. 1 root root   3145728 Sep 11 11:00 ./a.txt
-rw-r--r--. 1 root root        21 Sep 11 10:57 ./test01/a.txt
-rw-r--r--. 1 root root 104857600 Sep 11 11:00 ./test02/test01/b.txt
-rw-r--r--. 1 root root  20971520 Sep 11 11:01 ./test02/test01/c.txt
-rw-r--r--. 1 root root     48894 Sep 11 10:58 ./test03/test01/a.txt
-rw-r--r--. 1 root root    108894 Sep 11 10:58 ./test03/test01/b.txt
-rw-r--r--. 1 root root    588895 Sep 11 10:58 ./test03/test01/test01/a.txt
-rw-r--r--. 1 root root   1288895 Sep 11 10:58 ./test03/test01/test01/c.txt
复制代码

 

002、

复制代码
[root@pc1 test01]# ls
a.txt  test01  test02  test03
[root@pc1 test01]# find ./ -type f -exec ls -l {} +         ## 借助find列出文件大小
-rw-r--r--. 1 root root   3145728 Sep 11 11:00 ./a.txt
-rw-r--r--. 1 root root        21 Sep 11 10:57 ./test01/a.txt
-rw-r--r--. 1 root root 104857600 Sep 11 11:00 ./test02/test01/b.txt
-rw-r--r--. 1 root root  20971520 Sep 11 11:01 ./test02/test01/c.txt
-rw-r--r--. 1 root root     48894 Sep 11 10:58 ./test03/test01/a.txt
-rw-r--r--. 1 root root    108894 Sep 11 10:58 ./test03/test01/b.txt
-rw-r--r--. 1 root root    588895 Sep 11 10:58 ./test03/test01/test01/a.txt
-rw-r--r--. 1 root root   1288895 Sep 11 10:58 ./test03/test01/test01/c.txt
[root@pc1 test01]# find ./ -type f -exec ls -l {} + | awk '{print $5, $NF}'   ## 输出文件大小和文件名
3145728 ./a.txt
21 ./test01/a.txt
104857600 ./test02/test01/b.txt
20971520 ./test02/test01/c.txt
48894 ./test03/test01/a.txt
108894 ./test03/test01/b.txt
588895 ./test03/test01/test01/a.txt
1288895 ./test03/test01/test01/c.txt
[root@pc1 test01]# find ./ -type f -exec ls -l {} + | awk '{print $5, $NF}' | sort -n | tail -n 1  ## 输出文件
104857600 ./test02/test01/b.txt
复制代码

 

 

003、找出指定目录下的最小文件

复制代码
[root@pc1 test01]# ls
a.txt  test01  test02  test03
[root@pc1 test01]# find ./ -type f -exec ls -l {} \;
-rw-r--r--. 1 root root 21 Sep 11 10:57 ./test01/a.txt
-rw-r--r--. 1 root root 104857600 Sep 11 11:00 ./test02/test01/b.txt
-rw-r--r--. 1 root root 20971520 Sep 11 11:01 ./test02/test01/c.txt
-rw-r--r--. 1 root root 48894 Sep 11 10:58 ./test03/test01/a.txt
-rw-r--r--. 1 root root 108894 Sep 11 10:58 ./test03/test01/b.txt
-rw-r--r--. 1 root root 588895 Sep 11 10:58 ./test03/test01/test01/a.txt
-rw-r--r--. 1 root root 1288895 Sep 11 10:58 ./test03/test01/test01/c.txt
-rw-r--r--. 1 root root 3145728 Sep 11 11:00 ./a.txt
[root@pc1 test01]# find ./ -type f -exec ls -l {} \; | awk '{print $5,$NF}'    ## 列出所有文件及其大小
21 ./test01/a.txt
104857600 ./test02/test01/b.txt
20971520 ./test02/test01/c.txt
48894 ./test03/test01/a.txt
108894 ./test03/test01/b.txt
588895 ./test03/test01/test01/a.txt
1288895 ./test03/test01/test01/c.txt
3145728 ./a.txt                                                             ## 取出最小文件
[root@pc1 test01]# find ./ -type f -exec ls -l {} \; | awk '{print $5,$NF}' | sort -n | head -n 1
21 ./test01/a.txt
复制代码

 。

 

posted @   小鲨鱼2018  阅读(115)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-09-11 vmware 安装manjaro虚拟机全过程
2022-09-11 linux 中 生成文件的sha1码
2022-09-11 R语言中取消par函数对上一步绘图的设置(绘图默认)
2022-09-11 R语言中plot绘图指定绘图的背景色、前景色
2022-09-11 R语言绘图调整绘图图形的背景色
2022-09-11 linux中如何实现vmware虚拟机与本地共享文件夹
点击右上角即可分享
微信分享提示