Hi all
how can I have script to rename the following directory pattern from
from
dir-192.168.30.0 dir-192.168.30.144 dir-192.168.30.184
To:
dir-10.0.30.0 dir-10.0.30.144 dir-10.0.30.184
thank you
Send instant messages to your online friends http://uk.messenger.yahoo.com
On Fri, 02 Nov 2007 02:22:30 +0800 (CST) adrian kok adriankok2000@yahoo.com.hk wrote:
how can I have script to rename the following directory pattern from
dir-192.168.30.0 To: dir-10.0.30.0
rename 192.168 10.0 dir*
adrian kok wrote:
Hi all
how can I have script to rename the following directory pattern from
from
dir-192.168.30.0 dir-192.168.30.144 dir-192.168.30.184
To:
dir-10.0.30.0 dir-10.0.30.144 dir-10.0.30.184
If this is to rename individual files from 192.168.30.0=>192.168.30.144 then
for (( i = 0 ; i <= 143; i++ )) do mv 192.168.30.$i 10.0.30.$i done
thank you
You're welcome.
http://www.freeos.com/guides/lsst/
On Fri, 2007-11-02 at 02:22 +0800, adrian kok wrote:
Hi all
how can I have script to rename the following directory pattern from
from
dir-192.168.30.0 dir-192.168.30.144 dir-192.168.30.184
To:
dir-10.0.30.0 dir-10.0.30.144 dir-10.0.30.184
If you are just renaming directories, or files, and not files in directories, the following should work:
for i in 0 144 184 ; do mv dir-192.168.30.$i dir-10.0.30.$i ; done
Or in a bit prettier form:
for i in 0 144 184 do mv dir-192.168.30.$i dir-10.0.30.$i done
Phil
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
--- Phil Schaffner Philip.R.Schaffner@NASA.gov wrote:
On Fri, 2007-11-02 at 02:22 +0800, adrian kok wrote:
Hi all
how can I have script to rename the following directory pattern from
from
dir-192.168.30.0 dir-192.168.30.144 dir-192.168.30.184
To:
dir-10.0.30.0 dir-10.0.30.144 dir-10.0.30.184
If you are just renaming directories, or files, and not files in directories, the following should work:
for i in 0 144 184 ; do mv dir-192.168.30.$i dir-10.0.30.$i ; done
Or in a bit prettier form:
for i in 0 144 184 do mv dir-192.168.30.$i dir-10.0.30.$i done
Phil
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
On Fri, 02 Nov 2007 03:18:35 +0800 (CST) adrian kok adriankok2000@yahoo.com.hk wrote:
But I have several hundred those pattern directories!
What's wrong with the rename command?
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
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/'`
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
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
Was there an problem with Frank's response from earlier?
rename 192.168 10.0 dir*
It is a nice simple solution. You don't have to loop, or use extra commands, just copy and paste that one command to your machine, and all directories will be renamed. I just did it on 1000 directories, and it took 0.052 seconds:
[mike@test-box test]$ ls -ld dir-192.168.0.* | wc -l 1000 [mike@test-box test]$ time rename 192.168 10.0 dir*
real 0m0.052s user 0m0.012s sys 0m0.040s [mike@test-box test]$ ls -ld dir-10.0.0.* | wc -l 1000
Mike