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.

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:

umount - device is busy

I you get “device is busy” when running umount, try

sudo lsof | grep /dev/xxxx
# or
sudo fuser -cu /dev/xxxx

Upgrading CentOS 6 to PHP 5.4 (or 5.5)

  • SCL is the way to go since it has RedHat’s blessing

Note that it is the .conf file that controls which version of php is used. For some reason this does not seem to be available for php55.

Syndicate content