# Step 1: Delete the offending entries in the buffer while read -r i; do history -d "$i" done < <(HISTTIMEFORMAT= history | awk '$2 == "open" { print $1 }' | sort -rn) # Step 2: write out the amended buffer to HISTFILE immediately history -w