[NTLUG:Discuss] "find -exec" -vs xargs -OR- subshells in -exec

Richard Geoffrion ntlug at rain4us.net
Fri May 26 11:57:44 CDT 2006


Stuart Johnston wrote:

>Richard Geoffrion wrote:
>  
>
>>I'm trying to rename a bunch of mangled files.  I want to replace all of 
>>the tilde (~) characters with dashes (-).
>>
>>    
>>
>rename is just a perl script so you could probably copy it over to your 
>system.  Or, move your mv and sed commands into a shell script and run 
>that from find:
>
>  
>
on my Slack 10.0 system, it appears to be a binary file.  (It seems to 
be completely missing in OSX)

>$ cat ren
>#!/bin/bash
>
>mv $1 `echo $1 | sed y#~#-#`
>
>find . -name *~* -exec ./ren {}  \;
>  
>

And of course that worked.  At one point I had a passing idea to do 
something like this..but I was so wrapped up in trying to make this a 
one-liner.   I still don't understand the shell WHYs and WHEREFOREs as 
to why the -exec command didn't work.  I'm sure it has to do with 
starting a subshell under a subshell..

oh well. the evil deed is done and the mangled files have been demanglified.

THX!

-- 
Richard




More information about the Discuss mailing list