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.


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:



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.




Commands tagged osx from sorted by
Terminal - Commands tagged osx - 51 results
function expand_url() { curl -sI $1 | grep Location: | cut -d " " -f 2 | tr -d "\n" | pbcopy }
2011-08-21 05:30:09
User: gt
Functions: cut grep tr

Expand a URL, aka do a head request, and get the URL. Copy this value to clipboard.

chflags -R nouchg ./
2011-08-17 08:39:16
User: matths

otherwise you get this error message:

svn: Can't move '.svn/tmp/entries' to '.svn/entries': Operation not permitted

pbpaste | ssh user@hostname pbcopy
2011-04-24 16:30:48
User: DavidLudwig
Functions: ssh
Tags: ssh osx clipboard

This uses ssh to transfer the contents of one Mac's clipboard to another's. This only works with plain text, sadly. Trying to transfer images will just clear out the remote machine's clipboard, and rich text will be converted to plain text. Using the "Remote Login" must be enabled on the remote machine (via System Preferences' Sharing panel) for this to work.

IFS=`echo -en "\n\b"`; for i in $(curl http://feeds.digg.com/digg/container/technology/popular.rss | grep '<title>' | sed -e 's#<[^>]*>##g' | tail -n10); do echo $i; echo $i | sed 's/^/Did you hear about /g' | say; sleep 30; done
2010-06-07 22:16:19
User: echosedawk
Functions: echo grep sed sleep tail
Tags: bash sed curl osx

Instead of having someone else read you the Digg headlines, Have OSX do it. Requires Curl+Sed+Say. This could probably be easily modified to use espeak for Linux.

defaults write /Library/Preferences/com.apple.loginwindow DesktopPicture "/System/Library/CoreServices/Finder.app/Contents/Resources/vortex.png"
2010-03-30 22:52:19
User: rpavlick
Functions: write
Tags: terminal osx

Change the file location in the second half of the string to the exact file location of your chosen picture.

defaults write com.apple.dashboard devmode YES
2010-03-30 22:50:27
User: rpavlick
Functions: write
Tags: osx dashboard

Enables widgets to be placed onto the desktop. Click and hold the widget and press F12 to drag it onto the desktop. Repeat the process again to drag a widget back onto the dashboard. You may need to log off or restart for it to take effect.

hdiutil convert /path/imagefile.iso -format UDRW -o /path/convertedimage.dmg
hdiutil convert /path/imagefile.dmg -format UDTO -o /path/convertedimage.iso
say WORD
2010-03-26 15:23:32
User: haivu
Tags: Os X osx

I often use this command to learn pronunciation of unfamiliar words.

function setTerm() { PROFILE=${1}; echo "tell app \"Terminal\" to set current settings of first window to settings set \"${PROFILE}\""|osascript; };
security unlock-keychain; security find-generic-password -ga "/Users/mruser/.ssh/id_dsa" 2>&1 > /dev/null
2010-02-02 21:14:57

This must be run the first time while logged into your Mac desktop, as it will graphically prompt for access permissions. Subsequent uses will not prompt, assuming you select "Always allow".

long_command; say I am all done
2010-01-27 19:03:01
User: haivu
Tags: audio osx

I often run some command that takes a while to finish. By putting the say command afterward, I get an audio notification.

Please note that this command (say) only works on Mac OS X and not Linux.

hdid somefile.dmg
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=OUTPUT.pdf -c .setpdfwrite -f INPUT.pdf
2009-12-14 21:30:22
User: deijmaster
Functions: gs

Remove security from PDF document using this very simple command on Linux and OSX. You need ghostscript for this baby to work.

`pbpaste` | pbcopy
2009-09-21 23:10:11
User: drewk
Tags: Os X bash osx pipes

The backtick operator, in general, will execute the text inside the backticks. On OS X, the pbpaste command will put the contents of the OS X clipboard to STDOUT. So if you put backticks around pbpaste, the text from the OS X clipboard is executed.

If you add the pipeline | pbcopy, the output from executing the command on the clipboard is placed back on the clipboard.

Note: make sure the clipboard is text only.

sudo dscl localhost -append /Local/Default/Groups/admin GroupMembership username
2009-09-03 04:40:10
User: kulor
Functions: sudo

adding users to groups on OS X is not a straightforward process, you need to use the new in built in Directory Service command line utility...

du -hd 1
2009-08-10 13:11:22
User: Tuirgin
Functions: du
Tags: disk usage osx

OSX's BSD version of the du command uses the -d argument instead of --max-depth.

pbpaste | tidy -xml -wrap 0 | pbcopy
pbpaste | ssh user@hostname 'cat > ~/my_new_file.txt'
2009-07-14 16:32:03
User: mikedamage
Functions: ssh
Tags: ssh osx clipboard

Redirects the contents of your clipboard through a pipe, to a remote machine via SSH.

opendiff <file1> <file2>
2009-06-16 03:22:52
User: claytron

This command will open up the two files in FileMerge on OS X. You can also compare two directories.

opendiff directory1 directory2

NOTE: FileMerge is a part of the OS X Developer Tools, available on the install disc.

sudo pmset schedule sleep "08/31/2009 00:00:00"
2009-05-14 09:31:32
User: hobzcalvin
Functions: sleep sudo

Schedule your Mac to sleep at any future time.

Also wake, poweron, shutdown, wakeorpoweron. Or repeating with

sudo pmset repeat wakeorpoweron MTWRFSU 7:00:00

Query with

pmset -g sched

Lots more at http://www.macenterprise.org/articles/powermanagementandschedulingviathecommandline

export LSCOLORS=gxfxcxdxbxegedabagacad
2009-05-04 04:07:36
User: haivu
Functions: export
Tags: bash ls osx

I use terminal with black background on the Mac. Unfortunately, the default ls color for the directory is blue, which is very hard to see. By including the line above in my ~/.bash_profile file, I changed the directory's color to cyan, which is easer to see. For more information on the syntax of the LSCOLORS shell variable:

man ls

I tested this command on Mac OS X Leopard

sudo pmset -a hibernatemode 1
sudo installer -pkg /Volumes/someapp/someapp.mpkg -target /
2009-04-28 19:43:56
User: sud0er
Functions: sudo
Tags: osx

Installing most OSX apps is just a matter of dropping it in /Applications, either GUI-wise or with cp -r. However, many packages are distributed in "mpkg" format, and those have to be installed with an installer. If you don't want to go to the trouble of firing up VNC to install an mpkg, you can use the "installer" command.

This will install an application from a .mpkg it to /Applications system-wide. To install a program for just one user, replace "-target /" with "-target username".

hdiutil attach somefile.dmg
2009-04-28 19:41:42
User: sud0er
Tags: osx

To unmount, replace "attach" with "eject"