Last active
March 27, 2019 15:36
-
-
Save kai-qu/d84d94d05e8ce974d12cdfd101123da7 to your computer and use it in GitHub Desktop.
Please run the script on a copy of your history and not the actual history file. This script only works on bash history. See usage instructions below. (code by Gaurav Manek)
This file contains hidden or 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
#!/usr/bin/bash | |
while IFS='' read -r line || [[ -n "$line" ]]; do | |
IFS=' =' read -r -a array <<< "$line" | |
for index in "${!array[@]}" | |
do | |
if [ $index -eq 0 ] || [[ "${array[index]:0:1}" == "-" ]]; then | |
printf "%s\t" "${array[index]} " | |
else | |
printf "%s\t" $(echo "${array[index]}" | md5sum | cut -c-32) | |
fi | |
done | |
printf "\n" | |
done |
For zsh
, you can do the following:
cat <filename> | cut -d\; -f2 | ./sanitize.sh > myhistory.tsv
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
chmod u+x sanitize.sh
cat <filename> | bash sanitize.sh > myhistory.tsv
Input:
<filename>
, the path to (a copy of) your bash history.Output:
myhistory.tsv
, a version of your bash history with all personal information (non-commands and non-flags) replaced by its MD5 hash.Dependencies:
md5sum
, the hash function we use. This comes pre-installed on Ubuntu, and installation instructions are here for Mac.