-exec argument


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting -exec argument
# 1  
Old 11-09-2008
-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
# 2  
Old 11-09-2008
Typically the syntax for the the exec action in the find utility is
Code:
   -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'.
# 3  
Old 11-12-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies

2. UNIX for Advanced & Expert Users

Error:--test: argument expected--Even though i give an argument.

Hi All, I am running the script VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt result=`cat har1out.mytxt | grep $1' echo $result echo $1 { if then echo pass else echo fail fi (2 Replies)
Discussion started by: harsha85
2 Replies

3. UNIX for Advanced & Expert Users

Using -exec with and without -name

Hi, I need to delete the last N days file using find. I am trying to use find . -mtime -10 -print which lists down required files. but when i use find . -mtime -10 -exec ls -lrt {} \; it gives me all files in the directory including the required files but the required files... (7 Replies)
Discussion started by: v_m1986
7 Replies

4. Shell Programming and Scripting

find: missing argument to `-exec' while redirecting using find in perl

Hi Friends, Please help me to sort out this problem, I am running this in centos o/s and whenever I run this script I am getting "find: missing argument to `-exec' " but when I run the same code in the command line I didn't find any problem. I am using perl script to run this ... (2 Replies)
Discussion started by: ramkumarselvam
2 Replies

5. UNIX for Dummies Questions & Answers

exec

Hi, i don't understand this part of one script exec >> $Log_File 2>&1 (1 Reply)
Discussion started by: messi777
1 Replies

6. Shell Programming and Scripting

Make script that run with argument if not run from configuration file argument

Hello, Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file i.e I am workiing on a script which will run through crontab and the script will chekout the code ,zip and copy to the... (3 Replies)
Discussion started by: rohit22hamirpur
3 Replies

7. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

8. UNIX for Advanced & Expert Users

-exec cp

Hi, on AIX 6.L I want to copy the result of grep -v to test directory then : `hostname`@oracle$ls -l | grep -v RINT -exec cp {} test grep: can't open -exec grep: can't open cp grep: can't open {} test:°`. Can you help me ? Thank you. (3 Replies)
Discussion started by: big123456
3 Replies

9. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

10. UNIX for Dummies Questions & Answers

How to find the last argument in a argument line?

How to find the last argument in a argument line? (4 Replies)
Discussion started by: nehagupta2008
4 Replies
Login or Register to Ask a Question