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

Answers


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.


Need Your Help

What is the difference between check and foreign key?

sql oracle

i am quite confused about the difference between a FOREIGN KEY and CHECK constraint - they appear to me to achieve the same result.

Select by AID command is not working

smartcard apdu emv

I want to re-develop new desktop application to read information from EMV smart card and I have logs from previous (working) application.