Linux shell tricks (I)

The UNIX command line has always characterized by its sheer power. Even Microsoft realized in 2006 that their servers could not compete agains UNIX servers without a powerful command line, so they created PowerShell.

Mastering the command line, and all it’s small utilities, is a task that takes years to accomplish. The UNIX philosophy says that each program must “do one thing, and do it well”. The trick here is know which programs do which things.

With the time, every UNIX user ends up with a handful of commands that do every day work easier, that do in one line things that otherwise would have taken much longer.

So, in the following weeks, I’ll be writing a series of posts with those commands.

Here is the first part.

* Compare a remote file with a local file:

ssh user@host cat /path/to/remotefile | diff /path/to/localfile -

* Serve current directory tree at http://HOSTNAME:8000/

python -m SimpleHTTPServer
* Compile with colorized output, multicore CPU support, and low CPU priority:
nice -n 19 colormake -j 3

* Colorized diff:


* Guess your current public IP:

curl -s | grep -o \" [[:digit:].]\+\" "

* Copy *.h, *.c and *.cpp to other host for debugging:

rsync -a --cvs-exclude --progress --exclude='.*/' --include='*/' --include='*.c'
      --include='*.h' --include='*.cpp' --exclude='*' SOURCE DEST

* Make a backup of a directory

tar -cjvvf backup$(date +%Y%m%d_%H%M%S).tar.bz2

* Generate a list of random IPs:

nmap -n -iR 0 -sL | cut -d" " -f 2

* Benchmark an HTTP server:

ab -n 9000 -c 900 localhost:8080/index.php

* Display ncurses based network monitor:

nload -u m eth0
ethstatus -i eth0
ifstat -nt

* The same but by process:

nethogs -p eth0
ss -p
lsof -P -i -n

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s