next up previous
Next: Pipes and Redirection Up: Introduction to the Linux Previous: Shells

More Shell Commands

There are a few other shell commands that may prove useful. The history command shows the last commands you typed, and you can give a number as an argument to change how many commands are displayed.

[phasnip@mijpnb1 Linux]$ history 5
    22  10:58   cd ~
    23  10:58   setenv MYVAR hello
    24  10:58   echo $MYVAR
    25  10:59   cd Teaching/Linux/
    26  10:59   history 5
To repeat the last command, use !!.

[phasnip@mijpnb1 Linux]$ !!
history 5
    23  10:58   setenv MYVAR hello
    24  10:58   echo $MYVAR
    25  10:59   cd Teaching/Linux/
    26  10:59   history 5
    27  11:00   history 5
Notice that the very first line of output tells you what `!!' was expanded to.

We can also run any of the commands in the history in one of two ways. The first is to use a single ! followed by the number of the command

[phasnip@mijpnb1 Linux]$ !27
history 5
    24  10:58   echo $MYVAR
    25  10:59   cd Teaching/Linux/
    26  10:59   history 5
    27  11:00   history 5
    28  11:01   history 5

The second is to use a single ! followed by some text. The shell we execute the last command that started with this text.

[phasnip@mijpnb1 Linux]$ !echo
echo $MYVAR
hello

if we type anything after the first bit of text it will be appended to the expanded command.

[phasnip@mijpnb1 Linux]$ !echo everyone
echo $MYVAR everyone
hello everyone



Phil Hasnip 2007-08-23