用于solaris的`solaris + xargs命令

yae*_*ael 2 linux solaris find xargs exec

命令

find /tmp -name 'core*' -type f -print0 | xargs -0
Run Code Online (Sandbox Code Playgroud)

在 Linux 上工作正常,但xargs -0在 Solaris 上选项不合法

xargsSolaris 10的等效选项 ( ? )是什么

第二个问题:
是否可以更改语法:

find /tmp -name 'core*' -type f -print0 | xargs -0
Run Code Online (Sandbox Code Playgroud)

因此它将适用于操作系统 - Linux 和 Solaris

我在我的solaris 10机器上尝试:

find /tmp -name 'core*' -type f -print0 | xargs -0
xargs: illegal option -- 0
xargs: Usage: xargs: [-t] [-p] [-e[eofstr]] [-E eofstr] [-I replstr] [-i[replstr]] [-L #] [-l[#]] [-n # [-x]] [-s size] [cmd [args ...]]
Run Code Online (Sandbox Code Playgroud)

jor*_*anm 5

无论是-print0寻找和-0给xargs的不是POSIX,并且可能无法使用无处不在。该+命令终止符-exec是POSIX的一部分,将完成相同的任务。这是一个例子。

find /tmp -type f -name 'core*' -exec rm {} +
Run Code Online (Sandbox Code Playgroud)

  • @yael 这就是 `+` 终止符所做的。 (3认同)