Tag Info

Hot answers tagged

59

You can achieve removal from the history file using the commandline in two steps: Typing history -d <line_number> deletes a specified line from the history in memory. Typing history -w writes the current in-memory history to the ~/.bash_history file. The two steps together remove the line permanently from the in-memory history and from the ...


44

Just edit the file ~/.bash_history.


35

I have found the solution to my problem in the ZSH documentation. Oh-my-zsh seems to map the ↑ and ↓ Keys to something like bindkey '\e[A' history-search-backward bindkey '\e[B' history-search-forward Which yields the exact behavior I described above. The ZSH Documentation describes the behavior of history-search-backward as Search backward in the ...


22

To prevent a command from being added to the history in the first place, make sure that the environment variable HISTCONTROL contains among its colon-separated values the value ignorespace, for example (add e.g. to .bashrc): $ export HISTCONTROL=ignorespace This will prevent any command with a leading space from being added to the history. You can then ...


19

You've probably got INC_APPEND_HISTORY set. The INC_APPEND_HISTORY option, from man zshoptions: This options works like APPEND_HISTORY except that new history lines are added to the $HISTFILE incrementally (as soon as they are entered), rather than waiting until the shell exits. The option that you want is APPEND_HISTORY: APPEND_HISTORY If ...


15

history -s command


14

First of all, if the command you're about to issue is sensitive, unsafe, or you just don't need it cluttering up your history, it is best/quickest to just prevent it from entering the history in the first place. Make sure that $HISTCONTROL contains ignorespace: (bash)$ echo $HISTCONTROL ignoredups:ignorespace Then proceed any command you don't want in ...


10

You can search the history using Ctrl+R and then type the search string (e.g. iw to find iwconfig). Then you can then still navigate through the history at that point with the up and down arrow keys, or press Ctrl+R again to find the previous occurence.


10

Hit F7 to bring up a list of the last few commands, then you can hit the first letter to jump to the first matching entry. Hit the same letter repeatedly to move up commands with the same first letter (working from newest from oldest).


9

Several techniques: Prevent sensitive information from being stored in the history file If you've entered some password on a command line, then realize that all commands are logged, you could either: Force exit the current session without saving history: kill -9 $$ This will drop all current history. Type ↑ (up arrow) in the open bash session ...


8

Bash History Any new commands that have been issued in the active terminal can be appended to the .bash_history file with the following command: history -a The only tricky concept to understand is that each terminal has its own bash history list (loaded from the .bash_history file when you open the terminal) If you want to pull any new history that's ...


7

If you supply a negative argument to Alt-., it reverses direction. The easiest way to do that (with standard keybindings) is Alt-- (equivalent to an argument of -1). So, after one or more Alt-. keypresses, pressing Alt-- will cause the next Alt-. to go in the reverse direction. (Just ignore the argument dialog which appears when you press Alt--.)


7

You need to mark the nonprinting sections of the prompt with \[ ... \] so bash can tell they won't take up space on screen. Try: export PS1="\w \[\e[0;32m\]\$(vcprompt -f '[%n:%b]')\[\e[m\]\$ "


6

Copy & Paste this to your .zshrc: Cursors are using local history: bindkey "${key[Up]}" up-line-or-local-history bindkey "${key[Down]}" down-line-or-local-history up-line-or-local-history() { zle set-local-history 1 zle up-line-or-history zle set-local-history 0 } zle -N up-line-or-local-history down-line-or-local-history() { zle ...


6

Your history is logged by your shell. Bash, for example, uses the file ~/.bash_history by default. It is also not limited by your current session, but the history is usually persisted beyond that, up to what the environment variables HISTSIZE and HISTFILESIZE allow. More information on how the history works in bash is available in it's man page, in the ...


6

Assuming your shell is bash, this question has been asked and answered on SO. Press Ctrl-U to delete the command line from the location of the cursor up to the beginning. Precede this by Ctrl-E if the cursor isn't at the end of the line. Or press Ctrl-C to cancel the current prompt and obtain a new one, which has the benefit that you still see the command ...


5

history -s command You can even bind a keystroke to do this for you. You can enter this at a Bash prompt: bind '"\C-q": "\C-a history -s \C-j"' or add this to your ~/.inputrc: "\C-q": "\C-a history -s \C-j" then you can type something and press Ctrl-q and it will be added to the history without being executed. The space before "history" causes the ...


5

After a bit of practice, I found how to use the workaround solution. I matched the correct syntax to print a filtered list, I did it with history | grep iwconfig (it wasn't so difficult after all); with the output I can use !n with the now easy-to-read filtered list.


5

There are two reasons why your script will not work as intended: The bash environment for a running script is "non-interactive" and does not have the history features enabled. The bash environment for a running script is independent from the environment you are interactively working in. Depending on your use case the easiest solution might be to source ...


4

You need to set HISTFILE for your users to the location you need, set the following in .bash_profile for the user, and for new users set it in the user skeleton directory, most likely /etc/skel/.bash_profile export HISTFILE=/home/$USER/.bash_history


4

If you need to remove several lines at the same time I normally use this: history | grep <string> | cut -d ' ' -f 3 | awk '{print "history -d " $1}' If you need to remove the last command you can use: history -d $((HISTCMD-2))


4

Here's one way to set up history-search-backward and history-search-forward: Step1: Put the following in your /etc/inputrc file: $if mode=emacs "\ep": history-search-backward "\en": history-search-forward $endif (Or simply put the following between in the existing if statement) "\ep": history-search-backward "\en": history-search-forward Step2: ...


4

You can setup a special zle widget to show only local history items: function only-local-history () { zle set-local-history 1 zle up-history zle set-local-history 0 } zle -N only-local-history Assuming, that ↑ is bound to up-line-or-history (I think that is default), you can bind this widget to another key stroke, like ...


4

I wanted the same behaviour for zsh with oh-my-zsh installed and found plugin history-substring-search. I achieved the same behaviour described above by adding the plugin to my ~/.zshrc: plugins=(git brew npm history-substring-search) I guess this plugin did not exist back when this question was raised. Just an alternate way to achieve the same thing. ...


3

Cleaner version of the Scott's answer: Put this to .bash_profile: if [ ! -z "$EXECUTE_COMMAND" ]; then history -s "$EXECUTE_COMMAND" $EXECUTE_COMMAND fi Start bash this way: $ EXECUTE_COMMAND='ping 127.0.0.1' bash -l PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. 64 bytes from 127.0.0.1: icmp_req=1 ttl=64 time=0.177 ms ... ^C 5 packets ...


3

history | sed -i 59d 59 is the line number. Cannot be anything sweeter than this :)


3

Use the script command DESCRIPTION Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1).


3

That's easy... if you know the corresponding option: unsetopt HIST_VERIFY Put this in your ~/.zshrc and do source ~/.zshrc if you want that behavior to be permanent. Explanation from man zshoptions: HIST_VERIFY Whenever the user enters a line with history expansion, don't execute the line directly; instead, perform history expansion and ...


3

When you log in to the remote machine, the sshd there allocates a pseudo-terminal and starts your login shell. Any processes you start, background or foreground, are child processes of that shell. (Read up on "fork", "parent process", and "child process"; use the "pstree" command to look at the state of the system.) If you disconnect, for example by closing ...



Only top voted, non community-wiki answers of a minimum length are eligible