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*

10
  • 2
    Why not "history -n" (reload lines not already loaded) instead of "history -c; history -r" ? Commented Sep 14, 2011 at 20:40
  • @Graham: I did not want to use history -n because it messes up the history counter. Also, I found history -n to be too unreliable. Commented Sep 16, 2011 at 12:02
  • 2
    One disadvantage: Commands with multi-line strings are normally still preserved in the current session. With this trick, they are split into individual lines instantly. Using -n for -c -r does not help, neither does cmdhist or lithist. I don't think there is a workaround at this point. Commented Feb 1, 2012 at 12:30
  • 40
    After trying this for a bit, I've actually found that running only history -a, without -c and -r, is better usability-wise (though it's not what the question asked). It means commands you run are available instantly in new shells even before exiting the current shell, but not in concurrently running shells. This way Arrow-Up still always selects the last-run commands of the current session, which I find much less confusing. Commented Feb 4, 2012 at 15:15
  • outstandingly good answer, this works reliably unlike the more common "history -a; history -n" Commented Jan 12, 2013 at 22:07