Linux – What does “{} \;” mean in find (in Linux)

command linefindlinux

Sometimes I see a command like

find . -name * -exec ls -a {} \;

I was asked to execute this.

What does {} \; mean here?

Best Answer

The \; is a ; fed to the program (find) by the \ escape preventing it from be handled by the shell (normally would separate commands). The -exec argument interprets everything as a command up to that inserted ; that ends the -exec stuff. Within the -exec stuff an argument of {} means "insert the file name here". So if the files were "foo" and "bar" it would execute "ls -a foo" then "ls -a bar". So all that meaning only means that because -exec is there.

The -name * part of it might have been meant with * in quotes. If it is not in quotes it will do very unpredictable things because all the file names will be inserted in place of the * you have, and those names might do bad stuff to this command. Leave -name * out for a safer run of this command (but I don't know your intentions to understand why that was in there).

Related Question