Reset bash history search position
There is Meta + >, which is bound to end-of-history
and useful if you're in the middle of your history. The meta key is usually the Alt key.
If you see that your incremental history search isn't successful, you can use Ctrl + G, which is bound to abort
and restores the previous line and history position.
Check the manual for more commands like these.
Control-r reverse-i-search in Bash: how do you reset the search in Cygwin?
I never tried making this the default when hitting Esc, but Bash uses readline
for input, which accepts Emacs-style keybindings by default, so you can go to the bottom using M->
(usually either by combining Meta/Alt and > or by following the Esc key with >).
If M->
does not work because your terminal does not let you enter that, try ^G
(Ctrl and G
simultaneously). That is the "cancel" stroke in Emacs and usually works with readline
too.
How to delete history in a range in linux bash
for ((i=258;i<=262;++i)); do "history -d $i"; done;
as you said, is simply not working due to quotes
for i in {5..10}; do history -d $i; done;
is working, but you must ensure to have entries from 5 to 10, which in your examples, you don't have.
Take into account that every item you remove, the position indexes of the other items scale down of one.
Basically you should reverse loop items:
for i in {10..5}; do history -d $i; done;
to not be affected by the position index changes while looping.
Edit
As Cyrus suggested, there's another approach.
You want to remove items from 258 to 262, a total of 5 entries (262 is included)
You can delete 5 times the entry at position 258.
Taking advantage of the index scaling down of one every time you delete an item:
- the first time, you delete the item 258
- the second time, you delete the ex-item 259, that has scaled down to 258
- the third time, you delete the ex-ex-item 260, that has scaled down to 259 (in the first delete) and to 258 (in the second delete)
- the fourth time, you delete the ex-ex-ex-item 261, that has scaled down to 260 (in the first delete), to 259 (in the second delete) and to 258 (in the third delete)
- the fifth time, you delete the ex-ex-ex-ex-item 262...
How do I change bash history completion to complete what's already on the line?
Probably something like
# ~/.inputrc
"\e[A": history-search-backward
"\e[B": history-search-forward
or equivalently,
# ~/.bashrc
if [[ $- == *i* ]]
then
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
fi
(the if statement checks for interactive mode)
Normally, Up and Down are bound to the Readline functions previous-history
and next-history
respectively. I prefer to bind PgUp/PgDn to these functions, instead of displacing the normal operation of Up/Down.
# ~/.inputrc
"\e[5~": history-search-backward
"\e[6~": history-search-forward
After you modify ~/.inputrc
, restart your shell or use Ctrl+X, Ctrl+R to tell it to re-read ~/.inputrc
.
By the way, if you're looking for relevant documentation:
Bash uses The GNU Readline Library for the shell prompt and history.
Recovering raw history from current bash session
history -a
will overwrite your bash history file with the history returned by the history
command for the current session.
You need to copy your current bash history, and can then append it to the original file.
It does not, however, bring back the first 500 entries.
Thanks to @markp-fuso for this solution.
Preserve bash history in multiple terminal windows
Add the following to your ~/.bashrc
:
# Avoid duplicates
HISTCONTROL=ignoredups:erasedups
# When the shell exits, append to the history file instead of overwriting it
shopt -s histappend
# After each command, append to the history file and reread it
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"
Related Topics
Profiling Arbitrary Cuda Applications
Git - Crlf Issue in Windows + Linux Dual Boot
File/Directory Permissions Trailing + ( Drwxr-Xr-X+ )
Unix/Linux Ipc: Reading from a Pipe. How to Know Length of Data at Runtime
Reading Kernel Memory Using a Module
How to Cancel Command in Grunt Shell
Mmap Flag Map_Uninitialized Not Defined
Linux Device Driver Unsafe Fxsave/Fxrstor Bug - Any Precedents
Mpc/Mpd on Linux: How to Play Local Wav File
Add Timestamp to Cat Output from Shell Script
How The File Size Is Limited on a Specific File System
Hbase Does Not Run After ./Start-Hbase.Sh - Permission Denied
How to Change File Extension in Linux Shell Script