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 using export from sorted by
Terminal - Commands using export - 92 results
export PS1='\D{%a %D %T}> '
ls -1 *.jpg | while read fn; do export pa=`exiv2 "$fn" | grep timestamp | awk '{ print $4 " " $5 ".jpg"}' | tr ":" "-"`; mv "$fn" "$pa"; done
2009-08-10 00:52:22
User: axanc
Functions: awk export grep ls mv read tr

Renames all the jpg files as their timestamps with ".jpg" extension.

export HISTCONTROL=ignoreboth
2009-07-15 16:05:03
User: ioggstream
Functions: export
Tags: history

Don't track in history commands starting with whitespace.

Moreover ignore duplicates from history.

To be set in .bashrc


$ export HISTCONTROL=ignoreboth

$   echo antani

$   history|grep -c antani

export LANG=C; grep string longBigFile.log
2009-07-14 12:48:02
User: ioggstream
Functions: export grep
Tags: grep LANG

greps using only ascii, skipping the overhead of matching UTF chars.

Some stats:

$ export LANG=C; time grep -c Quit /var/log/mysqld.log


real 0m0.191s

user 0m0.112s

sys 0m0.079s

$ export LANG=en_US.UTF-8; time grep -c Quit /var/log/mysqld.log


real 0m13.462s

user 0m9.485s

sys 0m3.977s

Try strace-ing grep with and without LANG=C

export IFS=$(echo -e "\n")
2009-07-09 15:25:37
User: darkpand
Functions: echo export

When you use a "for" construct, it cycles on every word. If you want to cycle on a line-by-line basis (and, well, you can't use xargs -n1 :D), you can set the IFS variable to .

export http_proxy=<user>:<pass>@<server>:<port> ftp_proxy=<user>:<pass>@<server>:<port>
2009-05-12 14:36:42
User: fritz_monroe
Functions: export

History usually only gives the command number and the command. This will add a timestamp to the history file.

Note: this will only put the correct timestamp on commands used after the export is done. You may want to put this in your .bashrc

export LSCOLORS=gxfxcxdxbxegedabagacad
2009-05-04 04:07:36
User: haivu
Functions: export
Tags: bash ls osx

I use terminal with black background on the Mac. Unfortunately, the default ls color for the directory is blue, which is very hard to see. By including the line above in my ~/.bash_profile file, I changed the directory's color to cyan, which is easer to see. For more information on the syntax of the LSCOLORS shell variable:

man ls

I tested this command on Mac OS X Leopard

alias tproxy='ssh -ND 8118 user@server&; export LD_PRELOAD="/usr/lib/libtsocks.so"'
export PS1='\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[00m\]: '
2009-03-18 22:05:48
User: kamiller
Functions: export
Tags: color prompt

It colors the machine name and current directory different colors for easy viewing.

export PS1='\n[\u@\h \! \w]\n\[\e[32m\]$ \[\e[0m\]'
2009-03-09 15:34:22
User: haivu
Functions: export
Tags: bash

I put that line in my .bash_profile (OS X) and .bashrc (Linux).

Here is a summary of what the \char means: n=new line, u=user name, h=host, !=history number, w=current work directory

The \[\e[32m\] sequence set the text to bright green and \[\e[0m\] returns to normal color.

For more information on what you can set in your bash prompt, google 'bash prompt'

export PS1="${PS1%\\\$*}"' \t \$ '
export IFS=$'\n';for dir in $( ls -l | grep ^d | cut -c 52-);do du -sh $dir; done
newhostname=$(hostname | awk -F. '{print $1 "." $2}'); ipaddress=$(nslookup `hostname` | grep -i address | awk -F" " '{print $2}' | awk -F. '{print $3 "." $4}' | grep -v 64.142);PS1="[`id -un`.$newhostname.$ipaddress]"' (${PWD}): '; export PS1
2009-02-16 20:11:53
User: simardd

changes the PS1 to something better than default.

[username.hostname.last-2-digits-of-ip] (current directory)

export PS1='\[\e]0;\h \u \w\a\]\n\[\e[0;34m\]\u@\h \[\e[33m\]\w\[\e[0;32m\]\n\$ '
2009-02-13 19:49:17
User: OS2
Functions: export

used in an if-then-else in case the default shell is ksh, not bash.

The $(basename ${0#-}) is handy to echo which shell and strip the dash some flavors put in front of "bash"

if [ $(basename ${0#-}) == "bash" ] ; then

export PS1='\[\e]0;\h \u \w\a\]\n\[\e[0;34m\]\u@\h \[\e[33m\]\w\[\e[0;32m\]\n\$ '



ESC=`echo "\033"`

BEL=`echo "\007"`

RAW=`echo "\r"`

export PS1='-${RAW}${ESC}]0;${HOST} ${USER}${BEL}-${ESC}[0;34m${USER}${ESC}[0m@${ESC}[0;34m${HOST%%.*}${ESC}[0;33m${ESC}[0m $ '


export SSH_AUTH_SOCK=`find /tmp/ssh* -type s -user [user] -mtime -1 | head -1`
2009-02-05 20:55:41
User: wwest4
Functions: export head

Must be done as root - will cause subsequent ssh connections to use the identities available via the [user]'s agent socket.

export PS1='C:${PWD//\//\\\}>'