如何将 xargs 与 find 一起使用?

发布于 2025-01-11 16:17:33 字数 242 浏览 3 评论 0原文

我在磁盘上有大量文件,并尝试使用 find 进行 xargs 以获得更快的输出。 <代码>查找 . -printf '%m %p\n'|sort -nr

如果我写 find 。 -printf '%m %p\n'|xargs -0 -P 0 sort -nr,它给出错误参数行太长。删除 -0 选项会出现其他错误。

I have a large number of files on disk and trying to xargs with find to get faster output.
find . -printf '%m %p\n'|sort -nr

If I write find . -printf '%m %p\n'|xargs -0 -P 0 sort -nr, it gives error argument line is too long. Removing -0 option gives other error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

却一份温柔 2025-01-18 16:17:33
  • 并行命令,例如 xargsGNU parallel
    仅当任务可以分为多个独立的任务时才适用
    作业,例如使用同一命令一次处理多个文件。
    无法将 sort 命令与这些并行命令一起使用。

  • 虽然 sort--parallel 选项,但它可能不适用于
    管道输入。 (未完全评估。)

作为旁注:

  • xargs 的机制是它从以下位置读取项目(大多数情况下是文件名):
    标准输入并通过组合生成单独的命令
    每个项目的参数列表(要执行的命令)。然后你就会
    请参阅语法 .. | xargs .. sort 不正确,因为每个文件名
    作为参数传递给 sort,然后 sort 尝试对内容进行排序
    文件的内容。

  • xargs 的 -0 选项告诉 xargs 输入项是分隔的
    由空字符而不是换行符。输入时很有用
    文件名包含特殊字符,包括换行符。
    为了使用此功能,您需要连贯地处理管道
    以这种方式流:将 -print0 选项添加到 find-z 选项
    排序。否则项目会被错误地连接并会导致
    参数行太长错误。

  • The parallelism commands such as xargs or GNU parallel
    are applicable only if the task can be divided into multiple independent
    jobs e.g. processing multiple files at once with the same command.
    It is not possible to use sort command with these parallelism commands.

  • Although sort has --parallel option, it may not work well for
    piped input. (Not fully evaluated.)

As side notes:

  • The mechanism of xargs is it reads items (filenames in most cases) from
    the standard input and generates individual commands by combining
    the argument list (command to be executed) with each item. Then you'll
    see the syntax .. | xargs .. sort is incorrect because each filename
    is passed to sort as an argument then sort tries to sort the contents
    of the file.

  • The -0 option to xargs tells xargs that input items are delimited
    by a null character instead of a newline. It is useful when the input
    filenames contain special characters including a newline character.
    In order to use this feature, you need to coherently handle the piped
    stream in that way: putting -print0 option to find and -z option
    to sort. Otherwise the items are wrongly concatenated and will cause
    argument line is too long error.

对你再特殊 2025-01-18 16:17:33

建议使用locate命令而不是find命令。

您可能想使用 updatedb 命令更新文件数据库。

此处了解有关 locate 命令的更多信息。

Suggesting to use locate command instead of find command.

You might want to update files database with updatedb command.

Read more about locate command here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文