In need of a handy cheat sheet filled with commands you can use in your Linux terminal? This page has got you covered with lots of commands for lots on different use cases. Missing a command? Feel free to send me your ideas, questions and suggested commands in the comments.
Install a full LAMP stack with just one command
sudo apt install lamp-server^
Notes: this stack contains PHP5 on Ubuntu 14.04 or lower, and PHP7 on Ubuntu 16.04 or higher. Not tested with non-LTS releases.
Install PhpMyAdmin
sudo apt install phpmyadmin
Install and configure basic SMB/CIFS shared folder
sudo apt install samba
sudo smbpasswd -a bart
sudo echo "[bart]" >> /etc/samba/smb.conf
sudo echo "path = /home/bart" >> /etc/samba/smb.conf
sudo echo "valid users = bart" >> /etc/samba/smb.conf
sudo echo "read only = no" >> /etc/samba/smb.conf
sudo service smbd restart
Install security updates only
sudo unattended-upgrades -d
Upgrade to the next LTS release
sudo do-release-upgrade
Cleanup the package database and no longer needed packages
sudo apt autoremove && sudo apt clean && sudo apt autoclean
List kernel version and Ubuntu release version
uname -a && lsb_release -a
Edit and update grub settings
sudo nano /etc/default/grub
update-grub
Get unique IPs accessing your site
For Apache:
cat /var/log/apache2/access.log | awk '{print $1}' | sort -u
For NGINX:
cat /var/log/nginx/access.log | awk '{print $1}' | sort -u
Use Ubuntu as a NAT router
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p
Get bash history
cat ~/.bash_history
Get SSH login attempts that exceed set limits
cat /var/log/auth.log | grep "attempts"
Get successful local and remote login attempts
cat /var/log/auth.log | grep "systemd-logind"
Check for open, listening ports
netstat -tulpn
Get RAM usage information
free -m
Get processes currently running as root
ps aux | grep "root"
Stop and start interface
ifconfig eth0 down
ifconfig eth0 up
Note: replace eth0 with your desired network interface.
Manually set static IP on interface
ifconfig eth0 192.168.1.20 netmask 255.255.255.0 broadcast 192.168.1.255
Check for running systemd services
systemctl list-units --state=running --type=service
Check for configuration errors
jounalctl -xe
Get cron jobs
Hourly cron jobs:
ls /etc/cron.hourly
Daily cron jobs:
ls /etc/cron.daily
Weekly cron jobs:
ls /etc/cron.weekly
Monthly cron jobs:
ls /etc/cron.monthly
Other cron jobs:
ls /etc/cron.d
Hardware/software info
List PCI devices:
lspci
List block devices:
lsblk
List USB devices:
lsusb
List CPU devices
lscpu
List general HW info
lshw
List loaded kernel modules
lsmod
File/directory creation, parsing and IO
Create new file
touch new.file
Get contents of file
cat new.file
Overwrite a file
echo "Hello, dear Linux user!" > new.file
Append to a file
echo "Hello, dear Linux user!" >> new.file
Get lines containing a substring
cat new.file | grep "user"
Permissions
Set ownership of a folder, recursively:
chown -R www-data:www-data /var/www/html
Note: this sets the ownership of the /var/www/html folder to the default web server user and group.