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.

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!

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

3 Answers 3

up vote 4 down vote accepted

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.

share|improve this answer

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

find -name '*:*' -delete
share|improve this answer
    
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
    
okay thanks ;-) –  schöppi Dec 20 '10 at 15:45
    
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 '{}' \;

share|improve this answer

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.