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 - 51 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/

system_profiler SPHardwareDataType | awk '/UUID/ { print $3; }'
2014-07-25 06:54:40
Functions: awk
0

Gets the Hardware UUID of the current machine using system_profiler.

stat -f%Su /dev/console
pbpate | sort | pbcopy
/opt/homebrew-cask/Caskroom/vlc/2.1.0/VLC.app/Contents/MacOS/VLC --sout-avcodec-strict=-2 -I dummy $video :sout="#transcode{vcodec=h264,vb=1024,acodec=mpga,ab=256,scale=1,channels=2,audio-sync}:std{access=file,mux=mp4,dst=${video}.m4v}" vlc://quit
2014-03-08 13:53:13
User: brainstorm
0

Transcodes mpg2 files, that cannot be read by iMovie to m4v files.

sysctl -a | grep boottime | head -n 1
alias t="tee >(pbcopy)"
2014-01-24 12:41:07
User: lgarron
Functions: alias
0

Very convenient to for sending data to the clipboard for processing.

However, note that tee will affect the buffering of the output (stdout won't be update very live).

brew install ssh-copy-id; ssh-copy-id user@host
pbpaste | xargs wget
2013-08-11 23:12:10
User: loopkid
Functions: xargs
0

On Linux substitute pbpaste with `xsel --clipboard --output` or `xclip -selection clipboard -o` (untested)

google() { gg="https://www.google.com/search?q="; ff="firefox"; if [[ $1 ]]; then "$ff" -new-tab "$gg"$(echo ${1//[^a-zA-Z0-9]/+}); else echo 'Usage: google "[seach term]"'; fi }
2013-08-01 22:21:53
User: lowjax
Functions: echo
2

Usage: google "[search string]"

Example: google "something im searching for"

This will launch firefox and execute a google search in a new tab with the provided search string.

You must provide the path to your Firefox binary if using cygwin to $ff or create an alias like follows:

alias firefox='/cygdrive/c/Program Files (x86)/Mozilla Firefox/firefox.exe'

Most Linux flavors with Firefox installed will use just ff="firefox" and even OSX.

hdiutil eject -force /Volumes/CDNAME
2013-04-23 14:32:38
User: zagdul
Functions: eject
Tags: osx
0

sometimes this helps, when eject button fails

/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
2013-04-23 14:27:10
User: zagdul
Tags: bash osx
0

This keeps the user logged in but shows the login screen. Very useful when connecting remotely to an OSX-Server via VNC

find /Applications -type d -maxdepth 1 -exec sh -c 'echo "{}"; (plutil -convert xml1 -o - "{}/Contents/Info.plist" | xpath /dev/stdin "concat(\"v\", /plist/dict/string[preceding-sibling::key[1]=\"CFBundleShortVersionString\"]/node())" 2>/dev/null)' \;
2013-03-29 14:01:23
User: darkfader
Functions: find sh
Tags: osx
-1

Uses find, plutil and xpath.

Note: Some applications don't have proper information. system_profiler might be better to use.

It's a bit slow query.

Due to command length limit, I removed -name "*.app" and CFBundleName.

ls -lT -rt | grep "^-" | awk 'BEGIN {START=2002} (START <= $9){ print $10 ;START=$9 }' | tail -1
2013-02-24 23:39:22
User: Glamdring
Functions: awk grep ls tail
Tags: ls date osx
0

On the Mac, the 'ls' function can sort based on month/day/time, but seems to lack ability to filter on the Year field (#9 among the long listed fields). The sorted list continuously increases the 'START' year for the most recently accessed set of files. The final month printed will be the highest month that appeared in that START year. The command does its magic on the current directory, and suitably discards all entries that are themselves directories. If you expect files dating prior to 2002, change the START year accordingly.

while i=1; do /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep CtlRSSI; sleep 0.5; done
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

diskutil list
members () { dscl . -list /Users | while read user; do printf "$user "; dsmemberutil checkmembership -U "$user" -G "$*"; done | grep "is a member" | cut -d " " -f 1; };
2012-05-20 11:34:33
User: eduo
Functions: cut grep printf read
-1

Group membership in OS X is a mish-mash of standards that end up meaning there's almost a half-dozen of ways to belong to a group, what with group inheritance and automatic assignment. This means there's no easy command to find out all groups a user belongs to. The only sensible way then is to list all users and then query each user for membership.

NOTE: This is a function. Once input you can execute it by calling with a groupname.

ash prod<tab>
2012-05-12 19:51:02
User: c3w
-1

http://github.com/c3w/ash

. a Ruby SSH helper script

. reads a JSON config file to read host, FQDN, user, port, tunnel options

. changes OSX Terminal profiles based on host 'type'

USAGE:

put 'ash' ruby script in your PATH

modify and copy ashrc-dist to ~/.ashrc

configure OSX Terminal profiles, such as "webserver", "development", etc

run "ash myhostname" and away you go!

v.2 will re-attach to a 'screen' named in your ~/.ashrc

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

curl "http://api.twitter.com/1/statuses/user_timeline.xml?count=1&screen_name=barackobama" | egrep -w "<text>(.*)</text>" | sed -E "s/<\/?text>//g" | say
2012-02-27 18:46:33
User: beerdeaap
Functions: egrep sed
Tags: twitter osx say
0

speaks out last twitter update using 'say'

tmux show-buffer | pbcopy
txt="";for i in {1..20};do txt=$txt"$i. ";done;say $txt" Ready or not, here I come"
2011-12-11 05:51:22
User: antic
-3

Hide-and-Seek is one of the greatest games in the parent's arsenal. Your kid runs off and hides for several minutes, while waiting for you to find him/her. This gives you time to catch a breath and check your email without feeling like a loser. If you'd also like to take advantage of the counting time--claiming that thinking space as your own--use this command on your OSX terminal to maximize downtime. Also, if your kid is like mine, you can get away with "for i in {1..100};" :)

sudo chown -R nobody:admin /Applications/XAMPP/xamppfiles/htdocs/