What does the '\' in find -exec command


Trivia Category: Science: Mathematics
Difficulty: Hard
In Topology, the complement of an open set is a closed set.
True or False?

 
Thread Tools Search this Thread
# 1  
What does the '\' in find -exec command

Hi,
I have two scripts that remove files. One works fine and is coded
Code:
find -name "syst*" -mtime +1 -exec rm {} \;

The other is almost the same - only thing missing is the '\'. On that script though I keep getting:
rm syst1202.file ?

etc

Does the \ make that difference or is it a permissions problem

Cheers


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 08-06-2012 at 09:11 AM.. Reason: code tags
# 2  
The exec action needs to be terminated by a ; which in turn may need to be escaped (e.g. by a leading \) form expansion by the shell. Excerpt from fnd's man page:
Quote:
-exec command ;
Execute command; true if 0 status is returned. 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 everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a `\') or quoted to protect them from expansion by the shell.
I'm puzzled by the error msg you quote, I'd expected sth. like find: missing argument to `-exec'

Last edited by RudiC; 08-06-2012 at 09:21 AM.. Reason: typo
# 3  
It is to keep the shell from interpreting the semicolon and have it as part of the find command. Another option is to add just an unescaped + at the end of the find command. The + will execute the command with grouped arguments instead of per result found by find when using {} \; and so will have a better performance.
Maybe escaped and unescaped works in your shell (somehow), but the usual way is to escape it. I assume you will be on the safe side with that.

Last edited by zaxxon; 08-06-2012 at 12:06 PM.. Reason: added info; spelling
This User Gave Thanks to zaxxon For This Post:
# 4  
Hi RudiC,
The missing '\' was unrelated...it turned out to be a basic permissions problem which I'd overlooked!
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux find command seems to not transmit all the result to the '-exec command'

Hello. From a script, a command for a test is use : find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb ! -newer /tmp/000_skel_file_end -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' Tha command... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Shell Programming and Scripting

Find and move command with exec

Hi all, I am trying to find files newer than a given file and them mv them to a new location. So I far I have: find . ! -newer <file_name> -exec ls -l {} \; and find . ! -newer <file_name> -exec mv /TEMP_LOCATION {} \; find is not liking this. Anyone know how to modify the last... (2 Replies)
Discussion started by: jonnyd
2 Replies

3. UNIX for Dummies Questions & Answers

[Solved] weird in find -exec command

i feel weird with this 2 command find /tmp/*test* -user `whoami` -mtime +1 -type f -exec rm -f {}\; find /tmp/*test* -user `whoami` -mtime +1 -type f -exec ls -lrt {}\; the first one return correct which only delete those filename that consist *test* where second command it listed all the... (12 Replies)
Discussion started by: lsy
12 Replies

4. Shell Programming and Scripting

find command with -exec

Hi all, Please could someone help with the following command requirement. I basically need to find files NEWER than a given file and order the result on time. My attempt so far is as follows: find . -newer <file_name> -exec ls -lrt {} ;\ But I dont seem to get the right result... (12 Replies)
Discussion started by: jonnyd
12 Replies

5. Shell Programming and Scripting

find command to use multiple -exec options

Hello All, Is there a way to make exec do a couple of operations on a single input from find? For example, find . -type d -exec ls -l "{}" ";" I would like to give the result of each "ls -l" in the above to a wc. Is that possible? I want to ls -l | wc -l inside exec. How do I... (1 Reply)
Discussion started by: prasanna1157
1 Replies

6. Shell Programming and Scripting

find command with -exec

Hi People, I have a directory full of compressed files (.Z extention) In many of these files there is a string pattern (3800078163033) I want to find all file names which contain this string in their text. Regards, Abhishek (2 Replies)
Discussion started by: max29583
2 Replies

7. UNIX for Dummies Questions & Answers

Find command with prune and exec options

Hi, I'm using the following command to get a list of files on the system. find /releases -type f -exec ls -l > /home/sebarry/list.txt '{}' \; however, its searching a directory I don't want it to search so I know I have to use prune but I don't seem to be able to get prune and exec to work... (2 Replies)
Discussion started by: Sebarry
2 Replies

8. UNIX for Advanced & Expert Users

Find command with prune and exec

Hi, I'm using the following command to get a list of files on the system. find /releases -type f -exec ls -l > /home/sebarry/list.txt '{}' \; however, its searching a directory I don't want it to search so I know I have to use prune but I don't seem to be able to get prune and exec to work... (1 Reply)
Discussion started by: Sebarry
1 Replies

9. UNIX for Dummies Questions & Answers

find command exec error

Hi All, i am writing a shell script in korn shell which deletes all the files in a directory once in every 10DAYS. the directory has different format files. the script has something like this; cd /home/data/pavi echo "Please Enter the Number of Days to search for" read DAYS... (2 Replies)
Discussion started by: pavan_test
2 Replies

Featured Tech Videos