linux - find命令的-exec选项为何不能用管道命令代替?
高洛峰
高洛峰 2017-04-17 11:58:05
0
1
815

这里有个命令

find / -perm +7000 -exec ls -l {} \;

我想这样写

find / -perm +7000 | ls -l

发现不行,为什么?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
伊谢尔伦

First of all, what is a pipeline, that is, the standard output of the previous program is used as the standard input of the following program.

The

find command will print out the found files on the terminal (standard output); if ls -l operates as 在 终端等待输入, 用户输入一个文件名, 打印出文件信息. then this is what you want. But ls -l will not actually read the terminal.

xargs converts the standard output of the previous program into the command line parameters of the next program.
For example, if find / -perm +7000 returns /tmp/1.txt, then the last command in find / -perm +7000 | xargs ls -l is actually ls -l /tmp/1.txt

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template