CSE 303, Autumn 2009
Homework 1: having a bash
Due Thursday, October 8, 2009, 11:30 PM
100 points total
No turn-in for Part I; Submit Part II via the Catalyst
dropbox -- more information forthcoming; submit Part III via a Catalyst
Quiz (you are allowed to backtrack, edit, save and resume the
quiz, and review it before submitting it)
This assign has three objectives related to basic use of Unix via the
bash shell:
- Making certain you can login to an appropriate Unix
machine.
- Demonstrating that you have a basic knowledge of some key Unix
concepts.
- Demonstrating that you can apply some basic Unix commands to
perform simple computations and operations.
For most people, working with the actual commands may help build a
better basic understanding of the concepts, so objectives 2 and 3 will
be reversed in the actual assignment below. But you can do them in
whatever order you prefer.
Part I: Using a Unix machine (6 points)
You will access to a Linux or other Unix environment
for working on your homework for this course. There are several ways to
do this:
- go to a CSE basement lab (002, 006, 022) and log in to a Linux
box there;
- remotely log in to the CSE department's
attu.cs.washington.edu
server using ssh; or
- setting up a computer of your own that runs Linux or another
Unix environment.
All our materials will address what is probably the easiest, most
general solution: using attu.
The materials will be essentially the same if you login in one of the
labs on a Linux box; if you run your own Unix system, there may or may
not be differences: we're happy to take a quick look at some problems,
but we will not be your system administrator (sysadmin) if you decide
to roll your own.
- Connect to attu.cs.washington.edu
using ssh (which stands
for secure
shell).
- If you are on a Mac or Linux box, you can connect to the attu
server by opening a Terminal window and typing the command
ssh attu.cs.washington.edu
- Otherwise, to connect to
attu
we recommend that you install
an SSH and SFTP shell / file
transfer program for connecting to Linux servers, such as
- SSH
Tectia (Windows). To download SSH Tectia, click the Tectia
link, and then on the page
that appears, click the link "Download
the software from our server. You
must acknowledge
agreement to the Export Regulations before you download." Then a "Software Export
Regulations" page appears and you have to click "I Agree" to continue. You'll be given the
link to download and install the program.
- Macs generally have a Terminal application installed that
includes the
ssh
, sftp
, and scp
commands, so you probably don't have to install, but if you do you can
try Secure
Fetch or Fugu.
- If you have trouble finding or using ssh, please ask for help -- for
this, you can ask anybody who knows how to find it and run it
(including
the 303 staff, of course).
- Change your shell to bash, and (optionally) change your password.
- The first time you
connect, you must change your shell to bash by running the chsh command. When chsh asks you what shell you
want to use, type /bin/bash.
Then logout and then reconnect to attu;
it will remember your preference for bash from then on. If
when you enter chsh,
you see an error like chsh: command not
found -- then there is a problem with your "path" (that is,
where Unix looks for programs to execute). If this happens, for
this, you can ask anybody who knows how to find chsh and run it (including
the 303 staff, of course).
- Use passwd to
change your password -- this isn't necessary if you've changed it
recently.
There is no turn-in for Part I: but you can't do parts II and III
without having done it.
Part II: Using basic Unix commands (44
points)
For each numbered item below, write a single bash shell
statement that will perform the operation(s) requested. For full
credit, each of your solutions:
- Must be a single one-line shell statement and may if needed
redirect input/output or combine commands using <, >, and |.
- Must not include the ;
operator (which executes two separate statements on one
line) or the && or
|| operators (which
join two commands together with a boolean and/or condition).
- Must be able to work properly either on attu or on the basement lab
computers. (If you work on other system, you are responsible for
ensuring that they transfer properly.)
- Each command must run from your the shell's working
directory; in other words, don't use cd as part your
solutions. (Start in your home directory.)
- List all files in the /var/lib
directory, in the standard format (no
special parameters required).
- List all files in /usr/share/dict,
using the long format (-l flag).
- Find all lines in /usr/share/dict/linux.words
(on attu -- equivalent
if elsewhere) that have a double 'z' ("zz") in them (these must both be
lower-case 'z').
- Find these same lines again and (as part of the same one-line
shell statement) place them in the file zz.txt.
- Find all lines in the same file that have a double 'z' where
either 'z' can be lower- or upper-case (that is, all four combinations
"zz", "zZ", "Zz" and "ZZ" match) and place them in the file zz1.txt.
- Using zz.txt and zz1.txt, determine what
additional matches, if any, are found when case is ignored.
- Count the number of lines in zz1.txt (do not count the
number of characters or words, just lines).
- Create a subdirectory names assign1-scratch.
- In this subdirectory create a file ww.txt that contains all the
lines in /usr/share/dict/linux.words
that have a double 'w' (lower-case only).
- In this subdirectory, create a file wwzz.txt that contains all of ww.txt followed by all of zz1.txt.
- Display in alphabetical order all lines in wwzz.txt that contain a double
'o' (lower-case only).
In terms of grading, the points will come primarily from the
correctness
of your answers: Does the command you gave perform the action
specified? A point may be deducted from each item answered with
an unnecessarily clunky or an unnecessarily slick solution -- we are
looking for basic, solid solutions that are reasonable given a
rudimentary understanding of a small set of Unix commands.
Note: The answers to all questions in this assignment can be phrased
entirely using the commands ls,
grep, cat, sort, and mkdir. You may use other
commands if you like, but you
should constrain yourself to those from lecture or from the Linux
Pocket Guide textbook. Ask the staff if you are
unsure whether a particular command is allowed.
Part III: Unix concepts -- and a few
details to get you there (50 points)
Available now.