Updated: 2017-01-20 00:52 EST
PS1
Shell Promptfind
to list all the pathnamesmydir
btop1
, btop2
, btop3
Do not print this assignment on paper!
- On paper, you will miss updates, corrections, and hints added to the online version.
- On paper, you cannot follow any of the hyperlink URLs that lead you to hints and course notes relevant to answering a question.
- On paper, scrolling text boxes will be cut off and not print properly.
08h00 (8am) Friday October 7, 2016 (end of Week 5)
echopath.txt
WARNING: Some inattentive students upload Assignment #03 into the Assignment #02 upload area. Don’t make that mistake! Be exact.
This is how you are expected to complete this assignment. Read all the words before you start working.
Do not print this assignment on paper! On paper, you cannot follow any of the hyperlink URLs that lead you to hints and course notes relevant to answering a question.
This assignment is based on your weekly Class Notes and covers these topics:
For full marks, follow these directions exactly:
You will create file system structure in your CLS home directory containing various directories and files. You can use the Checking Program to check your work as you do the tasks.
You can check your work with the Checking Program as often as you like before you submit your final mark. Some task sections below require you to finish the whole section before running the Checking Program; you may not always be able to run the Checking Program successfully after every single task step. The assignment tells you where you can check your work.
When you are finished the tasks, leave the files and directories in place on the CLS as part of your deliverables. Do not delete any assignment work until after the term is over!
Assignments may be re-marked at any time on the CLS; you must have your term work available on the CLS right until term end.
Since I also do manual marking of student assignments, your final mark may not be the same as the mark submitted using the current version of the Checking Program. I do not guarantee that any version of the Checking Program will find all the errors in your work. Complete your assignments according to the specifications, not according to the incomplete set of the mistakes detected by the Checking Program.
You must complete the two Worksheets before attempting this assignment. The worksheets depend on the Readings in the weekly course notes, especially Command Arguments and Options and Pathnames.
These worksheets prepare you to do the rest of the tasks listed below. Failure to complete the worksheets will make the rest of this assignment very difficult. Do the worksheets first! Record and save all your worksheet answers for study and quizzes!
You can download Libre Office (or Open Office) for Windows to edit the Worksheet *.odt
files and save your answers. (Or you can print the PDF and write your answers on paper.) Do not use MSWord; it will mangle the format of the worksheet.
Record and save all your worksheet answers for study and quizzes!
Do a Remote Login to the Course Linux Server (CLS). All work in this assignment must be done on the CLS.
Failure to complete the worksheets will make the rest of this assignment very difficult. Do the worksheets first!
Many students find it extremely helpful to draw a quick graph/picture of their file system directory structure on paper before attempting to answer questions about relative pathnames.
You need to be able to visualize the relative locations of names in the file system tree to answer these questions. Draw the trees on paper!
All references to the “Source Directory” below are to the CLS directory ~idallen/cst8207/16f/assignment03/
and that name starts with a tilde character ~
followed by a user name with no intervening slash. The leading tilde indicates to the shell that the pathname starts with the HOME directory of the account idallen
(seven letters).
You do not have permission to list the names of all the files in the Source Directory, but you can access any files whose names you already know.
PS1
Shell PromptIndexPS1
variable syntax shown in Section 2 of Worksheet #02 HTML, set your shell prompt to include your user name, your computer name, and the basename of your current working directory. (See the definition of basename in the Pathnames class notes.)
[abcd0001@idallen-ubuntu ~]$
Set your PS1
prompt every time you log in to the CLS, so that the prompt changes to tell you you the basename of your current working directory. This is faster than typing pwd
all the time! You will learn later how to create a .bashrc
file to make this happen automatically every time you log in to the CLS.
Tip Feature: If you use
\w
instead of\W
in thePS1
prompt string, the shell will display the full absolute path of your current working directory instead of just the basename. You may or may not like this feature; it doesn’t leave much room on the command line to type commands without having the command line wrap around to the next line. You choose.
As mentioned in List of Commands You Should Know, you must keep a list of command names used each week and write down what each command does. Without that list to remind you of what command names to use, you will find assignments very difficult.
CST8207-16F
directory in your CLS HOME directory.Assignments
directory in the CST8207-16F
directory.assignment03
directory in the Assignments
directory.Hint: You can create the entire directory tree above using one single command with one option and one pathname argument, as you did at the end of Section 4 in Worksheet #02 HTML. System administrators like to work efficiently – they learn how to do things quickly.
Check the structure of this directory tree by making your HOME directory your current directory and using one of these tree
commands below. Try both command lines below and use the command that gives the best-looking output in your terminal.
$ tree CST8207-16F
$ tree -A CST8207-16F
The correct output will look similar to the ASCII tree diagram below. The spelling and capitalization must be exactly as shown.
CST8207-16F
`-- Assignments
`-- assignment03
This assignment03
directory is called the Base Directory for most pathnames in this assignment. Store your files and answers in this Base Directory, not in your HOME directory or anywhere else.
Run the Checking Program to verify your work so far.
Re-read the part at the start of this assignment about drawing file system diagrams on paper. Do it.
Make the Assignments
directory that you created above your current directory.
Run the command that shows your current working directory. One line should display on your screen that looks similar to this:
/home/abcd0001/CST8207-16F/Assignments
pwd.txt
Redo the previous command, and this time redirect the output of the command into the file pwd.txt
in the current directory (just as you did in Assignment #02).
Hint: Recall that you can redirect into a file any output that appears on your terminal screen. You did this using the date
command to create the file date.txt
in Assignment #02.
Move (rename) the pwd.txt
file from the current directory (Assignments
) down into your Base Directory using the shortest relative pathname to do the move. (You did work similar to this in Section 4 of Worksheet #03 HTML.) Remember this relative pathname.
Use a command that shows file names to confirm that there are no files left in the current Assignments
directory. (You will only see the directory basename of the Base Directory in the current directory.)
Use the echo
command to display on your terminal screen the relative pathname that you just used as the second argument to the previous move command.
Hint: Redo the move command with the move command name and the first argument replaced by echo
so that only the second pathname echoes to the terminal screen. Do not include the first pathname.
echopath.txt
Without changing directories, redo the previous echo
command, and this time redirect the output of the command (the relative pathname) into the file echopath.txt
in your Base Directory (not in the current directory).
Hint: For the redirection output file pathname, you must use a relative pathname that leads from your current directory Assignments
down into the Base Directory. The relative pathname will contain one embedded slash separating two name components. The basename of the relative pathname must be the destination file name echopath.txt
Confirm that the Base Directory contains the new echopath.txt
file.
Run the Checking Program to verify your work so far.
find
to list all the pathnamesIndexFrom the current Assignments
directory, change directories and make the CST8207-16F
directory that you created above your current directory, using the shortest relative pathname to change from Assignments
to CST8207-16F
. Remember this relative pathname.
There should be no files in this CST8207-16F
directory. The only name here should be the Assignments
directory. If there are other files in CST8207-16F
, delete them before continuing.
parent.txt
Without changing directories, use the echo
command to save the relative pathname argument you just used, into file parent.txt
in your Base Directory (not in the current directory).
Hint: As you did above, redo the change directory command with the change directory command name replaced by echo
so that the pathname argument echoes to the terminal screen. When that works, add redirection to redirect the screen output into the correct file in the Base Directory (not in the current directory).
Hint: For the redirection output file pathname, you must use a relative pathname that leads from your current directory CST8207-16F
down into the Base Directory. The relative pathname will contain two embedded slashes separating three name components. The basename of the relative pathname must be the destination file name parent.txt
Still in the current CST8207-16F
directory, use the command from the worksheet to recursively walk the current directory and print all the pathnames under the current directory on your screen.
Hint: You used this exact command to print all the pathnames under the current directory in Section 8 of Worksheet #02 HTML.
f0und.txt
Repeat the same recursive command you just used and redirect the output of the command into file f0und.txt
in your Base Directory (not in your current directory). Note the strange spelling of the file name.
Hint: For the redirection output file pathname, you must use a relative pathname that leads from your current directory CST8207-16F
down into the Base Directory, as you did above. See the previous Hints.
Use a command that shows file names to confirm that the parent.txt
and f0und.txt
files are located only in the Base Directory and not in the current directory or anywhere else.
Run the Checking Program to verify your work so far.
You may find it easier to type if you make the Base Directory you created above (
assignment03
) your current directory for this section. The file names in this section have been deliberately chosen to contain characters that look similar but are not the same. Pay strict attention to the names used.
newcal,txt
cal.txt
file you created in Assignment #02 HTML into the Base Directory using the new name newcal,txt
for the file. (Note carefully the punctuation character used in this name.)1ldir
1ldir
directory in the Base Directory. Pay careful attention to the name; the first two characters of the name are not the same.1ldir
create two new directories named one
and two
(three letters each).one
create new directory 0neOne
(six characters, including one digit zero).two
create new directory twOtwo
(six letters, including one that is upper-case).Hint: You can create the entire directory tree above using one single command with one option and two pathname arguments, as you did at the end of Section 4 in Worksheet #02 HTML. System administrators like to work efficiently – they learn how to do things quickly.
Check the structure of this directory tree using the same command as you used in the previous section. The correct directory tree under the Base Directory must look similar to the ASCII tree diagram below. The spelling and capitalization must be exactly as shown.
1ldir
|-- one
| `-- 0neOne
`-- two
`-- twOtwo
lIdir
Copy the directory 1ldir
to new directory lIdir
using the correct directory copy option, as you did in Section 3 of Worksheet #03 HTML. Pay careful attention to the new directory name; the first two characters of the name are not the same.
Hint: lIdir
must not exist before you do this copy! If it already exists, recursively remove it before you do the copy, or else you will get a spurious incorrect extra level of directory such as lIdir/1ldir
Check that the tree structure of lIdir
is exactly the same as the tree structure of the 1ldir
directory from which you copied it.
Run the Checking Program to verify your work so far.
Make the Base Directory your current directory and then use a command to recursively generate a list of all pathnames using your 1ldir
directory as the starting directory. (You used this recursive command above, and many times in the Section 8 in the end of Worksheet #02 HTML. Do not use the tree
or ls
commands. Use the 1ldir
directory as your starting directory.)
The recursive output of all pathnames under your 1ldir
directory will be exactly five lines long and will contain this exact line in the output somewhere (along with another four lines):
1ldir/one/0neOne
Make sure the exact line above appears as one of the five lines!
mypaths.txt
When the five lines of recursive output above on your screen looks correct, redirect the output of the command into the file named mypaths.txt
in the 0neOne
directory that you created earlier under the lIdir
directory.
Hint: Draw a file system tree diagram so that you know what relative pathname to use. Don’t try to invent the pathname in your head!
Hint: For the output redirection file, use a relative path from your current directory down into the 0neOne
directory under lIdir
. The relative pathname will contain three embedded slashes separating four name components. The basename of the relative pathname is the destination file name mypaths.txt
Make the 0neOne
directory under lIdir
your current directory. (Make sure you get the right one under lIdir
and not 1ldir
! Display your current working directory and make sure.)
Hint: Draw a file system tree diagram so that you know what relative pathname to use. Don’t try to invent the pathname in your head!
Use a command to list the files in the current (0neOne
) directory to confirm that the mypaths.txt
file is here. Use another command to display the contents of the mypaths.txt
file, and make sure it contains exactly five lines of pathnames from under the 1ldir
directory.
mypaths.txt.copy
From in the 0neOne
directory, copy the mypaths.txt
file (from the current directory) into the twOtwo
directory that is also under the lIdir
directory, giving it the new name mypaths.txt.copy
as the destination file name for the copy. Use relative pathnames to do the copy.
Hint: Draw a file system hierarchy picture to help you derive the correct relative pathname. For the destination file, use a relative path from your current directory that goes up the tree and then down into the two
directory. The relative pathname will contain four embedded slashes separating five name components. The basename of the relative pathname should be the destination file name.
copycmd.txt
echo
; type the word echo
followed by a space at the start of the command line, in front of the copy command name.copycmd.txt
in the Base Directory. No output should appear on screen.The copycmd.txt
file should contain on one line: the copy command name followed by two relative pathname arguments, exactly as you typed it in the preceding question.
Hints: Because the copycmd.txt
output file must be located in the Base Directory, not in the current 0neOne
directory, you need to specify a relative redirection output pathname that goes up several levels to the Base Directory. The relative pathname will contain three embedded slashes and many parent directories. The basename of the relative pathname is the destination file name copycmd.txt
You will need to use the echo
command to create another file later in this assignment. Remember how you used it here.
Run the Checking Program to verify your work so far.
mydir
IndexExecute this exact command line in your account on the CLS:
~idallen/cst8207/16f/assignment03/create_mydir.sh
~
directly in front of the account name idallen
, indicating to the shell that the pathname starts with the HOME directory of idallen
(seven letters).mydir
The command will create a directory named mydir
in your Base Directory. The directory will contain some sub-directories and files.
To know what files and directories have been created by the above command line, use a command that will recursively show all the files and directories under a starting directory. (You already used this command, above.) Make sure you use the correct command to recursively show all the files and directories, not just the first layer.
You can re-execute the above create_mydir.sh
command line to start this task over from scratch, if you make errors in this part of the assignment, but you will have to rename or remove the existing mydir
first.
You will be asked to make some changes to this existing set of files and directories. You must not make any changes other than the changes asked. If you accidentally create or delete files not required, you may change the modify time of sub-directories and you will have to erase the whole directory and start over.
All the following commands in this task section apply to files and directories under the new mydir
directory. You will have to use commands to find some of the file names mentioned here; they may be located under sub-directories. (See Searching and Finding Files.) Some of these tasks may require more than one command to complete.
Find and read the file named README.txt
(located somewhere under some directory under mydir
). You have to find this file.
Read and then delete the file foo.txt
that is in the same directory as the README.txt
file. (Do not delete any other decoy files named foo.txt
that may be in other directories.)
bar.bak
bar
to be bar.bak
(This is a move, not a copy. It renames the file.) Make sure you rename the file, not any decoy directories with the same name.bar
mydir
directory, create a new empty directory named bar
(three letters). (Make sure you create bar
under mydir
, not in your HOME or any other directory.)movestuff
stuff
(not the directory with the same name) and move (rename) that stuff
file to be named movestuff
under the new directory bar
that you just created. (This is a move/rename, not a copy.) Make sure you move the file, not any directory with the same name.Run the Checking Program to verify your work so far.
btop1
, btop2
, btop3
IndexYou may find it easier to type if you make the Base Directory your current directory for this section.
When the word count is given for a command, the numbers are the values you should get if you pipe the command output into the word count command, e.g.
date | wc
btop1
btop1
in your Base Directory.btop1
create two new directories named bdir1
and bdir2
(four letters and one digit each).bdir1
create new directory bdir1-1
(four letters, two digits, and one dash).bdir2
create new directory bdir2-1
(four letters, two digits, and one dash).Hint: You can create the entire directory tree above using one single command with one option and two pathname arguments, as you did at the end of Section 4 in Worksheet #02 HTML. System administrators like to work efficiently – they learn how to do things quickly.
Verify that the directory tree under btop1
looks similar to the ASCII tree diagram below. The spelling and capitalization must be exactly as shown:
btop1
|-- bdir1
| `-- bdir1-1
`-- bdir2
`-- bdir2-1
Make the Base Directory your current directory and then use a command to recursively generate a list of all pathnames using btop1
as the starting directory.
Hints: You used this recursive command many times in Section 8 of Worksheet #02 HTML. Do not use the tree
or ls
commands. The recursive output of all pathnames will be exactly five lines long and will contain this exact line in the output somewhere (along with another four lines):
btop1/bdir2/bdir2-1
Make sure the exact line above appears as one of the five lines! The word count of this command output must be: 5 5 70
and if the count is wrong, re-read all the words in ths step.
btop1find.txt
When the recursive output above on your screen looks correct, redirect the five lines of output of the command into the file named btop1find.txt
in the Base Directory. (That file name has one digit in it.) The word count of this file must also be: 5 5 70
.
RTFM in the Manual and find the single-letter option to the copy program that preserves mode, ownership, and timestamps when you copy. Make a note of this option in your own course notes; you will use it often as a system administrator.
btop2
Under your Base Directory create another directory btop2
that contains a copy of everything you created under btop1
, with the timestamps preserved.
Hint: The fastest way to do this is with a single recursive copy command, as you did in Section 3 of Worksheet #03 HTML, but add the option to preserve timestamps. Hint: Do not create the btop2
directory before you copy, or else you will get a spurious incorrect extra level of directory such as btop2/btop1
mt
Use a command to create an empty file named mt
in each of the five directories from btop2
down. You will create five empty files, one in each of five directories. Hint: You can do this with one single command name and five relative pathnames. If you’re using the cd
command to do this, you’re wasting time.
Make the btop2
directory your current directory and then use a command to recursively generate a list of all pathnames under your current directory. The recursive output of all pathnames under your current directory will be exactly ten lines long and will contain this exact line in the output somewhere (along with another nine lines):
./bdir2/bdir2-1/mt
Make sure the exact line above appears as one of the ten lines! The word count of this command output must be: 10 10 115
and if the count is wrong, re-read all the words in this step.
btop2find.txt
btop2find.txt
in your Base Directory (not in the current directory). The word count of this file must also be: 10 10 115
.btop3
btop3
that contains a copy of everything that you created under btop2
, with timestamps preserved. Hint: See the previous Hint!mt3, mt2-1
etc.Under btop3
rename each of the mt
files to have the number of the immediate parent directory that contains it, e.g. rename btop3/mt
to be btop3/mt3
and bdir2-1/mt
to be bdir2-1/mt2-1
, etc. You don’t know enough scripting yet to do this with a script; do each file manually.
Hint: The -type f
option to find
may be useful here to generate a list of only file names and not show directory names.
Make the btop3
directory your current directory and then use a command to recursively generate a list of all pathnames under your current directory. The recursive output of all pathnames under your current directory will be exactly ten lines long and will contain this exact line in the output somewhere (along with another nine lines):
./bdir2/bdir2-1/mt2-1
Make sure the exact line above appears as one of the ten lines! The word count of this command output must be: 10 10 124
and if the count is wrong, re-read all the words in this step.
btop3find.txt
btop3find.txt
in your Base Directory (not in the current directory). The word count of this file must also be: 10 10 124
Run the Checking Program to verify your work so far.
mymaze
Create a new directory named mymaze
in your Base Directory.
Under the Source Directory there is a directory named maze
(four letters) with many, many sub-directories and sub-sub-directories, etc. (The maze contains over 20,900 pathnames.) In this large maze, find the one file with a 12-character basename that looks similar to abcd0001-txt
but where the eight-character abcd0001
part of the name is replaced by your own account userid.
maze
directory there because you know its name.maze
directory contains many hidden sub-directories; you need a special option to see hidden files and directories.cd
or ls
to find the file in the maze; the maze is very big. Use the correct command to recursively search the maze
directory for the file name.b.
of Section 8 of Worksheet #02 HTML.XXX
in the file, it is not the right file.mazepath.txt
When the above command has found your personal abcd0001-txt
file in the maze and outputs exactly one line, put the absolute pathname of your personal file (one line) into a file named mazepath.txt
in the mymaze
directory that you created in step 1 above.
Hint: It must be the absolute pathname. You will have to draw a file system diagram and figure out what that pathname is; no command will show it to you. You can test your absolute pathname by giving it as an argument to a command that reads pathnames, e.g. to ls
, wc
, cat
, etc. and make sure you get no error message.
Hint: You can use the echo
command with output redirection to put one line of text into any file. (You used the echo
comand in a similar way to create the one-line copycmd.txt
file, earlier.) When you know the absolute pathname, give the echo
command one argument that is the absolute pathname of your personal file in the maze. Make sure the pathname echoes onto your screen. Then, add output redirection to this echo
command so that the echo
output goes into the mazepath.txt
file and not onto your screen. The mazepath.txt
file should contain one line that is the absolute pathname of the found file in the maze.
treasure.txt
Copy only your one personal file from the maze into your mymaze
directory using the new file name treasure.txt
. Read the file to make sure it’s the right one before and after you copy it into your own mymaze
directory; the file content will tell you clearly that you have found the right file. If you see XXX
in the file, it is not the right file.
Hint: Be careful not to copy the entire maze
directory! Copy only the contents of one file into mymaze
.
Run the Checking Program to verify your work so far.
That is all the tasks you need to do.
Check your work a final time using the Checking Program below and save the standard output of that program into a file as described below. Submit that file (and only that one file) to Blackboard following the directions below.
When you are done, log out of the CLS before you close your laptop or close the PuTTY window, by using the shell exit
command:
$ exit
Summary: Do some tasks, then run the Checking Program to verify your work as you go. You can run the Checking Program as often as you want. When you have the best mark, upload the single file that is the output of the Checking Program to Blackboard.
Since I also do manual marking of student assignments, your final mark may not be the same as the mark submitted using the current version of the Checking Program. I do not guarantee that any version of the Checking Program will find all the errors in your work. Complete your assignments according to the specifications, not according to the incomplete set of the mistakes detected by the Checking Program.
There is a Checking Program named assignment03check
in the Source Directory on the CLS. You can execute this program by typing its (long) pathname into the shell as a command name:
$ ~idallen/cst8207/16f/assignment03/assignment03check
You will learn of ways to make this shorter in future assignments.
When you are done, execute the above Checking Program as a command line on the CLS. This program will check your work, assign you a mark, and display the output on your screen.
You may run the Checking Program as many times as you wish, allowing you to correct mistakes and get the best mark. Some task sections require you to finish the whole section before running the Checking Program at the end; you may not always be able to run the Checking Program successfully after every single task step.
When you are done with this assignment, and you like the mark displayed on your screen by the Checking Program, you must redirect only the standard output of the Checking Program into the text file assignment03.txt
in your Base Directory on the CLS, like this:
$ ~idallen/cst8207/16f/assignment03/assignment03check >assignment03.txt
$ less assignment03.txt
assignment03.txt
file name.YOUR MARK for
assignment03.txt
(containing the output from the Checking Program) from the CLS to your local computer.
YOUR MARK for
assignment03.txt
file from your local computer to the correct Assignment area on Blackboard (with the exact name) before the due date:
assignment03.txt
file from your local computer. Make sure the assignment file has the correct name on your local computer before you attach it. Attach only your assignment03.txt
file for upload. Do not attach any other file names.assignment03.txt
file on the Upload Assignment page, scroll down to the bottom of the page and use the Submit button to actually upload your attached assignment03.txt
file to Blackboard.Use only Attach File, Browse My Computer on the Upload Assignment page. Do not enter any text into the Write Submission or Add Comments boxes on Blackboard; I do not read them. Use only the Attach File, Browse My Computer section followed by the Submit button. If you need to comment on any assignment submission, send me EMail.
You can revise and upload the file more than once using the Start New button on the Review Submission History page to open a new Upload Assignment page. I only look at the most recent submission.
You must upload the file with the correct name from your local computer; you cannot correct the name as you upload it to Blackboard.
You will also see the Review Submission History page any time you already have an assignment attempt uploaded and you click on the underlined assignment03 link. You can use the Start New button on this page to re-upload your assignment as many times as you like.
You cannot delete an assignment attempt, but you can always upload a new version. I only mark the latest version.
Your instructor may also mark files in your directory in your CLS account after the due date. Leave everything there on the CLS. Do not delete any assignment work from the CLS until after the term is over!
I do not accept any assignment submissions by EMail. Use only the Blackboard Attach File, Browse My Computer. No word processor documents. Plain Text only.
Use the exact file name given above. Upload only one single file of Linux-format plain text, not HTML, not RTF, not MSWord. No fonts, no word-processing. Linux plain text only.
NO EMAIL, WORD PROCESSOR, PDF, RTF, or HTML DOCUMENTS ACCEPTED.
No marks are awarded for submitting under the wrong assignment number or for using the wrong file name. Use the exact 16-character, lower-case name given above.
WARNING: Some inattentive students don’t read all these words. Don’t make that mistake! Be exact.
READ ALL THE WORDS. OH PLEASE, PLEASE, PLEASE READ ALL THE WORDS!