Home  >  Q&A  >  body text

linux - find命令的-exec选项为何不能用管道命令代替?

这里有个命令

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

我想这样写

find / -perm +7000 | ls -l

发现不行,为什么?

高洛峰高洛峰2742 days ago774

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 12:00:05

    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

    reply
    0
  • Cancelreply