tech 154 midterm solutions. question 1: short definitions
TRANSCRIPT
TECH 154 Midterm
Solutions
Question 1: Short Definitions
a) superblock
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.
b) hidden file
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.
c) tty
tty Either a terminal (or terminal simulation) or
the command to display which terminal # you are using.
d) metacharacter
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: & ; || &&
e) flags vs arguments
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.
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.
a) last
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.
b) finger
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.
c) uptime
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.
d) cal
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.
e) stat
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.
f) touch
touch
Create empty files and updates their modified and accessed time values.
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)
Question 3: Misc
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.
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.
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.
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
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
Question 4: HTML
….next week
Question 5: Security
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?
For directories: o=x (navigable only)
For html files: o=r (readable only)
That’s It
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
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 ½.
Who is the root user?
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.)
Die Hard – The SysAdmin version
http://xkcd.com/705
Question 6: Tasks
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.
extract lines 500-700
head –n 700 dataFile | tail –n 201
orsed -n –e ‘500,700p’ dataFile
extract lines relating to Dr. Sarav on March 3rd
... | egrep “Dr Sarav” | egrep “March 3”
Requires 2 egreps, not one
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