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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands tagged mac from sorted by
Terminal - Commands tagged mac - 35 results
system_profiler SPHardwareDataType | awk '/UUID/ { print $3; }'
2014-07-25 06:54:40
Functions: awk

Gets the Hardware UUID of the current machine using system_profiler.

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
openssl rand -hex 6 | sed 's/\(..\)/:\1/g; s/^.\(.\)[0-3]/\12/; s/^.\(.\)[4-7]/\16/; s/^.\(.\)[89ab]/\1a/; s/^.\(.\)[cdef]/\1e/'
2014-04-23 21:43:38
User: phil_m
Functions: sed
Tags: Network bash mac

The sed script ensures that the "random" MAC address is unicast (bit 0 of first byte == 0) and local (bit 1 of first byte == 1)

rvm --default use ruby-1.9.3
/usr/bin/java -Xmx256M -XstartOnFirstThread -Dcom.android.sdkmanager.toolsdir=android-sdk/tools -classpath android-sdk/tools/lib/sdkmanager.jar:android-sdk/tools/lib/swtmenubar.jar:android-sdk/tools/lib/x86_64/swt.jar com.android.sdkmanager.Main avd
echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
2013-09-19 03:25:14
Functions: echo

If the HISTTIMEFORMAT is set, the time stamp information associated with each history entry is written to the history file, marked with the history comment character.

sudo port selfupdate && sudo port upgrade outdated && sudo port clean --all installed && sudo port -f uninstall inactive
alias updatedb="sudo /usr/libexec/locate.updatedb"
2013-01-21 17:46:57
User: jhyland87
Functions: alias

MAC OSX doesn't come with an updatedb command by default, this will emulate the updatedb thats on a typical Linux OS.

Simply add it to your ~/.bash_profile

alias locate='if [ $((`date +%s`-`eval $(stat -s /var/db/locate.database); echo $st_mtime`)) -gt 3600 ]; then echo "locate: db is too old!">/dev/stderr; sudo /usr/libexec/locate.updatedb; fi; locate -i'
2013-01-21 17:45:50
User: jhyland87
Functions: alias echo locate stat sudo
Tags: locate osx mac

MAC OSX doesn't come with a locate command, This will do the same thing as the locate command on a typical Linux OS.

Simply add it to your ~/.bash_profile

ssh -t HOSTNAME 'tail -f LOGFILE' | while read; do growlnotify -t "TITLE" -m "$REPLY"; done
pmset -g batt | egrep "([0-9]+\%).*" -o --colour=auto | cut -f1 -d';'
2012-03-23 23:23:46
User: deshawnbw
Functions: cut egrep

adjusting the field "f1" will give you additional information such as

f1 = 98%

f2 = discharging

f3 = 2:02 remaining

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.

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

cat /sys/class/net/*/address
2011-06-03 05:52:37
User: houghi
Functions: cat
Tags: mac

No need for the ls -r and a sort is also not really needed.

cat `ls -r /sys/class/net/*/address` | sort -u
sort -u < /sys/class/net/*/address
2011-05-18 17:50:44
User: marssi
Functions: sort
Tags: sort mac

List all MAC addresses on a Linux box. sort -u is useful when having virtual interfaces.

python -c "from itertools import imap; from random import randint; print ':'.join(['%02x'%x for x in imap(lambda x:randint(0,255), range(6))])"
ruby -e 'puts (1..6).map{"%0.2X"%rand(256)}.join(":")'
2010-12-08 10:01:31
User: eightmillion

Ruby version.

Also, a perl version:

perl -e 'printf("%.2x.",rand(255))for(1..5);printf("%.2x\n",rand(255))'
macchanger -A (nic)
2010-12-07 20:22:54
User: pebkac
Tags: Network bash mac

You have to install the package macchanger but this command will create a random mac from a list of known manufacturers. If you want to make a complete random mac, use the -r option .

for i in {1..6}; do printf "%0.2X:" $[ $RANDOM % 0x100 ]; done | sed 's/:$/\n/'
2010-12-07 19:26:58
User: forcefsck
Functions: printf sed
Tags: Network bash mac

Shorter and more straightforward.

Also in perl:

perl -e 'print join(":", map { sprintf "%0.2X",rand(256) }(1..6))."\n"'
h=0123456789ABCDEF;for c in {1..12};do echo -n ${h:$(($RANDOM%16)):1};if [[ $((c%2)) = 0 && $c != 12 ]];then echo -n :;fi;done;echo
2010-12-05 01:35:03
User: dabom
Functions: echo
Tags: Network bash mac

Doubt it actually generates valid mac addresses but this version doesn't need any external commands so it runs much faster.

Much shorter as well.

for i in {0..1200}; do for i in {1..12} ; do echo -n ${hexchars:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/:\1/g' | sed 's/.\(.*\)/\1/' ; echo; done
2010-12-04 16:44:11
User: Raymii
Functions: echo sed

First set the variable $hexchars:


Change the number in the first for loop if you need less then 1200 mac addresses

echo 00:16:3e$(gethostip | awk '{ print tolower(substr($3,3)) }' |sed 's/.\{2\}/:&/g' )
2010-09-23 16:46:21
User: chwilk
Functions: awk echo sed

Useful for creating MAC addresses for virtual machines on a subnet. 00:16:3e is a standard Xen OID, change as needed.

find . -name "*noticia*" -name "*jhtm*" -name "*.tpl" -exec grep -li "id=\"col-direita\"" '{}' \; | xargs -n1 mate