NimbUx
Posts: 93
Joined: Fri Jan 03, 2020 10:33 am

deleting the current selected *history* line from Bash, et al, ?

Fri Feb 14, 2020 1:17 pm

Have been reviewing "man history" but couldn't find if there is some convenient way, like at a key-press, while scrolling back the Bash (or other compatible) history buffer, to *delete* the line currently shown - permanently removing it from the historic....
I'm reminded of JPsoftware's 4DOS and 4NT shells which had a comparable history mechanism, inspired, no doubt, from *x shells, and where "Ctrl-D" would delete the current item, but obviously that key cannot work similar under Linux.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 25033
Joined: Sat Jul 30, 2011 7:41 pm

Re: deleting the current selected *history* line from Bash, et al, ?

Fri Feb 14, 2020 1:47 pm

history -d <line number> seems the closest.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

stubright
Posts: 112
Joined: Sat Dec 24, 2011 11:12 pm

Re: deleting the current selected *history* line from Bash, et al, ?

Sat Feb 15, 2020 2:50 am

not exactly convenient but

Code: Select all

nano ~/.bash_history
from terminal could do what you want (replace nano with your favourite terminal text editor)

GlowInTheDark
Posts: 380
Joined: Sat Nov 09, 2019 12:14 pm

Re: deleting the current selected *history* line from Bash, et al, ?

Thu Feb 27, 2020 12:41 am

NimbUx wrote:
Fri Feb 14, 2020 1:17 pm
Have been reviewing "man history" but couldn't find if there is some convenient way, like at a key-press, while scrolling back the Bash (or other compatible) history buffer, to *delete* the line currently shown - permanently removing it from the historic....
I'm reminded of JPsoftware's 4DOS and 4NT shells which had a comparable history mechanism, inspired, no doubt, from *x shells, and where "Ctrl-D" would delete the current item, but obviously that key cannot work similar under Linux.
Some notes on this:
1) "man history" is interesting, but that's primary of value to C programmers. Not much in there of a UI nature.

2) I am familiar with the 4DOS functionality to which you refer (it was nice), and I'm pretty sure bash doesn't have anything like that. Although, there's a *LOT* of text in "man bash" about the various keys that do various things (for both fans of Emacs and fans of vi). I'm in the vi camp, and I've learned and used many of these things, but feel like there's tons of things in there that I've never needed to learn. But I didn't see anything in there along the lines of interactively deleting history lines (in the manner you would like).

3) (This is the substantive part of this post) The focus in bash seems to be more on avoiding cluttering up the history list with junk in the first place. There is a shell variable HISTCONTROL that you might be interested in. I have long had HISTCONTROL set to "ignoreboth", but I have recently added "erasedups" to it. That seems to alleviate the main problem with the history list - which is it cluttering up with duplicate lines, as you execute the same stuff over and over.

Another thing that might be useful, but which I have not tried/tested yet, is using HISTIGNORE to ignore "short" commands. I have a general feeling that there's not much point in putting commands shorter than, say, 3 characters, into the history list. E.g., I have "j" aliased to "jobs -l" and I use this a lot, but it would be nice if that didn't waste a history list slot every time I use it.

I'm not sure what the "pattern" would be to match strings of length less than 3.

Anyway, hope this helps. Let me know if you figure anything else out.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Return to “Beginners”