Results 1 to 6 of 6
hi
i ve a directory which contains many files and have a common name in the begining say like
APIO_spec_min
APIO_spec_min1
APIO_spec_min2
APIO_spec_typ1
...
now i would like to replace ...
- 02-02-2009 #1Just Joined!
- Join Date
- Jan 2009
- Posts
- 12
rename the files in a directory
hi
i ve a directory which contains many files and have a common name in the begining say like
APIO_spec_min
APIO_spec_min1
APIO_spec_min2
APIO_spec_typ1
...
now i would like to replace the entire files with the name
s2c_spec_min
s2c_spec_min1
s2c_spec_min2
....
kindly help me out...
- 02-03-2009 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Try "rename". There are various different commands of that name.
- 02-03-2009 #3Just Joined!
- Join Date
- Jan 2009
- Posts
- 12
doesn t work..
rename command doesnt work...
or may be i dont know the usage.. could you explain that command for my files.
- 02-04-2009 #4Linux Guru
- Join Date
- Oct 2007
- Location
- Tucson AZ
- Posts
- 1,939
Make sure you are in the correct directory to run this command:
rename APIO s2c APIO_*
- 02-06-2009 #5Just Joined!
- Join Date
- Feb 2009
- Posts
- 3
In bash, at the command line, in your directory:
This is from memory, but I think it is correct. The echos are only to show that something is happening. Can all be on one line, but backslashes might make it easier to read in a post.Code:for fileName in `ls -1`; \ do echo $fileName; \ export newFileName=`echo $fileName | sed s/APIO/s2c/`; \ echo $newFileName; \ mv $fileName $newFileName; \ done
¦ {Þ
- 02-07-2009 #6Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
Command find combined with either sed or tr can handle this kind of task pretty well:
find . -name "APIO*" | while read line; do mv $line `echo $line | tr -s 'APIO' 's2c'`; done
find . -name "APIO*" | while read line; do mv $line `echo $line | sed 's/APIO/s2c/g'`; done


Reply With Quote
