Remove user history cleaning - only clean root
User bash histories are now completely skipped. The script only cleans root's bash history. Changes: • Removed user history detection and cleaning • Removed prompt for user history cleaning • Only root bash history is cleaned (last 50 entries) • Faster execution, no prompts for user accounts
This commit is contained in:
@@ -73,46 +73,8 @@ if [ -f ~/.bash_history ]; then
|
|||||||
history -w
|
history -w
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean bash history for all users (optional - skip if only root is used)
|
# Skip user bash histories - only clean root
|
||||||
echo "→ Checking user histories..."
|
# (User histories are not touched to avoid affecting normal user operations)
|
||||||
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..."
|
|
||||||
|
|
||||||
# Remove last 50 lines from user history
|
|
||||||
total_lines=$(wc -l < "$user_home/.bash_history")
|
|
||||||
if [ "$total_lines" -gt 50 ]; then
|
|
||||||
lines_to_keep=$((total_lines - 50))
|
|
||||||
head -n "$lines_to_keep" "$user_home/.bash_history" > "$user_home/.bash_history.tmp"
|
|
||||||
mv "$user_home/.bash_history.tmp" "$user_home/.bash_history"
|
|
||||||
chown "$username:$username" "$user_home/.bash_history" 2>/dev/null
|
|
||||||
echo " ✓ Cleaned (removed last 50 entries)"
|
|
||||||
else
|
|
||||||
> "$user_home/.bash_history"
|
|
||||||
chown "$username:$username" "$user_home/.bash_history" 2>/dev/null
|
|
||||||
echo " ✓ Cleared (file had < 50 entries)"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
else
|
|
||||||
echo " ✓ Skipped user histories (only root cleaned)"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Clean system logs (pattern-based for logs, not history)
|
# Clean system logs (pattern-based for logs, not history)
|
||||||
echo "→ Cleaning system logs..."
|
echo "→ Cleaning system logs..."
|
||||||
|
|||||||
Reference in New Issue
Block a user