3 ms·
It's not a command but it is still useful. When you are typing a long command and you realize that you need to do other command or set of commands first, usuall
by matheusalmeida 15y ago
It's not a command but it is still useful. When you are typing a long command and you realize that you need to do other command or set of commands first, usually you type ctrl + c to cancel it. By default it does not save in the history. If you put # (comment the command) in front of the command (you can do it quickly with Ctrl + a #) and then you can use Ctrl + r to get it back. I'm sure there are other ways to save the command in the history but it is a simple way to have the same effect.
- telemachos 15y agoWhat I usually do in that situation is Ctrl + u (delete all the way back to the start of the line), then type the intermediate command, then Ctrl + y (place the deleted partial line back on the prompt, with my cursor at the end where it was). This assume Emacs-style bindings for the shell.
- reinhardt 15y agoI just put a random character instead of # to get "command not found".
- sjs 15y ago# seems safer... what if you're typing a mv command on a BSD machine that also has GNU binutils and the random character you hit is a "g"? Bad news.
- sjs 15y agoFor those using zsh hit alt-q to stash the current command. After you run the next command your stashed line will be brought back for you. alt-h behaves similarly but runs `man <command you were typing>`, so if you have this: $ rsync - and need to check the options, hit alt-h and the man page for rsync comes up. When you exit you'll be back at: $ rsync -
- joshcorbin 15y agoEven better: just type \ (line continuation) at point that you realize that you need to do something else first. Then hit Ctrl-c to cancel once you get to the new line.