Created
May 7, 2021 12:44
-
-
Save ggarnier/d7b752742cf8e97d55ff0cda379fbc1b to your computer and use it in GitHub Desktop.
Remove duplicates from .bash_history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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