I found the following very useful command on this site:
find -type f -name '*.bz2' -execdir bzgrep "pattern" {} \;
But I don't understand what the {} \; means, can anyone explain?
Thanks
I found the following very useful command on this site:
find -type f -name '*.bz2' -execdir bzgrep "pattern" {} \;
But I don't understand what the {} \; means, can anyone explain?
Thanks
Placeholders in find.
{} denotes 'whatever you found'.
; means end of statement. The \ lets find see it, without the shell interpolating it.
It's often considered sensible to use '{}' (e.g. with single quotes) because the shell will interpolate {}.
-execdir bzgrep "pattern" {} \;
^ ^ ^ ^ ^^
| | | | ||
| | | | |end of the execdir flag
| | | | |
| | | | shell escape
| | | |
| | | 2. argument to bzgrep
| | | {} is substituted with the current filename
| | 1. argument to bzgrep
| |
| the command to run
execute a command
i.e. for each file that find finds, it runs bzgrep where {} is substituted with the file name.
The ; is needed to end the -execdir, so you can e.g. have other flags to the find command after it. the \ is used to escape the ;, since a ; on the shell would otherwise be interpreted as a command separator (as in e.g. the oneline cd /etc ; ls -l). Single quoting the ; would also work, ';' instead of \; - at least in bash.
Or as the manpage sayes:
-exec command ;
Execute command; All following arguments to find are taken to be arguments to the command until an argument consisting of ‘;’ is encountered. The string ‘{}’ is replaced by the current file name being processed
{} is the filename find found ant to substituted in the exec(dir) command.
\; is end of command given after execdir. You need the backslash, since it is not used to show the end of the complete unix command (find).