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 set from sorted by
Terminal - Commands using set - 47 results
set -x
source_print(){ set | sed -n "/^$1/,/^}$/p"; };
2010-11-24 15:55:34
User: glaudiston
Functions: sed set

useful if you want to get the source code of a in memory function

set $(ps -e o command= | grep "^/usr/bin/X "); while [ x"$1" != x"-auth" ]; do shift; done; sudo x11vnc -display :0 -auth "$2"
set env DYLD_INSERT_LIBRARIES = /usr/lib/libgmalloc.dylib;b szone_error
2010-10-13 20:25:48
User: frank514
Functions: env set

setting gdb with this option / breakpoint before running the process will cause it to break whenever an memory allocation operation is not kosher.

(cd /bin; set -- *; x=$((1+($RANDOM % $#))); man ${!x})
function countdown { case "$1" in -s) shift;; *) set $(($1 * 60));; esac; local S=" "; for i in $(seq "$1" -1 1); do echo -ne "$S\r $i\r"; sleep 1; done; echo -e "$S\rBOOM!"; }
2010-06-30 12:20:01
User: kniht
Functions: echo seq set sleep
Tags: timer counter

The biggest advantage over atoponce's nifty original is not killing the scrollback. Written assuming bash, but shouldn't be terribly difficult to port to other shells. S should be multiple spaces, but I can't get commandlinefu to save/show them properly, any help?

vix(){ vim +'w | set ar | silent exe "!chmod +x %" | redraw!' $@; }
2010-05-27 21:12:48
User: dooblem
Functions: ar set vim
Tags: vim vi chmod
vix /tmp/script.sh

Open a file directly with execution permission.

Put the function in your .bashrc

You can also put this in your vimrc:

command XX w | set ar | silent exe "!chmod +x %" | redraw!

and open a new file like this:

vi +XX /tmp/script.sh
set -eu
2010-04-07 11:54:40
User: wipu
Functions: set

By default bash expands an unbound variable to an empty string. This can be dangerous, if a critical variable name (a path prefix for example) has a typo. The -u option causes bash to treat this as an error, and the -e option causes it to exit in case of an error. These two together will make your scripts a lot safer against typos.

The default behaviour can be explicitly requested using the ${NAME:-} syntax.

A (less explicit) variation: #!/bin/bash -eu

xv() { case $- in *[xv]*) set +xv;; *) set -xv ;; esac }
2010-02-14 20:57:29
User: cfajohnson
Functions: set

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.

function setx(){ sed '/[xv]/!Q2' <<< $- && { set +xv; export PS4=">>> "; } || { export PS4="`tput setaf 3`>>> `tput sgr0`"; set -xv; }; }
2010-02-14 01:25:44
User: AskApache
Functions: export sed set

Running this command turns shell tracing and shell verbose debugging on or off. Not only does it do that, it also uses your terminals builtin method of setting colors to make debugging much easier.

It looks at the current shell options contained in the $- special bash variable and that lets this function set the opposite of the current value. So from the shell you could do a:

setx; echo "y" | ( cat -t ) | echo "d"; setx

and it will turn on debbuggin.

This is an amazingly useful function that is perfect to add system-wide by adding it to /etc/profile or /etc/bashrc.. You can run it from the shell, and you can also use it in your shell scripts like my .bash_profile - http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html

set-proxy () { P=webproxy:1234; DU="fred"; read -p "username[$DU]:" USER; printf "%b"; UN=${USER:-$DU}; read -s -p "password:" PASS; printf "%b" "\n"; export http_proxy="http://${UN}:${PASS}@$P/"; export ftp_proxy="http://${UN}:${PASS}@$P/"; }
2010-02-04 13:12:59
User: shadycraig
Functions: export printf read set

Prompts the user for username and password, that are then exported to http_proxy for use by wget, yum etc

Default user, webproxy and port are used.

Using this script prevent the cleartext user and pass being in your bash_history and on-screen

set -x
set -o noclobber
2010-01-08 21:06:44
User: eastwind
Functions: set

If you set noclobber to on, bash won't allow redirection to overwrite existing files .

set -o noclobber command turn the option on (default it s off ) .

You can still append information but not overwrite the file .to turn it back off use : $ set +o noclobber .

I use it because i overwrite a file by accident , after thought , content of the file was very important , creating a one more file mean nothing for my hard disk (we are not anymore on the 64 k memory time) , but content of file is far much important . What we call exeprience :(

set -o vi
2009-12-22 20:40:10
User: andykazmaier
Functions: set

Once issuing the command, hit "esc" and then "k" (not together) to enter the search mode at the shell prompt (each time), and invoke the search with "/" as if you would in vi. Type a command and see the most recently used instance of that command. Use "n" and "N" to go forward and backwards through other instances of that command.

set | fgrep " ()"
2009-10-22 17:48:54
User: haivu
Functions: fgrep set

If you issue the "set" command, you'll see a list of variables and functions. This command displays just those functions' names.

Add to ~/.inputrc: set match-hidden-files off
set -o vi
2009-03-20 16:29:03
User: Viaken
Functions: set
Tags: readline vi

This lets you use your favorite vi edit keys to navigate your term.

To set it permanently, put "set editing-mode vi" in your ~/.inputrc or /etc/inputrc.

set -o noclobber
2009-03-10 01:39:18
User: vududevil
Functions: set

Use set +o noclobber and you will be able to replace files again

amixer -c 0 set PCM 2dB+
2009-02-22 22:06:46
User: Fate
Functions: amixer set
Tags: audio

this will increase the volume by 2 decibels on the pcm channel. the argument to -c is for which sound card to use, the arg after set is the channel (PCM, Master, etc.) and what to set by.

related commands:

amixer -c 0 set PCM 2dB-

decrease volume by 2 decibels

amixer -c 0 set PCM toggle

toggle mute/unmute

this is for alsa systems

for mac os (and maybe other UNIX systems) osascript -e 'set Volume *' where * is any number (can have decimal points) between 0 and 10

set -o vi
unset files i; set -f; O=$IFS; while IFS= read -r -d $'\0' files[i++]; do :; done < <(find . -name '*.avi' -print0) && IFS=$O; set +f && echo "Running: mplayer \"${files[ $(( $RANDOM % ${#files[@]} )) ]}\""
2009-02-18 16:53:57
User: DEinspanjer
Functions: echo find read set unset

unsets variables used by the one-liner

sets up the IFS bash variable to not be affected by whitespace and disables extra glob expansion

uses read to slurp the results of the find command into an array

selects an element of the array at random to be passed as an argument to mplayer

set -o vi; ls -l jnuk<ESC>bCjunk
2009-02-05 22:58:51
User: jonty
Functions: ls set

If you spend all day editing in vi then switching your fingers to Emacs mode just for the command line can be difficult. Use set -o vi in your bash shell and enjoy the power of a real editor.