Visit Our UNIX and Linux User Community


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 :(
# 36  
Old 08-31-2009
jlliagre , please accept that there is known anomolous behaviour in versions of "find ... -exec {} \;" which can be mitigated by quoting '{}' or "{}". The fact that the unquoted variant works in some modern unix variants came as a revelation to me.

Let's not forget the o/p.
# 37  
Old 09-01-2009
As I wrote, I have no problem accepting my opinion being challenged and I would be surprised but grateful to anyone proving I'm wrong in that case.

However, there is currently absolutely no evidence anyone, including the open poster, is experiencing a different find(1) behavior than the only one that I consider technically possible.

The OP didn't run the simple script I suggested him to do to figure it out. I tested the very same OS the OP is using, Ubuntu, and the quotes weren't required. You failed to cite an OS where quote are required when the path contains spaces and one you tested didn't behave the way you were expecting.

I have thus no reason to change my mind about what I still consider a urban legend.

To clarify, I'm not against the idea some exotic shell implementation might require quoting the curly braces. I'm just telling neither files having embedded spaces nor the find command implementation play any role in that hypothetical requirement.
# 38  
Old 09-01-2009
Hi jlliarge. I cited Sunos 4.1.1 based on a comment I made in an old script, though I no longer have a copy of the O/S. This is not the only time I have come across the problem.

The wikipedia section on "find" mentions "In some shells, the {} must be quoted". I can't argue with that.

find - Wikipedia, the free encyclopedia


The wiki looks pretty accurate bar not mentioning differences between "/pathname" and "/pathname/" in some unixes.


In this comprehensive GNU-based generic man page for find(1) it specifically states to quote '{}' . It also warns about security hole in the POSIX implementation of "find ... -exec" which I did not know about.

http://unixhelp.ed.ac.uk/CGI/man-cgi?find

This independent researcher has gone to town on checking what works in various versions of find. See under "Embedded {}". He describes some quite radical different behaviours of {} which does support my case.

http://www.in-ulm.de/~mascheck/various/find/

Last edited by methyl; 09-01-2009 at 09:06 AM.. Reason: Further example of examples
# 39  
Old 09-02-2009
Quote:
Originally Posted by methyl
Hi jlliarge. I cited Sunos 4.1.1 based on a comment I made in an old script, though I no longer have a copy of the O/S. This is not the only time I have come across the problem.
Please clarify. What is the problem you came across ?

#1 : That the shell you used was requiring quotes around the curly braces regardless of whether the file that will be found contains a space or not.

#2 : That the find command implementation you were using was requiring the curly braces to be quoted when a found file was containing a space.

As I wrote, I have no problem believing case #1 is possible. I'm still convinced problem #2 is a urban legend. All the links you provided are only referring to #1, i.e. the shell expanding {} to something else, just like the semicolon is expanded to an end of instruction and so need to be either escaped or quoted with most if not all shells.
The open poster claim #2 is real which I can't agree with.
# 40  
Old 09-02-2009
Quote:
Originally Posted by jlliagre
Please clarify. What is the problem you came across ?

#1 : That the shell you used was requiring quotes around the curly braces regardless of whether the file that will be found contains a space or not.

#2 : That the find command implementation you were using was requiring the curly braces to be quoted when a found file was containing a space.

As I wrote, I have no problem believing case #1 is possible. I'm still convinced problem #2 is a urban legend. All the links you provided are only referring to #1, i.e. the shell expanding {} to something else, just like the semicolon is expanded to an end of instruction and so need to be either escaped or quoted with most if not all shells.
The open poster claim #2 is real which I can't agree with.
I completely agree. #1 is possible, #2 is not feasible because it would require that find internally split a string and pass it a separate args to exec, I do not believe there is or was any version of find that did/does that.

The gnu find manual, like the wikipedia article explicitly states quoting might be necessary to avoid #1, there is no mention of #2.
# 41  
Old 09-02-2009
Quote:
Originally Posted by reborg
#2 is not feasible because it would require that find internally split a string and pass it a separate args to exec, I do not believe there is or was any version of find that did/does that.
And even if such a broken find version exists, quoting the {} wouldn't have any effect on embedded spaces.
# 42  
Old 09-03-2009
jlliagre and reborg. Quoting {} as "{}" or '{}' seems to be outside your experience. I personally have not hit weird quirks with modern Solaris or modern HP-UX though I view every command implementation in AIX as an adventure.
I didn't expect the o/p to be using Ubuntu Linux, but anomolous behaviour of "find ... -exec" is well documented as is anomolous behaviour of "find" in general. Whether the issue is in shell or "find" itself is academic.
I have hands-on experience of many unix variants which were volume sellers but far from perfect.
Don't forget that we are concerned about what happens when you don't use quotes. I have never seen an issue after using quotes (though I have read of such issues).
It's a bit like using $LINENO or $EXIT in modern scripts. You might get away with it and you might not.

Forgot to answer one of your earlier questions. In one event a supplied script to clean /tmp of old temporary files from a well-known dirty commercial application contained "find /tmp/ ... -exec rm {} \;". It worked for a while. The filenames of the temporary files contained a middle string which was entered by the user. The cleanup script eventually failed with a syntax error on encountering a filename containing space characters. The fix was to quote {} as "{}" .
I suppose the big question is whether the character displayed as a space character on an old dumb terminal was actually a space character? We shall never know.

Last edited by methyl; 09-03-2009 at 02:34 AM..
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #208
Difficulty: Medium
Open Shortest Path First (OSPF) was designed as an exterior gateway protocol (EGP) for use in an autonomous systems such as a local area network (LAN).
True or False?

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 "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|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

Featured Tech Videos