Make user history cleaning optional in trace eraser
User bash history cleaning is now optional with a prompt, since most users only work as root. Changes: • Added user count detection • Prompts: "Clean user bash histories too? (y/n) [n]" • Default is "no" (skip user histories) • If no users exist, automatically skips • Only cleans root history by default (faster, covers 99% of use cases) This makes the script faster and more sensible for typical usage where only root is used to run the toolkit.
This commit is contained in:
@@ -73,9 +73,22 @@ if [ -f ~/.bash_history ]; then
|
||||
history -w
|
||||
fi
|
||||
|
||||
# Clean bash history for all users
|
||||
# Clean bash history for all users (optional - skip if only root is used)
|
||||
echo "→ Checking user histories..."
|
||||
user_count=0
|
||||
for user_home in /home/*; do
|
||||
[ -d "$user_home" ] && user_count=$((user_count + 1))
|
||||
done
|
||||
|
||||
if [ "$user_count" -eq 0 ]; then
|
||||
echo " ✓ No user accounts found (skipped)"
|
||||
else
|
||||
echo " Found $user_count user account(s)"
|
||||
echo ""
|
||||
read -p " Clean user bash histories too? (y/n) [n]: " clean_users
|
||||
|
||||
if [ "$clean_users" = "y" ] || [ "$clean_users" = "Y" ]; then
|
||||
for user_home in /home/*; do
|
||||
if [ -f "$user_home/.bash_history" ]; then
|
||||
username=$(basename "$user_home")
|
||||
echo " → Cleaning history for $username..."
|
||||
@@ -94,7 +107,12 @@ for user_home in /home/*; do
|
||||
echo " ✓ Cleared (file had < 50 entries)"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
else
|
||||
echo " ✓ Skipped user histories (only root cleaned)"
|
||||
fi
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Clean system logs (pattern-based for logs, not history)
|
||||
echo "→ Cleaning system logs..."
|
||||
|
||||
Reference in New Issue
Block a user