404
votes

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.

14
  • 5
    There is a similar thread on Server Fault as well: serverfault.com/questions/7346/…
    – Chealion
    Oct 7, 2009 at 23:07
  • 5
    You can use open for everything: URLs, images, documents. I use it everyday.
    – olt
    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
    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.
    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
    Jul 26, 2010 at 4:40

133 Answers 133

1 2 3 4
5
0
votes

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.

0
votes

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.

0
votes

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.

0
votes

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

0
votes

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

0
votes

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.

0
votes

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'
0
votes

Add aliases for phrases that you commonly mistype

alias sdou='sudo'
alias suod='sudo'
alias sodu='sudo'
alias gerp='grep' 
-1
votes

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

4
  • Wow. Thank you Google for doing what aalib and libcaca never could. Making a sensible interface to just do what I want. Sep 23, 2011 at 17:56
  • Or whoever made them. Perhaps not Google. Sep 23, 2011 at 18:16
  • @VxJasonxV I don't remember who made them. I uploaded them to my Google Docs so I have a copy of them somewhere.
    – daviesgeek
    Sep 23, 2011 at 18:24
  • Oh, that's your upload. Cool. The color one is broken BTW, it is built for PowerPC, no Intel. Sep 23, 2011 at 18:34
-1
votes

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"
3
  • Configure your terminal to close shell when existed cleanly, and then: alias q="logout". Nov 2, 2011 at 20:06
  • There’s no need to simulate a Command-W key press. Just tell Terminal to close the tab or window, e.g.: tell application "Terminal" to close the front window
    – Chris Page
    Nov 3, 2011 at 5:04
  • Hey yeah, Jason, thats better indeed. Had no idea about that terminal preference. @Chris: Im not that good at applescript so forgive me for my ignorance.
    – romeovs
    Nov 3, 2011 at 9:37
-1
votes
alias ka="killall"

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

-1
votes

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.

-3
votes
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";
}
1
  • I think the reason why you got downvotes on this was because you didn't explain what each of the aliases does.
    – daviesgeek
    Oct 21, 2011 at 5:34
1 2 3 4
5

You must log in to answer this question.

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