Tuesday, July 8, 2008

rm *$*

So today I was harshly reminded that in UNIX (and by extension, in Mac OS X Terminal), the "*" and "$" symbols do not mean "asterisk" and "dollars", they mean "HAHAHA FUCK YOU, ASSWIPE".

I wanted to get rid of some files named "CollatzSieveUnthreaded$1.class", "FermatChecker$1.class", "FermatChecker$2.class", etc; these are backup class files created by the Java compiler. I figured doing rm *$* would do the trick, because Java uses the "$.class" convention to mean "useless backup in the same directory as the original", and none of my other files have a "$" in them. I foolishly assumed that "*" worked like it does everywhere other than in regex parsers.

Of course, all you holier-than-me UNIX geeks already see the problem with that command. The asterisk wildcard character in regular expressions means "the preceding element zero or more times", and the dollar symbol stands for "the ending position of the string or the position just before a string-ending newline" (thanks, Wikipedia). So "*$*" basically means "any string at all". Awesome.

Thankfully, Time Machine had come to the rescue 18 minutes prior, and my data was safe and sound on Themistocles, my external drive. So I didn't actually lose anything. But it's the principle of the thing!

0 comments: