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
。
分类:
linux shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!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虚拟机与本地共享文件夹