Tar command examples

tar stands for ‘tape archive’. It’s a widely known and used command, useful to create compressed archive files and decompress them. tar syntax is rather unorthodox.

Create compressed archive

For tar.gz:

# tar cvzf foobar.tar.gz /home/foobar
# tar cvzf foobar.tgz /home/foobar

For tar.bz2:

# tar cvjf foobar.tar.bz2 /home/foobar

Extract archive

# tar xvf <archive>

To extract content into a given directory:

# tar xvf <archive> -C /path/to/directory;

List archive content

# tar tvf <archive>

Extract only a given file

# tar xvf <archive> <file>

Add file to an archive

# tar rvf <archive> <file>


fping is a program like ping which uses the Internet Control Message Protocol to determine if a target host is responding. Contrary to it model fping can be use to target any number of targets. Its output is also designed to be easier to parse.

Command examples

To test a simple host:

fping is alive

To scan an entire network by sending just one packet by IP:

fping -a -r 0 -g

You can make the process faster by decreasing the interval between packet with the -i parameter:

fping -a -i 1 -r 0 -g

To use a list of IP:

fping -a < host_list.txt

Remount a filesystem as read/write

Sometimes due to a failed update or a bad manipulation you may end up with no other choice then reboot your system into ‘recovery mode‘. In this setting the root partition is mounted in read only. To remount it in read/write:

# mount -o remount,rw /

GNU screen for serial null modem connection

GNU screen has a lot of cool functionalities. For example you can use it like a terminal emulator for serial null modem connection.

Simply start a screen session with the device and speed as parameters:

screen /dev/ttyS0 9600

For deconnecting, send a break command with C-a b.

Disable PC speaker

If you recycle an old desktop machine into a ‘home’ server, maybe you have a machine with a PC speaker. To disable this annoying little thing:

  • unload the pcspkr module: rmmod pcspkr
  • blacklist the module to prevent udev from loading it:
# echo "blacklist pcspkr" > /etc/modprobe.d/nobeep.conf

[Bash] PS1 eye-candy

Bash has several prompts which can be customized:

  • PS1 is the primary prompt which is displayed before each command
  • PS2 is the prompt displayed when a command needs more input (e.g. a multi-line command)
  • PS3 is the prompt displayed for Bash’s select built-in which displays interactive menus
  • PS4 is the prompt displayed when debugging bash scripts to indicate levels of indirection

Customizing PS1

Personally i like the change the PS1 color depending the type of the machine i’m logged on. Green for ‘standard’ host, red for ‘production’, purple for ‘production VM’, etc…

vi /root/.bashrc
# add the following snippet:

# Customize PS1 Prompt #

# Bold Red
# COLOR='01;31m'
# Red
# COLOR='00;31m'
# Green
# COLOR='00;32m'
# Bold Green
# Yellow
# COLOR='00;33m'
# Purple
# COLOR='00;35m'
# Light blue
# COLOR='00;36m'

# Debian stuff - Add a tag if we are in a chroot
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
        debian_chroot=$(cat /etc/debian_chroot)

# PS1 variable
PS1="${debian_chroot:+($debian_chroot)}\[\033["$COLOR"\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "