限制查找结果的数量,head 不工作

limit number of results of find, head is not working

除了 head 之外,还有什么可以将我的 find 命令的结果限制为只有 50 个? find -L $line | head 50 | -exec ls {} > $a$(basename $line) \;

上面的东西不工作。我想限制我的输出,因为它需要很长时间来完成任务并降低我的计算机性能。 :<

xargs 代替 exec 怎么样?

检查一下,效果不错。 find / -type f | head -n5 | tr '\n' '[=12=]' | xargs -0 ls

您的情况: find -L $line | head -n50 | tr '\n' '[=13=]' | xargs -0 ls > $a$(basename $line)

要使用 <newline> 处理文件名,最好使用空分隔符:

find -L "$line" -print0 | head -z -n 50 | xargs -0 ls > "$a$(basename "$line")"