据我了解,以下含义应完全相同:
ls -1 | xargs file {}
ls -1 | xargs -I{} file {}
如果未指定-I选项,则默认为-I {}。
我想列出当前目录中的所有文件,并对每个文件运行file命令。有些名称中有空格。但是,我注意到了差异。见下文:
$ ls -1
Hello World
$ ls -1 | xargs file {}
{}: ERROR: cannot open `{}' (No such file or directory)
Hello: ERROR: cannot open `Hello' (No such file or directory)
World: ERROR: cannot open `World' (No such file or directory)
$ ls -1 | xargs -I{} file {}
Hello World: directory
显式指定-I {}时,文件名中的空格将按预期方式处理。
3
“如果未指定-I选项,则默认为-I {}” –这是错误的,至少对于GNU xargs而言是这样。
—
jjlin
我理解我的错误。我应该指定
—
foresightyj
xargs file或xargs -I{} file {}。不应该这样xargs file {}。我猜想在显式指定-I {}时,bash会将其视为file "Hello World"。如果没有-I {},则将其视为file Hello World。
(1)此讨论与shell(bash)无关。(2)最好知道的
—
斯科特,
-1选项ls,但是当输出ls是文件或管道时,默认情况下它处于启用状态,因此在这里不需要它。(3)您-I对已弃用-i(小写I)选项感到困惑。 -ifoo等同于-Ifoo,但普通-i等同于-I{}。但是使用-I{}。(4)如果您确实想做自己想做的事情,为什么不随便说呢file *?
@Scott我的初衷是写`find。名称“ * .mov” | xargs -I {}文件{}`可以递归查找所有mov文件并
—
foresightyj
file在其上运行。但是我想出了一个使用的简单示例ls。你是对的。为此,file *是最好的。
找到了
—
Cristian Ciupitu
-exec。