Bart Simons

Bart Simons

Thoughts, stories and ideas.

Bart Simons



Ubuntu Cheat Sheet

Bart SimonsBart Simons

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
Get unique IPs accessing your site

For Apache:

cat /var/log/apache2/access.log | awk '{print $1}' | sort -u


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 netmask broadcast
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:


List block devices:


List USB devices:


List CPU devices


List general HW info


List loaded kernel modules

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"

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.

Bart Simons

Bart Simons

View Comments