Compare Version Number

dpkg --compare-versions 1.2.7-0trusty lt 1.2.7+0trusty && echo true

lt: less than
gt: greater than

Package Information

apt-cache policy PACKAGE_NAME

This will give you information about available versions and which version will be installed and from where:

$ apt-cache policy libqt5opengl5-dev

  Installed: 5.2.1+dfsg-1ubuntu14.3
  Candidate: 5.2.1+dfsg-1ubuntu14.3
  Version table:
 *** 5.2.1+dfsg-1ubuntu14.3 0
        500 http://ch.archive.ubuntu.com/ubuntu/ trusty-security/main amd64 Packages
        500 http://ch.archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     5.2.1+dfsg-1ubuntu14 0
        500 http://ch.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages

Hash Sum Mismatch

sudo rm -rf /var/lib/apt/lists/*
sudo apt-get clean
sudo apt-get update

List Packages from Repository

List all packages that are installed from a specific repository/ppa.

sudo apt-get install aptitude
aptitude search "?origin (ethz) ?installed"

List Packages without Repository

List all packages that are installed, but do not belong to a repository/ppa.

sudo apt-get install apt-show-versions
apt-show-versions | grep 'No available version'


TLP documentation

Install the following:

sudo add-apt-repository ppa:linrunner/tlp
sudo apt-get update

sudo apt-get install tlp tlp-rdw
sudo apt-get install tp-smapi-dkms acpi-call-dkms

Check which of the above modules (tp-smapi-dkms acpi-call-dkms) you need.

sudo tlp-stat -b -s -c

Modify the battery thresholds:

sudo vim /etc/default/tlp

Blacklist the Bluetooth device to avoid disconnections:

$ lsusb

Bus 003 Device 004: ID 8087:07dc Intel Corp.

add this 8087:07dc to the file /etc/default/tlp


To (re)start tlp without a reboot:

sudo tlp start

Charge battery full (ignoring the threshold once):

sudo tlp fullcharge

Recalibrate the battery:

sudo tlp recalibrate


Connect Logitech MX Master

If you already tried to connect the MX Master, remove the Bluetooth device. And execute the following steps. Source


[bluetooth]# power off
[bluetooth]# power on
[bluetooth]# scan on
[bluetooth]# connect XX:XX:XX:XX:XX:XX
[Arc Touch Mouse SE]# trust
[Arc Touch Mouse SE]# connect XX:XX:XX:XX:XX:XX
[Arc Touch Mouse SE]# pair
[Arc Touch Mouse SE]# unblock
[Arc Touch Mouse SE]# power off
[bluetooth]# power on

Connect Headphones

To ensure the headphones connect with A2DP and not with HSP/HFP.

sudo vim /etc/bluetooth/audio.conf

Add the lines:


Restart Bluetooth:

sudo service bluetooth restart

Find Files

Delete Empty Folders

find . -empty -type d -delete

Delete Temporary Files

find . -type f -name '*.~' -delete

Large Files

sudo find / -size +1G -ls


Remove Old Ubuntu Kernel

dpkg -l | grep linux-image-

sudo apt-get purge linux-image-3.5.0-{17,18,19}-generic

Remove Old Ubuntu Kernel

First remove any leftover temporary files from previous kernel updates.

$ sudo rm -rv ${TMPDIR:-/var/tmp}/mkinitramfs-*

Determine the version number of the currently running kernel, which you DO NOT want to remove.

uname -r

List all the kernels, including the booted one (4.2.0-21-generic in this example), in the package database and their statuses.

dpkg -l | tail -n +6 | grep -E 'linux-image-[0-9]+'

To free space in /boot we’ll remove an initrd.img file for a suitable old kernel manually, this is necessary due to a kenel packaging bug.

sudo update-initramfs -d -k 4.2.0-15-generic

Now we’ll use dpkg in order to TRY to purge the kernel package for the same old kernel:

sudo dpkg --purge linux-image-4.2.0-15-generic

NOTE: The previous command will probably fail, as there probably is a depending linux-image-extra package installed together with a ‘generic’ kernel package. In general, the output of the previous command will tell which package you need to remove first. In this example case you would run

sudo dpkg --purge linux-image-4.2.0-15-generic linux-image-extra-4.2.0-15-generic

Finally, we will fix the package installation process that previously failed.

sudo apt-get -f install         ## Try to fix the broken dependency.

Start Custom OS/Kernel

sudo vim /etc/default/grub

Edit the following line:

GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 3.13.0-53-generic"

Update grub.

sudo update-grub


Change Java Version

Download e.g. jdk-8u121-linux-x64.tar.gz from Oracle and unzip the folder to e.g. /opt/jdk1.8.0_121.

sudo update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_121/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_121/bin/javac 1

sudo update-alternatives --config java
sudo update-alternatives --config javac

java -version
javac -version


Scan IP Addresses

Angry IP Scanner

sudo nmap -sP

sudo arp-scan --retry=8 --ignoredups -I wlan0

Show DNS

nmcli dev list iface wlan0 | grep IP4.DNS


sudo vim /etc/resolv.conf


sudo vim /etc/resolvconf/resolv.conf.d/head

Restart Network Interface

sudo ifdown eth0
sudo ifup eth0

Terminal Analyse


Share Internet Over WIFI/Ethernet

iptables -t nat -A POSTROUTING -s -o wlan0 -j MASQUERADE
iptables -t nat -A POSTROUTING -s -o eth0 -j MASQUERADE


auto eth0
iface eth0 inet static


auto eth0
iface eth0 inet static

IP Tables - Jenkins

Add Rules

Jenkins tutorial

List iptables rules:

iptables -L -n

Add rules:

sudo iptables -I INPUT 1 -p tcp --dport 8443 -j ACCEPT
sudo iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT
sudo iptables -I INPUT 1 -p tcp --dport 443 -j ACCEPT
sudo iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT

Add forwarding:

sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8443

Save rules:

sudo sh -c "iptables-save > /etc/iptables.rules"
sudo apt-get install iptables-persistent

Remove Rules

Remove rules

Problem Solving

CLion Keyboard ibus Fix


This solution is if you would like to upgrade ibus in Ubuntu 14.04.4 LTS to the latest version (at the time of writing is 1.5.11).

I recently had to install Intellij on a clean installed Ubuntu machine. These are the steps I took:

  1. Install the dependencies

    sudo apt-get install libdconf-dev libnotify-dev intltool libgtk2.0-dev libgtk-3-dev libdbus-1-dev
  2. Download the ibus 1.5.11 source code (linked from here)

  3. Extract the files (tar -xvf ibus-1.5.11.tar.gz) and cd into the extracted folder

  4. While in the ibus source folder, follow the instructions from step 1 to install ibus 1.5.11:

    ./configure --prefix=/usr --sysconfdir=/etc && make
    sudo make install
  5. Restart Intellij IDE or whichever jetbrain’s IDE that is in question

dbus Fix

Maybe rename ~/.dbus and ~/.dbus-keyrings.

sudo service dbus restart

Graphics Card Repair (Black Screen)

Remove a (not working) Nvidia graphics card driver:

  1. Boot
  2. If screen is black, press Ctrl + Alt + F1
  3. Login with your username and password
sudo stop lightdm
sudo apt-get purge nvidia*
sudo apt-get install xserver-xorg-video-nouveau
sudo reboot

gvfs Fix

sudo umount ~/.gvfs
sudo rm -rf ~/.gvfs

usbserial Fix

sudo modprobe usbmon
sudo modprobe usbserial vendor=<VENDOR ID> product=<PRODUCT ID>


Start SSH Agent

eval $(ssh-agent)


Audio Settings

To change your audio settings in command line, use e.g. alsamixer.


File Manager

A command line file manager.

sudo apt-get install mc

PDF Editor PDFtk

E.g. take some pages and store them in a new PDF.

sudo apt-get install pdftk
pdftk full.pdf cat 1-5 output outfile_p1-5.pdf


USB Information

Get extended information about an USB device (serial, vendor/product id, …).

udevadm info -q all -n /dev/ttyUSB0
// or
udevadm info --attribute-walk --name=/dev/ttyUSB0

Restart udev.

sudo systemctl restart udev
sudo udevadm trigger

Get video information.

v4l2-ctl --all -d /dev/video0
v4l2-ctl --list-formats -d /dev/video0