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'

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

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

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.