Last Updated: February 25, 2016
·
871
· mountaincode

Bash save for later

This is a very simple tip, but I use it all the time. What do you do when you're typing a long shell command and you realize you forgot some other commands that need to happen first? You could cut and paste to a text editor to save it for later or you could prepend your other commands and hope you don't make a mistake.

$ do_something && do_something_else && do_something_later with_a | lot_of `complex_args` > "and stuff you don't want to type a second time"

I like to hit ctrl-a (go to start of line) then comment out the line.

$ #do_something_later with_a | lot_of `complex_args` > "and stuff you don't want to type a second time"
$ do_something
$ do_something_else

Now I can do a bunch of work in the shell. When I want to go back to my long complex command, I hit ctrl-r (reverse history search) then hash. Then I can just uncomment instead of retyping everything.

(reverse-i-search)`#': #do_something_later with_a | lot_of `complex_args` > "and stuff you don't want to type a second time"

3 Responses
Add your response

Good tip! And you can also use Ctrl-a, Ctrl-k and Ctrl-y sequence.

over 1 year ago ·

Cheers!

over 1 year ago ·

@dongli That's works well too. It looks like there's also a "kill ring" like in Emacs so that you can hit Alt-y if you want to cycle through lines you've killed in the shell.

over 1 year ago ·