简体   繁体   中英

Renaming files like 20141207_190822.jpg to “2014-12-07 19.08.22.jpg” in linux or MacOS X

How in Linux or MacOS X to rename a bunch of files with names 20141207_190822.jpg and 20141207_190823.mp4 to this format:

2014-12-07 19.08.22.jpg and 2014-12-07 19.08.23.mp4

?

I've found many examples how to just add something to the beginning of filename, but here I need to change the mask by inserting symbols in the middle of filenames and replacing _ with space " ".

Thank you

Try doing this :

$ rename 's@^(\d{4})(\d{2})(\d{2})_(\d{2})(\d{2})(\d{2})@$1-$2-$3 $4.$5.$6@' *

警告 There are other tools with the same name which may or may not be able to do this, so be careful.

If you run the following command :

$ file $(readlink -f $(type -p rename))

and you have a result like

.../rename: Perl script, ASCII text executable

then this seems to be the right tool =)


If you don't have this command, search your package manager to install it or do it manually


Last but not least, this tool was originally written by Larry Wall, the Perl's dad.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM