Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

21
  • 44
    The problem with this PROMPT_COMMAND solution is that the numbers for each history item changes after each command :(. For example if you type history and 1) ls 2) rm, then you do !1 to repeat 1, the history number might change and might run the rm command... Commented Nov 7, 2012 at 12:28
  • 4
    When I do this, other already-open terminals don't have the last entered command when I press 'Up' until after I issue a command in that terminal - is this expected? If so, is there a way to truly modify other terminals' history instantly? Commented Dec 19, 2012 at 2:15
  • 10
    @Suan, this seems right to me based on the commands. I found that we can issue a null command (just press enter key) to get the history to update. Commented Apr 10, 2013 at 18:13
  • 5
    Actually history -a (...) does not trigger erasing duplicates according to this answer to the question Bash history: “ignoredups” and “erasedups” setting conflict with common history across sessions. This answer also gives the sequence of history -<option> commands that works with HISTCONTROL=ignoredups:erasedups setting. Commented Feb 29, 2016 at 20:49
  • 36
    There is no reason to export the HISTCONTROL and PROMPT_COMMAND variables: you are defining them in .bashrc so they will be defined in every shell (even in non-interactive ones, which is also wasteful). Commented Jun 21, 2016 at 14:43