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.
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:
- In your workspace create a directory called data.
- Download this file to your computer and move it into your newly-created data
directory: https://josephus.hsutx.edu/classes/sa/source/data.tgz
- Extract the files. The remaining steps will be performed in this data directory
containing the extracted files.
- Delete the gotthought directory and everything in it.
- Make a copy of alice.txt called greenalice.txt.
- 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)
- In the same file replace all occurrences of “Cheshire” with “Green”.
Save and exit the file.
- Use the diff command to compare alice.txt with greenalice.txt.
How many lines differ between the two files? (Save)
- Take moment to play around with the wc command (which counts lines, words,
and characters in a file).
- Use ls, wc and the pipe to count how many .txt files
are in the current directory. (Save)
- Use find, wc and the pipe to count how many .txt files
are in the current directory and all of its subdirectories. (Save)
- Create a subdirectory called fun and copy zip1999.zip into it
and then make it your working directory.
- 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.
- 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)
- Use the tar command to extract the files from p1source.tgz
inside fun. How many files were extracted from p1source.tgz?
(Save)
- Without leaving the fun directory, copy the file pc.txt
from the games directory to it.
- Return to the parent directory and delete fun and all the files in it.
- 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.
- 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.
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.
- Return to the data directory you created using the steps
above.
- 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.
- 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.
- Use sed to replace all lines that begin with a hypen, with a blank
line. (Save)
Use the tar command to create a hw01.tgz file that contains these files:
- stats.txt
- Contains notes you took of various values and command along
with descriptions of the the meaning of those values and commands.
- greenalice.txt
- Contains text of Alice in Wonderland with
all instances of “Cheshire” replaced with “Green”.
- Ident.java
- Contains properly indented Java program.
- cap.jpg
- 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.