0

以下是什么意思?

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

我看过这里但不完全理解

-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 {} \;我不清楚。

问候

4

2 回答 2

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 之前使用反斜杠。是的,你可以使用它,但在这里绝对没用。

于 2012-06-17T11:09:51.437 回答
3
find myDirectory -name myFile -exec ls \-ln {} \;

它说myFile在目录中查找myDirectory,一旦找到所有文件,然后执行文件列表命令,即在 linix 中ls带有命令选项 -l-n找到的文件。

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

于 2012-06-17T11:09:30.753 回答