Skip to content

Instantly share code, notes, and snippets.

@ggarnier
Created May 7, 2021 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ggarnier/d7b752742cf8e97d55ff0cda379fbc1b to your computer and use it in GitHub Desktop.
Save ggarnier/d7b752742cf8e97d55ff0cda379fbc1b to your computer and use it in GitHub Desktop.
Remove duplicates from .bash_history
# This script removes duplicate lines from .bash_history file.
# It preserves the order from the latest usage of each command,
# to make it easier to search with ctrl+r
from os import path
bash_history_path = path.expanduser("~/.bash_history")
with open(bash_history_path, "r") as f:
lines = f.readlines()
clean_history = []
for line in reversed(lines):
if line not in clean_history:
clean_history.append(line)
print("".join(reversed(clean_history)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment