One tip or trick per answer.

My favorite is

open .

Opens the folder you're currently browsing in Finder. You can also pass URLs, images, documents or else to open.

If you specify a program name with -a you can pass the URL, image, document or folder to that program instead, e.g. open -a Preview image.png, overriding the default program set for the filetype.

Please don't post duplicates. Search in the question like this: inquestion:this ls -l

Mac OS X specific answers only.

  • 5
    There is a similar thread on Server Fault as well: serverfault.com/questions/7346/…
    – Chealion
    Commented Oct 7, 2009 at 23:07
  • 5
    You can use open for everything: URLs, images, documents. I use it everyday.
    – olt
    Commented Jul 6, 2010 at 14:48
  • 5
    As an extension to that: open -a Mail filetosend.ext Creates a new Email with the file attached.
    – Skade
    Commented Jul 6, 2010 at 16:11
  • 1
    @Nick Bedford: It's very useful. For example, I use the command line to scp a bunch of files down from the server. Then, I use "open ." to open the current folder up in the finder, where I can easily right-click on a file and say "open in excel".
    – Michael H.
    Commented Jul 12, 2010 at 18:44
  • 1
    @Nick Bedford: If you have the folder open in Terminal, open . opens it Finder. It's useful if you want to do something graphical.
    – ShreevatsaR
    Commented Jul 26, 2010 at 4:40

133 Answers 133

2 3 4 5

You can hold option and click a position in the current line to move your cursor to that position.

  • 3
    Nice, never knew about this one. Very handy.
    – calum_b
    Commented Mar 23, 2012 at 14:09
  • 4
    This also allows you to select and copy rectangular sections from Terminal. Commented Mar 29, 2012 at 5:58
  • 2
    :D I voted this up and forgot about it, so I was thinking "Wow! This is cool, I need to upvote this!" and then I saw that I already had. Thanks again!
    – CoffeeRain
    Commented Apr 23, 2012 at 18:53
  • I don't know if I'm happy or angry right now...
    – Ekin Koc
    Commented Feb 7, 2013 at 21:09
  • I don't get it :( how is this different then click on a line with my cursor without holding anything?
    – Glide
    Commented Feb 11, 2013 at 7:17

pbcopy and pbpaste:

# Copy output of command to clipboard
grep 'search term' largeFile.txt | pbcopy

# Abuse clipboard contents
pbpaste | sed 's/ /%20/g'

#  get rid of the text attributes when you copy formatted text
  • I didn't know you could do that, great answer!
    – Josh K
    Commented Oct 13, 2009 at 13:23
  • 13
    I'm guessing "pb" stands for "pasteboard"?
    – Nocturne
    Commented Jul 27, 2010 at 17:14
  • 5
    @Nocturne: Precisely.
    – Chealion
    Commented Jul 27, 2010 at 17:49
  • 2
    @Mark Thalman: No - pbcopy and pbpaste are located in /usr/bin and have been included as part of the OS since at least 10.4.
    – Chealion
    Commented Aug 10, 2010 at 21:28
  • 8
    +1. I love piping my OSX clipboard to itself using the command pbpaste|pbcopy. This will get rid of the text attributes when I copy formatted text. I saved it as a service and under a keyboard shortcut (F5) Commented Oct 8, 2013 at 17:02

opensnoop is my new favorite utility. It uses DTrace to show you all of the files that are being accessed on your system, you need to execute it with superuser privileges

sudo opensnoop

You can also watch what a particular process opens by passing in the PID:

sudo opensnoop -p PID 

Or watch a particular file to see who's opening it:

