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.

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

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using export from sorted by
Terminal - Commands using export - 89 results
export LANG=C; grep string longBigFile.log
2009-07-14 12:48:02
User: ioggstream
Functions: export grep
Tags: grep LANG
0

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

Some stats:

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

7432

real 0m0.191s

user 0m0.112s

sys 0m0.079s

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

7432

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
8

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>
export HISTTIMEFORMAT="%F %T "
2009-05-12 14:36:42
User: fritz_monroe
Functions: export
32

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
2

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
5

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
7

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
-4

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
1

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\$ '

else

HOST=`hostname`

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 $ '

fi

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
1

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//\//\\\}>'