I am using Ubuntu 10.04, and I have a directory with a bunch of files. We changed the naming scheme of the files a while ago, and now I want to delete all the old ones.

New Name scheme: December_12_2010.zip

Old Name Scheme: December_11_2010_17:54:18_map.zip

I was looking through regular expressions, and I want to see how to do it with them, but I couldn't figure it out. My limited knowledge wasn't enough to get me the right combination. I saw the ":" and thought the best way to delete the files was to say "Delete all files with a ':' in them", but no luck. I would love some guidance!

  • Do you have installed speech recognition software? If not, talking to your computer is in fact useless. :) – dolmen Mar 26 '11 at 20:52

Try rm *:*. That certainly works for me and if it doesn't work for you it would help if you provided the details of the error message.

It would also be possible to rename the files if there's only one per day. Automating that wouldn't be a major challenge.


If the files are really a bunch you should use find instead:

find -name '*:*' -delete
  • why find and not rm? just for my interest ;) – schöppi Dec 19 '10 at 22:00
  • 2
    Because the shell will expand rm *:* in something like rm file1 file2 ... and there's a limit for the length of a command. – cYrus Dec 19 '10 at 22:19
  • You forgot to give a directory. And find will look for files not only in the given directories but also in all subdirectories. Beware! – dolmen Mar 26 '11 at 20:55

If you're after a regex, this should work:-

find . -regex '.*/*[0-9][0-9]:[0-9][0-9]:[0-9][0-9]*' -exec rm -fv '{}' \;

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.