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 tagged macosx from sorted by
Terminal - Commands tagged macosx - 42 results
date -r 1390196676
docker ps -q | xargs -n 1 docker inspect | jq '.[0].NetworkSettings.Ports +{} | map(select(. != null)[0].HostPort) | map("-L \(.):localhost:\(.)") ' | sed -n 's/.*"\(.*\)".*/\1/p' |xargs boot2docker ssh -N
ioreg -l | grep Capacity
2014-05-22 11:39:49
User: oieesah
Functions: grep
Tags: macosx battery

Better to use this command instead of installing whole new application to check the battery stats.

function google () { st="$@"; open "http://www.google.com/search?q=${st}"; }
2014-05-07 03:14:05
User: plasticphyte

Searches Google, but requires no "", and will also search all terms input in the CL, eg:

> google foo bar

returns search URL "

You could also use awk to replace all spaces with a +, which is how the Google search handles spaces, but that makes it more than one line.

brew update && brew upgrade
echo 'Dir.foreach("/usr/local/Cellar/cowsay/3.03/share/cows") {|cow| puts cow; system "fortune | cowsay -f /usr/local/Cellar/cowsay/3.03/share/cows/#{cow}" }' | ruby
2013-04-15 12:27:38
User: orkoden
Functions: echo

Shows a list of all installed cows saying a fortune. Also lists the cows names. Pic your favorite cow!

Needs cowsay, fortune and ruby installed. The path only applies to OS X with cowsay installed using homebrew. On Linux it might be /usr/share/cowsay/cows/ or similar. Uses ruby just because.

brew update && brew upgrade `brew outdated`
2012-03-07 14:26:41
User: farazyashar

As of March 7, 2012:

brew update - downloads upgraded formulas brew upgrade [FORMULA...] - upgrades the specified formulas brew outdated - lists outdated installations

Note updating all packages may take an excruciatingly long time. You might consider a discriminating approach: run `brew outdated` and select specific packages needing an upgrade.

For more information see homebrew's git repository: https://github.com/mxcl/homebrew

defaults write com.apple.terminal FocusFollowsMouse -string YES
2011-07-26 02:15:04
User: ratonovitch
Functions: write

In Mac OS X, by default, you have to click the mouse on a Terminal window before you can type in it. You can change this behavior to mimic the X11 behavior of focusing on the window on mouseover.

open -a Finder <path>
defaults write com.apple.dock persistent-others -array-add '{tile-data={}; tile-type="spacer-tile";}'; killall Dock
2011-07-26 02:05:17
User: ratonovitch
Functions: killall write

Insert an additional (moveable) spacer on the right side of the Dock in Mac OS X

defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'; killall Dock
2011-07-26 02:03:29
User: ratonovitch
Functions: killall write

Insert an additional (moveable) spacer on the left side of the Dock in Mac OS X

alias google='open http://www.google.com/search?q="'
2011-06-29 20:23:20
Functions: alias


google query_with_spaces "

so, make sure to end your query with a double quote

sw_vers [-productName|-productVersion|-buildVersion]
/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background &
hdiutil mount -owners on -mountrandom /tmp -stdinpass /path/to/my.sparsebundle
openssl base64 -in base64.decoded.txt -out base64.encoded.txt
2010-08-13 20:39:10
User: argherna

I have a mac, and do not want to install mac ports to get the base64 binary. Using openssl will do the trick just fine. Note, to decode base64, specify a '-d' after 'base64' in the command. Note also the files base64.decoded.txt and base64.encoded.txt are text files.

COPYFILE_DISABLE=true tar cvf newTarFile.tar Directory/
2010-07-01 09:36:48
User: alainkaa
Functions: tar
Tags: macosx

Using the COPYFILE_DISABLE=true environment variable you can prevent tar from adding any ._-files to your .tar-file on Mac OS X.

somecommand | open "mailto:?body=$(cat - | stripansi | urlencode)"
2010-02-25 19:44:27
User: fletch
Tags: macosx email

This depends on 'stripansi' and 'urlencode' commands, which exist on my system as these aliases:

alias stripansi='perl -ple "s/\033\[(?:\d*(?:;\d+)*)*m//g;"'

alias urlencode='perl -MURI::Escape -ne "\$/=\"\"; print uri_escape \$_"'

The `open` command handles URLs on a Mac. Substitute the equivalent for your system (perhaps gnome-open).

I don't use system `mail`, so I have this aliased as `mail` and use it this way:

git show head | mail
brew update && brew install `brew outdated`
define(){ local y="$@";curl -sA"Opera" "http://www.google.com/search?q=define:${y// /+}"|grep -Eo '<li>[^<]+'|sed 's/^<li>//g'|nl|/usr/bin/perl -MHTML::Entities -pe 'decode_entities($_)';}
2010-01-30 13:08:03
User: gthb
Functions: grep sed

This version works on Mac (avoids grep -P, adding a sed step instead, and invokes /usr/bin/perl with full path in case you have another one installed).

Still requires that you install perl module HTML::Entities ? here's how: http://www.perlmonks.org/?node_id=640489

defaults write /Library/Preferences/com.apple.NetworkAuthorization UseShortName -bool YES
2009-12-01 05:39:36
User: offworlder
Functions: write
Tags: macosx

This command will use the short username (ie: bsmith) instead of the full (or long) name (ie: Bob Smith), by default in the network authentication dialog, ie: when connecting to servers. Resulting in one less step/time saved.

Simply change the boolean value to "NO" (ie: "... -bool NO") to revert to the system's default behavior.

ps -ec -o command,rss | grep Stainless | awk -F ' ' '{ x = x + $2 } END { print x/(1024) " MB."}'
2009-11-04 19:01:22
Functions: awk grep ps

Adds up the total memory used by all Stainless processes: 1 Stainless, 1 StainlessManager and 1 StainlessClient per tab open.

defaults write com.macromates.textmate OakDefaultLanguage 17994EC8-6B1D-11D9-AC3A-000D93589AF6
2009-10-20 07:10:34
User: vigo
Functions: write

When you press "cmd+n" in TextMate, you can have "HTML" language as default document format... You can also define other languages too. You need to know the UUID of your language bundle.

curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/<title>\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p"
2009-09-07 21:56:40
User: postrational
Functions: awk sed tr

Checks the Gmail ATOM feed for your account, parses it and outputs a list of unread messages.

For some reason sed gets stuck on OS X, so here's a Perl version for the Mac:

curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^<title>(.*)<\/title>.*<name>(.*)<\/name>.*$/$2 - $1/'

If you want to see the name of the last person, who added a message to the conversation, change the greediness of the operators like this:

curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^<title>(.*)<\/title>.*?<name>(.*?)<\/name>.*$/$2 - $1/'