开发者

Rename multiple file with same extension in a directory

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