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 @ 2023-09-11 11:18  小鲨鱼2018  阅读(96)  评论(0编辑  收藏  举报