Linux

SSH tunnel establish

ssh -f -N -L <remote_port>:localhost:<local_port> <user>@<server>

for example:

ssh -f -N -L 5432:localhost:5432 [email protected]

more info: ubuntu help, ssh magic (russian)

netcat to send files
ON SENDER:

nc -k -l [port] -q 1 < [filename]

for example:

nc -k -l 10000 -q 1 < video.mp4

ON RECEIVER:

echo "message" | netcat sender_ip sender_port > filename -

for example:

echo "dumping ya shit" | netcat 10.3.16.80 10000 > video.mp4 -

virtualbox

What to do if the guest machine can’t start

sudo apt-get autoremove virtualbox-dkms

sudo apt-get install build-essential linux-headers-$(uname -r) dkms virtualbox-dkms

in BIOS turn off secure boot, turn on vurtualization!

ffmpeg

compress with 2 passes, no resize

ffmpeg -y -i 2_1.mp4 -preset veryslow -c:v libx265 -b:v 150k -pass 1 -an -f mp4 /dev/null && ffmpeg -i 2_1.mp4 -preset veryslow -c:v libx265 -b:v 150k -pass 2 -c:a aac -b:a 64k output150_h265.mp4

enumerate video codecs available

ffmpeg -encoders

compress with 1 pass and desired filesize (ffmpeg will TRY to fit it, it’s not 100% true size)

ffmpeg -i 2_1.mp4 -c:v libx265 -c:a aac -b:a 128k -fs 150k output.mp4

FFMPEG useful links

https://ffmpeg.org/ffmpeg.html

https://trac.ffmpeg.org/wiki/Encode/H.264

https://trac.ffmpeg.org/wiki/Encode/H.265

blue color screen filter

sudo apt install redshift

set desired color temperature (5000K)

redshift -O 5000

reset redshift

redshift -x

append some data to file

simple way

echo "info" >> file.txt

with bigger block

cat > file <<EOF
info
info
info
EOF

or

tee -a file > /dev/null <<EOT
info
info
info
EOT

Just print to screen:

cat <<EOF
info
info
info
EOF
trim disks in Ubuntu
sudo fstrim -v /

https://www.maketecheasier.com/enable-trim-for-ssd-in-ubuntu/

Coloring output

####### tput

####### echo -e

for i in {0..255} ; do echo -en "\e[48;5;${i}m   $i  \e[0m" ; done; echo; echo
for i in {0..255} ; do echo -en "\e[38;5;${i}m   $i  \e[0m" ; done; echo;

for clbg in {40..47} {100..107} 49; do
	for clfg in {30..37} {90..97} 39; do
		for attr in 0 1 2 4 5 7; do
			echo -en "\e[${attr};${clbg};${clfg}m ^[${attr};${clbg};${clfg}m \e[0m"
		done
		echo
	done
done

More here

Parameters expansion

https://wiki.bash-hackers.org/syntax/pe

Tmux cheatsheet

https://gist.github.com/MohamedAlaa/2961058

JQ examples

https://remysharp.com/drafts/jq-recipes https://stedolan.github.io/jq/manual/

YQ reference

https://mikefarah.gitbook.io/yq/

Ubuntu: Purge disabled snaps

sudo snap list --all | while read snapname ver rev trk pub notes; do if [[ $notes = *disabled* ]]; then sudo snap remove "$snapname" --revision="$rev"; fi; done

Systemd - list services

sudo systemctl list-unit-files | grep enabled | sort

Archive content with preserving permissions

https://askubuntu.com/questions/225865/copy-files-without-losing-file-folder-permissions

SSH tunneling

https://www.ssh.com/ssh/tunneling/example

expose local computer ports via SSH

ssh -R 9080:localhost:9080 -R 9090:localhost:9090 -R 8081:localhost:8081 -R 9999:localhost:9999 -R 37922:localhost:22  <server>