22 Feb 2010

Linux shell commands

Posted by gavin

A number of commands and trick that I regularly use in Linux to make my life easier.

!$

Typing !$ into a bash command will substitute the last argument from the previous command.

[gavin@pc]: date > test.txt
[gavin@pc]: cat !$
Mon Feb 22 12:02:53 WET 2010

!! will provide the whole of the previous command

[gavin@pc]: updatedb
updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db'
[gavin@pc]: sudo !!

Adding bind Space:magic-space to ~/.bashrc will mean that pressing space after entering either of these commands will immediately convert (e.g. !$ will be replaced with test.txt).

!* provides all of the arguments from the previous line, e.g.

[gavin@pc]: touch a.txt b.txt c.txt
[gavin@pc]: chmod 777 !*

will create 3 files and set the permissions on each to 777.

Finally, using !somecommand will search backwards through the command history to match a command

[gavin@pc]: cat test.txt
[gavin@pc]: date > test.txt
[gavin@pc]: !ca
Mon Feb 22 12:02:53 WET 2010

You don’t have to enter the whole command, just enough to match the line you want.

VN:F [1.8.0_1031]
Rating: 0.0/10 (0 votes cast)
  • Print
  • Add to favorites
  • Facebook
  • StumbleUpon
  • del.icio.us
  • FriendFeed
  • Twitter
  • Digg

Tags: , ,

Leave a Reply

Message:

  • Browse

    or
  • Latest Content

  • Gallery

    2008_0427Stanage0019 2008_0505SevenSisters0016 IMG_6796 2010_0102XmasAndNewYear0105
  • Tags

  • RSStwitter logo

  • Comments