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:
ls | list contents of current directory |
pwd | display the working directory |
cd ~ | go to the home directory |
cd Desktop | change 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 |
nano | A simple UNIX text editor. Use nano to edit your hosts file |
Miscellaneous Commands:
top | List running processes (and memory usage) in sorted order; press Q to quit. |
control-c | Terminates most operations. |
date | Displays the current date and time. |
man <command> | Displays help / the manual page of a command. |
history | Displays 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 !*. |
sudo | Lets 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.