These are mainly for my benefit, collected from a variety of sources. Will be updated as required.

System

Swappiness

Let’s only use our hard drive instead of RAM if we need to

$ cat /proc/sys/vm/swappiness
$ 60
# sysctl vm.swappiness=10

Bash

add to your ~/.bashrc

alias up='sudo apt-get update && sudo apt-get upgrade'                          
alias ll='ls -lha' 

The next one let’s your run $ mem sshd or $ mem python3 to see memory usage for all processes.

mem()
{
    ps -eo rss,pid,euser,args:100 --sort %mem | grep -v grep | grep -i $@ | awk '{printf $1/1024 "MB"; $1=""; print }'
}

Files

Copy file permissions

simon@computer:~/web/workdir/content/img$ chmod --reference=eczema-arm.
jpg compost-2021-05-13-*

Count files in a directory

ls | wc -l

Backup to server using rsync

simon@computer:~/books/pdf$ rsync -avc . simon@server:/home/simon/backup/books/pdf

SSH

Put this in your ~/.bashrc on your server

# show when we are using SSH                                                    
if [ -n "$SSH_CLIENT" ]; then text=" [ssh] "                                
fi

Web

Apache2 (httpd)

simon@server:~ [ssh] $ sudo apachectl
Usage: /usr/sbin/apachectl start|stop|restart|graceful|graceful-stop|configtest|status|fullstatus|help
       /usr/sbin/apachectl <apache2 args>
       /usr/sbin/apachectl -h            (for help on <apache2 args>)

Enable a module: sudo a2enmod rewrite

Check conf files /etc/apache2/sites-available/website.conf

simon@server:~ [ssh] $ sudo apachectl configtest
Syntax OK

Get apache configuration details:

simon@server:~ [ssh] $ sudo apachectl -V
Server version: Apache/2.4.46 (Debian)
Server built:   2021-01-20T07:40:46
Server's Module Magic Number: 20120211:93
Server loaded:  APR 1.6.5, APR-UTIL 1.6.1
Compiled using: APR 1.6.5, APR-UTIL 1.6.1
Architecture:   64-bit
Server MPM:     event
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"

which modules are loaded?

simon@server:~ [ssh] $ sudo apachectl -M
Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 brotli_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 expires_module (shared)
 filter_module (shared)
 headers_module (shared)
 mime_module (shared)
 mpm_event_module (shared)
 negotiation_module (shared)
 pagespeed_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 socache_shmcb_module (shared)
 ssl_module (shared)
 status_module (shared)

Enable a site: sudo a2ensite somewebsite.conf

Read the docs:

man apachectl and man a2ensite

Multimedia

ffmpeg

Some videos are way bigger than they should be. You’ll need to run mkdir conv in the target directory as this is where the sanitised vids will be saved.

for name in *.mp4;
do ffmpeg -i "$name" -vcodec libx264 -crf 28 -preset faster -tune film "conv/${name%.*}.mkv" ;
done

As above but also resize from 1080p to 720p

for name in *.mp4; 
do ffmpeg -i "$name" -vf scale=-1:720 -vcodec libx264 -crf 28 -preset faster -tune film "conv/${name%.*}.mkv";
done