This is a brief reference of commands in the Terminal application, which can be found on a Mac in Launchpad. A more thorough guide to Terminal commands (based on UNIX, which underlies the Mac operating system) is available at unbuntu.com.
The following commands can be typed into the Terminal window with the following results:
Command | Result | Words the Command Abbreviates |
---|---|---|
pwd | prints the path from the root (e.g., /Users/name) | print working directory |
cd | by itself, cd takes you to the default working directory | change directory |
cd / | takes you to the root directory | |
cd .. | takes you up one directory level | |
cd ../.. | takes you up two directory levels | |
cd directory_name | moves you into the named directory (inside the working directory | |
ls | lists subdirectories in the current working directory | list [directories] |
ls -lha | lists hidden items in the current working directory | list hidden (items) |
Here is what a Terminal window looks like when several of the simple commands above are used:
The following commands can be typed into the Terminal window with the following results:
Command | Result |
---|---|
ctrl + p | copies the previous command |
ctrl + r | allows you to copy part< of the previous command |
You can also just scroll through previous commands by using the up and down arrow keys on your keyboard.
The following command opens files in Terminal for editing:
Command | Result |
---|---|
nano ~/.file_name | Opens the file (e.g., "nano ~/.zshrc" opens the Terminal configuration file.) |
Other editing commands are shown at the bottom of the nano editing window.
The following commands can be typed into the Terminal window with the following results:
Command | Result |
---|---|
mkdir new_directory_name | Creates a new directory. |
cp -R ~/directory_path/file_or_directory_name /new path/file_or_directory_name | Copies a directory or file to the specified location. The "-R" option causes the contents of a folder to get copied. There's no need to use that option when copying a file. |