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 mac from sorted by
Terminal - Commands tagged mac - 34 results
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
0

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
0

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
1

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
0

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
2

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
0

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
0

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
0

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
4

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
2

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
3

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
0

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
2

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
2

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
2

First set the variable $hexchars:

hexchars="0123456789ABCDEF"

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

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

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
ifconfig | awk '/HW/ {print $5}'
2009-11-05 18:00:50
User: Cont3mpo
Functions: awk ifconfig
0

Simple MAC adrress, thanks to ifconfig.