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.

Universal configuration monitoring and system of record for IT.
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

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!
Hide

Top Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 12,302 results
history -c
echo "" > .bash_history
perl -e '$i=0;while($i<10){open(WGET,qq/|xargs lynx -dump/);printf WGET qq{http://www.google.com/search?q=site:g33kinfo.com&hl=en&start=$i&sa=N},$i+=10}'|grep '\/\/g33kinfo.com\/'
2009-10-16 12:20:17
User: op4
Functions: grep perl xargs
Tags: web browser
0

not my cmd... found on the web

HDD=$(df | awk ' NR>3 (S=$5) (M=$6) { if (S>90) print "Your Systems "M" is """S" Full" } ') ; [[ $HDD ]] && echo "$HDD" | mail -s "Hard-Drives Full" [email protected] -- -f [email protected] >/dev/null
tail -F file | egrep --color 'pattern|$'
gconftool -t str -s /desktop/gnome/background/picture_filename "`find /DIR_OF_JPGS -name '*.jpg' | shuf -n 1`"
2009-10-16 01:17:47
User: cbrinker
2

Every time this is run it will change your background picture. For added fun

Add some DBUS magic:

. $HOME/.dbus/session-bus/`cat /var/lib/dbus/machine-id`-0

export DBUS_SESSION_BUS_ADDRESS

and a crontab entry:

*/5 * * * * above_command_in_script.sh >/dev/null 2>/dev/null

now wallpaper changes every 5 mins

for i in ~/Desktop/Personal/Wallpapers/*.jpg ; { size=$((`identify -format "%wx%h" $i | sed 's/x/*/'`)) ; if [[ $size -lt 800001 ]] then ; rm -f "$i" ; fi; }
2009-10-16 00:21:21
User: cbrinker
Functions: rm sed
0

For all of the jpgs in a directory, determine their size and if below a threshold remove them forcefully.

mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq -oac mp3lame -lameopts br=98 -o output.wmv input.mpg
[ $(df / | perl -nle '/([0-9]+)%/ && print $1') -gt 90 ] && df -hP | mutt -s "Disk Space Alert -- $(hostname)" [email protected]
2009-10-15 21:11:54
User: syssyphus
Functions: df perl
3

put it in crontab to get an alert when / is over 89% utilization.

find . -name "whatever.*" -print0 | rsync -av --files-from=- --from0 ./ ./destination/
perl -i -ne 'print uc $_' $1
seq -w 100 | sed 's/^/login/'
2009-10-15 13:56:56
User: lawrence
Functions: sed seq
-4

This command generates a sequential login list. Good to be used as a source of new logins.

tail -f file | egrep --color=always $\|PATTERN
2009-10-15 13:08:30
User: sitaram
Functions: egrep file tail
Tags: color
-2

but you can't see the colors in that sample output :(

seq 10 |xargs -n1 echo Printing line
2009-10-15 11:05:35
User: Waldirio
Functions: echo seq xargs
Tags: echo xargs seq
0

Nice command to create a list, you can create too with for command, but this is so faster.

sed -n 5p <file>
2009-10-15 11:00:48
User: Waldirio
Functions: sed
38

You can get one specific line during any procedure. Very interesting to be used when you know what line you want.

chr () { printf \\$(($1/64*100+$1%64/8*10+$1%8)); }
2009-10-15 07:01:54
User: dennisw
Functions: printf
5

I've corrected the function. My octal conversion formula was completely wrong. Thanks to pgas at http://mywiki.wooledge.org/BashFAQ/071 for setting me straight. The new function is from pgas and is very fast.

Putty -d 8080 [server]
2009-10-15 06:54:58
User: felix001
0

Run this on a windows machine then add your localhost as a socks server for port 8080 within your web browser. Your traffic will now be proxying and sent via your server over ssh.

tail -f FILE | grep --color=always KEYWORD
PROMPT_COMMAND=command
2009-10-15 06:01:18
User: haivu
Tags: bash prompt
1

For example, if you are the type who type ls very often, then

PROMPT_COMMAND=ls

will ls after every command you issue.

n=$RANDOM$RANDOM$RANDOM; let "n %= 10000000000"; echo $n
gzip *
ls | xargs -n1 gzip
for file in *.foo; do gzip "$file"; done
2009-10-15 01:27:05
User: dfrios
Functions: file gzip
1

It gzip each file in a directory separately

seq 4|xargs -n1 -i bash -c "echo -n 164.85.216.{} - ; nslookup 164.85.216.{} |grep name"|tr -s ' ' ' '|awk '{print $1" - "$5}'|sed 's/.$//'
script_path=$(cd $(dirname $0);pwd)
2009-10-14 16:04:03
User: jgc
Functions: cd dirname
Tags: cd pwd PATH
7

Another way of doing it that's a bit clearer. I'm a fan of readable code.