[NTLUG:Discuss] "find -exec" -vs xargs -OR- subshells in -exec
Robert Thompson
ntlug at thorshammer.org
Mon May 29 21:59:08 CDT 2006
> ..but I was so wrapped up in trying to make this a one-liner.
$ touch 1~1.foo
$ for i in `find . -name *~*`; do mv $i `echo $i | sed y^~^-^`; done
$ ls
1-1.foo
$
Anything that can go into a shell script can go on the cli. Sometimes it's just easier to put it into a script (for comments, resuse, complexity, etc). Other times a one-off doesn't need it.
Robert Thompson
On Fri, May 26, 2006 at 11:57:44AM -0500, Richard Geoffrion wrote:
> 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
>
>
> _______________________________________________
> http://ntlug.pmichaud.com/mailman/listinfo/discuss
More information about the Discuss
mailing list