Search code examples
bashsedunix-timestampdate-formattingfile-rename

How to batch convert timestamp to human date in filename?


I have a set of files with the following filename format <epochtimestamp>.topic-of-post.md, for example 1436310000.server-3-2-1.md.

I need to batch convert the timestamp part to human readable date in the format of YYYY-MM-DD, example 2014-10-14.token-revocation.md

How could I go about automating this process on a Windows system? I have Cygwin installed and some basic knowledge of bash scripting.


Solution

  • With the Perl rename command, you can do

    rename 'use Time::Piece; s/(^\d+)/my $t = localtime($1); $t->ymd/e' [0-9]*.md