-exec argument

Hi All ,

I need to know why we use '{}' after using the -exec argument .

For example why we have use '{}' with bzip2 command and not used it with the echo command in the bellow command

find . -name "$file" -mtime +5 -exec echo "* Compressing File : $file " \; -exec bzip2 -z '{}' \;

and what the \ mean ?

thanks

Typically the syntax for the the exec action in the find utility is

   -exec command [args ...] [{}] ;

This says to find that it should execute 'command' on each matching file. Any following arguments are taken to be arguments to "command" until an argument consisting of `;' is encountered.

Typically ';' needs to be guarded by '\' to prevent the shell thinking that it has reached the end of arguments for the find utility rather than at the end of arguments to the exec action.

The optional string '{} ' is used to tell find to replace '{}' by the name of the current file being processed i.e. pass the filename as an argument to 'command'.

Thanks my freind for your replay :
but let me sumrrize the following :

1- we use -exec to execute and shell command for the files theat matches the criteria of the find command .

2- we use ; after the -exec to mention that it's the end of this command and we guard it withe the \ in order to prevent the shell interpreter from terminiating the find command
by thinking it's the end of find command instead of the -exec.

3- we use '{}' to replase the file name which is passed as a pram.