Index

File Conversions

pdf to image

install imagemagick convert
sudo apt-get install imagemagick
convert pdf to jpg
convert [name].pdf [name].jpg
convert pdf to bmp
convert [name].pdf [name].bmp

images

install imagemagick convert
sudo apt-get install imagemagick
rotating images
convert "$name" -rotate 180 "rotated-$name"

video

install ffmpeg
sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get update
sudo apt-get install ffmpeg
re-encode with a bitrate of 350.000 (to shrink file)
ffmpeg -i source.mp4 -b 350000 destination.mp4
re-encode with a single frame per second (to shrink file)
ffmpeg -i source.mp4 -r 1 destination.mp4
re-encode all files in one folder to another folder
find -type f -exec ffmpeg -i {} -r 1 ../converted/{} \;

audio

concatenate wav files
sox file1.wav file2.wav output.wav
store mp3 stream (e.g. internet radio) to a file
streamripper [url] -a [file]
curl --output [file] [url]
extract a chunk from an mp3
mp3splt /tmp/input.mp3 [minutes].[seconds](.[millis])? [minutes].[seconds](.[millis])?
split a mp3 file into 50 minute chunks
mp3splt [file] -t 50.00

Base 64

base 64 encode

echo user:password | base64

base 64 decode

base 64
echo Z2VuaWFsZSBzaGl0DQo= | base64 --decode
hex decode
echo 68697070652073686974210d0a | xxd -r -p

sha1

calculate sha1 hash for file
sha1sum $file

json

pretty format json
echo '{"a":"b", "c":"d"}' | python -m json.tool
echo '{"a":"b", "c":"d"}' | jq .
call url and pretty format returned json
curl http://example.com/path -H "Content-Type: application/json" | python -m json.tool
curl http://example.com/path -H "Content-Type: application/json" | jq .
pretty format contents of file
cat [file] | python -m json.tool
jq . [file]
extract value of key "a"
echo '{"a":"b", "c":"d"}' | jq .a
extract the "message" (object or value) contained in every array entry of the contents object
jq ".contents[] | .message"
For every element in an array extract the address object, but only if the .address.country is set to "BE"
jq '.[].address | select(.country == "BE")'
For every element in an array extract the address.city, but only if the .address.country is set to "BE"
jq '.[].address | select(.country == "BE") | .city'
jq manual: https://stedolan.github.io/jq/manual/

xml

select an xml element with its contents
xmlstarlet sel -t -c '//[element]'
select the value of an xml attribute
xmlstarlet sel -t -v '//[element]/@[attribute]'
namespace example: extract all artifactId's from a pom
xmlstarlet sel -N n="http://maven.apache.org/POM/4.0.0" -t -v '//n:artifactId' -n pom.xml