Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a command to bash history without executing it? [closed]

Tags:

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.

like image 262
Rene Avatar asked Mar 04 '16 23:03

Rene


People also ask

How do I run a command in history?

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.

What does Do not store command in bash history?

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.

How do I see previous bash commands?

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.

What does Ctrl-R do in bash?

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.

Why can't I See my Bash commands in 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 ;)

How to clear the history of the Bash shell in Linux?

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.

How do I put all of history into Var in Linux?

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:

How to execute a command from history in Linux terminal?

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).


1 Answers

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

like image 181
Richard Hamilton Avatar answered Oct 11 '22 23:10

Richard Hamilton