Try:
# find <parent dir> -type d -name dir-192.168.* -exec mv {} `echo {} | sed 's/192.168./10.0./'` ;
That should recursively rename all directories from one naming scheme to another.
-Ross
-----Original Message----- From: centos-bounces@centos.org centos-bounces@centos.org To: CentOS mailing list centos@centos.org Sent: Fri Nov 02 09:28:45 2007 Subject: Re: [CentOS] script help
I run it but it has error.
sed 's/^dir-192.168/dir-10.0/'` sed: read error on dir-192.168.0.31: Is a directory
--- Toby Bluhm tkb@MidwestInstruments.com wrote:
Toby Bluhm wrote:
adrian kok wrote:
Hi Phil
thank you
But I have several hundred those pattern
directories!
I did think to cat those directories in a file "olddir"
eg:
dir-192.168.30.0 dir-192.168.30.144
dir-192.168.30.184
........................................
and sed 's/dir-192.168/dir-10.0/g' olddir >
newdir
but i don't know how to move rename the directories in olddir to newdir
Thank you again
Assuming dir-192.168* are all in one directory
level, cd to that dir:
for olddir in `ls -1 | grep dir-192.168` do newdir=`echo $olddir | sed
's/^dir-192.168/dir-10.0/'`
mv $olddir $newdir done
That sed line should be: 's/^dir-192.168/dir-10.0/'`
-- Toby Bluhm Midwest Instruments Inc. 30825 Aurora Road Suite 100 Solon Ohio 44139 440-424-2240
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Send instant messages to your online friends http://uk.messenger.yahoo.com _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
______________________________________________________________________ This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender and permanently delete the original and any copy or printout thereof.
Ross S. W. Walker wrote:
Try:
# find <parent dir> -type d -name dir-192.168.* -exec mv {} `echo {} | sed 's/192.168./10.0./'` ;
That should recursively rename all directories from one naming scheme to another.
... except for the fact that the `echo {} ...` will be evaluated by the shell and not find, so this is the same as:
find <parent dir> -type d -name dir-192.168.* -exec mv {} {} ;
Not very useful ;)
Cheers, Michael
Michael D. Kralka wrote:
Ross S. W. Walker wrote:
Try:
# find <parent dir> -type d -name dir-192.168.* -exec mv {} `echo {} | sed 's/192.168./10.0./'` ;
That should recursively rename all directories from one
naming scheme to
another.
... except for the fact that the `echo {} ...` will be evaluated by the shell and not find, so this is the same as:
find <parent dir> -type d -name dir-192.168.* -exec mv {} {} ;
Not very useful ;)
Yes, thanks for pointing that out, it would have to be put into a loop then.
# for dir in `find <parent dir> -type d -name dir-192.168.* -print`; do # mv $dir `echo $dir | sed 's/192.168./10.0./'` # done
I also just saw the earlier post on the 'rename' command which does it all for the OP and should be a lot faster then a shell script.
-Ross
______________________________________________________________________ This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender and permanently delete the original and any copy or printout thereof.