CS/CE 218 Lecture -*-Outline-*- * directories and files advert: fundamentals, most frequently used commands in all of Unix. essentials for protecting files and understanding why you can't do something you might want to. ** terminology: file, directory Q: What can a directory do that a file can't? Q: What can a file do that a directory can't? ** current working directory (sections 3.1 and 3.3) this is maintained by the OS on behalf of your each process (job) so it's a property of the shell Q: can you fill in the following table: command | effect | sets current working directory | prints name of current working directory ? this is an abstract data type! do we care *how* the shell stores the working directory? Q: What's the mistake in the display and text at the bottom of page 45? how do you get back to your home directory? ** directories another ADT does the book tell how directories are stored? Does it matter? Q: How would you model (mathematically describe) a directory, using something other than a "filing cabinet"? a table of file names and associated files a mapping from file names to files (draw the picture) Q: Can you make a picture of the top 3 levels of the directory ~leavens? What principles are used to organize files? *** observing (reading) directories (section 3.2) what's the most important option of ls? Q: can you make a table like the following that gives mnemonics for each of the options of ls option | mnemonic -a | all files -l | long list ... | ... ? Q: Why is it useful to have a shorthand name for the current directory? Q: What could be the logic behind the names "." and ".."? Q: How would you investigate the suspicious situation described at the bottom of page 60? Note: hidden files is a bit of a misnomer. *** creating and removing directories (sections 3.10 and 3.14) Q: Why is a special command (mkdir) needed to make a directory? Q: Why do you think a directory can't be removed with rmdir if it contains any files? *** changing (writing) directories (sections 3.11-3.13) Q: What commands change (write) directories? Q: Does cp change the "from" (source) file? Q: Would it be better to have a separate command for renaming files and another for moving but not renaming them? pictures of file systems always look like trees (not general graphs). can you prove that with the commands seen so far the shape will always be a tree? (use induction) Give the "true picture" of info in a directory and inodes (draw it) does it make sense for two file names to have the same inode? can do it using the "ln" command Q: If file "y" exists and you execute "mv x y", is file "y" written? Q: If file "y" exists and you execute "rm y", is file "y" written? So why does the system ask you if you want to remove y when y has no write permission? Q: Should you be able to use mv to move directories? Can you? but mv can rename subdirectories ** pathnames and filenames draw a tree of directories and files (with directory /x/y/z) note: file names no longer restricted to 14 characters (limit is ~256) *** full (absolute) paths Q: what character always starts a full path name? what is it called? how do you follow a full path name? *** relative paths Q: Can you get from any directory to any other using a relative path? **** dot (.) and dot dot (..) Q: what does the . mean in "/x/./y/z"? what is a simpler version of ./f? to make it clear, I like sometimes relative paths with ./ Q: what does the .. mean in "/x/../y/z"? how would you picture the "operation" of interpreting .. on a tree? **** adding relative paths to absolute paths if go from /x/y to z, what is the full path? show on tree, then... _____________________ /x/y + ./z = /x/y/z _____________________ does this also work to add 2 relative paths? is it commutative? **** subtracting paths to get relative paths from the top: suppose we're in /x/y and want a relative path to /x/y/z. Do this on the tree picture first. Then derive it as follows: _____________________ /x/y/z (to) - /x/y (from) = ./z = z /x/y/z (to) - /x (from) = ./y/z = y/z _____________________ what is /x - /x/y/z? (not defined) from the bottom: suppose we're in /x/y/z and want a relative path to /x/y. Do it on the tree, then... _____________________ /x/y (to) - /x/y/z (from) = .. this is like a negative number _____________________ can combine these ideas: _____________________ /x/w/q (to) - /x/y/z (from) = (/x + ./w/q) - /x/y/z = /x - /x/y/z + ./w/q = ../.././w/q = ../../w/q _____________________ *** conventions for file names (section 3.5) I often use hyphens in file names, but for C programs best to use underscore (_). Q: How might you pass some of the names in the BIG TROUBLE list on page 50 to a command? Q: What advantages/disadvantages do you see in having case be significant in file names? **** suffixes Q: What is the suffix for C programs? I use .txt as suffix for plain text files. Q: What is the advantage of having suffix conventions instead of rules? *** patterns for matching file names (section 3.15) This is part of the shell (file name expansion) * is pronounced "star" unlike MS-DOS, * can appear in the middle of a pattern; * can also match . in a file name Q: How many characters may be in a file name matched by "x*"? by "?"? Q: What pattern matches all the files whose names start with dot (.), except for "." and ".."? .[!.]* Q: Does * match the path "a/b"? Q: What pattern matches all the C program files in a directory? *.c or better: *.[ch] ** files what commands look at the contents of a file? Q: why do you think there are so many ways to look at the contents of a file?