How do I rename multiple files beginning with a Unix timestamp - imapsync issue

谁说胖子不能爱 提交于 2019-11-28 13:08:10
Gilles Quenot

Try doing this with rename :

$ rename -n 's/^\d+/(stat($_))[9]/e' [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*

from the shell prompt. It's very useful, you can put some code like I does in a substitution for stat with the e modifier.

You can remove the -n (dry-run mode switch) when your tests become valids.

warning http://pix.toile-libre.org/upload/original/1377510865.png 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 (linux)

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

and you have a result like

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

and not containing:

ELF

then this seems to be the right tool =)

If not, to make it the default (usually already the case) on Debian and derivative like Ubuntu :

$ sudo update-alternatives --set rename /path/to/rename

(replace /path/to/rename to the path of your perl's rename command.


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.


Edit

As stated here, if you have the following error :

Argument list too long

Then use find like this :

find -type f -name '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*' -print0|
    xargs -0 -n1 rename -n 's/^\d+/(stat($_))[9]/e' 

(try it without -n1, that should works too)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!