My own linux cheatsheet

cause im lazy and have alzheimers

(this list will constantly be expanded)
  1. ffmpeg
  2. MySQL
  3. Linux
  4. NodeJS & npm
  5. Python3


ffmpeg converts videos. Simple examples:

ffmpeg -i -vcodec h264 -acodec aac output.mp4
ffmpeg -i -vcodec libvpx -acodec libvorbis output.webm
ffmpeg -i input.mp4 -b:a 96k -vf scale="iw/4:-1" -crf 80 out.mp4

The first one converts to mp4, the second to webm, the third just heavily compresses the video and audio.
A list of possible Arguments:
Usage: ffmpeg -i input.file X output.file
where X equals a number of 'arguments':

// Convert Music to lower bitrate
-map 0:a:0 -b:a 96k

//Set bitrate (compresses if lower than source, a = audio, v = video)
-b:v 1M
-b:a 96k

//Change scale of video (iw = width, ih = height, -1 means auto)
-vf scale="iw/2:-1"
-vf scale="1280:720"

//Add Text to the video
-vf drawtext="text='MyTextHere': fontcolor=white: fontsize=24: x=(w-text_w)/2: y=(h-text_h)/2"

//Compress video (Should be between 20 and 28, 51 is max and looks ew)
-crf 24
-crf 51

//Change Video Codec ('copy' means copy the input video codec)
-vcodec h264
-vcodec libvpx
-vcodec copy

//Change Audio Codec
-acodec aac
-acodec mp3
-acodec copy

//Remove Audio / Video

//Example mp4 to mp3 convert
ffmpeg -i in.mp4 -vn -acodec mp3 out.mp3

//Convert a video from 30 to 60 FPS
ffmpeg -i Input.mp4 -filter:v "minterpolate='fps=60'" Out60.mp4

//Make 2 input files side by side (-r makes the framerate be 60)
ffmpeg -i 30.mp4 -i 60.mp4 -r 60 -filter_complex hstack comparison.mp4

//Cut Video (time either in 00:01:23.000 or in seconds format, here seconds are used)
//This would cut the video, so that only second 3 to 8 plays (5 seconds long)
// -t = duration, -ss = starttime
-ss 3 -t 5

//Convert a folder from mp4 to mp3
for i in *.mp4; do ffmpeg -i "$i" "$(basename "$i" .mp4)".mp3  ; done

// Copy codes (copy video and audio stream, makes video cutting way quicker)
-c copy


After installing mysql-server:


Creating a new user in mysql:
mysql -u root -p
CREATE USER 'martin'@'localhost' IDENTIFIED BY 'MyOwnPasswordHere?';
GRANT ALL PRIVILEGES ON mydb.* TO 'martin'@'localhost';


//change folder
cd folder

//go back one folder
cd ..

//you can string folders together
cd ../folder1/folder2

//edit text files
nano file

//list files in your current folder

//list files in a folder
ls folder

// list all files, in a list, with human readable filesizes
ls -ahl

//output file to console
cat file.txt

//output file to console but with scroll option
less file.txt

//create folder
mkdir folder

//create file
touch file

//remove file
rm file

//open a "task manager" (or install htop, it's better)

//show IP Addresses
ip a

//want to know if you have internet? ping something

//want to stop a process currently on console? press CTRL+C
tail -f access.log

//download a web page

//get help about a command (in this example: command1)
man command1

//find files recursively
find . -name "*.txt"

//change permissions of folder + subfolders to user
sudo chown -R user:user folder/

//search through a log file for user
cat access.log | grep "user"

//continuously output log file
tail -f access.log

//show filesize of current folder + subfolders
du -sh

//show available storage space
df -h

//move files from folder to current directory
mv folder/* .

//delete folder and everything inside it
rm -r folder

//zip folder
zip -r folder

//copy folder
cp -r folder archive/folder

//only output the first few lines / the last few lines
head file.txt
tail file.txt

//only output the last 3 lines
tail -n 3 file.txt

//restart system services
systemctl restart apache2

//get status of service
systemctl status apache2

//add service to autostart (enable = autostart, disable = no autostart)
systemctl enable apache2

//systemctl for older systems:
service apache2 status

//update program list for installations
apt-get update

//update older programs
apt-get upgrade

//install a new program (for example htop)
apt-get install htop

//search for packages containing name (for example htop)
apt-cache search htop

//make a file executeable
chmod +x file

//list open ports
netstat -plunt

//make a command run in the background with & (not recommended for tail -f and similar)
zip -r folder &
nordvpn connect germany &

//make a command run in a seperate "window"
apt-get install screen
screen -S minecraft
//This creates a new "screen" with the name minecraft
//executes the server there
//and returns from the screen back to your normal console (CTRL+A & D)
//screen is like a new "window" that you can open
//to return to a previous screen
screen -r minecraft

//Move every file from "foldername" that ends with ".txz" to "/dest/path"
find foldername -name '*.txz' -type f -exec mv {} '/dest/path' \;

//Download list of youtube videos seperated with \n:
youtube-dl -x -f best --batch-file filename.txt

Example iptables (CentOS has this in /etc/sysconfig/iptables):
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited

Run a command x times:
for run in {1..100}; do command; done

Example fail2ban (in /etc/fail2ban/jail.local):
//For Debian
bantime = 900
maxretry = 3
enabled = true

//For CentOS
bantime = 900
maxretry = 3
banaction = iptables-allports
enabled = true

Getting SSL Certificates (for https):
sudo apt-get install certbot python-certbot-apache
certbot --apache

NodeJS & npm

Install node and npm via binary:
Get the newest version of node&npm here: (Linux Binaries (x64))

sudo mkdir -p /usr/local/lib/nodejs
sudo tar -xJvf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/nodejs 

Add the following to the end of ~/.profile:
  # Nodejs
  export PATH=/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin:$PATH

Then refresh your profile:
  source ~/.profile

Now you can use npm & node:
  npm version
  node -v

If you have a ~/.bash_profile file you have to add the following to it:
  # Load user profile file
  if [ -f ~/.profile ]; then
    . ~/.profile

Then your .profile (aka. nodejs) file will load automatically upon login.

It's also good to link node and npm to locations the systems expect them to be in.
In this example with x64 v12.18:
  sudo ln -s /usr/local/lib/nodejs/node-v12.18.0-linux-x64/bin/node /usr/local/bin/node
  sudo ln -s /usr/local/lib/nodejs/node-v12.18.0-linux-x64/bin/node /usr/bin/node
  sudo ln -s /usr/local/lib/nodejs/node-v12.18.0-linux-x64/bin/node /usr/lib/node
  sudo ln -s /usr/local/lib/nodejs/node-v12.18.0-linux-x64/bin/npm /usr/bin/npm
  sudo ln -s /usr/local/lib/nodejs/node-v12.18.0-linux-x64/bin/npm /usr/local/bin/npm

Python 3

#Read file with codec "latin-1" line for line
with open("file.txt","r",encoding="latin-1") as f:
  data = f.readlines()
  for line in data: