Change filenames recursively

Matthew Anderson manderson at ETC1.net
Thu Feb 1 14:32:42 UTC 2007


This seems to work for the current directory but not for any sub
directories and files under the sub directories.

Thanks!

-----Original Message-----
From: redhat-list-bounces at redhat.com
[mailto:redhat-list-bounces at redhat.com] On Behalf Of Gary Stainburn
Sent: Thursday, February 01, 2007 4:46 AM
To: General Red Hat Linux discussion list
Subject: Re: Change filenames recursively

On Wednesday 31 January 2007 21:48, Ray Van Dolson wrote:
> On Wed, Jan 31, 2007 at 03:57:30PM -0500, Matthew Anderson wrote:
> > I have hundreds of files that start with a * (asterisk) for the
> > filename.  I am needing to change the asterisk in every file to a _
> > (underscore).  Does
> >
> > Anyone know what command I can use to recursively do that?  I
appreciate
> > any help anyone can provide me.
>
> The following should work:
>
>   for i in `find . -type f -name '\**'`; do mv $i `echo $i | sed -e
> 's/\*/_/g'`; done
>
> This will only work if there is one '*' in the filename as the sed
command
> replaces all asterisks with underscores.  You can adjust if your needs
> differ.
>
> Ray

The best answer I've seen, but surely to remove the problem of multiple 
asterisks all you have to do is remove the 'g' modified from the end of
the 
regex. This *should* work as the criteria of the find ensures the 1st *
is at 
the beginning.

Gary
-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000


-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request at redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list




More information about the redhat-list mailing list