For e.g.

Ubuntu focal; branch for 2020
Ubuntu bionic; branch for 2018

lsb_release -a

# Useful Commands

ls -a
    list files in a directory; -a is for all
ls -la
    list files with more details like file permissions
less
    Similar to cat but crops result according to screensize
    Use cntl+g to reach the top most
gedit
    edit a file in text editor
source
    executes a file
pwd
    prints the full path of the current directory
cp
    copy files from one directory to another
    to copy a directory add flag "-r"
mv
    move files from one directory to another
The tilde (~) is a Linux "shortcut" to denote a user's home directory
    Use it to avoid typing the home directory all the time
    For example, cd ~/development/moodle
vim
ignore the '>' from below commands:
    to edit a file
        press i (start insert mode) > esc > :wq enter
    to edit a read only file
        press i > esc > :w -!sudo tee %
cat
    read files
rm (remove files or directories)
    rm <file name>
    rm -r <directory name>
ls
    ls -al
        ls -al /var/backups/pg/pg-12-main/current/pg-

double tab
    automatically enters the most possible command
Create a symlink (shortcut link)
    ln -s <original location> <desired location>
ssh <hostname>
    Accept ssh key on a server (hostname)
Screen Record
    Ctrl+Alt+Shift+R
Open terminal
    Ctrl+Alt+T
Lock workstation
    Windows key + L
top
    runs the task manager (windows terminology) on linux machine
download folder from a server
    scp -r <server-name>:<path> <path-local-machine>
    scp -r learn-xxxxxx-xxxxxx-testing-web1:/var/lib/sitedata/victoria-testing-moodle/lang/mi_wwow_old ~/development/backup
find
    find string pattern in folder
        grep -r "string to be searched" /path/to/dir
    find file in a directory
        find /path/to/folder/ -iname *file_name_portion*
sudo -u postgres -i
    run login shell as a -u (user)
sudo -l
    See sudo permissions for logged in user. Useful when lets say you are trying to use sudo -u www-data.
tail
    tail shows the last 10 entries useful in case of lets say seeing records from syslog for cron
    tail var/log/
    tail -t var/log/syslog
    tail -n var/log/syslog (specify the no of entries you want to see)
Read archived files
    zless <filename>
Control external monitor brightness
    xrandr -q | grep " connected"
    xrandr --output HDMI-2 --brightness 1.1

# BashRC File

.bashrc file is used to add elements to $PATH (among other things); To edit it you can use:
    gedit ~/.bashrc
    Add the required edits
    Save it
    source ~/.bashrc

This will execute the changes done to it. It is mainly used for configuring install applications on your linux machine.

# $HOME

$HOME is sits in the shell and points to the home directory

# Cron Scheduler

https://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html

# Zip

gunzip *.gz

# Create large test files

Install pdftk and then combine files as required
    pdftk document.pdf document.pdf cat output document200.pdf
    https://visibleearth.nasa.gov/images/73751/july-blue-marble-next-generation-w-topography-and-bathymetry

# Operation not permitted

Run the command as sudo as a user of the file owner
For e.g. sudo -u www-data rm 383141_idnumbersmsd.txt

# Linux screen

https://linuxize.com/post/how-to-use-linux-screen/

# List empty directories

find . -name .git -prune -o -type d -empty -print

# Deletes empty directories

find . -empty -type d -delete

# Find apache version

apache2 -v

# Restart apache server

sudo service apache2 restart

# HTTPS

TLS/SSL
https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-18-04

# error logs location of a site

Depends on the configuration of the webserver.
Let's say nginx could store its logs in /var/log/nginx/error.log and site specific logs in /var/log/sitelogs/<sitename>/error.log

# Investigating error logs

Find a word in the multiple log files.

zgrep  -c "New public key has been" /var/log/sitelogs/error.log*
zless /var/log/sitelogs/error.log-20220113.gz | grep "New public key has been"

# Diskspace

sudo du -h --max-depth=1 -x /
sudo du -h --max-depth=1 -x /<folder-name>

# Find IP address of my machine

hostname -I
In windows we use ipconfig

# Ubuntu switch PHP version

sudo update-alternatives --config php

# pipe output to file

Make behat |tee behat.log