A symbol representing the blue rose.

Spellbook

A man and a woman, using the magic powers of Lisp.

There are many useful digital actions I do not perform enough to recall through rote memory. This is a page for when those actions need to be performed.

dd

After torrenting the Linux distribution ISO of your choice, inserting a USB flash drive into the device's USB port, finding it's name with lsblk, and making sure that it is unmounted, you can create a bootable USB with the command below. Replace /dev/sdx with your drive and do not append the partition number. Also, set if to the correct path to the ISO file.

dd bs=4M if=/path/to/distro.iso of=/dev/sdx status=progress oflag=sync

diff

This command will display the differences between two directories' contents:

diff -qr

du

This command will display the example directory's size in a human-readable format:

du -sh example

exiftool

This command will remove all metadata from image.jpg:

exiftool -all= image.jpg

ffmpeg

This bash script is handy when you need to convert the contents of a whole-ass directory:

for i in *.m4a; do ffmpeg -i "$i" "${i%.*}.mp3"; done

grep

This command will print every line of file y that begins with string x.

grep "^x" y | { grep -v grep || true; }

ImageMagick

This command will resize image.jpg down to a 622 pixel width:

magick image.jpg -resize 622x image.jpg

This command will convert every .webp file in the current directory into a .jpg:

mogrify -format jpg *.webp

mv

This bash script is handy when you need to change the file extension of every .old file in the directory:

for foo in *.old; do mv $foo `basename $foo .old`.new; done

Regular Expressions

Apply (?<=This)(.*)(?=string) to This string is an example string, and it will match every character between This and the last occurence of string. If you'd like to include those two inputs in the result, use This(.*)string. If you only want to match up to the first occurence of string, substitute .* for .*?. If there is a newline in your string, make sure your regex engine's "dotall" mode is activated!

sdcv (StarDict Console Version)

StarDict requires dictionary files (DICT format) to search from. You can find some good ones on the StarDict website. To start, you can download the Collaborative International Dictionary of English by clicking this link.

Next, navigate to the folder where you will place your dictionary with cd /usr/share. Then use sudo mkdir to make a stardict/ directory, and a dic/ directory within it.

Next, we'll uncompress and move the dictionary in one go, using the following command (modify INSERTNAME with the name of the file you've downloaded).

sudo tar -xjvf INSERTNAME -C /usr/share/stardict/dic

Enter your password, and voila! To use StarDict, type sdcv followed by the word you're looking for.

systemd

Links

Using systemd-boot instead of grub in Arch Linux
Systemd Timers for Scheduling Tasks

upower

Type upower -e to check battery health on your laptop.

You'll see the following:

/org/freedesktop/UPower/devices/line_power_ADP1  
/org/freedesktop/UPower/devices/battery_BAT0  
/org/freedesktop/UPower/devices/DisplayDevice

Enter:

upower -i /org/freedesktop/UPower/devices/battery_BAT0

Check energy-full and energy-full-design to see the performance of your battery. To know if the battery needs to be replaced, divide the number next to "energy-full" by the number next to "energy-full-design", and multiply the result by 100. You'll get a percentage.

The percentage you get is how much your battery holds of its original capacity. If the number is >50%, it might be time to replace the battery.

vim

1,$s/x/y/g will replace every occurence of x in your file with y. You can leave y's spot in this spell empty if you wish to use this to erase shit rather than replace shit.

%s/^/x/ will append x to the beginning of every line of your file.

%s/$/x/ will append x to the end of every line of your file.

youtube-dl

youtube-dl -f mp4 --output "%(title)s.%(ext)s"

This will download whatever Youtube video you point it at, giving you an .mp4 to watch. Add --yes-playlist if you want to do this with an entire playlist.

youtube-dl --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output "%(title)s.%(ext)s"

This will extract the audio from whatever Youtube video you point it at, giving you an .mp3 to listen to. Add --yes-playlist if you want to do this with an entire playlist.