Linux命令 , 如何按大于x的大小查找文件?

3 人关注

我试图找到尺寸大于 "x "的文件,例如:32字节。

但我在 ls --help 中发现的只是 ls -S 。,只是按大小排序,没有满足我的要求。

我是Linux的新手,我试过谷歌,但我不知道我应该用什么关键词来寻找答案,谁能给我建议,谢谢!

3 个评论
你的问题不是关于编程的,而是关于Linux命令的,最好是在 服务器故障.com .如果你想问一些关于shell脚本的问题,请先阅读这个。 stackoverflow.com/help/mcve
谢谢你,我下次会这样做
linux
shell
DumDumGenius
DumDumGenius
发布于 2016-02-17
4 个回答
rslemos
rslemos
发布于 2022-04-27
已采纳
0 人赞同

Try to use the power of find utility.

查找大于32字节的文件。

find -size +32c

当然,你也可以要求小于32字节的文件。

find -size -32c

而文件的精确32字节。

find -size 32c

For files with 32 bytes or more:

find -size 32c -o -size +32c

或不小于32字节(与上述相同,但以另一种方式书写)。

find ! -size -32c

以及32和64字节之间的文件。

find -size +32c -size -64c

而且你还可以应用其他常见的后缀。

find -size +32k -size -64M
    
如果你遇到 find: illegal option -- i 的错误,请在 find 后指定要搜索的文件夹。添加一个点来查找当前文件夹中的文件。 find . -size +32k -size -64M
Ludwig
Ludwig
发布于 2022-04-27
0 人赞同

Try this:

find . -size +32c -ls

你可以为你想要的尺寸改变32。在这种情况下,我使用了你的例子。

Don't forget the c suffix. Otherwise find will count 512-byte blocks.
你们两个人给我的两个答案都很好 :D 但是我想我会给@rslemos最好的答案标签,因为他 "比我早1分钟",但还是要感谢你们!
很高兴能帮上忙,:)
avivamg
avivamg
发布于 2022-04-27
0 人赞同

解释 : Use unix command find Using -size oprator

查找工具对列出的每个路径递归目录树,根据目录树中的每个文件评估一个表达式(由 "基数 "和 "操作数 "组成)。

Solution: 根据文件规定

-size n[ckMGTP]
             True if the file's size, rounded up, in 512-byte blocks is n.  If n is fol-
             lowed by a c, than the primary is true if the file's size is n bytes (charac-
             ters).  Similarly if n is followed by a scale indicator than the file's size
             is compared to n scaled as:
             k       kilobytes (1024 bytes)
             M       megabytes (1024 kilobytes)
             G       gigabytes (1024 megabytes)
             T       terabytes (1024 gigabytes)
             P       petabytes (1024 terabytes)

使用方法。执行find操作,带有-size标志和阈值测量参数:大于(+)/小于(-),数量(n)和测量类型(k/M/G/T/P)。

公式: find <path> -size [+/-]<Number><Measurement>

1.大于- 查找我当前目录(.)中大于500KB的所有文件

find . -size +500k 

2.少于- 在我的当前目录(.)中查找所有小于100兆字节的文件。

find . -size -100M

3.范围- 在我的当前目录(.)中查找大于500千字节小于100兆字节的特定文件(测试)(500k-1000k)

find . -name "test" -size +500k -size -100M

4.Complex 范围 with Regex找到所有文件系统(根/)中大于1GB且在本月创建的所有.mkv文件,并提出它们的信息。

find / -name "*.mkv" -size +1G -type f -ctime -4w | xargs ls -la