简体   繁体   English

在Linux中查找命令

[英]Find command in linux

What does the following means ? 以下是什么意思?

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

I've looked here but didn't understand exactly 我看过这里,但听不清楚

-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.

This part -exec ls \\-ln {} \\; 这部分-exec ls \\-ln {} \\; is not clear to me . 我不清楚。

Regards 问候

That means: find all files with a name myFile in the current directory and all its subdirectories and for every file that was found run ls -ln with the name of the file. 这意味着:在当前目录及其所有子目录中找到所有名称为myFile的文件,并为找到的每个文件运行带有文件名的ls -ln

For example: 例如:

$ 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

In this case find will run ls twice: 在这种情况下, find将运行ls两次:

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

Every time it will expand {} as the fullname of the found file. 每次它将扩展{}作为找到的文件的全名。

Also I must add that you need the backslash before -ln in this case. 另外,在这种情况下,我还必须添加-ln前需要反斜杠。 Yes, you can use it, but it is absolutely useless here. 是的,您可以使用它,但是在这里绝对没有用。

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

It says find myFile in directory myDirectory and once all the files are found then execute the file listing command, that is in linix ls with command options -l and -n on the files found. 它说在目录myDirectory找到myFile ,一旦找到所有文件,然后执行文件列表命令,即在linix ls ,对找到的文件使用命令选项-l-n

So, ultimately you will get all the myFiles accompanied with ls command result. 因此,最终您将获得所有myFiles以及ls命令结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM