Hack 53. Execute a specific command from history

In the following example, If you want to repeat the command #4, execute !4 as shown below.

# history | more
       1  service network restart
       2  exit
       3  id
       4  cat /etc/redhat-release

# !4
cat /etc/redhat-release
Fedora release 9 (Sulphur)

Comments on this entry are closed.

  • Jared Casey August 14, 2013, 3:26 pm

    I set an alias and use tail

    alias h=’history | tail’

    That way when your history gets long, you only see the most recently commands you executed.

    you could also do one that lets you control the number of results:

    alias hn=’history | tail -n $1′