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 Os X from sorted by
Terminal - Commands tagged Os X - 34 results
mount_smbfs '//user:p%40ss@server/share' /Volumes/share
2014-07-27 00:52:19
User: bupsy
0

If the password for the share your trying to mount contains special characters you can use URL escape characters.

The above command uses an example as follows:

username: user

password: p@ss

URL Encoded password: p%40ss

All credit goes to Richard York:

http://www.smilingsouls.net/Blog/20110526100731.html

Also check out this URL Decoder/Encoder to convert your passwords.

http://meyerweb.com/eric/tools/dencoder/

ls -1 | xargs ruby -e'puts ARGV.shuffle'
/bin/rm -f ~/Library/Application\ Support/Google/Chrome/Default/Local\ Storage/*google*
2013-06-14 19:39:12
User: poslfit
0

If you are a regular user of Google Chrome and Gmail Offline, you'll find that Gmail Offline stops working after a while due to corruption of its local storage in your browser. Worse, trying to use Google Chrome's "Clear Browsing Data" menu command to remove all the local storage is (1) overkill, because it deletes non-Google page local storage, and (2) ineffective, because once the storage is corrupt, Google Chrome doesn't know how to delete it either. Fortunately, it's all stored in obviously named files in your home directory; this command deletes the files directly, after which restarting Google Chrome will let you reinstall Gmail Offline correctly.

while i=1; do /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep CtlRSSI; sleep 0.5; done
#11671
cat /dev/urandom|od -t x1|awk 'NR > line { pos=int(rand()*15)+2;printf("%s",$pos);line=NR+(rand()*1000);digits = digits+2 } digits == 64 { print("\n");exit }'
2012-08-14 19:02:00
User: jetdillo
Functions: awk cat exit od
1

Use this the next time you need to come up with a reasonably random bitstring, like for a WPA/WPA2 PSK or something. Takes a continuous stream of bytes coming from /dev/urandom, runs it through od(1), picking a random field ($0 and $1 excluded) from a random line and then prints it.

alias path="/usr/bin/perl -e 'use Cwd; foreach my \$file (@ARGV) {print Cwd::abs_path(\$file) .\"\n\" if(-e \$file);}'"
2012-01-18 01:40:05
User: espider1
Functions: alias
1

The command creates an alias called 'path', so it's useful to add it to your .profile or .bash_profile. The path command then prints the full path of any file, directory, or list of files given. Soft links will be resolved to their true location. This is especially useful if you use scp often to copy files across systems. Now rather then using pwd to get a directory, and then doing a separate cut and paste to get a file's name, you can just type 'path file' and get the full path in one operation.

system_profiler SPApplicationsDataType | grep -A3 -B4 "Kind: PowerPC"
2011-08-17 14:53:08
User: TheQL
Functions: grep
Tags: Os X grep
0

No final count, but clean and simple output.

sort -R
2011-07-15 15:35:27
User: RyanM
Functions: sort
2

Randomizes a file. The opposite of sort is sort -R!

xset fp+ /Applications/Mathematica.app/SystemFiles/Fonts/Type1/
lsof -i -P | grep -i "listen"
2010-10-14 09:37:51
User: patko
Functions: grep
Tags: Os X
17

Particularly useful on OS X where netstat doesn't have -p option.

find -E ~/Music -type f -iname "*search terms*" -iregex '.*\.(3g[2|p]|aac|ac3|adts|aif[c|f]?|amr|and|au|caf|m4[a|r|v]|mp[1-4|a]|mpeg[0,9]?|sd2|wav)' -exec afplay "{}" \; &
2010-07-30 22:26:03
User: CamJN
Functions: find
Tags: Os X bash
1

It works best as part of a function, such as the following:

MUSICROOT=~/Music

function fplay {

if [ $1 = '-v' ]; then

shift 1

find -E $MUSICROOT -type f -iname "*$**" -iregex '.*\.(3g[2|p]|aac|ac3|adts|aif[c|f]?|amr|and|au|caf|m4[a|r|v]|mp[1-4|a]|mpeg[0,9]?|sd2|wav)' -print -exec afplay "{}" \; &

else

find -E $MUSICROOT -type f -iname "*$**" -iregex '.*\.(3g[2|p]|aac|ac3|adts|aif[c|f]?|amr|and|au|caf|m4[a|r|v]|mp[1-4|a]|mpeg[0,9]?|sd2|wav)' -exec afplay "{}" \; &

fi

}

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.

export var1=`ps -A | grep '[u]nique' | cut -d '?' -f 1`; echo${var1/ /}; kill -9 $var1
2010-03-22 21:06:58
User: headyadmin
Functions: cut export grep kill
Tags: Os X
-5

This will kill a specific process you don't know the PID of, when pidof and pgrep are not available, for example on OS X. var1 is created so that the whitespace can be trimmed before passing off to kill.

perl -wl -e '@f=<>; for $i (0 .. $#f) { $r=int rand ($i+1); @f[$i, $r]=@f[$r,$i] if ($i!=$r); } chomp @f; print join $/, @f;' try.txt
random -f <file>
cat ~/SortedFile.txt | perl -wnl -e '@f=<>; END{ foreach $i (reverse 0 .. $#f) { $r=int rand ($i+1); @f[$i, $r]=@f[$r,$i] unless ($i==$r); } chomp @f; foreach $line (@f){ print $line; }}'
2009-09-24 15:42:43
User: drewk
Functions: cat perl
0

The sort utility is well used, but sometimes you want a little chaos. This will randomize the lines of a text file.

BTW, on OS X there is no

| sort -R

option! There is also no

| shuf

These are only in the newer GNU core...

This is also faster than the alternate of:

| awk 'BEGIN { srand() } { print rand() "\t" $0 }' | sort -n | cut -f2-
`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.

system_profiler SPApplicationsDataType | perl -nl -e '@al=<>; $c=@al; while($j<$c){ $apps[$i].=$al[$j]; $i++ if ($al[$j] ) =~ /^\s\s\s\s\S.*:$/; $j++} while($k<$i){ $_=$apps[$k++]; if (/Kind: PowerPC/s) {print;}}'
2009-09-06 20:56:48
User: drewk
Functions: perl
Tags: Os X perl
0

This finds all the PowerPC apps recognized by OS X.

A better version is:

system_profiler SPApplicationsDataType 2> /dev/null | perl -

wnl -e '$i=$j=$k=$p=0; @al=; $c=@al; while($j

s[$i].=$al[$j]; $i++ if ($al[$j]) =~ /^\s\s\s\s\S.*:$/; $j++} while($k

apps[$k++]; if (/Kind: PowerPC/s) {print; $p++;}} print "$i applications, $p P

owerPC applications\n\n"'

but that is more than 255 characters...

system_profiler | mail -s "$HOSTNAME System Profiler Report" user@domain.com
2009-08-11 20:16:37
User: monkeymac
Functions: mail
4

Replace "user@domain.com" with the target e-mail address. Thanks to alediaz for "$HOSTNAME" which is very useful when running the command with Apple Remote Desktop to multiple machines simultaneously.

for y in 2009 2010 2011; do cal $y; done
sudo ipfw pipe 1 config bw 50KByte/s;sudo ipfw add 1 pipe 1 src-port 80
2009-07-02 23:17:49
User: miccaman
Functions: sudo
Tags: Os X pipe
1

sudo ipfw pipe 1 config bw 50KByte/s

Set the bandwidth (bw) limit to any number you want. For example you could have a 15kb pipe for X application and then a 100kb pipe for another application and attach things to those pipes. If a port isn’t attached to a pipe, it runs at full speed. Change the number (in this case 1) to a different number for a different pipe.

The next step is to attach your port.

sudo ipfw add 1 pipe 1 src-port 80

In this case anything on port 80 (http) will be set to a limit of 50Kbyte/s. If you want to attach a second port to this pipe, repeat the command but change the port number at the end.

src : http://www.mactricksandtips.com/2008/12/throttling-bandwidth-on-a-mac.html

echo "-------------" >> nicinfo.txt; echo "computer name x" >> nicinfo.txt; ifconfig | grep status >> nicinfo.txt; ifconfig | grep inet >> nicinfo.txt; ifconfig | grep ether >> nicinfo.txt; hostinfo | grep type >> nicinfo.txt;
sudo /Applications/Utilities/Adobe\ Utilities.localized/Adobe\ Updater5/Adobe\ Updater.app/Contents/MacOS/Adobe\ Updater
2009-06-25 08:07:47
User: miccaman
Functions: sudo
Tags: Os X
-9

adobe updater keeps popping up. (normal update fails, probably due to insufficient rights)

(src: http://aricsblog.blogspot.com/2007/12/adobe-updater-crashes-on-mac-os-x-and.html)

sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"
2009-04-04 01:41:48
User: peterc
Functions: grep sudo tcpdump
-2

Replace "en1" with your network interface (on OS X, usually en0, en1, eth0, etc..)