---------------------------------------------------- Chapter 4 Reading Guide - A Practical Guide to Linux ---------------------------------------------------- -IAN! idallen@ncf.ca Here is a Reading Guide and some review questions for Chapter 4 "The Linux Filesystem". You will find questions similar to these on tests and exams. * Omit the optional material related to Symbolic Links in this chapter. Chapter 4 - The Unix/Linux File System. - The file system hierarchy diagrams in this chapter are misleading. See the weekly lecture notes for a correct sample diagram. (Names in directories are separated from the things they name!) - It's up to every individual program on Unix to decide if file name extensions have any meaning; there is no system-wide support for one standard. For example, the C compiler has a convention that recognizes *.o and *.a as being object files and libraries, but the "more" command is unaware of this convention and happily displays these binary files as if they were plain text files. There is no universal concept that a file with a particular extension is associated with a particular application. Each application decides independently. - If you telnet twice to a Unix machine (either ACADUNIX or Floppix), and you change the working directory of the shell in one telnet session, does the working directory for the shell in the other sesion change too? - If you change the working directory of your shell, then you start up a new copy of the shell by typing, say, "ksh" or "bash", does the new copy of the shell have the changed working directory or the original working directory? - What is the difference between the command lines "ls" and "ls ."? (If you don't supply an argument to the "ls" command, on what pathname does it operate?) - True or False: The "mkdir" command creates a new directory, and then makes the new directory your current working directory. - What option to the "ls" command will change its output to enable you to distinguish file names from directory names? Create a shell command alias for "ls" that uses this option. (To create an alias, see the Linux text index entries for "alias".) - What is the difference between pathname "foo" and "./foo" and "./././foo"?$ (See the Notes file pathnames.txt for more practice with these kinds of pathnames.) - What is the difference between pathname "/bin/ksh" and "/bin/./ksh" and "/bin/./././././ksh"? (See the Notes file pathnames.txt for more practice with these kinds of pathnames.) - Try this on Floppix or ACADUNIX and explain this output (pay close attention to the glob patterns used): $ echo /* | wc 1 37 309 $ echo /*/* | wc 1 3192 46071 Remove the pipe to "wc" and you will see what the real output is. (The actual number of file names generated may change from day to day, depending on system usage.) What do you expect would be the shell expansion of "/*/*/*"? (Don't type this on ACADUNIX during the day - it's an expensive computation! Try it on Floppix only.) Would the pathname /bin/ksh be included in the expansion of "/*/*/*"? (Don't type this on ACADUNIX - it's a very expensive computation!) - Explain this ACADUNIX output, executed in the ROOT directory (pay close attention to the glob patterns used): $ cd / $ echo ./* | wc 1 37 346 $ echo */. | wc 1 24 179 Why is the number of words (the middle number) different? Exactly what is the difference between the shell glob patterns "./*" and "*/."? What would the number of words be for this variation: echo * | wc - Use the "ls" command to explore the list of "standard" directories given on page 75-76 and find out which ones are not present on ACADUNIX. (ACADUNIX is a proprietary IBM Unix system.) - Students who don't take the time to understand how relative pathnames work (especially "..") often type absolute path names to every file they want to access. Why does this slow them down, relative to students who use relative pathnames? What kind of Unix user are you choosing to be? - What Unix command renames files or directories? - What permissions do you need on a file or directory to be able to rename it? - The text says that directories cannot be copied with "cp". This is true of old versions of "cp". New versions, usually found only on Linux, can duplicate a directory and all of the files and directories inside it, if you supply the correct options. The man page for cp will tell you how. - What is the difference in behaviour between a directory that only has X permissions and a directory that only has R permissions? (See the Notes file "file_system.txt" for examples of this.) - What permissions are needed on a file to enable you to remove the file name from a directory? (Be careful - read the "file_system.txt" notes before you answer!) - Try an exercise similar to the one the bottom of page 81: Create a sub-directory. Create a file in that sub-directory. Remove X permission from the directory. (Use the ls command to verify that you have done this successfully.) Try to use "ls -l" on the sub-directory. In the text, doing this shows the contents of the sub-directory and the details about the files contained therein. What does it do for you? (The text is wrong.) - What information does the "-i" option to "ls" add to the output? - Execute these commands on ACADUNIX and explain the output: $ ls -li /usr/bin/*sh $ ls -li /usr/bin/*sh | sort How does adding the sort make decoding what you see easier? - If you own a file or directory, but you give me permission to write to it, can I use the "chmod" command to change its permissions? - True or False: The first time you create a file, you create a real file. Subsequent hard links to the file, made using the "ln" command, are only pointers to the file and aren't as strong as the original file name. Removing the original file name will destroy the file and all the links. Removing one of the links only affects that one link. - True or False: The "ln" command takes two arguments, so the maximum number of hard links a file can have is two. - True or False: To make a hard link to file "foo" that is named "bar", file "foo" must exist. - True or False: You can make a hard link to a directory. - What command recursively removes a directory and all the files and sub-directories contained under it? (Hint: RTFM rmdir, rm) - By using a positive number (e.g. +5) as an argument to the "tail" command, you can skip over the first N-1 lines of a file or of standard input. Try: who | tail +5 Now read Review Question #6 and write a Unix pipeline that answers part (a). The pipeline must count the number of file systems on the local machine. (You will need at least three commands in the pipeline.) Does the same pipeline work on ACADUNIX and on Linux? - Chapter 4 non-Advanced Review Questions: On ACADUNIX or Linux: 1 - 11 (all) - Chapter 4 Advanced Review Questions: On ACADUNIX or Linux: 12, 13, 14, 16 Unix commands studied (summary p.88): cd, chmod, ln, mkdir, pwd, rmdir