2012-06-17 57 views
0

以下内容的含义是什么?在linux中查找命令

find myDirectory -name myFile -exec ls \-ln {} \; 

我看着here但并没有确切地理解

-exec command True if the executed command returns a zero value as exit status. The end of command must be punctuated by an escaped semicolon. A command argument {} is replaced by the current path name. 

这部分-exec ls \-ln {} \;是我也不清楚。

问候

+2

题外话。但请尝试一个适当的手册页:例如http://unixhelp.ed.ac.uk/CGI/man-cgi?find。甚至维基百科:http://en.wikipedia.org/wiki/Find_(Unix)#Execute_an_action。 –

回答

5

这意味着:在当前目录及其所有子目录中查找名称为myFile的所有文件,并找到所有找到的文件,并使用该文件的名称运行ls -ln

例如:

$ mkdir a 
$ touch myFile a/myFile 
$ find -name myFile -exec ls -ln {} \; 
-rw-r--r-- 1 1000 1000 0 Jun 17 13:07 ./myFile 
-rw-r--r-- 1 1000 1000 0 Jun 17 13:07 ./a/myFile 

在这种情况下find将运行ls两次:

ls -ln ./myFile 
ls -ln ./a/myFile 

每次将扩大{}为找到的文件的全名。

此外,我必须补充说,在这种情况下,您需要在-ln之前使用反斜杠。是的,你可以使用它,但这里绝对没用。

3
find myDirectory -name myFile -exec ls \-ln {} \; 

它说,找到目录myDirectorymyFile,一旦所有的文件被找到,那么执行文件列表的命令,那就是在LINIX ls与命令选项上找到的文件-l-n

因此,最终你会得到所有的myFiles伴随着ls命令的结果。

+0

exec在每个找到的文件上执行该命令,而不是组 – fvu

+0

@fvu,这只是一个解释...我的意思是同样的事情。 – Rahul

+0

只是指出,解释可能会导致误解 - 你的编辑使它更清晰,+1 – fvu