0

They're named with date '+%d-%m-%Y, %a, %k.%M.%S'. I'm looking to rename them to date '+%Y-%m-%d, %a, %H.%M.%S'.

0

Use the prename command:

prename 's/^(..)-(..)-(....)/$3-$2-$1/; s/  / 0/' [list of files]

This will capture the day, month, year and rewrite it in year, month, day order. Then it will take all occurences of double spaces (which only occurs before the hour, and only it hour is <10, when formatted with %k) and transform it to " 0", which in practice makes it equivalent to %H.

prename is a Perl script included in most standard Perl installations (in my experience) and is thus probably already present on your system. It is often (e.g. on Debian based systems) linked to rename.

Use the -n (--no-act) switch to prename the first time you run it to only show what changes will be done when the switch is removed.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.