Troubleshooting (files):
Find a file or directory
find / -type f -name "filename" 2>/dev/null
find / -type d -name "dirname" 2>/dev/null
find files that contain a pattern
find . -type f -exec grep -l 'version' {} \;
Troubleshooting (system):
Find a file or directory
find / -type f -name "filename" 2>/dev/null
find / -type d -name "dirname" 2>/dev/null
check if machine is a vm or barebone
dmidecode -s system-manufacturer
check folder disk usage
du -hs * | sort -h
check open port
(echo > /dev/tcp/10.254.4.54/22) >/dev/null 2>&1 && echo "It's up" || echo "It's down"
check for listening ports
sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN
sudo ss -tulpn | grep LISTEN
sudo lsof -i:22 ## see a specific port such as 22 ##
sudo nmap -sTU -O IP-address-Here
Troubleshooting (SSL):
Check expiry date on .pem file
openssl x509 -enddate -noout -in /path/to/certificate.pem
Maintenance:
dry-run an update on OS
sudo yum check-update
Check if a reboot is required
needs-restarting -r
remove cache of updates for old data
rm -rf /var/cache/yum
block icmp
sysctl -w net.ipv4.icmp_echo_ignore_all=1
File manipulation:
remove empty lines from file
sed -i '/^$/d' <filename>
Account control:
change to root
sudo -i
Grep sudo users
rm -f /tmp/names; for user in $(getent passwd | cut -d: -f1); do count=$((count+1)); if sudo -l -U "$user" | grep -q "ALL"; then echo "$user" >> /tmp/names; echo "Checked $count of $(getent passwd | cut -d: -f1 | wc -l) users."; fi; done; clear; cat /tmp/names; rm -f /tmp/names
Logrotate Configuration Cheat Sheet:
This cheat sheet provides an extensive list of Logrotate configuration directives, their descriptions, and examples.
Use this as a quick reference to master log rotation on Unix-like systems.
Basic structure:
Each configuration block is tied to a log file or set of log files. Example:
/var/log/example.log {
daily
rotate 7
compress
missingok
notifempty
create 0640 root adm
}
Configuration Directives & Examples:
Basic Settings:
rotate <count>
Keep
daily | weekly | monthly | yearly
Frequency of rotation.
Compression Options:
compress
Compress old versions of log files with gzip.
nocompress
Do not compress old logs.
delaycompress
Postpone compression to the next rotation cycle (used with compress).
File Handling:
missingok
Ignore missing log files and don’t issue an error.
notifempty
Do not rotate the log if it is empty.
ifempty
Rotate the log even if it is empty (default behavior).
create <mode> <owner> <group>
Create a new log file with specified permissions.
copy
Make a copy of the log file and truncate the original.
copytruncate
Truncate the original log file after copying it (useful for active logs).
Date & Naming:
dateext
Append an extension with the current date to rotated log files.
dateformat .%Y-%m-%d
Custom format for dateext (e.g., .2025-06-06).
extension <ext>
Force specific extension for rotated files (e.g., .log).
Size-Based Rotation:
maxage <days>
Remove rotated logs older than
minsize <size>
Rotate only if log size is above
size <size>
Rotate if log file size meets threshold, regardless of time.
maxsize <size>
Do not rotate if log is larger than specified size.
Directory & Scripts:
olddir <dir>
Move rotated logs to a specified directory.
sharedscripts
Run postrotate script once for all matching logs.
postrotate/endscript
Script to run after log rotation.
prerotate/endscript
Script to run before log rotation.
firstaction/endscript
Run only once before rotation begins (before prerotate).
lastaction/endscript
Run once after rotation finishes (after postrotate).
tabooext + <ext>
Treat additional extensions as taboo (not rotated).
Full Example Configuration:
/var/log/myapp/*.log {
daily
rotate 10
size 100M
compress
delaycompress
missingok
notifempty
create 0640 appuser adm
sharedscripts
postrotate
systemctl reload myapp > /dev/null 2>&1 || true
endscript
}
Tips:
- Run
logrotate -d <config>
to debug your config without applying changes. - Use
logrotate -f <config>
to force rotation for testing. - Logrotate is typically triggered via cron or systemd timers.
- Keep your config DRY by centralizing shared logic in /etc/logrotate.conf and using includes.
Script: add sudo user
Create a sudo user that won’t prompt for password on executing sudo commands.
#!/bin/bash
# Ensure script is run as root
if [[ $EUID -ne 0 ]]; then
echo "❌ This script must be run as root"
exit 1
fi
# Prompt for new username
read -p "Enter new username: " username
# Check if user already exists
if id "$username" &>/dev/null; then
echo "⚠️ User '$username' already exists."
exit 1
fi
# Prompt for password (silent input)
read -s -p "Enter password for $username: " password
echo
read -s -p "Confirm password: " password_confirm
echo
# Check passwords match
if [[ "$password" != "$password_confirm" ]]; then
echo "❌ Passwords do not match."
exit 1
fi
# Create user with home directory and bash shell
useradd -m -s /bin/bash "$username"
# Set user password
echo "${username}:${password}" | chpasswd
# Add user to sudo group
usermod -aG sudo "$username"
# Create a sudoers file to allow passwordless sudo
echo "$username ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/$username"
chmod 440 "/etc/sudoers.d/$username"
echo "✅ User '$username' created with bash shell and passwordless sudo access."