Use case is:
I type a long command and then I realize I need to run something else first.
I usually run it then CTRL C immediately.
I guess I could also do echo "command" >> $HISTFILE
, but that won't work with quotes.
Another way to get to this search functionality is by typing Ctrl-R to invoke a recursive search of your command history. After typing this, the prompt changes to: (reverse-i-search)`': Now you can start typing a command, and matching commands will be displayed for you to execute by pressing Return or Enter.
Another way to prevent the shell from saving a command in history is to prefix the command with a space. But this depends fully on the value of the $HISTCONTROL shell variable defined in the ~/. bashrc Bash startup file. It should be set to have one of these values: ignorespace or ignoreboth, for this method to work.
Bash includes search functionality for its history. The typical way of using this is through searching backwards in history (most recent results returned first) using the CTRL + R key combination. For instance, you can type CTRL + R , and begin typing part of the previous command.
Ctrl+R – starts a reverse search, through the bash history, simply type characters that should be unique to the command you want to find in the history.
If you put space before the command, that won't save the command in history for some OS. In any given Bash session, set the history file to /dev/null by typing: Note that, as pointed out in the comments, this will not write any commands in that session to the history! Just don't mess with your system administrator's hard work, please ;)
To clean all the current history of the Bash shell, for example, all we have to do is to invoke the it with the -c option. We also have the chance to delete a specific command in the history, by using the -d option, and passing the line offset as argument. Imagine we want to remove line 1 from the current in-memory history.
will put all of history into var and you need some more logic to find the command you want. If you are using bash, which I presume you are; Type the history number: Then Press: Ctrl + Alt + e, Now the desired command from history is sitting in your prompt waiting to be executed without changing the default behavior of history:
Then Press: Ctrl + Alt + e, Now the desired command from history is sitting in your prompt waiting to be executed without changing the default behavior of history: It also works for aliases, substitutions, expansions and arguments of history say: $ echo !555:1, ~, $HOME, $ (echo hi).
Just use history -s arg
.
-s The args are added to the end of the history list as a single entry.
http://ss64.com/bash/history.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With