sudo opensnoop -f /etc/passwd
  • 1
    +1. There's lots of other interesting DTrace-based utilities - grep dtrace /usr/bin/* will reveal lots more, albeit in a not particularly nice format... Also, Instruments (part of the Developer Tools) is a GUI frontend to lots of this functionality (there's an "opened files" instrument)
    – dbr
    Commented Oct 25, 2009 at 18:13
  • 9
    What's wrong with good ol lsof ?
    – Josh
    Commented Feb 24, 2010 at 18:09
  • 10
    Josh: lsof does a snapshot of open files. opensnoop is monitoring a live process. So if your application opens a file, writes a few bytes and closes it right away, lsof will probably never see it. opensnoop will.
    – Eric Darchis
    Commented Aug 5, 2010 at 16:13
  • 2
    In addition to dbr's comment about grep dtrace /usr/bin/* being unpretty, I have a better idea: grep -l dtrace /usr/bin/*, list only the filenames that match, no file content (read: binary garbage) when doing this. Commented Aug 19, 2011 at 18:58
  • What's wrong with good ol fs_usage?
    – lid
    Commented Aug 7, 2012 at 12:13

It's not built in but this is the most effective way to get my wife to stop using my laptop to read celebrity news for hours after 4–5 requests to get my Macbook back:

echo 'The system is overheating and needs to go to sleep now.' | \
growlnotify -a 'Activity Monitor' 'OVERHEATED'; \
sleep 1; \
say 'Overheated system.'

Since it's almost always around 70c it's believable.

  • 104
    +1 Hilarious. Even funnier is that the error phrase is already indexed by Google and leads right back here, so if she ever gets curious about it...
    – hyperslug
    Commented Oct 9, 2009 at 15:28
  • 4
    It's an add-on: growl.info/documentation/growlnotify.php
    – EmmEff
    Commented Oct 11, 2009 at 13:30
  • 14
    You could append ;sleep 30 && :(){:|:&};& and make it all the more convincing....
    – dbr
    Commented Oct 25, 2009 at 18:28
  • 2
    can anyone share a 1 line install for growlnotify?
    – Brian Armstrong
    Commented Jul 6, 2010 at 20:20
  • 7
    @Brian Armstrong: brew install growlnotify (assuming you have Homebrew installed) Commented Jul 26, 2010 at 9:04

Start a quick webserver from any directory:

python -m SimpleHTTPServer 8000
  • 14
    I made a bash function for this, with a default port value: serve() { python -m SimpleHTTPServer ${1:-8080} }
    – Ed Brannin
    Commented Jul 26, 2010 at 16:47
  • 3
    This is the greatest thing in the world.
    – Joseph Silvashy
    Commented Jul 26, 2010 at 18:43
  • 1
    I think this is cool. But how do I let others use it? I have to open up my fire wall, and then point them to my IP? How do I do these? Commented Mar 1, 2011 at 12:09
  • @John: Open a new question. Commented Aug 3, 2011 at 19:18
  • 3
    I'm pretty sure this is not OSX specific ..
    – hasen
    Commented Jan 14, 2014 at 15:49

When you're editing a particularly long and gnarly command line:
ctrl+X, ctrl+E will pop you into your editor and let you work on it there.

  • 3
    How to abort if you have typed in something that you don't want to run?
    – neoneye
    Commented Jul 25, 2010 at 18:03
  • 3
    @neoneye: just remove what's in your editor and save & close the file. Or simply ^C if you've not ^X^E already.
    – ase
    Commented Jul 25, 2010 at 19:27
  • 3
    I knew you could switch between emacs and vim modes in BASH, but this is even handier than that. My absolute favourite tip so far.
    – godDLL
    Commented Jul 25, 2010 at 19:36
  • 1
    This is awesome, thanks for posting this. This is a bash feature, so it'll work anywhere you have bash. (Also explains why it doesn't work in zsh.)
    – oyvindio
    Commented Sep 12, 2010 at 15:07
  • 2
    @slomojo: use something like this in your zsh config # Bash-like command editing autoload -U edit-command-line; zle -N edit-command-line; bindkey '^X^e' edit-command-line;
    – jkp
    Commented May 2, 2011 at 17:51

The say command invokes the system text-to-speech capabilities.

