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

All commands from sorted by
Terminal - All commands - 11,925 results
gpg -c sensitive.txt; gpg sensitive.txt.gpg
if date -d 2006-10-10 >> /dev/null 2>&1; then echo 1; else echo 0; fi
2013-01-10 10:35:15
Functions: date echo
0

On CentOS at least, date returns a boolean for the common date string formats, including YYYY-MM-DD. In the sample output, you can see various invalid dates returning 0 whereas a simple regex check would return 1 for the invalid dates.

-d, --date=STRING display time described by STRING, not `now'

The version of date on OS X does not appear to have this same option.

while true; do filechanged=$(inotifywait -e close_write,moved_to --format "%w%f" .); haml $filechanged -q --no-escape-attrs > ${filechanged/.haml/.html}; done
2013-05-01 21:15:26
User: batandwa
0

Monitors the current directory for changes to HAML files and converts them to HTML.

rsync -a --append source-file destination
head -c 24 /dev/urandom | base64
2013-09-28 16:32:47
User: henix
Functions: head
Tags: random
0

Use less random number resources and less commands

for i in *; do mplayer "$i" && rm -i "$i"; done
2013-12-26 17:13:23
User: warkruid
Functions: rm
0

The glob pattern * expands to all files, no need for the 'ls' command.

The quotes around "$i" make sure filenames with spaces in them are handled correctly.

mplayer determines if it is a media file and plays it, or gives errors and the loop asks if this file has to be removed.

find ./ -type l -print0 | xargs -0 ls -plah
2014-03-20 20:36:39
Functions: find ls xargs
0

shows you the symlinks in the current directory, recursively, but without following them

puppet config print modulepath
ls -ld *(/)
host -la domain.com
2009-03-28 12:15:16
Functions: host
0

Perform a dns zone transfer (if is allowed on target dns server) and print result.

mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq -oac mp3lame -lameopts br=98 -o output.wmv input.mpg
range () { end=$(echo "$1 + $2 - 1" | bc); echo "$1-$end"; }
2009-11-12 22:53:08
User: bartonski
Functions: echo
0

for example:

echo "..1234567." | cut -c $(range 3 7)

yields

1234567

find ~/Music/iTunes/iTunes\ Media/. -name \*.ipa -exec basename {} \; | cut -d \. -f 1 > ~/Desktop/MyAppList`date +%s.txt`
2010-06-16 15:14:32
User: IsraelTorres
Functions: basename cut find
0

omit "> ~/Desktop/MyAppList`date +%s.txt`" if you don't want to print it to a file on your desktop and instead only want to display to console

created and tested on:

ProductName: Mac OS X

ProductVersion: 10.6.3

BuildVersion: 10D573

find * ! -name abc -type f -delete
find /path/to/folder/ -mindepth 1 -maxdepth 2 -name "*,v" -exec sudo rlog -L -R {} \;
parallel echo -n {}"\ "\;echo '$(du -s {} | awk "{print \$1}") / $(find {} | wc -l)' \| bc -l ::: *
ls -l `whereis gcc`
2011-11-15 19:45:08
User: knathan54
Functions: ls
Tags: which ls zsh
0

whereis (1) - locate the binary, source, and manual page files for a command

Not actually better, just expanded a bit. The "whereis" command has the following output:

whereis gcc

gcc: /usr/bin/gcc /usr/lib/gcc /usr/bin/X11/gcc /usr/share/man/man1/gcc.1.gz

therefore the 'ls' error on first line, which could be eliminated with a little extra work.

sudo dmidecode -s system-product-name
sed -n -e "/^\[/h; /priority *=/{ G; s/\n/ /; s/ity=/ity = /; p }" /etc/yum.repos.d/*.repo | sort -k3n
2012-09-06 00:09:09
User: eddieb
Functions: sed sort
0

This probably only works without modifications in RHEL/CentOS/Fedora.

while true; do eject && sleep `expr $RANDOM % 5` && eject -t; done;
2013-01-10 18:40:50
User: joeheyming
Functions: eject sleep
Tags: prank eject
0

Ssh to your co-worker's box and watch them go crazy when the cd player ejects

dpkg-query -Wf '${Installed-Size}\t${Status}\t${Package}\n' | sort -n | grep installed
pdfjam --clip true --trim '10mm 11cm 22pts 0' m.pdf
2014-07-08 10:57:54
User: qdrizh
Functions: true
0

This will crop each page of the PDF by 10mm left, 11cm bottom, 22pts right, and nothing from the top.

netstat -nr|egrep -v "Routing|Interface|lo0"|awk '{print $5}'|sort -u| while read l; do ifconfig $l ; echo " Station Addr: `lanscan -ia|grep "$l "|cut -d ' ' -f 1`" ; done
ls **/fred*~*junk*/*
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.