terminal commands

This tutorial shows you how to get to terminal and move around once you are there.

Terminal allows you to navigate with text commands rather than with your GUI/mouse.  Getting around in Terminal is a little like walking around an airport terminal, or a maze.  You need to remember your path to get to the proper destination.

Instructions / Example
1. Open up Terminal but keep this window open and in sight (look for Terminal in Applications/Utilities. Double click to open).
2. Download this folder to your desktop.  (It is called lollipops.)
3. When you open Terminal you are at the root of your user/usr folder.  So get to the lollipops folder from terminal you need to change the directory you are in.
4. cd is the command to change directories.
5. At the terminal prompt type cd desktop
6. Now type cd lollipops
5. What delicious things are in this folder? Type ls (lower case LS) to list its contents.
6. You see a folder inside lollipops called suckers that you want to get to.
7. Type cd suckers.
8.  And what is in here? ls suckers
9. A folder called tootsie_pop!  Let’s go there: cd tootsie_pop
9.  And what is in here? ls tootsie_pop
10. Candy?  Yes please.  But how can I be sure? Type cat candy.txt
11. You’re welcome.
12.  Note that if you knew where the candy was from the beginning you could have gone there directly by typing out the full path: cd desktop/lollipops/suckers/tootsie_pop
13.  Additionally, if you knew that you wanted to display that file with the cat command you could write out the whole shebang without changing directories at all:
cat desktop/lollipops/suckers/tootsie_pop/candy.txt
8. But note the difference between these three different path structures. The first way, following the instructions 1-10, takes you down one directory at a time, step by step.  The second (#12) names the whole path you would take from the start–and takes you there! The third (#13), however, doesn’t take you anywhere. You’re still in your home directory at the end, but the command cat follows the path.  The wizard-in-a-maze metaphor helps here.  If you are a wizard in a maze you cannot enter a new room unless you are at an entrance for it.  Similarly, you cannot get to a file without following the proper path to it.  Importantly, however, as a wizard you can send your spells to any location you want, as long as you know the correct path.

Another metaphor: public transport.  If you are familiar with your route, you can follow it pretty much without thinking, even if you have a lot of transfers and twists and turns.  If you are not familiar with your route, you might want to stop and take stock from time to time.

Useful commands include the following:

  • pwd prints the working directory
  • cd sub-directory-name changes the directory to a sub-directory you specify (note that the sub-directory must be within the current directory)
  • ls (lower case L and S) lists the contents of the directory
  • cat displays the contents of a file (better for short files)
  • cd .. takes you up one level, to the parent directory
  • just plain cd will take you back to your home directory (this is good if you get lost).
Share on FacebookTweet about this on TwitterPin on PinterestShare on Google+

Leave a Reply