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

Commands tagged osx from sorted by
Terminal - Commands tagged osx - 48 results
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
-2

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
0

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
0

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
2

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
-1

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
-2

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
38

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
7

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
0

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
3

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
3

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
-3

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
4

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
2

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
4

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
5

To unmount, replace "attach" with "eject"

ifconfig en1 | awk '/inet / {print $2}' | mail -s "hello world" email@email.com
2009-04-28 06:01:52
User: rez0r
Functions: awk ifconfig mail
9

This is useful if you have need to do port forwarding and your router doesn't assign static IPs, you can add it to a script in a cron job that checks if you IP as recently changed or with a trigger script.

This was tested on Mac OSX.