Command Line Interface
Scavenger Hunt

In this scavenger hunt, you will use the man, ls, pwd, cp, open and mv commands to hunt for images of baby animals. When you locate images of  baby animals, you will move them into a folder named "cubs-and-pups"

To begin, download the cli-scavenger-hunt folder and drag and drop it to your Desktop.

 
 
Screen Shot 2017-09-21 at 11.29.20 AM.png

1. To learn more about the ls command, which lists directory contents, check out the program’s manual:

$ man ls


2. Navigate through the ls manual page:

  1. Use the up / down arrow keys to move through the menu.

  2. Use the spacebar to "page down" in the menu, and the b key to "page up".


Screen Shot 2017-09-21 at 11.39.34 AM.jpg

3. Use the / key to find words in the manual page:

  1. Press / to find words in the manual page. Do a test by locating the word "color", which should lead you to the -G option.
    /color

  2. Use the up / down arrow keys to view results

  3. To exit the manual page, press the Q key.


4. Check your location, then move to the cli-scavenger-hunt folder:

$ pwd

then...
$ cd ~/Desktop/cli-scavenger-hunt


5. Create a list of files in your current directory:

$ ls

To display results horizontally (one entry per line):
$ ls -1


6. Use the -G option to identify different types of digital objects (folders, files, etc.):

$ ls -G

To display results horizontally (one entry per line):
$ ls -1G


7. Create a new folder entitled, "cubs-and-pups" in the cli-scavenger-hunt directory:

$ mkdir cubs-and-pups

When you find images of baby animals later in the exercise, you will move them into this folder.


8. Use the "clear" command to clear your Terminal window:

$ clear


9. Move into the bears directory. Create a list of *all* the files in the black-bears folder using the -R "recursive" option:

$ cd bears/
$ ls -1R

To display results in color:
$ ls -1RG


10. move into the "black-bears" folder: 


$ cd black-bears/


11. Use the "open" command to open the first image in the Preview application:

$ open black-bear1.jpg


12. Use the wildcard option with the "open" command to open all of the images in the current directory in the Preview application:

$ open black-bear*


13. Search through images of black bears and grizzly bears. When you find an image containing bear cubs, move it into the "cubs-and-pups" folder in the "cli-scavenger-hunt" directory.


The move or mv command moves a source file or location to a destination location, for example:

$ mv [SOURCE] [DESTINATION]

For this exercise, type "mv" and then drag and drop your source directory into the Terminal, hit the spacebar once, then drop in the destination directory. This will look something like:

$ mv [insert file path here] ~/Desktop/cli-scavenger-hunt/cubs-and-pups


14. Repeat these actions with each animal: bears, cougars, foxes and hedgehogs. For example: 

$ cd ~/Desktop/cli-scavenger-hunt/cougars/eastern-cougar
$ open eastern*
$ mv [insert file name here] ~/Desktop/cli-scavenger-hunt/cubs-and-pups

 

When you are finished, there should be four files in the the cub-and-pups folder!



EXTRA CREDIT

Search all folders for the invisible file!

Move between directories and search for a hidden "invisible" animal image. Files that are preceded by a "." character can't be seen in the Finder, but show up in the command line. For example, in the results below, the .bobcat4.jpg file is visible in the command line, but not the Finder:

.bobcat4.jpg
bobcat1.jpg
bobcat2.jpg
bobcat3.jpg

To view hidden files, use the ls command with the show attributes option:

$ ls -a

To view results vertically (one linen per entry):

$ ls -1a