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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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 JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2015-07-30 18:50:51
Functions: export
Tags: version java

Useful if you have multiple versions of Java installed. The 1.7 pkg for Mac doesn't tell you anything about where it's putting stuff.

nohist(){ export HISTFILE=/dev/null; }
2014-12-31 22:30:08
Functions: export

Yo run the `nohist` command and after that the commands won't get stored in the history file for the current session.

This makes no permanent changes.

export PATH=$PATH:/home/user/my_prog
( eval $(grep -z '^DBUS_SESSION_BUS_ADDRESS' /proc/$(pgrep -u $USER plasma-overlay)/environ); export DBUS_SESSION_BUS_ADDRESS; kquitapp plasma-overlay )
2014-09-01 12:49:58
User: mig_hg
Functions: eval export grep

So this first obtains address of the DBUS session, as it's not available by default over SSH. Then it tells plasma-overlay to exit. `kquitapp` is pretty much an equivalent of the qdbus calls.

export NEWUSER=newuser; mkdir /home/$NEWUSER; useradd -d /home/$NEWUSER -s /bin/bash -G sudo $NEWUSER; passwd $NEWUSER
export PORT=11211; ss -an4 | grep -E "ESTAB.*$PORT" | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr
export KEEP_KERNEL=2; dpkg -l 'linux-image*' | awk '/^ii/ { print $2 }' | grep "[0-9]" | awk 'BEGIN{i=1}{print i++, $0}' | grep `uname -r` -B99 | sort -r | tail -n+$(($KEEP_KERNEL+2)) | awk '{print $2}'| xargs apt-get -y purge
export HISTCONTROL=ignorespace
2013-07-25 08:31:10
User: gorynka
Functions: export
<space>secret_command;export HISTCONTROL=

This will make "secret_command" not appear in "history" list.

while read line; do export $line; done < <(cat input)
2013-03-15 08:14:04
User: dario
Functions: cat export read

This exports all lines of input file as environment variables, assuming each line is like these:



export l=$1; shift; rename 'my $l=$ENV{'l'}; my $z="0" x $l; s/\d+/substr("$z$&",-$l,$l)/e' "$@"
2013-03-13 15:14:20
User: hgrupht13
Functions: export rename

Use it as bash-script.

The first positional parameter specifies the fixed length of the numerical index.

Further params specify the files to manipulate.

export PATH=`echo -n $PATH | awk -v RS=":" '{ if (!x[$0]++) {printf s $0; s=":"} }'`
export HISTFILE=/dev/null
2013-02-18 16:37:01
User: sonic
Functions: export
Tags: history bash

just an alternative to setting the size, this allows you to scroll up and see your previous commands in a given session but when you logout the history is not saved. That's the only advantage to doing it this way..

export BLOCKSIZE='sudo blockdev --getsize64 /dev/sdc' && sudo dd if=/dev/sdc bs=1MB | pv -s $BLOCKSIZE | gzip -9 > USB_SD_BACKUP.img.gz
2013-02-05 18:10:25
User: hur1can3
Functions: dd export gzip sudo

This is a useful command to backup an sd card with relative total size for piping to pv with a progressbar

export HISTFILESIZE=99999
2013-01-02 09:25:06
User: totti
Functions: export

set how many commands to keep in history

Default is 500

Saved in /home/$USER/.bash_history

Add this to /home/$USER/.bashrc



export DISPLAY=$(tr '\000' '\n' < /proc/`pidof Xorg`/cmdline | egrep '^:[0-9]+')
2012-12-18 07:26:16
User: oernii2
Functions: egrep export tr

Not always does Xorg run on :0. For times like those, this script allows you to find out which it is.

export HISTSIZE=0
if [ -n "$SSH_CONNECTION" ]; then export TMOUT=300; fi
2012-11-03 18:39:25
User: Testuser_01
Functions: export

This will check if a user is logged in using ssh and will log out the user automatically after the specified time in seconds without data retrieval on the server side.

Will work with bash and zsh so put it into your sourced shell file on the server side.

Be aware that users can change this themselves as it's just a envoronment variable.

export MYSQL_PS1="mysql://\u@\h:/\d - \R:\m:\s > "
2012-11-03 18:22:16
User: Testuser_01
Functions: export

You can put this into your shell sourced file like .bashrc or .zshrc to have a different mysql prompt.

See http://dev.mysql.com/doc/refman/5.1/de/mysql-commands.html for more informations.

Beware that currently with mysql 5.5 the seconds are buggy and won't be displayed if you put this into a .cnf file. With the enironment variable this will work.

export proc=chrome && ps aux | grep $proc | grep -v grep |awk '{print $2}'
export PATH= $(echo $PATH | tr ':' '\n' | awk '!/matching string/' | paste -sd:)
export LESS='-x4FRSXs'
2012-05-25 16:46:15
User: SEJeff
Functions: export

# s = combine multiple lines of whitespace into 1

# x4 = set the tabstop to 4 instead of 8

# F = Exit if the output fits on 1 screen. This is similar to git diff

# R = Raw control chars. This allows you to pipe colordiff straight to less. ie: alias sdi="svn diff | colordiff | less"

# S = Chop off long lines

# X = Dont send termcap init and deinit scrings to the terminal

export HISTFILE="$HOME/.bash_history-$(hostname -s)"
2012-05-01 13:23:15
User: rdc
Functions: export

On systems where your home directory is shared across different machines, your bash history will be global, rather than being a separate history per machine. This setting in your .bashrc file will ensure that each machine has its own history file.

export PROMPT_COMMAND=$PROMPT_COMMAND'; export PWD_UPCASE="${PWD^^}"'; export PS1='C:${PWD_UPCASE//\\//\\\\}>'
2012-04-30 20:09:49
User: chungy
Functions: export

(This may be specific to bash only.) This transforms the current working directory to all uppercase characters and replaces forward slashes with backslashes, prepending the string with "C:" and appending a single ">". It serves no practical purpose, but may serve as a great practical joke if you can insert it to some victim's .bashrc :-)

export PS1="\[\e[01;32m\]\u@\h \[\e[01;34m\]\W \`if [ \$? = 0 ]; then echo -e '\[\e[01;32m\]:)'; else echo -e '\[\e[01;31m\]:('; fi\` \[\e[01;34m\]$\[\e[00m\]"
dng(){ local a;a=$(sed '/'"$1"'/!d' /etc/hosts |sed '=;'"${2-1,$}"'!d'|sed '/ /!d');echo $a|tr '\040' '\n'|nl -bp'[0-9]$'|less -E;export dn=$(echo $a|sed 's,.* ,,');export ip=$(echo $a|sed 's, .*,,');echo \$dn=$dn;echo \$ip=$ip;}
2012-04-01 23:57:09
User: argv
Functions: echo export less nl sed tr

usage: dng BRE [selection]

default selection is the last match

DNS is ok, but although domainnames may be easier to remember than IP numbers, it still requires typing them out. This can be error-prone. Even more so than typing IPv4 numbers, depending on the domainname, its length and complexity.