Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share
5  
There is a similar thread on Server Fault as well: serverfault.com/questions/7346/… –  Chealion Oct 7 '09 at 23:07
5  
You can use open for everything: URLs, images, documents. I use it everyday. –  olt Jul 6 '10 at 14:48
5  
As an extension to that: open -a Mail filetosend.ext Creates a new Email with the file attached. –  Skade Jul 6 '10 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". –  khedron Jul 12 '10 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 Jul 26 '10 at 4:40
show 9 more comments

migrated from superuser.com Dec 26 '10 at 8:40

This question came from our site for computer enthusiasts and power users.

locked by stuffe Mar 25 at 22:21

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

133 Answers

Local Web Server with Ruby

Here is the Ruby alternative to the Python one-liner for a local HTTP server (that is also posted in this thread):

ruby -run -e httpd . -p 8000

This will open a server in the working directory with a port number of 8000 so that you can access it in the browser at http://localhost:8000.

Change the 8000 to any port number that you would like to use.

share
add comment

Many answers have been given about how you can drag files and folders into the terminal window but Ciarán Walsh has made a utility called drag that allows you to drag files OUT of the terminal window. It’s even better with my patch that allows multiple files per drag operation.

share
add comment

I could not believe that the following is missing here. The best improvement of a OS X terminal is to make it feel UNIX/Linux like. My first intention was to show you a proper bash-completion completing several things like ssh or git correctly. I'm talking of standard behaviour I was used to from Linux.

But much more important is the missing package manger homebrew. With this you will get plenty of standard unix commands/apps/libraries.

First install homebrew via

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

and then get the sophisticated bash-completion via

brew install bash-completion

Dont ignore the message. You will have to edit .bash_profile. But its worth it. bash-completion completes brew too.

share
add comment

Ctrl+D is a shortcut for exit. Useful if you often work in nested ssh sessions.

share
add comment

It's been mentioned already that dragging a folder into a terminal app will get the path typed directly in it. You can additionally drop a folder onto the terminal app icon and a new terminal will be opened in that path directly

share
add comment

While a top already mentions option (alt)-click to move to a position in the line, in reality this works anywhere in the terminal. I use it most prominently in text editors.

Anywhere you can get by arrow-ing alt-click will get the cursor there as well.

This is the main reason I stopped using tabs in code in the early 90s, NCSA Telnet included this functionality back then for mac's System 7 and if tried to arrow its way through tabs, so it ended up going all over the place and beeping like crazy.

share
add comment

I use a lot this command

echo | pwd | pbcopy

It's simply copy current path to clipboard. I've also binded it with path alias

alias path='echo | pwd | pbcopy'
share
add comment

Add aliases for phrases that you commonly mistype

alias sdou='sudo'
alias suod='sudo'
alias sodu='sudo'
alias gerp='grep' 
share
add comment

Useless, but fun. Go and download the ASCII players from Google Docs. Install them in /usr/bin. Now you can have a movie player in Terminal. There is ASCIIbw and ASCIIcolor. I don't think I need to explain that one is color and one is black and white. To open a movie file type: ASCIIbw ~/Desktop/Test.mov

share
show 4 more comments

When I'm in terminal I expect every action to be given in written form, because there is no GUI.

Many of the terminal based apps have some kind of quit command to bring you back to shell. This is what I'm used to when in terminal.

To leave a terminal window or tab I aliased following command:

alias q="osascript -e 'tell application \"System Events\" to tell process \"Terminal\" to keystroke \"w\" using command down'"

EDIT:

better even is to do as Jason commented:

configure Terminal.app to close the window if the shell exited cleanly

alias q="logout"
share
show 3 more comments
alias ka="killall"

Probably one of my most used commands. I put this in my .bash_profile for easy access.

share
add comment

If you have XCode installed, running the command purge at the terminal is really helpful. It frees up all of your active and inactive RAM. It's useful for people like me who do a lot of audio production (or any kind of media editing for that matter) when you only have 4 GB RAM. You would be surprised how fast 4 GB gets used up.

share
add comment
alias alias_open="mate ~/.oh-my-zsh/lib/aliases.zsh"
alias alias_reload="source ~/.oh-my-zsh/lib/aliases.zsh"
alias lsa='ls -lahG'
alias l='ls -la'
alias ll='ls -l'
alias sl=ls # often screw this up
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'

#######
# GIT #
#######
alias gd="git diff"
alias gl="git log"
alias gu="git up"
alias gs="git status"
alias gf="git fetch"
alias gr="git remote -v"
alias gp="git push"
alias gph="git push heroku master"
alias gps="git push staging staging:master"
alias gpg="git push github master"
alias gpo="git push origin master"
alias gplh="git pull heroku master"
alias gpls="git pull staging staging:master"
alias gplg="git pull github master"
alias gplo="git pull origin master"
alias gpl="git pull"
alias gc="git commit -am"
alias gco="git checkout"
alias ga="git add ."

##########
# SYSTEM #
##########
alias cwd='pwd | pbcopy' #copy the working directory into the clipboard
alias grep="grep --color=auto"

####################################################
# Create box of '#' characters around given string #
####################################################

function box() { t="$1xxxx";c=${2:-#}; echo ${t//?/$c}; echo "$c $1 $c";echo ${t//?/$c}; }

########################
# Rip audio from video #
########################

# ("$1" for output file & "$2" for input file)
function audioextract()
{
mplayer -ao pcm -vo null -vc dummy -dumpaudio -dumpfile "$1" "$2"
}
# extract audio from DVD VOB files
# USAGE:  audioextractdvd input_file.vob output_file.ac3
function audioextract_dvd()
{
mplayer "$1" -aid 128 -dumpaudio -dumpfile "$2"
}

#######################
# Backup .bash* files #
#######################

function backup_bashfiles()
{
  ARCHIVE="$HOME/bash_dotfiles_$(date +%Y%m%d_%H%M%S).tar.gz";
  cd ~
  tar -czvf $ARCHIVE .bash_profile .bashrc .bash_functions .bash_aliases .bash_prompt
  echo "All backed up in $ARCHIVE";
}
share
show 1 more comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.