Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6557641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:05:58+00:00 2026-05-25T13:05:58+00:00

I’m writing my PROMPT_COMMAND=history -a;$PROMPT_COMMAND but I still get some duplicates from different terminal

  • 0

I’m writing my PROMPT_COMMAND="history -a;$PROMPT_COMMAND" but I still get some duplicates from different terminal sessions. It seems I still will get some duplicates but I get less using the command PROMPT_COMMAND="history -w;$PROMPT_COMMAND".

I know I can do the history -a;history -c; history -r but I don’t want them all synced. I only want that to occur when I call history -n. I’m basically down to using either history -a or history -w but I can’t seem to find the difference between the two. Which one would be better to have to avoid as many duplicates as possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:05:59+00:00Added an answer on May 25, 2026 at 1:05 pm

    history -a will append your current session history to the end of the history file.

    history -w will replace the content of the history file with your current session history.

    Which one avoids more duplicates? Theoretically neither. Neither -a nor -w checks for duplicates.

    One can argue that -w avoids more duplicates but only because it removes the previous content of the history file. So any potential duplicate entries in the file are eliminated. Along with anything else in the file.


    Background information:

    In any bash session there are at least two versions of history. One is the history that is stored in the memory of the currently running bash process (the session history). The other is the history saved on disk (the history file).

    Each running bash session has its own session history. Typically there is only on history file shared by all bash sessions.

    When working in bash you typically only work with the session history. the history file is only touched on certain events. some of the events are: bash startup, bash shutdown, invocation of history -a or history -w. There are more but that is beyond the scope of this question.

    Typically bash is configured as follows: on bash startup read from history file to session history. while running only manipulate the session history. on shutdown replace content of history file with current session history.

    Bash has features to avoid duplicates in the session history. But as far as i know no features to avoid duplicates in the history file.


    Bash features to avoid duplicates in the session history (not the history file):

    set the special bash variable HISTCONTROL to ignoredups. now if you execute the same command twice (immediately one after the other) the second will not be saved to session history. it does not remove previous entries which are not immediate.

    set the special bash variable HISTCONTROL to erasedups. now if you execute a command it will remove all previous instances of that command in the session history. but note it only does so in the current session history. It does not search for duplicates in the history file. It will also not prevent duplicates from entering your session history when using history -n (read entries from history file to session history).


    more details in the bash manual:

    about the history command.

    about the special variable HISTCONTROL.

    see also

    https://unix.stackexchange.com/questions/1288/preserve-bash-history-in-multiple-terminal-windows#

    https://serverfault.com/questions/337123/strange-bash-history-behaviour-when-running-multiple-sessions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.