CIT050 Index > Assignment 2

Assignment 2–Command Line Utilities

Read everything before doing anything.

Note: when these instructions have something to type in italics, substitute your own name or command for what is described. For example, if you see:

echo "your last name"

So, if your name were Grace Hopper, you’d type:

echo "Hopper"

In this assignment, we won’t always tell you exactly what to type, but we will tell you what we want as a result. For example, if the instructions say: “Display the name of the system you’re working on,” you have to figure out that the appropriate command is hostname.

Hint: to display the contents of a file, use cat, not ls or echo. Use less (or more) only if you are asked to display the contents of a file one page at a time, or need to see the file one page at a time.

You will also be filling in a form on this web page to answer some of the questions, and you will submit the form when you finish. First, please enter your login name (in the form linuxnnn):

Because there are two editions of the book, I will put the page numbers in the form 56-57/65-66, which means “pages 56-67 in the third edition and pages 65-66 in the second edition.” in the second edition." The page numbers for the new third edition will always be the ones I list first.

The Assignment

You will want to “rehearse” these steps. Do them a few times until you are sure you know what the correct commands are. Then, do them one more time as the final result to send to the instructor.

Since you may need to re-do commands several times to get everything right, you will need a way to reset everything to the way it was before you started. To do this, type the following command at the command prompt:

  1. Log in and type script at the prompt. The system will respond with

    Script started, file is typescript

    This means that the system will start “recording” all your input and output into a file named typescript.

  2. Type this command to copy a compressed file archive to your directory.

    cp ~linux199/a2files.tar.bz2 .

    Note that there is a blank and a period at the end of the command; you must type both of them or the command won’t work.

  3. Unpack the file. Hint: see pages 66-68/62-65 especially the “optional” box on page 68/65. Pay close attention to the last paragraphs of that box and adapt the commands to do this item. Read more about the tar command.

  4. Display the contents of file announce.txt (hint: page 52/48). This file contains part of Linus Torvalds’s announcement of the first version of Linux.

  5. Copy file announce.txt to file announce2.txt.

  6. Use the interactive option when copying file states to file announce2.txt; respond n when asked if you want to overwrite announce2.txt

  7. Display the contents of file announce2.txt.

  8. Display the contents of file dijkstra.txt one screen at a time.

  9. Find the location of the ssh utility.

  10. Find the location of files related to the ssh utility.

  11. List the users currently online and using the system. [edited 13 Feb 2013]

  12. Find out what kind of data file mystery contains; do not use the command you used in step 7! Type your answer here: The mystery file is a file. 665-656

  13. Find out what the differences are between files and

    How many lines appear in but NOT in

    How many lines appear in but NOT in

  14. Remove file remove_me.txt.

  15. Display the last five lines of the states file.

  16. Sort the states file; the output will display on the screen– the original file will remain untouched.

  17. Display only the last five lines of the result of sorting the states file. Hint: Pipe the output of sort to tail; see page 60/56 for pipes, page 57/53 for tail.

  18. The file stein contains a famous quote from Gertrude Stein, one word per line. Sort this file and don’t show any repeated words.

  19. Use grep to find out how many times the word “there” appears in file stein. Your answer: time(s).

  20. Display the file poem, skipping adjacent duplicate lines.

  21. Find out how big file announce.txt is by typing ls -l announce.txt; the number just before the date is the file size in bytes. Note: that is a letter ell after the dash, not a number one. It stands for “long format” listing. File size is:

  22. Compress file announce.txt using the gzip utility.
    What is the name of the resulting compressed file?

  23. Compress file announce2.txt using the bzip2 utility.

  24. Use ls -l (that’s an ell, not a digit one) on the files you created in the previous two steps. Which one is larger?

    Note: Try to list just those two files with one command. It can be done!

  25. Without changing the bzipped file from two steps ago, list its contents.

  26. Display the current date in the form Mmmm dd, yyyyy Do not put a leading zero before the day of the month. Here is an example of what output might look like:

    September 4, 2013

    Make sure you read the hint near the bottom of this page about the date command!

  27. Type exit at the command line to save the script file you started in step 1. The system will respond with:

    Script done, file is typescript
  28. Rename file typescript to a2script (hint: page 54/50).

When You Finish

that you filled in on this form to the instructor.

Email the instructor to let him know you’ve finished the assignment and he can look at your a2script file. (If you look at it yourself, you’ll see lots of hard-to-read stuff. Don’t get stressed about it.) Your email’s subject line must read as follows, or your assignment will not be graded. (Replace nnn with the number portion of your user name.)

CIT050 Assignment 2 - linuxnnn

Do not delete the files you created in this assignment; you will need them in the next assignment.

A Hint about date

If you just type date you get the whole date:

Mon Feb 12 15:31:07 PST 2013

However, you can set the format of the output with the % fields on pages 769-770/665-656 of the book. Let’s say you want the month, day, and year separated by slashes:

date '+%m/%d/%y'



Or, if you are in Europe, you want the full year, a space, the month, a space, and the day:

date '+%Y %m %d'

which produces

2013 02 12

What if you don’t want the leading zero on the "02" for the month? You use a minus sign after the %:

 date '+%Y %-m %d'


2013 2 12