Using "find" and "-exec rm" ... Just no luck :(

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using "find" and "-exec rm" ... Just no luck :(
# 8  
Old 08-26-2009
Originally Posted by methyl
It uses "rm -f" (files) rather than "rm -rf" (directories)
"rm -rf" removes files too so can't be the issue.
You need double quotes round the curly braces to preserve spaces.
You don't need these double quotes, spaces are already preserved without them so this can neither be the issue.

$ touch "a b"
$ find . -type f -name "* *" -exec ls -l {} +
-rw-r--r--   1 jlliagre jlliagre       0 Aug 26 23:23 ./a b

# 9  
Old 08-27-2009
YOU GUYS ROCK!!! Smilie .. Thank You! Much appreciated ... so the answer was the fact that the curly brackets needed quotes .. "{}" .. I now have a working script.

Again Linux and even more so, "Linux People" save the day!

# 10  
Old 08-27-2009
Originally Posted by Dean Rotherham
so the answer was the fact that the curly brackets needed quotes .. "{}"
This is odd. They shouldn't be needed. I guess you aren't using the regular "rm" command but some broken wrapper.

Also, if you work on Gnu/Linux, it might help if you tell it in the first place.
# 11  
Old 08-27-2009
It always helps to know which shell and which Operating System and version.
There is much variation in the "find" command.
The "{}" syntax was certainly needed in Berkeley unix, SCO unix and Unix System V.
# 12  
Old 08-27-2009
Great ... I'll include those details next time first, sorry .. just getting the hang of posting as such .. First Linux post Smilie ... But great I guess this thread an be closed. Must I do that or will the forum do that?
# 13  
Old 08-27-2009
Originally Posted by methyl
The "{}" syntax was certainly needed in Berkeley unix, SCO unix and Unix System V.
I don't remember having see that behavior with these OSes but filenames with embedded spaces were rare at that time. Anyway, have you examples of currently used find implementations that exhibit this behavior (outside Dean's experience which is perplexing me) ?

I believe that would violate the POSIX standard if I understand it correctly:

Quoted from
An argument containing only the two characters "{}" shall be replaced by the set of aggregated pathnames, with each pathname passed as a separate argument to the invoked utility in the same order that it was aggregated.
# 14  
Old 08-27-2009
Whatever O/S Dean_Rotherham is using should go on the list.

I have seen the problem so many times that I use the quote syntax out of habit (whether or not it is necessary on some O/S). If you are dealing with filenames or other strings which contain space characters just use quotes.

I really am the wrong person to discuss POSIX because I live in the real world and have seen many "standards" come and go.

The quote you supply is wonderfully ambiguous though to my mind it describe all the effects I have seen from all the versions of "find .... -exec" .

Last edited by methyl; 08-27-2009 at 06:03 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

These three finds worked as expected: $ find . -iname "*.PDF" $ find . -iname "*.PDF" \( ! -name "*_nobackup.*" \) $ find . -path "*_nobackup*" -prune -iname "*.PDF" They all returned the match: ./folder/file.pdf :b: This find returned no matches: $ find . -path "*_nobackup*" -prune... (3 Replies)
Discussion started by: wolfv
3 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep ""|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep ""|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. UNIX for Dummies Questions & Answers

No utpmx entry: you must exec "login" from lowest level "shell"

Hi I have installed solaris 10 on an intel machine. Logged in as root. In CDE, i open terminal session, type login alex (normal user account) and password and i get this message No utpmx entry: you must exec "login" from lowest level "shell" :confused: What i want is: open various... (0 Replies)
Discussion started by: peterpan
0 Replies
Login or Register to Ask a Question