h********0 发帖数: 440 | 1 In a directory, I have hundreds of files named like "a_*.txt"
now I want to change them to be named like "b_*.txt"
What Unix command can I use?
Thanks. |
r********g 发帖数: 1351 | 2 I don't know if you can use rename:
rename a b a_*.txt
I tried on linux, and it works.
【在 h********0 的大作中提到】 : In a directory, I have hundreds of files named like "a_*.txt" : now I want to change them to be named like "b_*.txt" : What Unix command can I use? : Thanks.
|
f******g 发帖数: 13917 | 3 这儿有一个小程序,测试过的。
for file in a_*.txt
do
mv ${file} $(echo ${file} | sed 's/a\(.*\)/b\1/')
done
【在 h********0 的大作中提到】 : In a directory, I have hundreds of files named like "a_*.txt" : now I want to change them to be named like "b_*.txt" : What Unix command can I use? : Thanks.
|
h********0 发帖数: 440 | 4 Thanks very much freelong.
Yes. That's something similar to what I am looking for.
I thought to use sed, but I am not very familiar with it.
If there any other easier way I can do this?
【在 f******g 的大作中提到】 : 这儿有一个小程序,测试过的。 : for file in a_*.txt : do : mv ${file} $(echo ${file} | sed 's/a\(.*\)/b\1/') : done
|
L***s 发帖数: 2944 | 5 I think this is the pretty easy way.
however, you can use PERL.
【在 h********0 的大作中提到】 : Thanks very much freelong. : Yes. That's something similar to what I am looking for. : I thought to use sed, but I am not very familiar with it. : If there any other easier way I can do this?
|
h********0 发帖数: 440 | 6 Thanks Lukas.
I never used perl~~
So, I will adopt freelong's code.
【在 L***s 的大作中提到】 : I think this is the pretty easy way. : however, you can use PERL.
|
w******p 发帖数: 166 | 7 u can do it w/o using sed:
for f in $(ls a_*) do; echo mv $f b_${f#*_}; done
verify that the mv commands prints ok, then remove the "echo" to do the real
thing |
h********0 发帖数: 440 | 8 cool, thank you, westcamp. |