Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Unix Command Line Lab for Computer Science Course - Prof. Derek Harter, Lab Reports of Computer Systems Networking and Telecommunications

Instructions and exercises for a lab in a computer science course focused on using the unix command line. The lab is divided into two parts, one to be completed in class and the other outside of class. The exercises cover various topics such as creating directories, editing files, using commands and flags, and redirection. Some exercises are more advanced and only required for graduate students.

Typology: Lab Reports

Pre 2010

Uploaded on 08/18/2009

koofers-user-q62
koofers-user-q62 🇺🇸

5

(1)

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Spring 2008 CSci 553 Lab 1
Lab 01: Part 1, In Class
Using the Unix Command Line
Instructions
Exercises 1.1 – 1.8 are to be completed in class before you leave. You need to create a
directory in your home directory named “lab01” (you must use the exact same name,
and remember that Unix is case sensitive, so “Lab01” is not the same name). Inside of
the directory “lab01” you will create and edit a file called “lab01-part1.txt”. You
should edit the file and type in your answers to the questions 1.1 – 1.8 before the end of
class, and ask the instructor to confirm you are done with this part before leaving.
Use this lab time not only to find the answers to the questions, but to practice your
skills in using the command line and editor to create directories, files and run
commands. The first portion of the lab is to be completed in class so that you may ask
the instructor for help and suggestions for any problems you may be experiencing
learning the bash shell and command line commands. You may use any of the
resources we have discussed to find the answers to the exercises, as well as the
textbook and online source materials. It is of course suggested that you try out and test
your answer where possible to verify it correctly answers the question.
Exercise 1.1
The instructor wants you to use a hitherto unknown command for
manipulating files. How would you get help on this command?
Exercise 1.2
Suppose ls shows you this:
Makefile biography.txt data enrolment.txt programs thesis
What argument(s) will make it print the names in reverse, like this:
thesis programs enrolment.txt data biography.txt Makefile
Exercise 1.3
What does the command cd ~ do? What about cd ~hpotter?
Exercise 1.4
What command will show you the first 10 lines of a file? The first 25? The
last 12?
Exercise 1.5
diff finds and displays the differences between two text files. For example,
if you modify earth.txt to create a new file earth2.txt that contains:
pf3
pf4

Partial preview of the text

Download Unix Command Line Lab for Computer Science Course - Prof. Derek Harter and more Lab Reports Computer Systems Networking and Telecommunications in PDF only on Docsity!

Lab 01: Part 1, In Class

Using the Unix Command Line

Instructions Exercises 1.1 – 1.8 are to be completed in class before you leave. You need to create a directory in your home directory named “lab01” (you must use the exact same name, and remember that Unix is case sensitive, so “Lab01” is not the same name). Inside of the directory “lab01” you will create and edit a file called “lab01-part1.txt”. You should edit the file and type in your answers to the questions 1.1 – 1.8 before the end of class, and ask the instructor to confirm you are done with this part before leaving. Use this lab time not only to find the answers to the questions, but to practice your skills in using the command line and editor to create directories, files and run commands. The first portion of the lab is to be completed in class so that you may ask the instructor for help and suggestions for any problems you may be experiencing learning the bash shell and command line commands. You may use any of the resources we have discussed to find the answers to the exercises, as well as the textbook and online source materials. It is of course suggested that you try out and test your answer where possible to verify it correctly answers the question. Exercise 1.  The instructor wants you to use a hitherto unknown command for manipulating files. How would you get help on this command? Exercise 1.  Suppose ls shows you this: Makefile biography.txt data enrolment.txt programs thesis  What argument(s) will make it print the names in reverse, like this: thesis programs enrolment.txt data biography.txt Makefile Exercise 1.  What does the command cd ~ do? What about cd ~hpotter? Exercise 1.  What command will show you the first 10 lines of a file? The first 25? The last 12? Exercise 1.  diff finds and displays the differences between two text files. For example, if you modify earth.txt to create a new file earth2.txt that contains:

Name: Earth Period: 365.26 days Inclination: 0.00 degrees Eccentricity: 0. Satellites: 1  you can then compare the two files like this: $ diff earth.txt earth2.txt 3c < Inclination: 0.


Inclination: 0.00 degrees 4a Satellites: 1  (The rather cryptic header "3c3" means that line 3 of the first file must be changed to get line 3 of the second; "4a5" means that a line is being added after line 4 of the original file.)  What flag(s) should you give diff to tell it to ignore changes that just insert or delete blank lines? What if you want to ignore changes in case (i.e., treat lowercase and uppercase letters as the same)? Exercise 1. -rwxr-xr-x 1 aturing cambridge 69 Jul 12 09:17 mars.txt -rwxr-xr-x 1 ghopper usnavy 71 Jul 12 09:15 venus.txt  According to the listing of the data directory above, who can read the file mars.txt? Who can write it (i.e., change its contents or delete it)? When was mars.txt last changed? What command would you run to allow everyone to edit or delete the file? Exercise 1.  Suppose you want to remove all files whose names (not including their extensions) are of length 3, start with the letter a, and have .txt as extension. What command would you use? For example, if the directory contains three files a.txt, abc.txt, and abcd.txt, the command should remove abc.txt , but not the other two files. Exercise 1.  What does rm *.ch? What about rm *.[ch]?

 Suppose all you wanted was a list of the files that contained lines matching a pattern, rather than the matches themselves—what flag or flags would you give to grep? What if you wanted the line numbers of matching lines? Exercise 1.  The command ls data > tmp.txt writes a listing of the data directory's contents into tmp.txt. Anything that was in the file before the command was run is overwritten. What command could you use to append the listing to tmp.txt instead? Exercise 1.  Create a directory called “bin” in your home directory. What command would you use in order to add your bin directory to the end of our PATH environment variable in the bash shell.


Exercise 1.G.  A colleague asks for your data files. How would you archive them to send as one file using the tar command? How could you compress them using either the gzip or bzip command? The tar command actually contains options so that you can do both the archiving and the compression at the same time. First show me how you would use tar along to do both the archiving and the compression at the same time. Then, for extra credit, show me how to do the same thing using the tar and bzip/gzip commands separately combined by a pipe.  Also discover how to do the reverse of the process, both using tar alone and for extra credit by using a pipe and tar and bzip/gzip separately. Exercise 1.G.  The find command allows you to search for files within and below a directory hierarchy that match a particular pattern (such as the name of the file, or the date when the file was created). How would you search for all files under the “/usr/local” directory ending with the .c file extension using the find command?  For extra credit, use a pipe and the xargs and grep command to search all of the .c source files you found in the previous step for the text “KNEE”. What was the command you used and which file under the “/usr/local” hierarchy is the only .c source file that contains that text?