Search my site
Twitter
Flickr
Archives

Blog Posts

Entries in tips (1)

Sunday
Nov282010

Fix Command Line Mistakes With Carat (^) Symbol Substitution

Open the Tip Jar Creative Commons License photo credit: usnationalarchives

Its time to open the tip jar again. The command line is incredibly powerful but requires perfect typing of commands and paths. I did not know how to fix a command until I read the lifehacker article. It seems every time I consider myself an expert I see a simple tip that *quashes* my ego back to novice status.

The Carat (^) symbol in many terminal or command shell environments is a simple text substitution command. It follows an idea of '^stringtorelpace^replacementstring'. This is great for fixing errors or substituting commands.

Fix a typo

mb2:~ mark$ la -lh /usr/local/nagios/etc/nagios.cfg
-bash: la: command not found
mb2:~ mark$ ^la^ls

This corrects the mistyped 'ls' command.

Change a command

Another interesting use is to change the command used. For example you may want to first list 'ls' the file to see if it exists, and if not, create it with 'nano'.

mb2:~ mark$ ls /usr/local/nagios/etc/nagios.cfg
ls: /usr/local/nagios/etc/nagios.cfg: No such file or directory
mb2:~ mark$ ^ls^nano

There are many time saving tricks that can be used with this simple command. Check out the source articles for more information.