Rename file with command line

来源:互联网 发布:h3c路由器端口ip设置 编辑:程序博客网 时间:2024/06/01 08:59

Rename file with command line

1.mv

I just want to rename one file, so I use mv to modify the filename

mv oldfilename newfilename

If necessary, you can use with directory. Just like:
mv ~/Documents/test.txt ~/Documents/test/test.txt

2.rename

However, when the file is very big, mv can behavior efficiently or not is a question.So, I need another solution.

Thus, I surf the Internet and find that I can use rename to rename myfile.

The usage is:
rename [-h|-m|-V] [-v] [-n] [-f] [-e | -E perlexpr]* |perlexpr [ files]

-n: list the file will be renamed
-v: list the file has been renamed

Yeah, it is a Perl expression, but I just know regex a little.

For instance, I’d like to rename “first_shell.sh” to “first.sh”, I can write:
rename ‘s/first_shell/first/’ *.sh
example.jpg

You can use man rename in terminal for help.

Poor User Experience~