Geek Essential Objectively finite, subjectively infinite.

17Nov/090

Linux Shell Tip

Here's an interesting short cut that I never knew "^" and "!" in linux shell.

It's an interesting short cut, but it going to need some getting used to.

Link to the original article is listed at the bottom of the page and the original content copied is as below.

Tip: ^ and ! in the shell

I’m astounded. So don’t people know about using ^ and ! in the shell?!? Last week I watched an experienced Linux user carefully hit the ↑ cursor key to get a previous line of history, then ←&→ just to make a simple edit!

Here’s my 30 second guide:

!! Repeat the previous command. Example: 

$ ls
bin  d  Desktop  rpmbuild  tmp
$ !!
ls
bin  d  Desktop  rpmbuild  tmp
!-2 (etc) Repeat the command 2 previously (so !! = !-1), or for any number previously. This is the most useful I think.
^foo^bar Replace foo with bar in the previous command. eg: 

$ ls -l /etx/httpd/conf.d/local.conf
ls: cannot access /etx/httpd/conf.d/local.conf: No
such file or directory
$ ^etx^etc
ls -l /etc/httpd/conf.d/local.conf
-rw-r--r-- 1 root root 76 2009-07-16 14:59 /etc/httpd/conf.d/local.conf
!foo Run the most recent command that started foo, eg: 

$ !ls
ls -l /etc/httpd/conf.d/local.conf
-rw-r--r-- 1 root root 76 2009-07-16 14:59 /etc/httpd/conf.d/local.conf

Today I discovered that these are called event designators. When I first saw someone using them it was on an Apollo workstation circa 1991, and I pretty quickly picked these up myself.

Original Link: http://rwmj.wordpress.com/2009/11/16/tip-and-in-the-shell/

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.