a collection of miscellaneous projects of Paul Philippov

Console Useful Tips

How to monitor progress of dd

$ dd bs=4M if=myimage.img of=/dev/sdc status=progress

How to compare lines in two text files

$ comm <(sort file1) <(sort file2) > file3

How to convert FLAC files into high fidelity MP3s in a batch

$ for a in *.flac; do lame -b320 "$a"; done

How to split MP3 by silence

$ mp3splt -s -p th=-30,min=1,rm filename.mp3

How to decode PDF streams

$ qpdf --qdf --object-streams=disable in.pdf out.pdf

How to recursively count files in a directory

$ find . -type f | wc -l

How to move all files from sub-directories to parent directory

$ find . -type f -exec mv {} . \;

How to view font information in MidnightCommander

echo '
# Fonts
  View=%view{ascii} fc-query %f
' >> ~/.config/mc/mc.ext

How to view SSL certificate information in MidnightCommander

echo '
# SSL Certificates
  View=%view{ascii} openssl x509 -in %f -text -noout
' >> ~/.config/mc/mc.ext

How to extract multiple zip-files into named directories, and delete original archives

$ for i in *.zip; do echo "$i"; unzip "$i" -d "${i%.*}" && rm "$i"; done

How to create gif preview images for multiple eps files in a directory

$ mkdir gif && for i in *.eps; do echo "$i"; convert "$i" "gif/${i%.*}.gif"; done

How to create a directory with permissions in one shot

$ install -o user -g group -m 0700 -d /path/to/newdir

How to fix file permissions after copying from Windows machine

$ find . -type f -exec chmod 644 {} \;

How to convert file names to lower case

$ rename y/A-Z/a-z/ *

How to delete empty files in the directory

$ find . -maxdepth 0 -type f -size 0 -delete

Adjust of omit maxdepth argument to delete in subdirectories, as well.

How to copy a list of files to the clipboard

$ ls -1 | xsel -i -b

How to strip trailing spaces from source files

$ sed -i 's/[[:space:]]*$//' \ **/*.{rb,erb,rake,conf,txt,csv,yml,html,css,js}

How to enable color in Git output

$ git config --global color.ui auto

How to remove remote Git branch

$ git push remotename :branchname

How to mount a WavPack with Cyrillic file names

$ sudo mount -t iso9660 -o loop,ro,iocharset=utf8 album.wv /mnt/cd

How to convert many TIFF files to JPEGs in a batch

$ for i in *.tif; do convert $i ${i%.*}.jpg; done

How to collect multiple small icons to one sprite

$ montage icons/*.png -tile 10x -geometry +0+0 sprite.png

How to strip a video file without re-coding

$ ffmpeg -i input.avi -vcodec copy -acodec copy -ss 00:00:03 -t 00:03:55 output.avi


$ avconv -i input.avi -c:v copy -c:a copy -ss 00:00:03 -t 00:03:55 output.avi

How to scan a document from console

one document from flat bed

$ scanimage --mode Color --resolution 150 > out.pnm

N pages from document feeder (Brother MFC-J615W)

$ scanimage -b --batch-count=N --source "Automatic Document Feeder(left aligned)"

How to extract all MIME entries from a text file

$ sudo apt-get install mpack
$ munpack -f textfile