File Conversions

mime types

get the mime type of a file (guestimate)
file -i [file]



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


remove password from pdf
qpdf --password=[password] --decrypt [pdf] [output_file]


install calibre convert
sudo apt-get install calibre
epub to text file
ebook-convert [file] [output]
supported formats list


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


install ffmpeg
sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get update
sudo apt-get install ffmpeg
re-encode to another file format
ffmpeg -i source.mp4 output.webm
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/{} \;
extract a chunk from a video file
ffmpeg -i [input file] -ss 0.50 -to 1 [output file]
ffmpeg -i [input file] -ss 1 -to 2 [output file]
ffmpeg -i [input file] -ss 1:02 -to 2:04 [output file]
ffmpeg -i [input file] -ss 0:01:02 -to 0:02:04 [output file]
ffmpeg -i [input file] -ss 0:01:02.00 -to 0:02:04.00 [output file]
merge 2 mkv files
sudo apt-get install mkvtoolnix
mkvmerge -o [output file] [file1] +[file2]


decode m4a to wav
faad [name].m4a
decode mp3 to wav
ffmpeg -i [name].mp3 [name].wav
encode wav to ogg
oggenc [name].wav
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 [file] [minutes].[seconds](.[millis])? [minutes].[seconds](.[millis])?
split a mp3 file into 50 minute chunks
mp3splt [file] -t 50.00


base 64 encode

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


cat [file] | md5sum


calculate sha1 hash for file
sha1sum $file


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 -H "Content-Type: application/json" | python -m json.tool
curl -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 first array element
echo '["a", "b"]' | jq '.[0]'
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 is set to "BE"
jq '.[].address | select(.country == "BE")'
For every element in an array extract the, but only if the is set to "BE"
jq '.[].address | select(.country == "BE") | .city'
for element parent append the values 'first' and 'second'
jq '.parent | "\(.first) \(.second)"'
reverse an array
jq 'reverse'
sort an array on the contained object's "name" property
jq '. | sort_by(.name)'
reverse sort array
jq '. | sort_by(.name) | reverse'
jq manual:


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="" -t -v '//n:artifactId' -n pom.xml
url encode
encoded=$(python -c "import urllib; print urllib.quote('''$url''')")