Skip to main content
38 events
when toggle format what by license comment
Apr 23 at 22:33 comment added John Smith I've had this, copied from this answer, in my .bash_rc for quite some time. It's still missing commands from other sessions, I can't figure out the logic of what it includes and what it doesn't but this definitely doesn't make it include everything.
Feb 2 at 4:53 comment added Daniel Kaplan @ChrisKimpton: The problem with this PROMPT_COMMAND solution is that the numbers for each history item changes after each command... Technically, isn't that the problem with this HISTCONTROL? I'm asking to make sure I understand the original answer
Feb 21, 2024 at 20:07 comment added Geremia @ChrisKimpton I use !? or ctrl-r more often anyways, so that's not a big deal.
Sep 11, 2021 at 12:20 comment added Socowi @dolmen @DeanM .bashrc runs only for interactive shells. Neither bash -c '...', nor bash script.sh, nor ./script.sh will execute the rc file. To confirm this yourself, add echo bashrc into your rc file or use strace --trace=file if you are paranoid.
Jan 19, 2021 at 14:01 comment added Cadoiz Consider this fantastic guide (search for "shopt"): catonmat.net/the-definitive-guide-to-bash-command-line-history
Jul 10, 2020 at 15:47 comment added Marek Židek Why is the history -c command needed? I anyone has a clue, please provide some details.
Jun 13, 2020 at 8:39 history edited Vlastimil Burián CC BY-SA 4.0
formatting only, minor edit
S Nov 5, 2019 at 20:31 history suggested suntzuisafterU CC BY-SA 4.0
When using the export command some strange behaviour occurs. Specifically, try running `bash` to reload the configuration file, then `echo $PROMPT_COMMAND`. The $PROMPT_COMMAND variable becomes n copies of this command when export is used!! Not good. The answer also does not specify why export
Nov 5, 2019 at 17:34 review Suggested edits
S Nov 5, 2019 at 20:31
Oct 9, 2019 at 6:11 comment added Dan Nestor Is the third $ in the variable expansion a typo?
Jun 17, 2019 at 0:56 comment added Marc.2377 Related to @dolmen's comment: using export in .bashrc
Jan 24, 2019 at 17:22 comment added DeanM @dolmen In order to avoid the definitions in non-interactive shells, add this: if [ -z "${PS1}" ]; then return; fi.
Jan 23, 2019 at 11:49 comment added dolmen @DeanM Incorrect solution: a shell script launched from a terminal has access to the terminal but is still non interactive (see the INVOCATION section of the bash manual).
Dec 22, 2018 at 0:47 comment added Dylanthepiguy It looks like the PROMPT_COMMAND in this answer breaks the ignoredups:erasedups, which intends to remove already existing duplicate entries. If you repeatedly alternate between two commands, and then look at the last several lines in the history, we can see that there are duplicates.
Sep 26, 2018 at 21:16 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).
Nov 7, 2017 at 16:50 comment added Kangarooo @ChrisKimpton history numbers dont change when added to history file a line witch you read with history command. It reads as it is already in history file. Executing !1 will be from that file executed. Added are only to number 3 n 4 n 5 etc not overwriting. Executing command is adding a line after all previious at end and not changing some previous.
S Oct 13, 2017 at 15:46 history suggested user1133275 CC BY-SA 3.0
Add the following to ~/.bashrc
Oct 13, 2017 at 14:14 review Suggested edits
S Oct 13, 2017 at 15:46
Jan 11, 2017 at 18:20 comment added zyxue I am trying to adopt this trick on Mac OS. It works great on a regular bash session where $PROMPT_COMMAND is set to update_terminal_cwd, a function set in line 9 of /etc/bashrc_Apple_Terminal (found via a trick learned here). But inside a screen session, $PROMPT_COMMAND becomes an empty string, which means /etc/bashrc_Apple_Terminal is probably not executed anymore. Do you know why? I tested that such problem doesn't happen on CentOS 6.7, where $PROMPT_COMMAND was set very differently.
Nov 2, 2016 at 21:10 review Suggested edits
Nov 2, 2016 at 21:42
Jun 21, 2016 at 14:43 comment added dolmen 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).
Feb 29, 2016 at 20:49 comment added Piotr Dobrogost 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.
Jan 22, 2015 at 12:37 comment added tommy.carstensen I don't think it's necessary to set ignoredups, if you already do erasedups?
S Dec 15, 2014 at 22:00 history suggested Tobu CC BY-SA 3.0
Go back to not using -cr, which somehow breaks at shell startup. Sorry.
Dec 15, 2014 at 21:46 review Suggested edits
S Dec 15, 2014 at 22:00
S Dec 15, 2014 at 21:14 history suggested Tobu CC BY-SA 3.0
Explain a bit more. I think the HISTCONTROL setting is broken, though
Dec 15, 2014 at 21:03 review Suggested edits
S Dec 15, 2014 at 21:14
S Dec 15, 2014 at 20:56 history edited HalosGhost CC BY-SA 3.0
history -c and -r can be combined; wewt syntax highlighting \o/
S Dec 15, 2014 at 20:56 history suggested Tobu CC BY-SA 3.0
history -c and -r can be combined
Dec 15, 2014 at 20:55 review Suggested edits
S Dec 15, 2014 at 20:56
S Mar 27, 2014 at 19:17 history suggested Harmony Orb CC BY-SA 3.0
It's generally safer to add things to the end of the prompt command than the beginning. Other commands in PROMPT_COMMAND won't be added to the history, but any command that uses $? needs to be at the front of PROMPT_COMMAND (for instance Powerline).
Mar 27, 2014 at 19:06 review Suggested edits
S Mar 27, 2014 at 19:17
Mar 14, 2014 at 22:06 comment added Rajat Gupta Could I put this setting globally in global bashrc so that it overrides settings for all users ?
Apr 10, 2013 at 18:13 comment added sage @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.
Dec 19, 2012 at 2:15 comment added Suan 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?
Nov 7, 2012 at 12:28 comment added Chris Kimpton 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...
Apr 26, 2011 at 23:07 vote accept Oli
Aug 26, 2010 at 14:37 history answered Pablo R. CC BY-SA 2.5