Mike’s Ultimate Unix Command Line Scavenger Hunt

How to Get Started

You’ll need to startup your virtual linux machine.  Go to Start Menu > All Programs > Oracle VM VirtualBox > Virtualbox.  Select the command line virtual machine off the list and hit start.

Eventually you’ll find yourself at a login screen.  Your username is “ubuntu” and your password is “reverse”.  Go ahead and login.  Then open a command line (it’s in accessories).  Maximize that sucker...you’ll be needing it.

Also start firefox (you can do that either on linux side or windows.  You’ll want to google some of this stuff I assure you.  You’re ready.

What You Need to Know

Things you need to know before you begin:

  1.  “man” (short for manual) is one way to get documentation.  So if you want to figure out what rm –rf does, type “man rm” and look through the options till you figure out what r and f mean.  There are a few shell commands that man won’t work for…in those causes you might try “help <commandname>”
  2. Occasionally, one of my commands might require a particular program be installed on your Linux installation.  Exactly how to install program packages varies between linux distros but on debian and ubuntu you say “sudo apt-get install <package-name>”.
  3. I’m gonna go forward assuming the shell you’re using is something similar to bash or zsh.  Sorry all you crazy ksh users!  Build your own Unix Command Line Scavenger hunt!

The Scavenger Hunt

Ok, here’s a set of challenges that everyone who’s serious about the UNIX command line should know.  I’ve ranked them approximately in order of unix l33tosity, beginning with the “just getting by” and ending with some tricks bridge the gap between command line hackery and outright unix programming.

  1. Change directory
  2. View the contents of a directory
  3. Delete a file
  4. Make a directory
  5. Rename a file
  6. Change to your home directory
  7. Copy a file to your current directory
  8. What does pressing control-c when a program is running after being invoked from the command line do?
  9. View all the files in the current directory that have a .html extension
  10. What does “rm –rf” do?  (I’d check what this one does before playing with it)
  11. What does “popd <directory>” do?
  12. Find if there is a file named “mikefile.txt” in this directory or an of its subdirectories
  13. What does “chmod a+x <filename>” do?
  14. What does pressing [TAB] while editing a command do?
  15. What does “grep Mike <filename>” do?
  16. Make the three nested directories “dir1/dir2/dir3” with a single command
  17. What does “ls -latr” do?
  18. Copy a directory and all its subdirectories
  19. What does pressing control-a and control-e do when editing a command do?
  20. What does pressing control-z when a program is running after being invoked from the command line do?
  21. What do the commands “fg” and “bg” do?
  22. Use screen to have two command lines running at once.
  23. Change the look of your command line prompt
  24. What does “ps wwwwaux | grep firefox” do?
  25. Use a for loop in the command line
  26. What does pressing control-r when editing a command do?
  27. Grep for all phone numbers in a file using regular expressions
  28. What does “sudo !!” do?
  29. What does “^foo^bar” do?
  30. Use the “perl –e” to do something interesting

Extra Fun

  1. What does typing history do?
  2. What does pressing up and down when editing the command line do?
  3. What does typing !5 do?
  4. What does “ls > <filename>“ do?
  5. Write a unix command to sort the lines of a file.

Some examples to talk through:

scripts

find . -name ‘*.o’ | xargs rm

wget -r -l 1 http://www.google.com

sort | uniq -c

convert image.jpg -crop 1404x980+664+100! -rotate 90 -scale 20%x20% out-image.jpg