How to use "rm" to remove files with a ":" in them?

2

1

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!

Wayfarer

Posted 2010-12-19T21:01:44.680

Reputation: 123

Do you have installed speech recognition software? If not, talking to your computer is in fact useless. :) – dolmen – 2011-03-26T20:52:40.533

Answers

4

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.

Cry Havok

Posted 2010-12-19T21:01:44.680

Reputation: 3 486

4

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

find -name '*:*' -delete

cYrus

Posted 2010-12-19T21:01:44.680

Reputation: 18 102

why find and not rm? just for my interest ;) – schöppi – 2010-12-19T22:00:48.613

2Because the shell will expand rm *:* in something like rm file1 file2 ... and there's a limit for the length of a command. – cYrus – 2010-12-19T22:19:54.067

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 – 2011-03-26T20:55:43.267

0

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 '{}' \;

Andy Smith

Posted 2010-12-19T21:01:44.680

Reputation: 691