Mike's PBX Cookbook

Basic OS X UNIX Commands

There are lots of OS X and UNIX tutorials on the web, but here is a collection of some basic commands which you might find usefull when working in Terminal on your Mac. A bigger list of OS X commands is here.

Navigate between directories:

lslist contents of current directory
pwddisplay the working directory
cd ~go to the home directory
cd Desktopchange directory to the desktop
cd ..go back up a directory
cd /go to the ROOT (top) directory
mkdir <folder>creates a directory
rmdir <folder>removes an empty directory

You can redirect the output of a command to a text file. Type ls > mydirectorylist.txt and press Return. A text file named mydirectorylist.txt appears containing the ouput from the ls command.

Work with files:

cp <file1> <file2>copies file 'myfile1' to 'myfile2'
mv <file1> <file2>moves file 'myfile1' to 'myfile2'
rm <file1>removes (deletes) file 'myfile1'
cat <file1>concatenate and display contents of myfile1
more <file1>displays a text file one page at a time. Press the spacebar to see the next page; press Q to quit.
tail <file1>display the last part of myfile1, useful for very large files
nanoA simple UNIX text editor. Use nano to edit your hosts file

Miscellaneous Commands:

topList running processes (and memory usage) in sorted order; press Q to quit.
control-cTerminates most operations.
dateDisplays the current date and time.
man <command>Displays help / the manual page of a command.
historyDisplays the last commands you typed. You can redo a command by typing an exclamation point (!) followed immediately (no space) by the number of that command in the history list. To repeat the last command, type !!. To repeat the last filename, type !*.
sudoLets you carry out commands for which the account you are using lacks authority. You will be asked for an administrator’s password. BE CAREFUL!

When you’re working in Terminal, you don’t have a Trash Can to which deleted files are moved pending ultimate disposal. Delete it, and it’s gone. In general, UNIX has no Undo function.