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 :(
# 15  
Old 08-27-2009
Sorry to insist but can you cite one of these OSes that implement find -exec that way ?
# 16  
Old 08-27-2009
I will not entertain the argument that all unix versions in use in the commercial environment are POSIX-compliant.

Just checked an old one:

Sunos 4.1.1

It has come as a revelation to me that find can pass a parameter containing space characters to exec {} without quoting "{}" . The usual solution involves piping to "xargs", though in practice I don't use either method myself unless requested by a customer.
In case you are wondering I have tried it today on a couple of modern unix O/S and it works without the quotes.

On reflection, the POSIX versions are the anomaly.

I was expecting an interjection from cfajohnson, but "find" is an external command and not covered by the POSIX shell.

There are many unix commands which I would like to see standardised but these are mostly to do with memory mapping, disc partitioning, and printing. (Controversial statement) POSIX avoids hardware.

Last edited by methyl; 08-27-2009 at 08:12 PM..
# 17  
Old 08-28-2009
I'm not surprised about your tests that match my experience. That leave the question about what find version the open poster is using unanswered ...

---------- Post updated at 10:21 ---------- Previous update was at 08:50 ----------

Originally Posted by Dean Rotherham
YOU GUYS ROCK!!! Smilie .. so the answer was the fact that the curly brackets needed quotes .. "{}" ..
I'm afraid your conclusion seems incorrect. After some research, I'm now convinced no known implementation of the find command need quotes. The idea they are required, even while documented in various web location, can't be but a urban legend.
In fact, using single or double quotes cannot have any effect on the find command given the fact the shell is removing them before passing the {} argument to the find command. Should you use a non standard shell that keep them, find behavior would be unspecified.
# 18  
Old 08-28-2009
Heyo guys,

I thought I'd just confirm my OS, nothing abnormal and if anything probably one of the most common OS, I'm on ubuntu. (So guess Debian) ... I will confirm though that without the quotes it definately doesn't work. I'm running the script on 50+ remote pc's and I get the same result on ALL. SO, not sure .. Sorry, Hope I didn't start chaos here Smilie ... Chat soon and I'll keep my eyes here for what the final conclusion is?

# 19  
Old 08-28-2009
No chaos at all, just an interesting discussion.

Can you run these commands on your machine to figure out what is going on:
touch "/tmp/find test"
find /tmp -name "find*test" -exec /bin/ls -l {} \;
find /tmp -name "find*test" -exec rm -i {} \;

Last edited by jlliagre; 08-28-2009 at 06:36 AM.. Reason: typos
# 20  
Old 08-29-2009
Hi jlliagre. No urban legend. Hands on commercial experience of a very wide range of unix flavours and of their predecessors. Sometimes I only find out oddities when porting tried-and-tested scripts and they misbehave. I don't have "ubuntu" Linux handy though.
One SCO unix came with a standard cron to clean /tmp which failed if there were filenames containing spaces or there were lots of files. Sound familiar?
# 21  
Old 08-29-2009
I'm not telling SCO scripts or any other ones can't be buggy, or course they can. I'm just telling I'm convinced using simple or double quotes around the {} in a find -exec statement does not and cannot have any effect. Of course it doesn't hurt to use them, just like the following commands works equally fine:
echo hello
echo "hello"

My point is these quote are unnecessary and not required regardless of the filename. I have no problem if you prove me wrong so feel free to demonstrate the quote are necessary with some OS, but do it with facts.
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