开发者

Rename multiple file with same extension in a directory

开发者 https://www.devze.com 2023-03-08 12:03 出处:网络
In Dir /home/test: a.244 b.244 c.244 d.244 I want to rename the files to just a, b, c , d. I want remove .244.

In Dir /home/test:

a.244
b.244
c.244
d.244

I want to rename the files to just a, b, c , d.

I want remove .244.

I have tried r开发者_开发问答ename s/.244// /home/test/*.244.

It doesn't work.


Debian, Ubuntu:

rename 's/\.244//' *.244

Fedora, other distros:

rename '.244' '' *.244


Poor man's rename :)

regex="$1"
shift
for i
do
    echo "$i" | sed "$regex" | xargs -n1 -J % echo mv "$i" "%"
done

Use it for example (dry run):

./my_rename "s/\.244//" *.244

If the result was ok - remove the "echo" from the "echo mv" ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消