Monday, November 26, 2007

Free Windows disk image tool

LifeHacker has an interesting article about a free Windows disk image tool called DriveImage XML. It's reasonably quick and offers the capability to restore a disk to an earlier state.

Monday, November 19, 2007

I/O redirection into an editor

Sometimes it's handy to redirect the output of a Linux/Unix command into an editor. One reason to do this might be to try to weed out unwanted search pattern matches when running grep. Fortunately the Linux (and before that Unix) developers have anticipated this need. Editors like vi, vim, gvim, and gedit (and possibly others I'm not aware of) can all accept the output of a command as the "file" being edited.

For example, you can direct the output of a grep command to gvim with the following command:

grep searchPattern | gvim -

If you really want to get fancy, you can pass a command to gvim to cause it to search for the same pattern you used grep to find by using the -c argument.

grep searchPattern | gvim -c/searchPattern -

Since searchPattern appears twice on the command line and engineers never want to type any extra characters, I'd define a command alias to perform this action. Since there are so many shells out there, I'll leave that as an exercise for the reader.

Sunday, November 18, 2007

Readability rating

I think the rating should be more like "Evil Genius". It must be all my posts about obscure Unix commands, eh?

Friday, November 16, 2007

Adding color to grep output

Most of the longtime Unix users like me love grep. Regular expressions make the silly wildcards available in Windows seem completely underwhelming.

One thing which I find makes grep even more useful is to configure it to highlight matching terms. Like most things I decide would be useful, a little poking about in the man pages shows that the Unix developers have anticipated my needs yet again. They've added a couple environment variables which can tell grep to highlight matching terms in the color of your choosing. Since I prefer my xterm windows with a dark background and light foreground colors, I find the following colors work well. Note - I use tcsh at home so you may need to alter these commands a bit to get them to work with your preferred shell.

# highlight search terms with a red background and white foreground
setenv GREP_COLOR '01;37;41'
setenv GREP_OPTIONS '--color=auto'

A word of warning is in order. I've found that using these terms can cause strange failures in seemingly unrelated activities. For example, I build Linux kernel modules at work and I've discovered that fails if I've got the grep color environment variables set (in the modpost step). So I've defined command aliases to set and unset the environment variables. That way I can easily enable grep colors before performing a grep and disable them again before doing something which may fail if grep colors are enabled.

Saturday, November 03, 2007

Rudy Rucker

One of my favorite SciFi authors, Rudy Rucker, has kindly released his latest novel called Postsingular under a Creative Commons license. This is a great way for people unfamiliar with Rudy's work to try it out. If you like it (and I'm sure most people will) please buy his earlier books. I like to keep my favorite authors gainfully employed because that means more good books for me to read.