分页: 1 / 1

[问题]请教 find ~ -name "crontab" | xargs ls -al 命令的奇怪问题

发表于 : 2007-12-12 14:06
JIAN
我在X终端下执行以下命令
find ~ -name "crontab" | xargs ls -al
home目录下是没有crontab这个文件的,但是仍然会执行xargs后面的命令
请问这是为什么?
用find ~ -name "crontab" -exec ls -al {} \;
是不会执行后面exec的命令的

发表于 : 2007-12-12 15:04
iblicf
find ~ -name "crontab" | xargs ls -al

xargs 的 stdin 接收 find 的 stdout ,,, 无论 find 找没找到结果,xargs 都会执行 ..

find ~ -name "crontab" -exec ls -al {} \;

-exec 是 find 命令的参数,find 找到结果才会调用 -exec fork 一个 "ls -al" 进程 ,{} 作为参数替换 ..

发表于 : 2007-12-12 15:11
eexpress
-exec拉。 还有特殊情况使用{}+

发表于 : 2007-12-12 15:29
JIAN
谢谢