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

Richard Geoffrion ntlug at rain4us.net
Fri May 26 09:33:32 CDT 2006


I'm trying to rename a bunch of mangled files.  I want to replace all of 
the tilde (~) characters with dashes (-).

Find can find the files, but I can't figure out how to rename the file 
once I have it on the command line.
(and for the purposes of this issue...on this particular machine,  I 
don't have the rename command ---- even though I tried using rename on 
another machine with no luck.)
(I hate it when machines have no luck)

rtcg at bobpc:/tmp# mkdir test
rtcg at bobpc:/tmp# cd test
rtcg at bobpc:/tmp/test# ls
rtcg at bobpc:/tmp/test# touch 1~1.jpg
rtcg at bobpc:/tmp/test# find . -name *~*
./1~1.jpg
rtcg at bobpc:/tmp/test# find . -name *~* -exec mv {} `echo {} | sed y#~#-#` \;
mv: `./1~1.jpg' and `./1~1.jpg' are the same file
rtcg at bobpc:/tmp/test# TESTFILE=1~1.jpg
rtcg at bobpc:/tmp/test# mv $TESTFILE `echo $TESTFILE | sed y#~#-#`
rtcg at bobpc:/tmp/test# ls
1-1.jpg
rtcg at bobpc:/tmp/test#


I've looked at xargs, but xargs just wants to run a command on the 
results.  I can't find how to manipulate the ??stout/stin'? that was 
passed to xargs.


Suggestions?

-- 
Richard




More information about the Discuss mailing list