Reputation: 447
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
Upvotes: 0
Views: 2172
Reputation: 64563
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.
Upvotes: 5
Reputation: 77876
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.
Upvotes: 3