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.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands tagged function from sorted by
Terminal - Commands tagged function - 119 results
function colorize() { c="--line-buffered --color=yes"; GREP_COLORS="mt=01;34" egrep $c '(^| 200 | 304 )' "${@}" | GREP_COLORS="mt=02;31" egrep $c '(^|"(GET|POST) .*[^0-9] 4[0-1][0-9] )' | GREP_COLORS="ms=02;37" egrep $c '(^|^[0-9\.]+) ';}
2013-08-14 21:05:34
User: mogsie
Functions: egrep

Puts a splash of color in your access logs. IP addresses are gray, 200 and 304 are green, all 4xx errors are red. Works well with e.g. "colorize access_log | less -R" if you want to see your colors while paging.

Use as inspiration for other things you might be tailing, like syslog or vmstat


tail -f access.log | colorize
open() { explorer /e, $(cygpath -wap "${1:-$PWD}"); }
2013-08-08 14:49:15
User: applemcg

use the shell default positional parameter syntax ${X:-default} in lieu of testing.

google() { gg="https://www.google.com/search?q=";q="";if [[ $1 ]]; then for arg in "$@" ; do q="$q+$arg"; done ; if [[ -f /usr/bin/chromium ]]; then chromium "$gg"$q; else firefox -new-tab "$gg"$q; fi else echo 'Usage: google "[seach term]"'; fi }
google() { gg="https://www.google.com/search?q="; ff="firefox"; if [[ $1 ]]; then "$ff" -new-tab "$gg"$(echo ${1//[^a-zA-Z0-9]/+}); else echo 'Usage: google "[seach term]"'; fi }
2013-08-01 22:21:53
User: lowjax
Functions: echo

Usage: google "[search string]"

Example: google "something im searching for"

This will launch firefox and execute a google search in a new tab with the provided search string.

You must provide the path to your Firefox binary if using cygwin to $ff or create an alias like follows:

alias firefox='/cygdrive/c/Program Files (x86)/Mozilla Firefox/firefox.exe'

Most Linux flavors with Firefox installed will use just ff="firefox" and even OSX.

rhost() { if [[ $1 =~ ^[0-9]+$ ]]; then sed -i "$1"d ${HOME}/.ssh/known_hosts; else echo "rhost [n]"; fi }
2013-08-01 21:10:34
User: lowjax
Functions: echo sed

Quickly remove the conflicting line (key) from current users known_hosts file when there is an SSH host conflict. Very nice when you get tired of writing out full commands. Ideally you would place this into your .bash_profile

Usage: rhost [n]

Example: rhost 33 (removes line 33 from ~/.ssh/known_hosts)

Function assumes the $HOME exists, you could alternatively use "~/.ssh/known_hosts"

Mac OSX likes a space for sed -i "$1" d

open(){ if [[ -n "$1" ]];then explorer /e, $(cygpath -mal "$PWD/$1");else explorer /e, $(cygpath -mal "$PWD");fi }
2013-07-31 01:15:14
User: lowjax

This alternative either opens the current working directory by just issuing the open function in the commandline. Or you can specify what directory you would like to open.

Example: open /cygdrive/c/Windows

Usage: open [path]

When no option is specified it will open the current working directory

=() { echo $(($*)); }
2013-05-03 04:27:07
User: xlz
Functions: echo

POSIX compliant arithmetic evaluation.

= 10*2+3

mkalias () { echo "alias $1=\"$2\"" >> ~\.bash_aliases }
2013-01-14 13:56:35
User: xr09
Functions: echo
Tags: alias function

Is used like this:

mkalias rmcache "rm -rfv app/cache/*"

function map() { [ -n "$1" ] && alias $1="cd `pwd`" || alias | grep "'cd "; }
typeset -f
2012-09-17 13:48:39
User: kLeZ
Tags: bash function

typeset command gives to stdout all the functions defined in a bash session, -f and -F switches are for: all functions names with body (-f) and all functions names only (-F).

buf () { oldname=$1; if [ "$oldname" != "" ]; then datepart="$(date +%Y-%m-%d).bak"; firstpart=`echo $oldname | cut -d "." -f 1`; newname=`echo $oldname | sed s/$firstpart/$firstpart.$datepart/`; cp -iv ${oldname} ${newname}; fi }
2012-08-15 08:31:44
User: juliushibert
Functions: cp cut sed

Appends the input file with the date format YYYY-MM-DD.bak. Also runs silently if you remove the -v on the cp at the end of the function.

function _xterm_cwds() { for pid in $(pidof -- -zsh) $(pidof zsh); do reply+=$(readlink /proc/$pid/cwd) done }; function xcd() { cd $1 }; compctl -K _xterm_cwds xcd
2012-07-12 19:59:46
User: aartur
Functions: cd pidof readlink

It gives a 'xcd' command for changing directory to one of CWDs of other ZSH processes (typically running in a terminal emulator). Useful for single-windowed terminal emulators like XTerm or Rxvt which don't have ability to pass CWD of one shell to another.

members () { dscl . -list /Users | while read user; do printf "$user "; dsmemberutil checkmembership -U "$user" -G "$*"; done | grep "is a member" | cut -d " " -f 1; };
2012-05-20 11:34:33
User: eduo
Functions: cut grep printf read

Group membership in OS X is a mish-mash of standards that end up meaning there's almost a half-dozen of ways to belong to a group, what with group inheritance and automatic assignment. This means there's no easy command to find out all groups a user belongs to. The only sensible way then is to list all users and then query each user for membership.

NOTE: This is a function. Once input you can execute it by calling with a groupname.

function have_here { find "${@:-.}" -type d \( -name .git -o -name .svn -o -name .bzr -o -name CVS -o -name .hg -o -name __pycache__ \) -prune -o -type f -print; }
2012-05-20 05:31:26
User: syscomet
Functions: find
Tags: function

Ever done a find to get content and been messed up by .git, .svn, .hg or the like spamming your results? Did you really want to grep over every copy of the file that existed in your git history?


grep -r PATTERN .


grep PATTERN -- $(have_here)

or if you really have too many files to put in one argv:

have_here | xargs grep PATTERN --
regenerateCSR () { openssl genrsa -out $2 2048; openssl x509 -x509toreq -in $1 -out $3 -signkey $2; }
mkgo newdir
calc() { echo "scale=4; ${*//,/.}" | bc -l; }
2011-10-24 19:58:20
User: fpunktk
Functions: bc echo

This is an "argument calculator" funktion. The precision is set to 4 and you can use dot (.) or comma (,) as decimal mark (which is great for german users with a comma on the numpad).

python -ic "from __future__ import division; from math import *; from random import *"
2011-10-24 19:47:27
User: fpunktk
Functions: python

This opens a python command line. You can use math and random and float-division is enabled (without appending .0 to integers). I just don't know how to specify a standard precision.

alias calc='python -ic "from math import *; from random import *"'
2011-10-24 08:15:41
User: Bonster
Functions: alias

use python as calculator, press ctrl+d to exit

reminder: when doing factions add atleast one decimal number like so

22.0/7 or 22/7.0

xpath () { xmllint --format --shell "$2" <<< "cat $1" | sed '/^\/ >/d' }
2011-10-05 07:45:16
User: sharfah
Functions: sed

This function uses xmllint to evaluate xpaths.

Usage: xpath /some/xpath XMLfile

quietly() { "$@" > /dev/null 2>&1; }
sshmysql() { ssh -L 13306: -N $* & }
2011-09-01 10:21:55
Functions: ssh

Create a secure tunnelled connection for access to a remote MySQL database.

For example, connect with MySQL Workbench to [email protected]:13306.

timeDNS () { { for x in "${local_DNS}" "" "" "" "" "" "" "" ""; do ({ echo -n "$x "; dig @"$x" "$*"|grep Query ; }|sponge &) done ; } | sort -n -k5 ; }
2011-08-18 01:11:53
Functions: dig echo grep sort

Evoke from the command like as:

timeDNS commandlinefu.com


This isn't too terribly practical, but it is a good code example of using subshells to run the queries in parallel and the use of an "anonymous function" (a/k/a "inline group") to group i/o.


I'm assuming you have already defined your local DNS cache as ${local_DNS}, (here, it's


You do need to install `moreutils` to get `sponge`.


If you're willing to wait, a slower version w/o sponge, (and w/o sorting), is this:


DNS () { for x in "" "" "" "" "" "" "" "" ""; do (echo -n "$x "; dig @"$x" "$*"|grep Query) ; done ; }

lsr() { find "${@:-.}" -print0 |sort -z |xargs -0 ls $LS_OPTIONS -dla; }
2011-08-15 03:10:58
User: h3xx
Functions: find ls sort xargs

Tells you everything you could ever want to know about all files and subdirectories. Great for package creators. Totally secure too.

On my Slackware box, this gets set upon login:

LS_OPTIONS='-F -b -T 0 --color=auto'


alias ls='/bin/ls $LS_OPTIONS'

which works great.

mergepdf() { gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf "$@" }
2011-07-28 11:12:15
Functions: gs

This is an expansion on a previous entry, which I've wrapped in a function and placed in my profile. The "$@" is a positional parameter, much like "$*", but the parameters are passed on intact, without interpretation or expansion; so you can simply call the function like this:

mergepdf *

This will output a merged PDF of all PDFs in the current directory. Alternatively, you can simply list them like so:

mergepdf 00.pdf 01.pdf 02.pdf ...

N.B. Passing a wildcard will merge all PDFs in the current directory in name order, e.g. 00.pdf 01.pdf aa.pdf ab.pdf