Last edit: 4 April 2021

General

#Display OS
uname -a

# Fetches the list of available updates
sudo apt update

# Installs some updates; does not remove packages
sudo apt upgrade

# Installs updates; may also remove some packages, if needed
sudo apt full-upgrade

# Removes any old packages that are no longer needed
sudo apt autoremove

# Distribution upgrade
sudo apt dist-upgrade

# OS upgrade
sudo do-release-upgrade

#Delete GZip files older than 14 days
find *.gz -mtime +14 -exec rm {} \;

#Tar and zip a folder
tar -zcvf archive-name.tar.gz source-directory-name

#Unzip and untar a file
tar -zxvf prog-1-jan-2005.tar.gz

#Update alternatives in /etc/alternatives e.g PHP versions, phar
sudo update-alternatives --config php
sudo update-alternatives --config phar
sudo update-alternatives --config phar.phar

Nginx

/etc/nginx/sites-available

#start nginx
service nginx start

#stop nginx
service nginx stop

#restart nginx
service nginx restart

#reload nginx
service nginx reload

#check nginx config
nginx -t

#check nginx status
service nginx status

MySQL

#start
sudo /etc/init.d/mysql start

#stop
sudo /etc/init.d/mysql stop

#restart
sudo /etc/init.d/mysql restart

#mySQL dump
mysqldump --opt -uUSERNAME -pPASSWORD -h HOSTNAME DATABASE_NAME FILENAME.sql

#mySQL version
mysql -V

# Change user password
mysql -u root -p
uninstall plugin validate_password;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword';
FLUSH PRIVILEGES;

Let’s Encrypt / Certbot

# Register SSL certificate
sudo certbot --nginx -d domain.com -d www.domain.com

# See list of certificates/renewals
sudo certbot certificates

# delete certificate and renewal
sudo certbot delete --cert-name domain.com

# Dry-run
sudo certbot renew --dry-run

PHP

# restart PHP-fpm
sudo service php<version>-fpm restart

systemctl

# directory of services
/etc/systemd/system/

# Display service status
systemctl status <service>

# or...
systemctl show <service>

# Find path to service
systemctl show ssh.service | grep Path

locate systemd | grep <service>

# Stop the service 
systemctl stop <service>.service

# Start the service 
systemctl start <service>.service

Docker

# List docker images
sudo docker images

# Remove docker image
sudo docker rmi <image-ID>