Sometimes I see a command like
find . -name * -exec ls -a {} \;
I was asked to execute this.
What does {} \;
mean here?
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).
-name *
argument, If you aren't sure if you need quotes around your *
, then you should add double, or single quotes. So it should be -name "*"
. To make it easier to see what happens when you don't use quotes type this command: set +x; find . -name * -print
and you'll see that what is actually passed to the find command is find . -name file1 file2 file3 file4 -print
(if you had file1, file2, file3, and file4
) in your current directory.
find
commands for Unix, Linux, OSX, Windows and probably everything else. That looks like *nix but I can't be sure.