Draconis Software Blog

Advanced Bash Features

Bash is probably the most popular shell, and is often the default shell in many Linux systems. In addition to features like tab completion, redirection and scripting functions which are popular, there are also many less commonly-known features which can be quite useful. Many of these advanced features are introduced in this guide (see also Part II).

There are two features in particular that I find particularly useful. First is the various history features in bash. Typing `history’ will give you the commands you’ve entered in the order they were entered. However there are many other ways to access the command history:

This brings us to bang-bang or !!. !! tells bash “repeat the last command I entered.” But the magic doesn’t stop there, if you order now, you’ll also receive !xyz. !xyz will allow you to run the last command beginning with xyz that you typed. Be sure to add enough to the abbreviation to make it unique or you could run into problems, for instance: In the example above, ps was ran twice, then pwd. If you typed !p you’d get the output of pwd. Typing !ps is just enough to be unique and will execute the ps -auxw | grep http entry in history. By typing just enough to make your history request unique, give you a much better chance of hitting your targeted command.

Another nice feature is the ability to move around and delete words using keyboard commands:

Once again, bash comes through for us. Here are some of the movement keystrokes that I use most often:

  • ^w erase word
  • ^u erase from here to beginning of the line (I use this ALL the time.)
  • ^a move the cursor to the beginning of the line
  • ^e move the cursor to the end of the line

There are more of course, but those are the ones you simply can’t live without. For those who don’t know the ^N notation means ctrl+N, don’t confuse it with hats mentioned above.

This guide also discusses some other nice tools like brace expansion, bash functions and aliases.

Additional Reading:

Del.icio.us Linkroll

del.icio.us logoI’ve (finally) added a linkroll to the Draconis Software Blog, provided by del.icio.us. Over time, I’ve been adding interesting programming, science, lifehack, and other related links to my bookmarks, and thought I’d share them here. Hope you find them useful.

Grokking WordPress: The WordPress Loop and Theme Files

WordPressThere are a lot of people out there using WordPress to run their blog (this one does), and understanding a bit of how it works can go a long way to wrangling it to meet your needs. Recently, I wanted to add several buttons to the bottom of my post pages: buttons to submit the pages to digg, Reddit, and other sites. The trick is, I didn’t know how to make changes to just the post pages (read: singles) and not to my index page. This article outlines the basics of how WordPress handles displaying pages, and how you can start customizing it a bit beyond just pluggable themes.

(Read the article)

RSP version 2.3 is out

RSPWe’ve been working on updating our network monitoring and management software RSP to version 2.3. This release focuses on making it easier for new users to start using the software (especially for those who aren’t necessarily interested in setting up a full-blown monitoring infrastructure). If you haven’t tried it out yet, download the trial version and let us know what you think! We’re constantly looking for feedback on our efforts.

(Read the article)