Tuesday, December 28, 2010

25 Even More – Sick Linux Commands

Here, urfix we know how much you guys love top Linux commands,

1) Monitor progress of a command
pv access.log | gzip > access.log.gz
Pipe viewer is a terminal-based tool for monitoring the progress of data through a pipeline. It can be inserted into any normal pipeline between two processes to give a visual indication of how quickly data is passing through, how long it has taken, how near to completion it is, and an estimate of how long it will be until completion. Source: http://www.catonmat.net/blog/unix-utilities-pipe-viewer/


2) Graphical tree of sub-directories
ls -R | grep “:$” | sed -e ‘s/:$//’ -e ‘s/[^-][^\/]*\//–/g’ -e ‘s/^/ /’ -e ‘s/-/|/’
Prints a graphical directory tree from your current directory

3) Delete all files in a folder that don’t match a certain file extension
rm !(*.foo|*.bar|*.baz)
Deletes all files in a folder that are NOT *.foo, *.bar or *.baz files. Edit the pattern inside the brackets as you like.

4) Easy and fast access to often executed commands that are very long and complex.
some_very_long_and_complex_command # label
When using reverse-i-search you have to type some part of the command that you want to retrieve. However, if the command is very complex it might be difficult to recall the parts that will uniquely identify this command. Using the above trick it’s possible to label your commands and access them easily by pressing ^R and typing the label (should be short and descriptive).

5) Define a quick calculator function
? () { echo “$*” | bc -l; }
defines a handy function for quick calculations from cli.
once defined:
? 10*2+3

6) Display a cool clock on your terminal
watch -t -n1 “date +%T|figlet”
This command displays a clock on your terminal which updates the time every second. Press Ctrl-C to exit.
A couple of variants:
A little bit bigger text:
watch -t -n1 “date +%T|figlet -f big”You can try other figlet fonts, too.
Big sideways characters:
watch -n 1 -t ‘/usr/games/banner -w 30 $(date +%M:%S)’This requires a particular version of banner and a 40-line terminal or you can adjust the width (“30″ here).

7) intercept stdout/stderr of another process
strace -ff -e trace=write -e write=1,2 -p SOME_PID

Read more: urfix's blog