Presentation is loading. Please wait.

Presentation is loading. Please wait.

CST8177 Midterm 1 010 - 11W Answers. Question 1 (10 marks) User clarke (home directory /home/clarke) has two directories in ~, ready and done, where he.

Similar presentations


Presentation on theme: "CST8177 Midterm 1 010 - 11W Answers. Question 1 (10 marks) User clarke (home directory /home/clarke) has two directories in ~, ready and done, where he."— Presentation transcript:

1 CST8177 Midterm 1 010 - 11W Answers

2 Question 1 (10 marks) User clarke (home directory /home/clarke) has two directories in ~, ready and done, where he does his testing. He has a script named pgm-1 that he is testing in first-level (alpha) testing, and another named pgm-2 in second-level (beta) testing. They are stored in the appropriate directories, pgm-1 in ready and pgm-2 in done. Therefore, the directory structure looks like this: [diagram deleted] In directory ready, create a hard link to pgm-2 in done, and in directory done, create a soft link to pgm-1 in ready. Note: You must use relative paths throughout, you may not use the cd command, and your present working directory is /home/clarke. List your commands here: clarke]$ ln done/pgm-2 ready/h-pgm-2 clarke]$ ln -s../ready/pgm-1 done/s-pgm-1

3 Displaying the result (not required) :./done: 648904 -rw-rw-r--. 2 pgm-2 648905 lrwxrwxrwx. 1 s-pgm-1 ->../ready/pgm-1./ready: 648904 -rw-rw-r--. 2 h-pgm-2 344668 -rw-rw-r--. 1 pgm-1 User/group and date/time removed for clarity. Note that done/pgm- 2 and ready/h-pgm-2 have link counts of 2, and both use inode 648904.

4 Question 2 (20 marks) The file gray contains the following text: 1:I must say a few words in this place about "Old Gray." Why he 2:was always called "Old Gray" is more than I know. His colour 3:could not have suggested the name, for he was a bright roan, 4:almost a bay. He was by no means a pretty animal, being raw- 5:boned, and never seeming to be in first-rate condition; but he 6:was endowed with remarkable sagacity and great endurance, and 7:was, moreover, a fleet trotter. It is part of a paragraph taken from The Project Gutenberg EBook of Life in Canada Fifty Years Ago, by Canniff Haight (1825-1901). Use the line numbers (just count them, 1 to last) in answering the following questions about grep and regular expressions:

5 a) Use grep -c to determine the number of lines: grep command:grep -c '.' gray Result on stdout:7 b) Which lines start with a capital (upper-case) letter? grep command:grep -n '^[A-Z]' gray Lines on stdout:1 c) Find all the lines with the word "Gray" or "gray"; use 2 different methods:: grep command 1:grep -n '[Gg]ray' gray grep command 2:grep -in 'gray' gray Lines on stdout:1, 2 d) Several lines begin with the letters "was"; find them: grep command:grep -n '^was' gray Lines on stdout:2, 6, 7

6 e) Several lines end with comma, period, or dash (',', '.', or '-'). Find them: grep command:grep -n '[[:punct:]]$' gray Alternate grep:grep -n '[,.-]$' gray Lines on stdout:3, 4, 7 f) If you knew that each and every sentence ends with a dot (period; full-stop) '.', that no line contains 2 sentences, and that there was no other use of the dot, what grep command would you use to count the number of sentences: grep command:grep -c '\.' gray How many sentences:4

7 Question 3 (5 marks) You recall that there are several cron-related directories in /etc but you have forgotten the names. Looking up the find command, you learn that -type d will select only directories, and you remember the -name keyword all by yourself. Write the find command that you will use to display all directories (there is more that one) with cron somewhere in their name (you are logged-in as root): find /etc -name '*cron*' -type d The result (not required): /etc/cron.monthly /etc/cron.d /etc/cron.weekly /etc/cron.daily /etc/cron.hourly

8 Question 4 (10 marks) You are in the directory dir1 (~/dir1) as user asimov. The directory has only one file named my-file with the contents "this is my file" followed by a newline character (ENTER). The file is therefore 16 bytes in size. Put the redirection needed to the right of the command, and show the output on the screen from each command below. Assume the commands are run in sequence. That is, a command will change the situation for all subsequent commands. Show any error messages as your best approximation; it doesn't have to be the exact text. a) Do not make any changes:cat my-file this is my file b) Do not make any changes:cat missing cat: missing: No such file or directory

9 c) Redirect stderr to the new file file-a: ls my-file missing 2> file-a my-file d. Do not make any changes:cat file-a ls: cannot access missing: No such file or directory d. Append stdout to file-a: ls my-file missing>> file-a ls: cannot access missing: No such file or directory d. Do not make any changes:cat file-a ls: cannot access missing: No such file or directory my-file

10 g. Redirect stdout to the new file file-b: ls my-file missing> file-b ls: cannot access missing: No such file or directory g. Do not make any changes:cat file-b my-file g. Append stderr to file-b ls my-file missing2>> file-b my-file g. Do not make any changes:cat file-b my-file ls: cannot access missing: No such file or directory

11 Question 5 (5 marks) You require a crontab file that will run the backup script from /home/share/bin every Monday at 4:05 in the morning, sending the output for your review to a file called backup.run in your home directory. You are logged in as arthur. You recall that, except for Day-of-Week (which is last), the time elements in the crontab entry are in increasing order. You do not at present have a crontab so you first create the file ~/crontab.arthur. a) List the content of your user crontab file: # min hr dom mon dow command 5 4 * * 1 /home/share/bin/backup > /home/arthur/backup.run b) Show the command you will use to add your file to cron's list: crontab ~/crontab.arthur


Download ppt "CST8177 Midterm 1 010 - 11W Answers. Question 1 (10 marks) User clarke (home directory /home/clarke) has two directories in ~, ready and done, where he."

Similar presentations


Ads by Google