Skip to content

Instantly share code, notes, and snippets.

@k8scat
Last active March 25, 2026 03:09
Show Gist options
  • Select an option

  • Save k8scat/b784398130b18e5b1cb7636a30d1deaf to your computer and use it in GitHub Desktop.

Select an option

Save k8scat/b784398130b18e5b1cb7636a30d1deaf to your computer and use it in GitHub Desktop.
clean traces
#!/bin/bash
set -e
if [[ $EUID -ne 0 ]]; then
exit 1
fi
unset HISTFILE
export HISTSIZE=0
export HISTFILESIZE=0
history -w && history -c && echo > ~/.bash_history
if [ -f ~/.bash_history ]; then
echo > ~/.bash_history
fi
if [ -f /root/.bash_history ]; then
echo > /root/.bash_history
fi
for user_home in /home/*; do
if [ -f "$user_home/.bash_history" ]; then
echo > "$user_home/.bash_history"
fi
done
for user_home in /root /home/*; do
[ -f "$user_home/.zsh_history" ] && echo > "$user_home/.zsh_history"
[ -f "$user_home/.zhistory" ] && echo > "$user_home/.zhistory"
[ -f "$user_home/.fish_history" ] && echo > "$user_home/.fish_history"
done
if [ -f /var/log/wtmp ]; then
echo > /var/log/wtmp
fi
if [ -f /var/log/btmp ]; then
echo > /var/log/btmp
fi
if [ -f /var/log/lastlog ]; then
echo > /var/log/lastlog
fi
log_files=(
"/var/log/syslog"
"/var/log/auth.log"
"/var/log/kern.log"
"/var/log/messages"
"/var/log/dmesg"
"/var/log/user.log"
"/var/log/daemon.log"
"/var/log/debug"
"/var/log/mail.log"
"/var/log/faillog"
"/var/log/lastlog"
)
for log in "${log_files[@]}"; do
if [ -f "$log" ]; then
echo > "$log"
fi
done
if [ -f /var/log/apt/history.log ]; then
echo > /var/log/apt/history.log
fi
if [ -f /var/log/apt/term.log ]; then
echo > /var/log/apt/term.log
fi
if [ -f /var/log/alternatives.log ]; then
echo > /var/log/alternatives.log
fi
if command -v systemctl >/dev/null 2>&1; then
systemctl restart rsyslog 2>/dev/null || true
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment