简体   繁体   English

在Linux或MacOS X中将文件20141207_190822.jpg重命名为“ 2014-12-07 19.08.22.jpg”

[英]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: 在Linux或MacOS X中如何将一堆名为20141207_190822.jpg和20141207_190823.mp4的文件重命名为以下格式:

2014-12-07 19.08.22.jpg and 2014-12-07 19.08.23.mp4 2014-12-07 19.08.22.jpg和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. 最后但并非最不重要的一点是,该工具最初是由Perl的父亲Larry Wall编写的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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