tech 154 midterm solutions. question 1: short definitions

47
TECH 154 Midterm Solutions

Upload: gordon-dixon

Post on 19-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: TECH 154 Midterm Solutions. Question 1: Short Definitions

TECH 154 Midterm

Solutions

Page 2: TECH 154 Midterm Solutions. Question 1: Short Definitions

Question 1: Short Definitions

Page 3: TECH 154 Midterm Solutions. Question 1: Short Definitions

a) superblock

Page 4: TECH 154 Midterm Solutions. Question 1: Short Definitions

superblock

An area on the disk indexed by inode values in which are stored file properties such as permissions, file type and link count and times related to the file, and pointers

Does NOT include the file name, which is stored along with the inode number.

A number of people memorized and reproduced a googled answer “contains characteristics of a file system”. This is very incomplete and IMV did not illustrate understanding of what it was.

Page 5: TECH 154 Midterm Solutions. Question 1: Short Definitions

b) hidden file

Page 6: TECH 154 Midterm Solutions. Question 1: Short Definitions

hidden files

Any file that begins with a period. Not shown normally when using shell patterns in commands like ls or stat.

Hidden files include . (current directory), .. (parent directory), vim swap files and other resources such as .vimrc.

They have NOTHING to do with security. “Security by Obscurity” is generally a very bad idea as it is not an adequate defence against a knowledgeable user. The purpose is to prevent users from being distracted or inadvertantly editing, modifying or deleting these files.

Page 7: TECH 154 Midterm Solutions. Question 1: Short Definitions

c) tty

Page 8: TECH 154 Midterm Solutions. Question 1: Short Definitions

tty Either a terminal (or terminal simulation) or

the command to display which terminal # you are using.

Page 9: TECH 154 Midterm Solutions. Question 1: Short Definitions

d) metacharacter

Page 10: TECH 154 Midterm Solutions. Question 1: Short Definitions

metacharacter

I never met a character I didn’t like. (never use this on a test!)

A character that is interpretted for its function rather than than taken literally.

Found in shell patterns, such as ?*[^]{}, globbing: $ ~, regular expressions, redirection such as | > <, or command grouping: & ; || &&

Page 11: TECH 154 Midterm Solutions. Question 1: Short Definitions

e) flags vs arguments

Page 12: TECH 154 Midterm Solutions. Question 1: Short Definitions

flags vs arguments

Both are found on the command line.

A flag is usually preceded by a single dash or a double dash and then a word. They modify the behaviour of the command.

Arguments are non-flag strings on the command line. (They do not include the command itself.) They often represent files or are associated with the flag that comes directly before it.

½ mark for each definition.

Page 13: TECH 154 Midterm Solutions. Question 1: Short Definitions

Question 2: Commands

Like any tool such as a hammer or a voltmeter, in order to understand how to use a command you have to use it. You have to pour yourself over what that command can do.

If you mereley copy someone else on an assignment or memorize a phrase you read you won’t be able to demonstrate that you understand what it does.

Page 14: TECH 154 Midterm Solutions. Question 1: Short Definitions

a) last

Page 15: TECH 154 Midterm Solutions. Question 1: Short Definitions

last

Displays all the login and logout times and point of access of all or specified users since the system log was created.

The last command uses the log file /var/2tmp. Our SysAdmin rolls over this log file at the beginning of January each year.

Page 16: TECH 154 Midterm Solutions. Question 1: Short Definitions

b) finger

Page 17: TECH 154 Midterm Solutions. Question 1: Short Definitions

finger

Given a userid, supplies their real name, shell, home directory, when they last logged in and current .plan and .project information.

Beyond the above it does not give access to a user’s files.

It also indicates if they have any mail messages, however mail has been mostly disabled on our system.

finger was designed to help people discover information about each other in order to encourage cooperation in a shared environment.

Page 18: TECH 154 Midterm Solutions. Question 1: Short Definitions

c) uptime

Page 19: TECH 154 Midterm Solutions. Question 1: Short Definitions

uptime

Not only shows how long the system has been running since the system was last started, it also shows the average load on the system and the number of people logged on.

It has nothing to do with individual logins or users.

Page 20: TECH 154 Midterm Solutions. Question 1: Short Definitions

d) cal

Page 21: TECH 154 Midterm Solutions. Question 1: Short Definitions

cal

Displays a calendar for the current or specifed month or year.

If you answered “displayed the (calendar) date” – that answer could be confused for the date command.

Page 22: TECH 154 Midterm Solutions. Question 1: Short Definitions

e) stat

Page 23: TECH 154 Midterm Solutions. Question 1: Short Definitions

stat

Displays properties of files such as inode, link count, permissions, times, ownership, device it is on.

Does not display content.

The use of the word “statistics” is contained in the question and is annotated as “circular”.

It may have worked in your high school. It has no value at a college level.

Page 24: TECH 154 Midterm Solutions. Question 1: Short Definitions

f) touch

Page 25: TECH 154 Midterm Solutions. Question 1: Short Definitions

touch

Create empty files and updates their modified and accessed time values.

Page 26: TECH 154 Midterm Solutions. Question 1: Short Definitions

g) vim commands

• :20,30d or :2011dd

• :w ~/lab6.html (you can’t save in /usr)• :1,$s/Unix/UNIX/g (OK if used as sed pattern)

Page 27: TECH 154 Midterm Solutions. Question 1: Short Definitions

