Technical Notes

These notes are my personal online notebook of useful commands and "how-to's". You are welcome to make use of them if you find them helpful. They obviously don't come with any warranty! Click on one of the category tags above for the notes in any category.

Preventing false mouse double-clicks under linux

Newer versions of Kubuntu are missing the advanced mouse options which let you debounce the mouse

sudo apt install xserver-xorg-input-evdev
sudo mkdir -p /etc/X11/xorg.conf.d

Then edit /etc/X11/xorg.conf.d/xorg.conf

and append:

Section "InputClass"
    Identifier "evdev-mouse"
    MatchIsPointer "yes"
    Driver "evdev"

You may have to reboot at this point

xinput --list           # find the id of the mouse (e.g.

Fixing a Linux broken boot

If the system has been corrupted, and there is no grub menu, then boot from a live CD, open a terminal and do this:

sudo fdisk -l # find the root filesystem
sudo mount /dev/sda2 /mnt #whatever your root filesystem is
sudo mount --bind /$D1 /mnt/$D1 &&
sudo mount --bind /$D2 /mnt/$D2 &&
sudo mount --bind /$D3 /mnt/$D3 &&
sudo mount --bind /$D4 /mnt/$D4

sudo chroot /mnt # You are now back in the main hard drive

cd /etc/default
cp grub grub.orig
vi grub
# change timeout from 0 to 10
# change STYLE from hidden to menu
# remove # from Ter

Compress a folder into a single file for backup

tar -cvjSf filename.tar.bz2 foldername
-c create
-v verboase
-j bzip2
-S Sparse files handled efficiently
-f filename

Wiping a Hard Drive Clean

To securely wipe a hard drive of all data, do:

apt install wipe
shred -vfz -n 2 /dev/sdb
  • Options above are verbose, force, zero out in an extra pass
  • Number of passes: -n 2

An alternative “light” way of doing this is to simply copy random bytes

fdisk -l /dev/$D # make sure we have the right device
dd if=/dev/urandom of=/dev/$D bs=4096 status=progress
  • If the progress info is not sufficient, then from another terminal session do the following and updates will appear in the original terminal
pgrep -l '^dd$'   # gives the pid: nnnn DD
watch -n 60 kill

Recover disk drive using ddrescue

See user manual here:…escue_manual.html

  • Install with apt install gddrescue

Example script:

  • /dev/sdc is the bad drive which is being recovered to /dev/sdb
# first pass to copy the good sectors and make a log file of the bad
ddrescue -n /dev/sdc /dev/sdb logfile
# second pass keeps retrying the bad sectors
ddrescue -dr3 /dev/sdc /dev/sdb logfile

# have a look at what we have and do some validation
fdisk /dev/sdb
e2fsck -v -f /dev/sdb1
e2fsck -v -f /dev/sdb2

# It might be necessary to manually copy partition

iptables configuration on a linux server

  • List current tables with line numbers and stats
iptables -L INPUT --line-numbers -v
  • Append another rule
iptables -A INPUT -s -j DROP
  • Delete rule #3
iptables -D INPUT 3
  • The moment you apply IPTABLE rule it immediately becomes active.But it will not survive a reboot.
  • To be able to survive IPTABLES a reboot in your network configuration file /etc/network/interfaces file (referring to a Debian/Ubuntu system) you need to add:
pre-up  iptables-restore < firewall.txt

Making changes persistent in CentOS 5

iptables rules are stored in memory.

A simple way of restoring the content of deleted text files

Undeleting a file is not easy in Linux.
However, if it's a text file, and you know a phrase from it, you can search the whole drive for the contents:
grep -a -C 200 -F "words in file" /dev/hda1 | more #change /dev/hda1 to whatever is appropriate

Setting up NFS on Ubuntu 16.04

Make sure userid’s and groupid’s match between the systems

  • e.g. usermod -u 1001 -g 504 -c "Andrew Fountain" andrewf

Set up the server

  • set up the fully qualified domain name, e.g.

SMART monitoring of USB drives on Linux

using smartmontools documentation, try:

smartctl -d sat,16 -i /dev/sdc # find if enabled
smartctl -d sat,16 -a /dev/sdc # display all info

more documentation:

Syndicate content