Skip to content

CHEATSHEET

Syncronize

rsync -avuP – /path/*(om[1,10]) destination@192.168.x.x:/path/

Linux

Append clip internals to end of file

echo `xsel` >> <filename>

alias

link () {
    echo `xsel` >> /mnt/c/Users/alexa/link
}

clip file internals

cat <name> | clip.exe

Convert all filenames to lowercase in bulk

$ mmv "*" "#l1"

rename all ‘.bakz’ files in the current directory to ‘.bak’, run:

$ mmv '*.bakz' '#1.bak'

help

man mmv

convert win path to bash

wslpath -m "$(pwd)"

run in win

cmd.exe /C start "$(wslpath -m "$(pwd)")"
echo "start P:\home\oleroma" | powershell.exe

COMMAND PROMPT

Open CURRENT dir in wtm

wt -d "%CD%"

WSL

wsl --set-version <distro name>

MIGRATE

clone apt packages

apt-clone

create list for dpkg

sudo dpkg --get-selections | sed "s/.*deinstall//" | sed "s/install$//g" > ~/pkglist

run package install process

sudo aptitude update && cat pkglist | xargs sudo aptitude install -y

GIT

git branch -d localBranchName
git push origin --delete remoteBranchName

SERIAL

minicom setsetial dmesg

sudo chmod 666 /dev/ttyS2
stty -F /dev/ttyS2 -a #check
stty -F /dev/ttyS2 sane 9600
cu -l /dev/ttyS2 -s 9600

AVR

avrdude -c arduino -p m328p -P /dev/ttyS2

compile into .bin

avr-gcc -Wall -g -Os -mmcu=attiny13 -o main.bin main.c

check size

avr-size -C main.bin

compile into HEX

avr-objcopy -j .text -j .data -O ihex main.bin main.hex

burn

  avrdude -v -p atmega328p -c arduino -P /dev/ttyS3 -b 9600 -D -U flash:w:/mnt/c/Users/alexa/ardu/main.hex:i
win () {

HEX="P:"
STR='\\wsl$\Ubuntu-20.04'
TEX="start `wslpath -w .`"
OKS='\'$1
if [[ "$TEX" == *"$STR"* ]];
then
echo "${TEX/'\\wsl$\Ubuntu-20.04'/$HEX}$OKS" | powershell.exe
else
cmd.exe /C start "$(wslpath -m .)"'\'$1
fi
}

Rename multiple files

count=0; for f in *; do [ -f "$f" ] && mv -i "$f" "cin_$((++count)).${f##*.}"; done

Image manipulations

mogrify -resize 960x528 *.png

mogrify -resize 960 *.png

mogrify -resize 960x528! *.png

remove space colored white

mogrify input.jpg -format png -bordercolor white -border 1 -fuzz 20% -fill none -draw "matte 0,0 floodfill" -shave 1x1 input.jpg

Gif manipulations

optimize gif

gifsicle -O3 input.gif -o output.gif --lossy

script to make gif from video with ffmpeg

1
2
3
4
5
6
7
#!/usr/bin/env zsh
palette="/tmp/palette.png"

filters="fps=10,scale=620:-1:flags=lanczos"

ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2

explode video

ffmpeg -i video.mp4 %04d.png

compile video from images

ffmpeg -start_number 19 -i %04d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4

reverse video

ffmpeg -i clip.avi -vf reverse reversed.mp4

stitch together

 ffmpeg -f concat -safe 0 -i list.txt -c copy out.mp4

FZF

CTRL-T - Paste the selected files and directories onto the command-line
Set FZF_CTRL_T_COMMAND to override the default command
Set FZF_CTRL_T_OPTS to pass additional options
CTRL-R - Paste the selected command from history onto the command-line
If you want to see the commands in chronological order, press CTRL-R again which toggles sorting by relevance
Set FZF_CTRL_R_OPTS to pass additional options
ALT-C - cd into the selected directory
Set FZF_ALT_C_COMMAND to override the default command
Set FZF_ALT_C_OPTS to pass additional options

File append

append to file

echo 'something' >> target.txt

insert line with text at the beginning

sed -i '1s/^/something \n/' target.md

WSL yank support

let s:clip = '/mnt/c/Windows/System32/clip.exe'  " change this path according to your mount point
if executable(s:clip)
    augroup WSLYank
        autocmd!
        autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif
    augroup END
endif

VIMSheet

list buffers

ls

replace in all buffers and write

bufdo %s/win10/win10-16ram/ge | update

tabs > buffers

taboo

buffers > tabs

tab ba (tab buffer all)

buffers > vertical windows

vert ba

buffers > horizontal

ba 

wrire and exit all

wqa

Git Change Signs

GitGutterSignsToggle

slash-flip

%s/\\/\//g

Vim viewport keybinding quick reference

sp will split the Vim window horizontally. Can be written out entirely as :split.

vsp will split the Vim window vertically. Can be written out as :vsplit.

Ctrl-w Ctrl-w moves between Vim viewports.

Ctrl-w j moves one viewport down.

Ctrl-w k moves one viewport up.

Ctrl-w h moves one viewport to the left.

Ctrl-w l moves one viewport to the right.

Ctrl-w = tells Vim to resize viewports to be of equal size.

Ctrl-w - reduce active viewport by one line.

Ctrl-w + increase active viewport by one line.

Ctrl-w q will close the active window.

Ctrl-w r will rotate windows to the right.

Ctrl-w R will rotate windows to the left.

Neils Ffmpeg Cheatsheet

HTML5 MP4 ffmpeg encoding

variable bit rate 1080p MP3:

   ffmpeg -i input_video -vcodec libx264 -crf 25 -preset medium -vf scale=-2:1080 -acodec libmp3lame -q:a 4 -ar 48000 -ac 2 output_video.mp4

fixed bit rate 1080p MP2:

   ffmpeg -i input_video -vcodec libx264 -b:v 1000k -vf scale=-2:1080 -acodec mp2 -b:a 256k -ar 48000 -ac 2 output_video.mp4

no audio:

   ffmpeg -i input_video -vcodec libx264 -b:v 1000k -vf scale=-2:1080 -an output_video.mp4

crop size (width:height:xoffset:yoffset):

   ffmpeg -i input_video -vf crop=1500:800:200:100 -vcodec libx264 -b:v 1000k -an output_video.mp4

trim time (-ss start time, -t duration):

   ffmpeg -i input_video -vcodec libx264 -b:v 1000k -an -ss 00:00:10 -t 00:00:10 output_video.mp4

mix audio and video:

   ffmpeg -i input_video -vcodec libx264 -b:v 1000k -vf crop=1120:876:0:100 -i input_audio -acodec mp2 -b:a 256k -ar 48000 -ac 2 -ss 00:00:20 -t 00:00:20 output_video.mp4

crop, pan, composite:

   ffmpeg -i input_video_1 -i input_video_2 -filter_complex '[1:v]crop=175:95:930:860[cropout];[cropout]scale=350:190[scaleout];[0:v][scaleout]overlay=10:10[outv]' -map '[outv]' -vcodec libx264 -b:v 1000k -map 0:a -acodec mp2 -b:a 256k -ac 2 -t 00:00:05 output_video.mp4

numbered images to video:

   ffmpeg -r 30 -i %04d.jpg -vcodec libx264 -b:v 1000k -vf scale=-2:1080 -an output_video.mp4

SSH

Active sessions

ss | grep -i ssh

System

rebuild all DKMS modules

ls /var/lib/initramfs-tools | \
    sudo xargs -n1 /usr/lib/dkms/dkms_autoinstaller start

Last update: February 20, 2022