Linux Cheatsheet

Here is a list of commands and howtos, which I found worth writing down over the last years.
There is usually no explanation given. If required, they can be found in the man pages or Ubuntu wiki. Use at your own risk! Never copy commands without thinking about them.
There will be new things appended from time to time.


Scan for SCSI drives


Select default wordbook/spelling

as root

Switch messages from local language to english


Monitor which files are written

systemctl disable rsyslog
echo 1 > /proc/sys/vm/block_dump

Follow dmesg in a live view

dmesg -wH

Permit dmesg as normal user

nano /etc/sysctl.conf
kernel.dmesg_restrict = 0

Create new user

adduser guest

Add user into groupt of other user

usermod -aG guest THEUSER

Completely disable DPMS

Problem is, screen wont show anything after disabled once
1. Create xorg.conf:
Xorg :1 -configure
2. Copy to proper location
3. Add to ServerLayout
Option "BlankTime" "0"
Option "StandbyTime" "0"
Option "SuspendTime" "0"
Option "OffTime" "0"
-> Not enough.
Section "Monitor":
Option "DPMS"
-> Not enough, KDE trinity sets the values too:
kcontrol -> disable power settings there

Enable Control+Alt+Backspace again

nano /etc/default/keyboard

Find all 32bit packages (left over from a 32->64bit system migration)

