HW01: Linux Command Line due Mon 23 Jan 12:00

We will be using a command-line interface (CLI) the entire seme...
...ese assignment is to help you become proficient in
those skills.

Linux Tutorial

Visit https://ryanstutorials.net/linuxtutorial/ and work through these sections: Basic Navigation, More About Files, Manual Pages, File Manipulation, Wildcards, Permissions, Filters, Grep and Regular Expressions, Piping and Redirection, Process Management, and Cheat Sheet. Be sure to do the Activities section in each tutorial.

Exercises on Command-Line

You'll need to jot down some things in a text editor as you go. In the instructions that follow there will be several times the instructions say “(Save)” which is your cue to record what you learned in a text file (named stats.txt) along with a description. It will be helpful to have two windows opened: one for editing stats.txt and one for issuing commands. Some of the commands may be new to you. Feel free to use the man command to get a quick description if you are not sure how to proceed.

Using the command-line complete these tasks:

  1. In your workspace create a directory called data.
  2. Download this file to your computer and move it into your newly-created data directory: https://josephus.hsutx.edu/classes/sa/source/data.tgz
  3. Extract the files. The remaining steps will be performed in this data directory containing the extracted files.
  4. Delete the gotthought directory and everything in it.
  5. Make a copy of alice.txt called greenalice.txt.
  6. Use a text editor to open greenalice.txt and find the line number of the first mention of “Cheshire”. (Save the line number to your text file)
  7. In the same file replace all occurrences of “Cheshire” with “Green”. Save and exit the file.
  8. Use the diff command to compare alice.txt with greenalice.txt. How many lines differ between the two files? (Save)
  9. Take moment to play around with the wc command (which counts lines, words, and characters in a file).
  10. Use ls, wc and the pipe to count how many .txt files are in the current directory. (Save)
  11. Use find, wc and the pipe to count how many .txt files are in the current directory and all of its subdirectories. (Save)
  12. Create a subdirectory called fun and copy zip1999.zip into it and then make it your working directory.
  13. Use unzip to unzip zip1999.zip. Take note of the size of zip1999.zip and of the files that were extracted from it (zipnov99.DBF and zipcodes.doc). (Save sizes) Then use a calculator to determine the space savings as a percentage.
  14. Remove all the files from the fun directory (but remain inside it). Then copy the file named p1source.tgz from the parent directory to fun. (Save)
  15. Use the tar command to extract the files from p1source.tgz inside fun. How many files were extracted from p1source.tgz? (Save)
  16. Without leaving the fun directory, copy the file pc.txt from the games directory to it.
  17. Return to the parent directory and delete fun and all the files in it.
  18. Use an editor to modify Indent.java so that it is properly indented. Instead of indenting each line one at a time look up how to indent a block of lines using your chosen text editor and indent accordingly. Save your changes.
  19. Don't delete this working directory yet ... we'll be using it in future steps.


Use the interactive lessons at https://regexone.com to learn/practice writing regular expressions. When you reach the screen with the graduation cap you can stop. Make a screen capture of the final screen and save it under the name cap.jpg. NOTE: This site has a section of additional exercises that you do not need to work through unless you just want extra practice.

Using sed

The program sed is a stream editor that will apply editing commands to whatever is fed into it. This can be done by piping output from another command to it or it can be applied to an existing file in place. Often you will want to use a regular expression to match a pattern and then insert new text after the pattern, delete the pattern, or replace the pattern. There are a number of decent sed tutorials online but not a single one that to me seemed the go-to tutorial. Take some time to play around with various sed commands and then proceed to the instructions below when you are ready to use it.

  1. Return to the data directory you created using the steps above.
  2. Use the wget utility to download this document into data: https://josephus.hsutx.edu/classes/ds/source/melville.txt. The following exercises should be applied to melville.txt in place so that the file is modified. (If you accidently destroy the file you can download a fresh copy.
  3. Use sed to remove the leading spaces on each line. Once you have a command that works save the command to stats.txt along with a description.
  4. Use sed to replace all lines that begin with a hypen, with a blank line. (Save)

What to Turn In

Use the tar command to create a hw01.tgz file that contains these files:
Contains notes you took of various values and command along with descriptions of the the meaning of those values and commands.
Contains text of Alice in Wonderland with all instances of “Cheshire” replaced with “Green”.
Contains properly indented Java program.
Is the screen capture of your completed regex tutorial.

Upload the .tgz file in Canvas. NOTE: You will need to get the hw01.tgz file on your local computer before you can upload it to Canvas. If you worked on a remote server (such as csci.hsutx.edu) you'll need to use sftp to transfer files to csci.hsutx.edu. Once you have turned in your work you can/should remove the data directory in which you've been working.