Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com 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 stackoverflow.com/questions/8168676/… –  Pumbaa80 Feb 2 '13 at 10:23

3 Answers 3

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'
    else
        history | grep -iEF "$*" | grep -v '^ *[0-9]* *h '
    fi
}

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

 
discard

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.