file /usr/bin/* | grep 32-bit | cut -f 1 -d ":" | apt-file search -f

App Armor

aa-enforce /etc/apparmor.d/usr.lib.firefox-esr.firefox-esr
aa-complain usr.bin.vlc

Remove unwanted drives from Save-As dialog

x-gvfs-hide as mount option or set the mount point to something else than /media
If this does not work (encrypted drives):
nano /etc/udev/rules.d/99-hide-disks.rules

Avoid swapping

nano /etc/sysctl.conf
vm.swappiness = 10

Kill nepomuk

cd /usr/share/autostart
rm nepomukserver.desktop

Add a script to startup (sysvinit)

update-rc.d defaults

Set CUPS policities

Replace "Require user @SYSTEM"
by "Allow from @LOCAL"

Use su instead of sudo

nano ~/.kde/share/config/kdesurc

Trinity wont run properly, conflicting with KDE4

Remove package kdelibs4c2

Copy whole Linux installation

rsync -aHuv --delete-before /usr/ /mnt/sdb9/usr/
rsync -aHuv --delete-after /sbin/ /mnt/sdb9/sbin/
rsync -aHuv --delete-after /bin/ /mnt/sdb9/bin/
rsync -aHuv --delete-after /lib/ /mnt/sdb9/lib/
rsync -aHuv --delete-after /opt/ /mnt/sdb9/opt/
rsync -aHuv --delete-after /var/ /mnt/sdb9/var/
rsync -aHuv --delete-after /boot/ /mnt/sdb9/boot/
rsync -aHuv --delete-after /initrd.img /mnt/sdb9/initrd.img
rsync -aHuv --delete-after /vmlinuz /mnt/sdb9/vmlinuz
rsync -aHuv --delete-after /etc/ /mnt/sdb9/etc/

Check for local modifications of config files

debsums -c -e | grep ^/etc/init.d

No systemd

echo -e 'Package: systemd\nPin: origin ""\nPin-Priority: -1' > /etc/apt/preferences.d/systemd
echo -e 'Package: *systemd*\nPin: origin ""\nPin-Priority: -1' > /etc/apt/preferences.d/systemd

Enable extra keys

Shows the map: xmodmap -pke
showkey -s


Unpack .tar.gz

gunzip filename.tar.gz
tar -xf filename.tar

Find files

locate -i xyz

Update files database

as root:

Search through the content of all files in a folder

find . -type f -exec grep "wxvlc" '{}' \; -print

Get date from files found

locate cookies.sqlite | xargs ls -l

Change the owner

chown [-R] newUser DirectoryOrFile

Benchmark harddisk with 4GB

bonnie -u USERNAME -d DIRECTORY -s 4096

Check a file system

fsck /dev/sdX

Create an encrpyted file system in a file

touch myfile
shred -n1 -s4600M myfile
losetup /dev/loop0 /path/to/myfile
With entering password: cryptsetup -y create mysecret /dev/loop0
With file as password: cryptsetup -d /mykey create mysecret /dev/loop0
Check it: dmsetup ls
Mount it: mount /dev/mapper/mysecret /mnt/tmp

Unmount it:
umount /mnt/tmp
cryptsetup remove mysecret
losetup -d /dev/loop0

Create password file

sha256 > mykey
Enter password

Create file system

mke2fs /dev/mapper/mysecret

Reenable Konqueror (KDE3, Trinity) to open compressed files

delete content in /usr/share/kubuntu-default-settings/kde-profile/default/share/mimelnk/application

Sync from local PC to remote PC

rsync -auv ./foo REMOTEPCNAME:/home/USERNAME/foo

Remotely sync with only specific files

rsync -auxXv -e "ssh -l USERNAME" --include='*.pdf' --exclude='*.*' "/home/USERNAME/DIRECTORY/" "IPV4:/home/USERNAME/DIRECTORY/"

Set name of an USB drive

mlabel -i /dev/sdd1 -s ::"ForRigol8GB"


Add a DNS server

nano /etc/resolv.conf

Add a route

sudo ip route add default via dev eth0

Stop Firefox being annoying

dom.webnotifications.enabled -> FALSE
media.autoplay.enabled -> FALSE
plugins.notifyMissingFlash -> FALSE
browser.tabs.WarnOnClose -> FALSE
browser.tabs.CloseWindowWithLastTab -> FALSE

Set your default browser to Firefox

update-alternatives --install /usr/bin/x-www-browser x-www-browser /usr/bin/firefox 10
update-firefox --config x-www-browser

Fix Thunderbird always opening attachments with the wrong program

Edit .icedove/YOURPROFILE/mimeTypes.rdf

Configure Apache

apt-get install apache2 libapache2-mod-php
nano /etc/apache2/ports.conf

nano /etc/apache2/sites-enabled/000-default.conf
After "DocumentRoot /var/www/html" add:
<Directory />
Options FollowSymLinks
AllowOverride None
For <Directory /var/www/> change into:
AllowOverride all

a2enmod rewrite
systemctl restart apache2

Convert old html files into UTF-8

recode html..utf8 < index0.php > index1.php

Setup MDNS

1. apt-get install avahi-daemon
2. nano /etc/nsswitch.conf
hosts: files mdns4_minimal dns mdns4 [NOTFOUND=return]
3. nano /etc/avahi/avahi-daemon.conf
4. service avahi-daemon restart
Hosts are now available under PCNAME.local

Secure SSH

nano /etc/ssh/sshd_config

Let a command run on a computer accessed by ssh in the background

1. tmux
2. Start wished command
3. Ctrl+B, D leaves tmux
4. tmux attach to reconnect later


Ignore files for SVN

svn propset svn:ignore *.suo .
svn propedit svn:ignore .


git init
git add .
git commit -m "Test"
git remote add origin
git remote -v
git pull origin master
git push origin master

Update to GIT

git commit -m "Foobar"
git push origin master

Ignorefile for GIT

nano .gitignore
One pattern per line, like: *~

File diff tool


Get the source of a package and build it

apt-get source xserver-xorg-video-ati
apt-get --build source xserver-xorg-video-ati

Fix dependencies and version of a package

dpkg-deb -x xserver-xorg-video-ati_7.5.0-1_i386.deb ati
dpkg-deb --control xserver-xorg-video-ati_7.5.0-1_i386.deb ati/DEBIAN
---Edit the files---
dpkg -b radeon xserver-xorg-video-radeon_7.5.0-2MalteM_i386.deb


Mount iso image

mount image.img /mnt/tmp -t iso9660 -o loop

Rotate an image

exiftool -Orientation='Rotate 270 CW' image.jpg

Resize all jpg files in a folder

for i in `ls`; do convert -resize 800x800 -quality 65 $i resized_$i; done

Convert a video file to a DVD compatible video file

ffmpeg -i movie.avi -aspect 4:3 -target pal-dvd dvd.mpg

Convert DVD compatible video file into a DVD file structure

dvdauthor -o dvd/ -t dvd.mpg

Burn a DVD file structure onto a DVD

growisofs -Z /dev/sr0 -dvd-video dvd/

Configure screen

Add in xorg.conf SubSection
Virtual 2048 2048
if xrandr delivers too small values
Generate proper modeline: cvt 1920 1080
xrandr --newmode "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync xrandr --addmode CRT1 1920x1080_60.00
xrandr --output CRT1 --mode 1920x1080_60.00
CRT1 can be namend VGA-0 or VGA_1 - depending on the driver

Convert midi to mp3

timidity foo.mid -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 64k bar.mp3

Restart Spacenav to make it work in Freecad

/etc/init.d/spacenavd restart

Remove help button from Konqueror (KDE3, Trinity)

Konqueror-> Titelleiste rechte Maustaste -> Fensterverhalten Festlegen -> Fensterdekoration -> Knöpfe -> Benutzerdefinierte Position von Titelleistenknöpfen -> Entfernen des Symbols per Drag and Drop

Merge PDFs

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=firstANDsecond.pdf -dBATCH first.pdf second.pdf

Convert file to webm

ffmpeg -i input.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis output.webm
ffmpeg -i input.MTS -threads 3 -c:v libvpx -crf 10 -vf scale=-1:1080 -b:v 6M -c:a libvorbis output.webm

Make tethering on smartphone work

All root applications need access to wireless lan

Make Frozen Throne installer work

After installing base game
cd ~/.wine/drive_c/windows
touch War3Unin.dat
touch War3Unin.exe

Set Alsa to run as 4.0 surrond system

1. nano /etc/pulse/daemon.conf
default-sample-channels = 4
default-channel-map = rear-left,rear-right,front-left,front-right
2. alsamixer
F6 -> HD Audio Generic
Channel Mod ->4ch
3. Restart Alsa, this saves the config changes done by alsamixer
4. pavucontrol: Select the output device "Analog Surround 4.0 + Analog Stereo Input"
5. Test the settings
Test tone front left: speaker-test -c 4 -t sine -P 8 -s 1
Test tone front right: speaker-test -c 4 -t sine -P 8 -s 2
Test tone back right: speaker-test -c 4 -t sine -P 8 -s 3
Test tone back left: speaker-test -c 4 -t sine -P 8 -s 4

Make Skype work again

env PULSE_LATENCY_MSEC=90 skypeforlinux
The number sec= could be 30 or 60 too