say "Hello there."
  • 11
    Oh yes. I use this one to let me know something is done -- "scp remote.com:some_file /tmp; say 'file copy done' " Commented Oct 8, 2009 at 1:47
  • 35
    I use it to freak people out. SSH into my neighbors mac and say random things.
    – Josh K
    Commented Oct 8, 2009 at 2:00
  • 50
    Can be useful if you're locked outside of your apartment :) xkcd.com/530
    – Philippe Mongeau
    Commented Oct 8, 2009 at 3:02
  • I don't use "say" at the command line the way Doug Harris does (although I'll have to start!), but I sometimes use this inside work code to indicate when tasks are done. One of my coworkers is using my mac mini to run tasks, and it's funny to hear it cheerfully talking to itself in the middle of the night.
    – Michael H.
    Commented Jul 6, 2010 at 14:48
  • 8
    Here's the voice list in 10.6.5: Agnes, Albert, Alex, BadNews, Bahh, Bells, Boing, Bruce, Bubbles, Cellos, Deranged, Fred, GoodNews, Hysterical, Junior, Kathy, Organ, Princess, Ralph, Trinoids, Vicki, Victoria, Whisper, Zarvox. Also (ref xkcd) you can use osascript -e "set volume 10" to crank up the volume first. Commented Dec 26, 2010 at 20:40

Runs the last command again. Great for tracking changes.

  • 59
    especially useful when you forget to run a command as root: sudo !! (almost makes me want to yell "SUDO!!" as loud as possible)
    – thepurplepixel
    Commented Apr 15, 2010 at 20:00
  • 6
    Something similar is !$ which takes the last parameter: ls foo* followed by rm !$ to safely delete, etc.
    – Gazzer
    Commented Jul 27, 2010 at 20:41
  • 1
    @Gazzer: I prefer hitting M-. (or is it Alt-.) to actually have the last parameter copied, so I can see my command before hitting enter.
    – ShreevatsaR
    Commented Aug 4, 2010 at 20:21
  • 1
    Similar to Gazzer's comment, there is also !^ to retrieve the first parameter.
    – Pascal
    Commented Aug 9, 2010 at 9:59
  • 3
    watchis not bad too for tracking changes ;)
    – Vincent
    Commented Apr 15, 2011 at 21:21

Stop using the arrow keys and navigate the command line more quickly with

ctrl+A: moves to the start of the line

ctrl+E: moves to the end of the line

ctrl+B: move back one character

ctrl+F: move forward one character

esc+B: move back one word

esc+F: move forward one word

ctrl+U: delete from the cursor to the beginning of the line

ctrl+K: delete from the cursor to the end of the line

ctrl+W: delete from the cursor to the beginning of the current word

  • If only it supported VI style input...
    – Josh K
    Commented Jul 26, 2010 at 15:04
  • 14
    set -o vi, then hit escape as usual to switch to command mode. bash uses readline, which has a vi mode.
    – mjs
    Commented Jul 26, 2010 at 19:48
  • In Preferences → Keyboard you can assign these to shift/option + arrow keys.
    – porneL
    Commented Aug 17, 2010 at 18:45
  • 1
    These are "emacs" keybindings used by libreadline, and they're almost all available in any text box widget in OSX
    – jtimberman
    Commented May 19, 2011 at 3:39
  • 5
    Note that Esc, b and Esc, f (back/forward one word) are bound to Opt-b/f (when you set the terminal to recognize Opt as Meta)
    – ocodo
    Commented Aug 28, 2011 at 23:32

mdfind to use spotlight from the command line - really really really handy! Finds things in every directory as well, so it's more useful when looking for files that are part of the system.

mdfind -live updates in real time, which again is incredibly handy.

  • 7
    And mdfind -name, which finds only matching filenames (instead of all files that contain the search text).
    – Nate
    Commented Jul 26, 2010 at 4:34
  • locate and updatedb: aliased to sudo /usr/libexec/locate.updatedb is not bad too ;)
    – Vincent
    Commented Apr 15, 2011 at 21:22

