By default when we copy and paste a file in same directory Ubuntu creates duplicate file and renames it to origname (copy).ext.

But I want to rename all those files such that the files like those names be renamed to origname_copy_02082016.ext means with todays date at the end just before extension.

How can I do that with regex and rename command ?

1 Answer 1


There are several rename(1)s out there, and they use different sets of options. Assuming your rename(1) supports Perl expressions, this should work:

rename -n "s/ \(copy\)/_copy_$(date +%d%m%Y)/" *

The -n option shows you what rename(1) would do without actually renaming anything. Remove -n when you're happy with the result.

  • Thanks man, it works, +1 for suggesting -n for review, one query, can I remove space from regex and it would match filename like news(copy).txt ?
    – Vicky Dev
    Commented Aug 2, 2016 at 7:37
  • @VickyDev Sure, you're supposed to modify it to suit your needs, not apply it blindly. Commented Aug 2, 2016 at 7:51
  • No, just some regex things I applied didn't work, so I asked. Nevermind, will try myself and check with -n.
    – Vicky Dev
    Commented Aug 2, 2016 at 9:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .