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:
- “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>”
- 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>”.
- 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.
- Change directory
- View the contents of a directory
- Delete a file
- Make a directory
- Rename a file
- Change to your home directory
- Copy a file to your current directory
- What does pressing control-c when a program is running after being invoked from the command line do?
- View all the files in the current directory that have a .html extension
- What does “rm –rf” do? (I’d check what this one does before playing with it)
- What does “popd <directory>” do?
- Find if there is a file named “mikefile.txt” in this directory or an of its subdirectories
- What does “chmod a+x <filename>” do?
- What does pressing [TAB] while editing a command do?
- What does “grep Mike <filename>” do?
- Make the three nested directories “dir1/dir2/dir3” with a single command
- What does “ls -latr” do?
- Copy a directory and all its subdirectories
- What does pressing control-a and control-e do when editing a command do?
- What does pressing control-z when a program is running after being invoked from the command line do?
- What do the commands “fg” and “bg” do?
- Use screen to have two command lines running at once.
- Change the look of your command line prompt
- What does “ps wwwwaux | grep firefox” do?
- Use a for loop in the command line
- What does pressing control-r when editing a command do?
- Grep for all phone numbers in a file using regular expressions
- What does “sudo !!” do?
- What does “^foo^bar” do?
- Use the “perl –e” to do something interesting
- What does typing history do?
- What does pressing up and down when editing the command line do?
- What does typing !5 do?
- What does “ls > <filename>“ do?
- Write a unix command to sort the lines of a file.
Some examples to talk through:
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