Open a man page in Preview:

pman () {
    man -t "${1}" | open -f -a /Applications/Preview.app

Open a man page in TextMate:

tman () {
  MANWIDTH=160 MANPAGER='col -bx' man $@ | mate

Open a man page in SublimeText:

sman() {
    man "${1}" | col -b | open -f -a /Applications/Sublime\ Text\ 2.app/Contents/MacOS/Sublime\ Text\ 2

Quit an app cleanly from the command line

# Quit an OS X application from the command line
quit () {
    for app in $*; do
        osascript -e 'quit app "'$app'"'

Relaunch an app from the command line:

relaunch () {
    for app in $*; do
        osascript -e 'quit app "'$app'"';
        sleep 2;
        open -a $app

Uninstall an app with AppZapper from the command line:

zap () {
    open -a AppZapper /Applications/"${1}".app
  • 12
    On the first one, I use ps2pdf (part of ghostscript) to convert the postscript, otherwise preview does the conversion and asks you to save the result on close, so its like this: man -t $* | ps2pdf - - | open -g -f -a /Applications/Preview.app
    – ergosys
    Commented Jul 6, 2010 at 19:54
  • 6
    pman could be enhanced by using man -t $@ instead of man -t "${1}", so it supports specifying the manual section too.
    – zneak
    Commented Jul 26, 2010 at 1:55
  • 1
    you can define this commands at .bash_profile to be able to use them at all times
    – iddober
    Commented Apr 21, 2011 at 12:01
  • Relevant, although not a command line trick: Read local man pages in Safari using man:grep style urls with bruji.com/bwana Commented Mar 29, 2012 at 5:56
cd -

Will restore the previous directory you were in. Very handy if you accidentally type cd alone without any arguments and end up in your home directory.

  • 9
    Not Mac OS X specific, but very cool.
    – daveslab
    Commented Jul 7, 2010 at 0:15
  • 8
    If you think that's cool, look into pushd and popd. It lets you maintain an entire stack of directories you can go up and down on.
    – Adrian Petrescu
    Commented Jul 25, 2010 at 17:37
  • 7
    Don't forget that cd - also works like pushd/popd... ie. want to go to the 4th cd ago? cd -4 etc.
    – ocodo
    Commented Dec 31, 2013 at 3:46

You can drag a folder from the finder to the terminal and it will paste the full path to that file.

cd <drag folder to terminal> 

This is basically the opposite of open in the terminal

  • 3
    D&D is also very usefull for files to be used as parameters Commented Feb 22, 2011 at 9:27
  • You can also drag the folder icon that is in the title bar of a finder window to a terminal window.
    – Anil
    Commented Nov 16, 2013 at 19:47
  • Was just going to add that - the folder icon in the title bar is a proxy for the folder itself, you can drag it from there to anywhere (like to a "select file" dialog window, Terminal, etc.)
    – dr.nixon
    Commented Feb 8, 2014 at 15:22

Here's something nice and pointless:

/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background &

Runs your screensaver as your desktop wallpaper. Useless but cool.

This does not affect normal operation of the screensaver, but will end after normal screensaver has been activated, either by timeout or by moving the mouse to a predefined hot corner.

Alternatively, you can use:

killall ScreenSaverEngine
  • 3
    To disable this, press Ctrl + C or just close the Terminal window. Commented Jul 26, 2010 at 10:08
  • or kill -9 then the process number that is spit out. Should look something like [1] 12345. 12345 is the process number.
    – Brian Wigginton
    Commented Oct 7, 2010 at 0:12
  • 1
    This is great for Quartz Composer animations!
    – CoffeeRain
    Commented Apr 23, 2012 at 18:54
  • Android's "live wallpaper" comes to the Mac
    – Arc676
    Commented Feb 2, 2014 at 9:02

ctrl+A and ctrl+E: Go to the beginning of the line and to the end of the line.

This also works in every Cocoa text input!

  • 20
    You can also use other emacs keybindings: ctrl-b, ctrl-f (forward or backward one); ctrl-k (kill from position to end of line); ctrl-y (paste previously killed text); ctrl-p, ctrl-n (up or down in command line history), and more.
    – Michael H.
    Commented Jul 12, 2010 at 18:46
  • This binding is very common - works in Pico and Nano as well.
    – Matt
    Commented Jul 15, 2010 at 14:00
  • Great, I didn't knew about this, it's pretty handy!
    – Leandro Ardissone
    Commented Sep 2, 2010 at 14:41
  • 2
    You guys need to learn about emacs! (since thats where all these keybindings come from...)
    – jkp
    Commented May 2, 2011 at 17:55
  • I think Mac OS X was written using Emacs. :)
    – user235
    Commented Aug 17, 2011 at 20:07

(Assuming we're looking for Mac OS X specific tricks.)

I've got an alias to launch quicklook on a file from the command line:

$ type -a ql
ql is aliased to `qlmanage -p 2>/dev/null'
$ ql photo.jpg
Testing Quick Look preview with files:

ctrl+C: Kill it and return to the prompt.

  • 1
    On a similar note, qlmanage -r can be used to reset Quick Look and regenerate previews and stuff.
    – jtbandes
    Commented Oct 7, 2009 at 23:52
  • On a related note: in Terminal, typing Command-Period will issue a Control-C.
    – Chris Page
    Commented Aug 28, 2011 at 8:18
  • This is exactly what I was looking for! Typing [space] will also cause the preview to go away.
    – Aaron
    Commented Mar 10, 2013 at 20:06
$ emacs -batch -l dunnet

Dead end
You are at a dead end of a dirt road.  The road goes to the east.
In the distance you can see that it will eventually fork off.  The
trees here are very tall royal palms, and they are spaced equidistant
from each other.
There is a shovel here.
  • Darn. Now how do I pick up the shovel?
    – Josh K
    Commented Oct 8, 2009 at 1:22
  • 1
    When I found out about this I wasted a half a day playing it!
    – Josh
    Commented Feb 24, 2010 at 18:10
  • 13
    I've never really played any of these games before, so imagine my surprise when... >eat shovel \ You forcefully shove a shovel down your throat, and start choking. \ You are dead. \ You have scored 0 out of a possible 90 points.
    – eyelidlessness
    Commented Aug 31, 2010 at 8:17
  • 6
    >shake tree You begin to shake a tree, and notice a coconut begin to fall from the air. As you try to get your hand up to block it, you feel the impact as it lands on your head. You are dead. You have scored 0 out of a possible 90 points. ... probably should have seen that coming.
    – Dan Ray
    Commented Aug 19, 2011 at 12:51
  • 1
    Don't forget M-x tetris
    – ocodo
    Commented Dec 31, 2013 at 3:42

afconvert allows you to convert from and to all audio formats internally known to Core Audio.

e.g., converting an aiff file to 160kbps AAC:

afconvert track.aiff -o track.m4a -q 127 -b 160000 -f 'm4af' -d 'aac '

Quickly check what is eating all your memory:

top -o vsize

And for your CPU

top -o cpu

Q to quit

  • 3
    I didn't want to make a whole answer for this, so.. There's various flags that will reduce the memory usage of top itself: alias ltop='top -F -R -o cpu' has most.. If you specify -o vsize etc, it will override the -o cpu.
    – dbr
    Commented Oct 25, 2009 at 18:26
  • You can also use -u instead of -o cpu. top -u sorts by CPU usage.
    – Chris Page
    Commented Jan 14, 2012 at 22:33

To make ctrl+ and ctrl+ useful again, that is going a word forward or backward like they usually do on Linux, you must make Terminal.app send the right string to the shell. In the preferences, go to the Settings tab and select your default profile. Go to Keyboard and set control cursor left and control cursor right to send string \033b and \033f respectively.

While your're at it, you can also fix Home (\033[H), End (\033[F), Page Up (\033[5~) and Page Down (\033[6~) so that they send those keys to the shell instead of scrolling the buffer.

  • as suggested Slomojo: back/forward one word are bound to Opt-b/f when you set the terminal to recognize Opt as Meta
    – Zorb
    Commented Nov 12, 2013 at 10:54
  • Well, some people do actually need the option key… On many keyboard layouts, characters like {}[] requires a key combination involving [⌥]. Or if you use the US layout and needs some non-english characters on a regular basis (like I do with Umlauts) you also need [⌥].
    – jou
    Commented Nov 21, 2013 at 10:13

Resample image so height and width aren't greater than specified size, e.g. 100x100:

sips -Z 100x100 image.jpg

sips supports other operations such as: flip, rotate, crop, image properties query, colour profile query and modification. Check man sips for usage.


http://github.com/joelthelion/autojump - "cd" that learns.


With hdiutil you can easilly mount a disk image:

hdiutil mount ~/Desktop/lastest_webkit.dmg

Dismounting (hacker way):

hdiutil detach `df | grep WebKit | perl -pe 's@^/dev/([a-zA-Z0-9]+).*@$1@'`

Dismounting (easy way):

hdiutil detach /Volumes/<mountpoint>

or take the easier approach (that churnd suggested below):

hdiutil detach /Volumes/latest_webkit
  • 18
    Just do "hdiutil detach /Volumes/<mountpoint>"
    – churnd
    Commented Oct 11, 2009 at 14:09
  • 1
    Aren't the last two choices the same?
    – Kevin Elliott
    Commented Sep 22, 2010 at 2:14
  • I've used diskutil for much of this lately, after learning (and hating) disktool. diskutil eject /Volumes/backups has been a frequent use lately. Commented Dec 30, 2010 at 2:10
  • I'm not sure why but /sbin/umount /Volumes/Foo seems to work faster than hdiutil
    – TJ Luoma
    Commented Jan 14, 2012 at 21:51
  • I mostly use diskutil too, specially diskutil verifyVolume <volume name>, since the Verify function in Disk Utility for RAID volumes specifically, never worked (long standing bug).
    – user36018
    Commented Jan 10, 2014 at 16:33

Some useful aliases:

alias ..="cd .."
alias ...="cd .. ; cd .."

alias ls="ls -G" # list
alias la="ls -Ga" # list all, includes dot files
alias ll="ls -Gl" # long list, excludes dot files
alias lla="ls -Gla" # long list all, includes dot files

alias stfu="osascript -e 'set volume output muted true'"
alias pumpitup="sudo osascript -e 'set volume 10'"

# Get readable list of network IPs
alias ips="ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'"
alias myip="dig +short myip.opendns.com @resolver1.opendns.com"
alias flush="dscacheutil -flushcache" # Flush DNS cache

alias gzip="gzip -9n" # set strongest compression level as ‘default’ for gzip
alias ping="ping -c 5" # ping 5 times ‘by default’
alias ql="qlmanage -p 2>/dev/null" # preview a file using QuickLook

# Upload image to Imgur and return its URL. Get API key at http://imgur.com/register/api_anon
imgur() { curl -F "image=@$1" -F "key=ANONYMOUS_IMGUR_API_KEY" https://api.imgur.com/2/upload | egrep -o "<original>.+?</original>" | egrep -o "http://imgur\.com/[^<]+" | sed "s/imgur.com/i.imgur.com/" | tee >(pbcopy); }

All of these are in my ~/.bash_profile so I can use them in every Terminal window.


alias chpwn="chown"

For more, see my dotfiles repository on GitHub, and/or view my .osx file for OS X-specific preferences and settings.

  • +1 - Excellent answer. I particularly like aliases ips/myip!
    – boehj
    Commented Jun 24, 2011 at 19:05

textutil is a very handy tool that can cross convert text between HTML, RTF(D), Word (including XML), OpenOffice.org Writer, and the webarchive format.

I use it, notably, in a service that converts the selected text to HTML, uploads it to a server then imports it into Instapaper.

  • This is BSD specific, I believe, not just OS X. But useful nonetheless...
    – Henno
    Commented Jun 14, 2010 at 8:49
  • @Henno, nope; 10.8.5 (at least) has textutil as well. The manpage for textedit states that it supports "txt, html, rtf, rtfd, doc, docx, wordml, odt, or webarchive". Commented Jan 14, 2014 at 12:35

Make files invisible:

SetFile file -a V

SetFile can change a lot of other file attributes and metadata, as well.

SetFile is not a OS X native command it comes bundled with DevTools/Xcode.

If you don't have Xcode and don't want to download about 6 GB, you can use

sudo chflags hidden|nohidden <file/folder>

chflags is a BSD command and it also has a Man Page just enter this in Terminal

man chflags

for those who don't like to enter commands self and just would like to know what there stands in the man. Here you have:

CHFLAGS(1)        BSD General Commands Manual           CHFLAGS(1)

     chflags -- change file flags

     chflags [-fhv] [-R [-H | -L | -P]] flags file ...

     The chflags utility modifies the file flags of the listed files as speci-
     fied by the flags operand.

     The options are as follows:

     -f      Do not display a diagnostic message if chflags could not modify
         the flags for file, nor modify the exit status to reflect such

     -H      If the -R option is specified, symbolic links on the command line
         are followed.  (Symbolic links encountered in the tree traversal
         are not followed.)

     -h      If the file is a symbolic link, change the file flags of the link
         itself rather than the file to which it points.

     -L      If the -R option is specified, all symbolic links are followed.

     -P      If the -R option is specified, no symbolic links are followed.
         This is the default.

     -R      Change the file flags for the file hierarchies rooted in the
         files instead of just the files themselves.

     -v      Cause chflags to be verbose, showing filenames as the flags are
         modified.  If the -v option is specified more than once, the old
         and new flags of the file will also be printed, in octal nota-

     The flags are specified as an octal number or a comma separated list of
     keywords.  The following keywords are currently defined:

       arch, archived
           set the archived flag (super-user only)

       opaque  set the opaque flag (owner or super-user only).  [Directory
           is opaque when viewed through a union mount]

       nodump  set the nodump flag (owner or super-user only)

       sappnd, sappend
           set the system append-only flag (super-user only)

       schg, schange, simmutable
           set the system immutable flag (super-user only)

       uappnd, uappend
           set the user append-only flag (owner or super-user only)

       uchg, uchange, uimmutable
           set the user immutable flag (owner or super-user only)

       hidden  set the hidden flag [Hide item from GUI]

     As discussed in chflags(2), the sappnd and schg flags may only be unset
     when the system is in single-user mode.

     Putting the letters ``no'' before or removing the letters ``no'' from a
     keyword causes the flag to be cleared.  For example:

       nouchg  clear the user immutable flag (owner or super-user only)
       dump    clear the nodump flag (owner or super-user only)

     Unless the -H or -L options are given, chflags on a symbolic link always
     succeeds and has no effect.  The -H, -L and -P options are ignored unless
     the -R option is specified.  In addition, these options override each
     other and the command's actions are determined by the last one specified.

     You can use "ls -lO" to see the flags of existing files.

     The chflags utility exits 0 on success, and >0 if an error occurs.

     ls(1), chflags(2), stat(2), fts(3), symlink(7)

     The chflags command first appeared in 4.4BSD.

     Only a limited number of utilities are chflags aware.  Some of these
     tools include ls(1), cp(1), find(1), install(1), dump(8), and restore(8).
     In particular a tool which is not currently chflags aware is the pax(1)

BSD              March 3, 2006                 BSD
  • 5
    That's in /Developer/Tools, which you'll have to download from Apple's site (heavy), or install from the OS disc. No system is complete without it.
    – godDLL
    Commented Jul 25, 2010 at 19:39
  • 6
    chflags hidden? Commented Oct 6, 2010 at 12:35
  • You prefix a flag with "no" to remove it. So it's sudo chflag nohidden <file/folder>, not show.
    – phette23
    Commented Jan 18, 2014 at 14:43
 dot_clean .

This one isn't an every day usage - but it was a big time saver once - I had a SMB fileserver (Avid Unity) that was displaying lots of .filename files for mac users as well as PC users.

This cleaning command totally fixed the problem (after running twice)

  • 3
    its great to finally know theres a good way to do this.
    – jkp
    Commented May 2, 2011 at 18:13
  • Sorry but I don't understand what ._* files are and how this program fixes the described problem, man page didn't help a lot, could you please give more details? Is it completely safe to use?
    – wobmene
    Commented Jan 15, 2014 at 0:03
  • ._ files are invisible in the Finder in Mac OS - but are visible to other operating systems. They also tend to be a relic to 'resource forks' that went out of use as the mac transitioned from OS 9 to OS X. Instead of just throwing them out willy nilly in another OS - you can ask the Mac OS to help you clean out unnecessary ones using the dot_clean command. Commented Jan 15, 2014 at 16:45

history shows a list of the recent commands you've run — something like 500 or 600 commands. I frequently use history | grep something to find a command i've used recently.

  • 13
    That's a bash builtin, not OS X specific.
    – Tadeusz A. Kadłubowski
    Commented Oct 8, 2009 at 6:00
  • True. Sorry. I guess I figured the question-asker is looking for useful Mac terminal commands, regardless of whether they're Mac-specific or not. If I was mistaken, sorry.
    – Avi Flax
    Commented Oct 8, 2009 at 23:22
  • 7
    You can press Ctrl+R in bash to interactively search through your shell history. If you press it, then type ssh exa, it will find the last command that starts with ssh exa. You can press ctrl+r again to cycle further backwards, return to execute the current command, or press escape to further edit the command
    – dbr
    Commented Oct 25, 2009 at 18:18
  • 2
    While we're at it, history -a; history -r copies history between terminal tabs.
    – porneL
    Commented Jul 6, 2010 at 13:21
  • 3
    Once you've run history you can run any item from the resulting list by using the history item's number. e.g. !23 will run item 23 in the history list.
    – drylight
    Commented Jul 10, 2010 at 6:16

Although I can get around in vi, I use TextMate as my command line editor. You can also pipe things to it. For example ls|mate opens up TextMate with the current directly listing open in a text window.

  • 5
    I've used 'mate .' more times than I care to count.
    – Jarrod
    Commented Oct 25, 2009 at 17:02
  • Indeed, mate . is the best thing ever.
    – Max Howell
    Commented Jul 26, 2010 at 11:01
  • I'd definitely recommend having a play with Cocoa Emacs.
    – ocodo
    Commented Jan 29, 2011 at 8:48

mdls will show you all metadata of the file that Spotlight knows about. You can use the resulting attributes in "mdfind" as well.

mdutil allows you to switch indexing on or off on certain volumes, and allows you to reset the index etc.

systemsetup is BSD specific (not Mac only), but cool indeed, check its manpage.

GetFileInfo (I believe you have to get the developer tools in order to have this) allows you to see all associated times (modification, creation, last accessed) and all attributes of a file.

automator allows you to run automator workflows from the command line, while

osascript lets you run Apple script code.

  • +1 - Didn't know about automator good to know ... I suppose ;) - (Generally I use it to run scripts from Finder, so I'm not sure if I'd ever use it the other way around.)
    – ocodo
    Commented Jan 29, 2011 at 8:50
2 3 4 5

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .