Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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'.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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