Tuesday, September 22, 2009

Gotcha Of The Day: cmd.exe is most definitely not bash

Yesterday, I was happily plugging away on a Windows system using the UnxUtils package to let me work my command line magic. I've found cmd.exe a passable shell environment - what with it's crude tab completion and all.

I wanted to zip up a bunch of files I had worked up, and rather than add to the archive I wanted a fresh archive. So, I typed out a command I regularly use on Linux:

 rm files.zip ; zip -r files.zip wp-content/themes wp-content/plugins

In English, this says: remove the file named files.zip, then zip up the themes and plugins directories into a file named files.zip.

I hit enter, and got some sort of strange warning on the screen. Then I got a sinking feeling. It took a few moments for the gravity of what I had just done to set in. My train of thought went like:

Hmmm, wait a second - ";" isn't a command separator on Windows, like it is on Unix. That means I just ran the command: rm files.zip zip -r .... And this command, is in fact equivalent to: rm -r files.zip files.zip .... And rm -r is a recursive delete.

Holy smokes! I just deleted the exact files I wanted to save, and at the same time, deleted the files.zip backup. Oh Crap!

In the end, this ooops only took a few minutes to recover. There was a recent backup of the files, and many of the files were still open in my editor, so I was able to simply re-save them.

But still, what a scare - it's been a while since I've had one of those.

Note to self: on Windows, use one command at a time.

No comments:

Post a Comment