My favourite OS. Been using it since 2004. Learnt the hard way, uphill both ways. I used to borrow DVDs from the library at work and give it a spin at home. I didn't have a working internet connection back then so I'd have to take notes on the error message, research them the next day at work, and fix it when I got back. Probably the most fruitful time I've had to date.

I distro-hopped every few months, and my fondest memories are of Slackware and, well, FreeBSD. I had a ton of fun with my Desktop: setting up IPv6 tunnels, dynamic DNS, apache, squid, privoxy, and generally playing with minimiastic window managers and the shell.

These days I stick with Fedora and love it.

General Linux

Centos 7 sources

Clone their helper repo first:

git clone

Go to their RPM project and select a project to clone. I'm picking coreutils here. This repo has a SPEC file and the patches to the original source.

git clone

The master branch is always empty. Checkout their c7 branch to see the SPECS and SOURCES folders for Centos 7, and run the helper script to fetch the source.

git checkout c7

dnsmasq custom dns server for a domain

Add a specific record like this in the dnsmasq configuration:


For everything else, dnsmasq will use the existing configuration in /etc/resolv.conf.

More here

diff and patch

cp somepackage somepackage-new
# make changes in somepackage-new
diff -ruN somepackage somepackage-new > mychanges.patch
# give the patch to someone else, who can now do:
cd somepackage
patch -p1 < mychanges.patch

More information than you'll ever need here.

ccache notes

Install from the repo as usual

sudo yum install ccache -y

One way to set it up:

bash-4.2 /bin$ cp ccache /usr/local/bin/
bash-4.2 /bin$ ln -s ccache /usr/local/bin/gcc
bash-4.2 /bin$ ln -s ccache /usr/local/bin/g++
bash-4.2 /bin$ ln -s ccache /usr/local/bin/cc
bash-4.2 /bin$ ln -s ccache /usr/local/bin/c++

Change timezone in centos:

ln -s /usr/share/zoneinfo/Asia/Kolkata /etc/localtime

For debian:

timedatectl set-timezone Asia/Kolkata

Install fonts in centos/linux:

System-wide :

mkdir -p /usr/share/fonts/greatvibes

User only :

mkdir ~/.fonts

Copy your font files in the appropriate folder and "register" them in the system with:

fc-cache -f -v

Linux date conversion (epoch to human readable)

Convert epoch time to human readable format:

date -d @1445305686.222

Howto add swap space:

dd if=/dev/zero of=/var/swap.img bs=1024k count=1000
mkswap /var/swap.img
swapon /var/swap.img

Disable firefox's verification of extension signing

xpinstall.signatures.required in about:config

(from newsblur's Goodies page)

If df shows no disk space even after deleting files, check this output:

sudo /usr/sbin/lsof | grep deleted

If you don't have lsof, just use this:

find /proc/*/fd -ls | grep  '(deleted)'

Useful linux diagnostic commands:

dmesg | tail
vmstat 1
mpstat -P ALL 1
pidstat 1
iostat -xz 1
free -m
sar -n DEV 1
sar -n TCP,ETCP 1

GNU/Screen scrollback:

Ctrl a Esc (then use Ctrl b/Ctrl f/Ctrl u/Ctrl d etc) and Esc to end

Quick fsck (solaris)

fsck -Fy ufs /dev/rdsk/c1d0s5

Debian - clean up orphaned files:

aptitude  remove --purge $(deborphan)

See filesystem usage:

/usr/bin/du --total --summarize --human-readable --one-file-system

GNU/Screen splitting windows

Tmux keybindings

And here's my .tmux.conf

set -g prefix C-a
unbind C-b
bind C-a send-prefix

set -g default-terminal "xterm-256color"

set -g history-limit 10000
set -g set-titles-string "#T"

unbind %
bind | split-window -h
bind - split-window -v

Colour in terminals

    arunsrin@ARUNSRIN-G2CA5 MINGW64 ~
    $ printf "\033[32mhi\033[0m"
Sequence   What it Does
ESC[1m     Bold, intensify foreground
ESC[4m     Underscore
ESC[5m     Blink
ESC[7m     Reverse video
ESC[0m     All attributes off

Bash Stty: Coredump etc

Ctrl \


kill -SIGQUIT <pid>

Override it with:

stty quit <some-binding>

Similarly for that age-old backspace not deleting a character problem:

stty erase ^h

To see the current terminal capabilities, run:

stty -a

Fix for xargs errors when filenames contain spaces

find . -name -print0 | xargs -0 ls -l

Bash faster navigation with cdpath

export CDPATH=:$HOME:$HOME/projects:$HOME/code/beech


with date filters

File formatting, wrapping etc

Huh, who knew this existed:

cat <some-verbose-output> | fold -70

Deleting files with odd names

There's more than one way. Here's one: find the inode with ls -i, then delete with:

find -inum <inode-number> -exec rm -i {} \;

See whitespace with cat

Use this:

cat -v -t -e <somefile>

Stat command: see inode information

The inode holds the address in the filesystem, access permissions, ctime/mtime etc

    arunsrin@ARUNSRIN-G2CA5 MINGW64 ~
    $ stat ntuser.ini
      File: ‘ntuser.ini’
      Size: 20              Blocks: 1          IO Block: 65536  regular file
    Device: a4b221d6h/2763137494d   Inode: 562949953421373  Links: 1
    Access: (0644/-rw-r--r--)  Uid: (1233064/arunsrin)   Gid: (1049089/ UNKNOWN)
    Access: 2015-07-21 18:57:13.142410100 +0530
    Modify: 2010-11-21 08:20:53.336035000 +0530
    Change: 2016-06-06 09:18:05.239486700 +0530
     Birth: 2015-07-21 18:57:13.142410100 +0530

    arunsrin@ARUNSRIN-G2CA5 MINGW64 ~

If the filename is odd and you can't paste it easily in the terminal, just try

ls -il

Bash debugging

Run the script with -xv in the shebang:

#!/bin/bash -xv
# do something

Bash suppress echo (for reading passwords)

In bash, while reading input from the user, if you want to suppress the echo on the screen (for sensitive inputs like passwords), do this:

stty -echo
stty echo


Try this:

sudo ngrep -d any <word> -q

-d any listens on any interface

-q is quiet mode so those #'s don't show.

Pretty-print json

cat somefile.json | python -m json.tool