Ops Command Cheatsheet
- #CLI
 - #Shell Script
 - #Tips
 - #Troubleshooting
 
- 2019/04/06
 
Linux
- Check for zombie processes
 
ps aux | grep [\<]defunct\>
- Show parents/children
 
ps auxf
- Kill a process
 
sudo kill -9 {PID}
- Disk usage
 
du -sh /path/to/dir
- Free space
 
df -h /path/to/dir
- CPU usage
 
top
- Memory usage
 
free -m
- List files sorted by mtime
 
ls -lrt
- List users
 
sudo cat /etc/passwd
- Switch user
 
sudo su - username
- SSH bastion config
 
cat ~/.ssh/config
- CPU details
 
sudo less /proc/cpuinfo
Shell
- Capture 
lsoutput into an array and loop: 
items=(`ls -l`)
for item in ${items[@]}
do
  # work
 done
- Discard stdout:
 
./script.sh > /dev/null
- Append stdout to a file:
 
./script.sh >> filename.log
Apache
- Service status
 
sudo service httpd status
- Test config (vhosts, etc.)
 
sudo service httpd configtest
- Graceful restart
 
sudo service httpd graceful
DNS
- Query records
 
dig domain.com
- Lookup domain info
 
nslookup domain.com
- Check ownership
 
whois domain.com
MySQL
- Service status / restart
 
sudo service mysqld status
sudo service mysqld restart
- Log in
 
mysql -u USER -h HOST -p
- Show databases / tables
 
SHOW DATABASES;
SHOW TABLES;
- Show global variables
 
SHOW GLOBAL VARIABLES;
SHOW GLOBAL VARIABLES LIKE 'pattern';
- List users / grants
 
SELECT Host, User FROM mysql.user;
SHOW GRANTS FOR 'user';
Cron
- Service status
 
sudo service crond status
- View jobs
 
crontab -l
  Share: 
X (Twitter)