Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a lot a commands that I want to run again, but there are a lot of them, and going up to them with the up arrow key is too long. Is it possible to get it in a cat/tail command and pipe it to a file ?

share|improve this question

migrated from Feb 2 '13 at 18:04

This question came from our site for professional and enthusiast programmers.

You don't need the up arrow. You can also just type Ctrl-r and then start typing one of your previous commands. Then type Ctrl-r repeatedly to cycle through a list of commands that match. – zedoo Feb 2 '13 at 10:07
It is stored in ~/.bash_history See also… – user123444555621 Feb 2 '13 at 10:23
up vote 3 down vote accepted

You can use the history command:

history > my_file
share|improve this answer
Great thanks I didn't know about it ! – Newben Feb 2 '13 at 10:03
FYI, the history command will output the contents of the .bash_history file, plus recently executed commands not yet stored in that file. – chepner Feb 2 '13 at 13:31

Type Ctrl-R and then type the first few letters of the command.

share|improve this answer

Adding this to ~/.inputrc would make the up and down arrows cycle through commands that match the start of the line:

"\e[A": history-search-backward
"\e[B": history-search-forward

I also use these functions a lot:

h() {
    if [ $# = 0 ]; then
        history 33 | sed '$d'
        history | grep -iEF "$*" | grep -v '^ *[0-9]* *h '

r() {
    history ${1-200} | sed 's/^ *[0-9]* *//' | tail -r > /tmp/recent
    open /tmp/recent -e

If you add " ": magic-space to .inputrc, you can insert command 1234 by typing !1234 and a space. But it also makes space stop work in irb and the interactive mode in gnuplot.

share|improve this answer
Very interesting ! – Newben Feb 3 '13 at 15:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.