Last edit: 22 July 2024

General

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#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
#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
#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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/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
/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
/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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#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;
#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;
#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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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
# 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
# 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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# restart PHP-fpm
sudo service php<version>-fpm restart
# restart PHP-fpm sudo service php<version>-fpm restart
# restart PHP-fpm
sudo service php<version>-fpm restart

systemctl

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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
# 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
# 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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# List docker images
sudo docker images
# Remove docker image
sudo docker rmi <image-ID>
# List docker images sudo docker images # Remove docker image sudo docker rmi <image-ID>
# List docker images
sudo docker images

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

TMUX

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# new named session
tmux new -s ramin
# detach from a session (inside a terminal)
tmux detach
# kill-session
tmux kill-session -t ramin
# go to last session
tmux a
# List all sessions
tmux ls
# new named session tmux new -s ramin # detach from a session (inside a terminal) tmux detach # kill-session tmux kill-session -t ramin # go to last session tmux a # List all sessions tmux ls
# new named session
tmux new -s ramin

# detach from a session (inside a terminal)
tmux detach

# kill-session
tmux kill-session -t ramin

# go to last session
tmux a

# List all sessions
tmux ls