Skip to main content
28 events
when toggle format what by license comment
Mar 6, 2024 at 4:31 comment added Geremia This puts each line of multi-line commands as separate commands in the history file. Viz., cmdhist works (multi-line commands converted to single-line ones separated with ;), but lithist (which uses \n instead) results in splitting multi-line commands into different commands/lines/entries in the history.
Sep 7, 2020 at 3:24 comment added sayap @dolmen Actually, there is also a strong reason to not do export PROMPT_COMMAND, as doing so will result in stale "Window Title" when inside a screen session.
Sep 26, 2018 at 21:15 comment added sage I recommend renaming HISTFILE as well - otherwise a single terminal can overwrite your entire history if run even once (as happened to me a few times before I changed HISTFILE).
Mar 7, 2018 at 18:07 comment added Aleksandr Levchuk This solution is much faster than Pablo R.'s popular answer. The prompt does not pause. I think my hist size was too big for this to work efficiently.
Jun 21, 2016 at 14:44 comment added dolmen There is no reason to export the variables: you are defining them in .bashrc so they will be defined in every shell (even in non-interactive ones, which is also wasteful)
May 4, 2016 at 15:05 comment added Giampaolo Rodolà You made my day!
Jul 21, 2014 at 12:23 comment added user844541 @trusktr can you share your code for href?
Jul 17, 2014 at 7:54 review Suggested edits
Jul 17, 2014 at 8:09
S Jun 21, 2014 at 20:52 history suggested dawud CC BY-SA 3.0
Remove edit message, as it is available in the revision history
Jun 21, 2014 at 20:47 review Suggested edits
S Jun 21, 2014 at 20:52
Mar 14, 2014 at 22:04 comment added Rajat Gupta Could I put this setting globally in global bashrc so that it overrides settings for all users ?
S Nov 8, 2012 at 17:58 history post merged (destination)
Oct 20, 2012 at 23:06 comment added pts Another problem with simplistic approaches like history -a; history -c; history -r is that commands are not merged in execution order, i.e. they don't guarantee pressing the Up key repeatedly would show commands in (reverse) order they were executed. (The script I wrote solves this by prepending the timestamp to each command.)
Oct 20, 2012 at 23:01 comment added pts Another problem with calling history -r at each prompt is that it's too slow (more than 0.2 sec) as soon as there are tens of thousands of entries. (The script I wrote solves this.)
Oct 20, 2012 at 23:01 comment added pts Another problem with PROMPT_COMMAND is if the long-running process (e.g. sleep 999) and the shell are both killed (because e.g. the terminal window is closed), then the command won't ever be saved to any history file. (The script I wrote solves this.)
Oct 16, 2012 at 15:56 comment added trusktr @pts I too was aiming for live behavior, but then I realized it is more convenient to have terminal specific histories which make working on different things in different terminals easier. I found this to be very useful: stackoverflow.com/questions/338285/#answer-7449399 Based on that, I made myself an alias called href that refreshes the history of my current terminal instantly and cleans up the history file in the process. Whenever I open a new terminal, that cleanup/sync is executed in my bashrc file so the new terminal has the latest history. I'm using that along with history -a
Sep 13, 2012 at 22:14 history migrated from stackoverflow.com (revisions)
May 3, 2012 at 15:29 comment added Ehtesh Choudhury @XiongChiamiov, yes I'd like to see that as well.
Mar 24, 2012 at 13:19 comment added sup @Xiong Chiamiov: how exactly should the resulting line be then? I cannot get this working
Dec 26, 2011 at 23:14 comment added Xiong Chiamiov @pts: Try trap 'history -a; history -c; history -r;' DEBUG instead of PROMPT_COMMAND.
Mar 25, 2011 at 13:43 comment added pts FYI None of the solutions mentioned here can solve the following problem. I have two shell windows A and B. In shell window A, I run sleep 9999, and (without waiting for the sleep to finish) in shell window B, I want to be able to see sleep 9999 in the bash history.
Feb 17, 2011 at 5:36 comment added Brandon Use this to get infinite history: bash eternal history. HOWEVER, this is complimentary to the code above, since it won't be reloaded automatically.
Aug 15, 2010 at 23:26 comment added kch @Charles Merriam see lesmana's answer. I now updated mine with the relevant bit.
Mar 18, 2010 at 0:33 comment added kch Not really a workaround, but I certainly feel less the need to use history replacements by using the arrow keys for history search. That is, it search lines in history starting with whatever you typed so far. In .inputrc: "\e[B": history-search-forward "\e[A": history-search-backward
Mar 17, 2010 at 19:33 comment added Charles Merriam Hmm.. This kills the ability to use $ !34, as the command numbers change every prompt. Is there a workaround @Davide @Schof @kch?
Oct 16, 2009 at 15:16 vote accept deadprogrammer
S Nov 8, 2012 at 17:58
Oct 13, 2009 at 17:39 comment added Davide The PS1 trick didn't work on AIX either, but this did! +1
Sep 19, 2008 at 17:49 history answered kch CC BY-SA 2.5