简体   繁体   中英

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 {} \\; 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.

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:

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

So, ultimately you will get all the myFiles accompanied with ls command result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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