在 Linux 目录中搜索确切数量的文件

searching an exact number of files in a Linux directory

我想使用这个

递归计算 Linux 目录中的文件
find DIR_NAME -type f | wc -l

我的问题是,如果在该文件夹中找到超过 1000 个文件,如何停止上面的查找执行? 可能吗 ?还是我需要等待找到执行?

您可以使用head来限制查找返回的行数:

find DIR_NAME -type f | head -n 1000 | wc -l

head 程序将在第一千行后退出,find 将收到 SIGPIPE 并退出。