What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands by EBAH from sorted by
Terminal - Commands by EBAH - 16 results
ps axu | grep [a]pache2
2012-12-15 19:37:19
User: EBAH
Functions: grep ps

Trick to avoid the form:

grep process | grep - v grep

awk '{cmd="date --date=\""$1"\" +\"%Y/%m/%d %H:%M:%S\" "; cmd | getline convdate; print cmd";"convdate }' file.txt
2012-02-28 14:08:52
User: EBAH
Functions: awk

Convert readable date/time with `date` command

sed "s/\s\+/;/g;s/^ //;s/ $//" filename.csv
MyVAR=84; awk '{ print "'"$MyVAR"'" }'
set colsep "{char}"
2011-04-05 10:48:48
User: EBAH
Functions: set
Tags: oracle

set colsep "&TAB" -- for tab separator

set colsep "|" -- for pipe separator


sed "s/^ *//;s/ *$//;s/ \{1,\}/ /g" filename.txt
2011-03-09 10:35:02
User: EBAH
Functions: sed
Tags: sed

The command removes all the spaces whithin a file and leaves only one space.

set list / set nolist
echo $EPOCH|awk '{print strftime("%c",$1)}'
/usr/bin/truss /usr/bin/date 2>&1 | nawk -F= '/^time\(\)/ {gsub(/ /,"",$2);print $2}'
nawk 'BEGIN {print srand()}'
2011-01-12 16:17:59
User: EBAH

For Solaris to obtain the same as:

date+%s like in linux

du -sk * | sort -rn | head
2011-01-03 10:49:40
User: EBAH
Functions: du sort


* find . -type f -exec ls -s {} \; | sort -n -r | head -5

* find . -type f -exec ls -l {} \; | awk '{print $5 "\t" $9}' | sort -n -r | head -5

awk 'BEGIN {FS=","} { print $1 " " $2 " " $NF}' foo.txt
2010-11-12 15:26:04
User: EBAH
Functions: awk

Set field separator char from command line.

Prints first, second and lsat columns.

let NOW=`date +%s`/86400 ; PASS_LAST_CHANGE=`grep $USER /etc/shadow | cut -d: -f3` ; PASS_LIFE=`grep $USER /etc/shadow | cut -d: -f5`; DAYS_LEFT=$(( PASS_LAST_CHANGE + PASS_LIFE - NOW)) ; echo $DAYS_LEFT
2010-11-05 23:03:48
User: EBAH
Functions: cut echo

This works only with GNU date.

In solaris the command:

date +%s

doesn't work.

You can try using the following instead:

nawk 'BEGIN {print srand()}'

should give the same output as date +%s under Solaris.

cat file.txt | sed -e /<opening tag>/d -e /<closing tag>/G | sed -e '/./{H;$!d;}' -e 'x;/<string to search>/!d;'
2010-11-04 10:31:15
User: EBAH
Functions: cat sed

Working with log files that contains variable length messages wrapped between open and close tags it may be useful to filter the messages upon a keyword.

This works fine with GNU sed version 4.2 or higher, so pay attention to some unix distros (solaris, hp-ux, etc.).

Linux should be ok.

dd if=/dev/zero of=foo.txt bs=1M count=1