My Personal Linux Cheat Sheet

Toto je zoznam užitočných príkazov z operačného systému GNU/Linux. Niektoré z nich už viem aj naspamäť, takže tento ťahák viac nepotrebujem, ale zverejňujem ich tu, nakoľko sa môžu hodiť aj ďalším.

Ak máte pre mna tip ako robiť nejakú vec lepšie a efektívnejšie, dajte mi vedieť. Rád tento ťahák zaktualizujem.

Awesome ViM Cheat Sheet

http://michael.peopleofhonoronly.com/vim/

Lower Swappiness

cat /proc/sys/vm/swappiness
sysctl -w vm.swappiness=5

Add vm.swappiness=5 to /etc/sysctl.conf

X Window PID

xprop | grep -i pid

Printing without cat

How to print without /bin/cat:
(for example when /bin/cat is on the corrupted filesystem)

( while read x; do echo $x; done ) < /proc/mdstat

Quick HTTP DDoS Attack Detection

netstat -anp | grep 'tcp\|udp' \
| awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

Debian Default Editor Change

sudo update-alternatives --config editor

Postfix Queue IDs

mailq | grep -v '^-' | grep -v '^\s\+' |  sed 's/^\(\w\+\).*$/\1/g'

Quick Samba Setup

# Uncomment security
security = share

# Add share
comment = Samba - Public Files (no security)
path = /import/samba
browsable = yes 
writable = yes
public = yes
guest ok = yes
guest only = yes
guest account = nobody

IPtables Allow All SSH

iptables -A INPUT -i eth0 -p tcp --dport 22 \
         -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 22 \
         -m state --state ESTABLISHED -j ACCEPT

VPS migration on LVM

dd if=/dev/server1/vps-lvname \
| ssh -c arcfour SERVER2-IP 'dd of=/dev/server2/vps-lvname bs=4M'

Remove PDF Password

qpdf --decrypt --password=PASSWORD input.pdf output.pdf

Add PDF Compression

Compress: High Quality

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 \
   -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH \
   -sOutputFile=output.pdf input.pdf

Compress: Good Quality

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
   -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH \
   -sOutputFile=output.pdf input.pdf

PDF Merge

pdftk 1.pdf 2.pdf cat output out.pdf

Scanned Images to PDF

convert image*.pnm -crop '496x720+0+0' +repage output.pdf

Cut and Rotate PDF document

This is especially handy for scanned passports. Adjust -density option for better resolution. Option -quality has probably no effect on this PDF conversion.

convert -density 200 in.pdf -quality 100 -crop '1005x1380+0+0' +repage out.pdf
pdftk input.pdf cat 1-endeast output output.pdf

Crop US-Letter to A4

If your iPhone Notes app is saving your A4 documents as US-Letters, this is the way how you can convert them back to A4:

pdfcrop --papersize=a4 file.pdf

Then it is also good to convert it to real A4 with pdfjam command below.

Create A4 or US-Letter from image

Use common convert utility to convert from image to PDF. Then you can alter PDF to proper size:

pdfjam --landscape --paper a4paper  --outfile output-A4.pdf source.pdf
pdfjam --landscape --paper usletter --outfile output-US.pdf source.pdf

Or reconvert existing PDF:

gs -sOutputFile=out.pdf      \
   -sDEVICE=pdfwrite         \
   -sPAPERSIZE=USLetter      \
   -dCompatibilityLevel=1.4  \
   -dNOPAUSE -dBATCH         \
   -dPDFFitPage              \
   in.pdf

Parameter PAPERSIZE can be USLetter, A4, etc.

Merge image and MP3s

ffmpeg -loop 1 -shortest -y -i image.jpg -i "concat:01.mp3|02.mp3" \
       -acodec copy -vcodec mjpeg result.avi

If quality is bad, change -vcodec mjpeg to -sameq.

Download folder from Google Drive

apt-get install golang git
go get -v github.com/prasmussen/gdrive
~/go/bin/gdrive download --recursive FOLDER-ID

Default Desktop Applications

Firstly we need to query mime type:

$ mimetype foo.gif
foo.gif: image/gif
$ mimetype ./
./:    inode/directory

Then check mime type:

XDG_UTILS_DEBUG_LEVEL=3 xdg-mime query default image/gif
XDG_UTILS_DEBUG_LEVEL=3 xdg-mime query default inode/directory

And finally set the default application:

xdg-mime default geeqie.desktop image/gif
xdg-mime default pcmanfm.desktop inode/directory

Other good file managers: Thunar, gentoo, spacefm, xfe.