Question 3: Misc

Page 28: TECH 154 Midterm Solutions. Question 1: Short Definitions

a) date format codes

date +’%A, Month: %B, %Y %T’

Format codes consist of a % followed by a letter. The letter specifies a value such at the year %Y or the time %T. Plain text is quoted literally.

Formatting has to do with the look of the output. It has nothing to do with export TZ (setting different time zones.)

This is a question where an example is helpful.

Page 29: TECH 154 Midterm Solutions. Question 1: Short Definitions

b) hard link vs symbolic link

Hard links are files that share the same inode value.

A symbolic link is a file that contains a path to the file it represents.

Hard links do not work across physical devices. Symbolic links do. The ln command (used for both) cannot create a hard link to a directory. Saying that a symbolic link can, just emphasizes the same point of difference. However . and .. are created as hard links to the current directory and the parent directory respectively.

Anyone who stated that either of these is a copy of a file deserves to be flogged with a wet noodle.

Page 30: TECH 154 Midterm Solutions. Question 1: Short Definitions

c)/usr/share/zoneinfo parent directory of timezone information

files.

/dev/null used with redirection to discard unwanted output. It is not a recycle bin and is not used

to delete files. It is not a directory.

/usr Unix systems resource directory. Subdirectories include bin, lib, include, src. Nothing to do with users!

. . (dot dot) - parent, not previous directory. cd - takes you to the previous directory.

Page 31: TECH 154 Midterm Solutions. Question 1: Short Definitions

d) 2> | >> <

2> - redirect output of stderr to a a file

| - pipe the output (stdout) of one command to the input of the next.

>> - append the output (stdout) of a command to a file

< - replace stdin with a file

Page 32: TECH 154 Midterm Solutions. Question 1: Short Definitions

e) Matching: ??[4-9].[^Dd]oc

• ?? any 2 characters• [4-9] - a single digit in the range of 4-9• . the character . itself. This isn’t a wildcard• [^Dd] any character BUT D or d• oc literally the characters ‘oc’.

xy7.Moc worksxyz.doc does not

Page 33: TECH 154 Midterm Solutions. Question 1: Short Definitions

Question 4: HTML

Page 34: TECH 154 Midterm Solutions. Question 1: Short Definitions

….next week

Page 35: TECH 154 Midterm Solutions. Question 1: Short Definitions

Question 5: Security

Page 36: TECH 154 Midterm Solutions. Question 1: Short Definitions

a) What are the minimal permissions on all files and directories do you set to make a web page visible to the outside world and nobody else, not even yourself?

Page 37: TECH 154 Midterm Solutions. Question 1: Short Definitions

For directories: o=x (navigable only)

For html files: o=r (readable only)

That’s It

Page 38: TECH 154 Midterm Solutions. Question 1: Short Definitions

b) What are the octal values you would use to set the following permissions: rw- r-x r – x

read is 4, write is 2, execute is 1.

rw = 4+2 r-x is 4+1

655 is your answer

Page 39: TECH 154 Midterm Solutions. Question 1: Short Definitions

c) What is the symbolic form of this chmod command: chmod 0636 ?*.doc

chmod uo=rw,g=wx ?*.doc

Just writing out rw- -wxr-x is only worth ½.

Page 40: TECH 154 Midterm Solutions. Question 1: Short Definitions

Who is the root user?

Page 41: TECH 154 Midterm Solutions. Question 1: Short Definitions

root

She’s the systems admin. She is all powerful. Worship at her feet. Defy her at your peril. She can completely ignore any and all permissions.

It is NOT you nor the current user. (Unless you are root, in which case you still need to provide an explanation similar to the above.)

Page 42: TECH 154 Midterm Solutions. Question 1: Short Definitions

Die Hard – The SysAdmin version

http://xkcd.com/705

Page 43: TECH 154 Midterm Solutions. Question 1: Short Definitions

Question 6: Tasks

Page 44: TECH 154 Midterm Solutions. Question 1: Short Definitions

Create This– TECH154

• |-- Course• | |-- Assign2.doc• | |-- Assign3.doc• | `-- Assign4.doc• |-- Fees• | |-- Ins.txt• | |-- Misc.txt• | |-- SL.txt• | `-- Tuit.txt• `-- Summary.xls

mkdir -p TECH154/{Course,Fees}

touch TECH154/Course/Assign{2..4}.doc

touch TECH154/Fees/{Ins,Misc,SL,Tuit}.txt

touch Summary.xls

The longer (and harder) way requires use of cd to navigate up and down subdirectories and takes longer to write out. Save time using command flags and shell patterns.

Page 45: TECH 154 Midterm Solutions. Question 1: Short Definitions

extract lines 500-700

head –n 700 dataFile | tail –n 201

orsed -n –e ‘500,700p’ dataFile

Page 46: TECH 154 Midterm Solutions. Question 1: Short Definitions

extract lines relating to Dr. Sarav on March 3rd

... | egrep “Dr Sarav” | egrep “March 3”

Requires 2 egreps, not one

Page 47: TECH 154 Midterm Solutions. Question 1: Short Definitions

Extract time, patient name and reason for the appointment

... | cut –d’;’ -f2 > theTime

... | cut –d’;’ -f3 > patient

... | cut -d’;’ -f5 > reason

display information in this format: Eye Exam: Jim Smith, 2:15 PM

paste -d’:,’ reason patient theTime