LWN.net Logo

CLI Magic: Using command history in the bash shell (Linux.com)

CLI Magic: Using command history in the bash shell (Linux.com)

Posted Jul 4, 2006 3:45 UTC (Tue) by michaelk (subscriber, #1978)
In reply to: CLI Magic: Using command history in the bash shell (Linux.com) by xoddam
Parent article: CLI Magic: Using command history in the bash shell (Linux.com)

! and such features are nice to know about for historical reasons (and to prove you're a l33t h4x0r), but they're about as useful as ex. AFAIK there are no terminals left that can't rewrite the prompt line; let me know if anyone's stuck with a Teletype® :-)

Much of the ! syntax is arcane, but a few things are very useful still. How about:

$ vi myprog.c
...
:wq
$ cc !$

And similar. That's faster than cursor+editing keys.


(Log in to post comments)

CLI Magic: Using command history in the bash shell (Linux.com)

Posted Jul 4, 2006 4:24 UTC (Tue) by xoddam (subscriber, #2322) [Link]

Well, you learn something new every day. Thanks!

... but this example hardly disproves that the syntax is arcane! :-)

CLI Magic: Using command history in the bash shell (Linux.com)

Posted Jul 4, 2006 7:38 UTC (Tue) by glettieri (subscriber, #15705) [Link]

!$ is useful. However, I prefer "Alt + .": it rewrites the last argument from the previous command line, and you can use it many times to get arguments further down in the command history.

it just gets better!

Posted Jul 4, 2006 7:46 UTC (Tue) by xoddam (subscriber, #2322) [Link]

"Invent something in the morning and they're making cheap imitations by
noontime!" -- Sesame Street

(I wish I could remember the name of the inventor; Google can't help me)

CLI Magic: Using command history in the bash shell (Linux.com)

Posted Jul 4, 2006 8:46 UTC (Tue) by NAR (subscriber, #1313) [Link]

It might be even faster if you have vim and a Makefile for myprog.c to startup vim and issue the
:make
command in vim to compile the file. There might even be a plugin or something that would compile the source without a makefile.

Bye,NAR

CLI Magic: Using command history in the bash shell (Linux.com)

Posted Jul 4, 2006 12:07 UTC (Tue) by tzafrir (subscriber, #11501) [Link]

:make myprog

And I have been through enough situations where the terminal is not fast enough. Either because it is dog slow or because I know exactly what I want to type.

Another useful combination:

$ which mozilla
/usr/bin/mozilla
$ sh -x `!!`

CLI Magic: Using command history in the bash shell (Linux.com)

Posted Jul 4, 2006 12:36 UTC (Tue) by Dom2 (guest, #458) [Link]

M-. is usually quicker to type than "!$"...

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds