Hide

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.
Hide

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:

Hide

News

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!
Hide

Top Tags

Hide

Functions

Hide

Credits

Commands by cfajohnson from sorted by
Terminal - Commands by cfajohnson - 19 results
today() { printf '%(%Y-%m-%d)T\n' -1; } ## bash-4
tee >(openssl md5 > sum.md5) <somefile | bzip2 > somefile.bz2
ls -l | grep ^-
xv() { case $- in *[xv]*) set +xv;; *) set -xv ;; esac }
2010-02-14 20:57:29
User: cfajohnson
Functions: set
4

Turn shell tracing and verbosity (set -xv) on/off in any Bourne-type shell

If either -x or -v is set, the function turns them both off.

If neither is on, both are turned on.

calc() { awk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'; }
chmod -R 774 .
p(){ printf "\033[%d;%dH\033[4%dm \033[m" $((RANDOM%LINES+1)) $((RANDOM%COLUMNS+1)) $((RANDOM%8)); }; clear;while :;do p; sleep .001;done
find /path/to/dir/ -type f -exec rm {} +
wget -qO - http://cfaj.freeshell.org/ipaddr.cgi
sed -e 's/{"url":/\n&/g' ~/.mozilla/firefox/*/sessionstore.js | cut -d\" -f4
printf "%s\n" !(pattern) ## ksh, or bash with shopt -s extglob
2009-11-26 14:09:56
User: cfajohnson
Functions: bash printf
Tags: ls grep
-1

There's no need for ls or grep; printf is builtin to most modern shells

die(){ result=$1;shift;[ -n "$*" ]&&printf "%s\n" "$*" >&2;exit $result;}
printf "%s\n" .*
2009-11-23 18:07:18
User: cfajohnson
Functions: printf
Tags: dotfiles
0

In most modern shells, printf is a builtin command.

[ -t 0 ] || exit 1
2009-11-20 23:14:49
User: cfajohnson
Functions: exit
Tags: shell script
21

Exit with error if script is not run in a terminal

wget -qO - http://www.sputnick-area.net/ip;echo
printf "%s\n" ${PATH//:/\/* }
while IFS=: read u x; do passwd -e "$u"; done < /etc/passwd
2009-11-20 21:49:34
User: cfajohnson
Functions: passwd read
0

This assumes that te original's 'passwd -e' forces a user to change password; it doesn't in the versions I have.

printf "%s\n" .*
ls -l | awk '$5 > 1000000' | sort -k5n