3

Sometimes I see a command like

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

I was asked to execute this.

What does {} \; mean here?

  • This question is similar, does it help you? – Jon Aug 29 '13 at 18:42
  • Please mention which operating system you are using. There are find commands for Unix, Linux, OSX, Windows and probably everything else. That looks like *nix but I can't be sure. – terdon Aug 29 '13 at 19:04
  • Yes i found the good answers here askubuntu.com/questions/85709/… – codeofnode Aug 29 '13 at 19:19
5

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.