Harley Hahn's Guide to
|
A Personal Note
Chapters...
Command
INSTRUCTOR |
Exercises and Answers for Chapter 23... The Unix Filesystem Review Question #1: What is a Unix file? What are the three main types of files? Describe each type. Answer Within Unix, a file is any source, with a name, from which data can be read; or any target, with a name, to which data can be written. The three categories of files are ordinary files (regular files), directories and pseudo files. An ordinary file contains data and resides on a storage device, such as a hard disk, CD, DVD, flash drive, memory card, or floppy disk. As such, ordinary files are the type of file you work with most of the time. A directory resides on a storage device and is used to organize and access other files. Conceptually, a directory "contains" other files. A pseudo file is used to access a service, usually provided by the kernel. Because pseudo files do not store data, they require no disk space. The most important types of pseudo files are special files, named pipes, and proc files. Review Question #2: Explain the difference between a text file and a binary file. Give three examples of each. Answer A binary file contains non-textual data that makes sense only when read by a program. Examples: executable programs, object files, images, music files, video files, word processing documents, spreadsheets, and databases. A text file contains only printable characters, with a newline character at the end of each line. Unix filters are designed to work with text files. Examples: source programs, HTML files, plain documents, shell scripts, and configuration files. Review Question #3: What is the Filesystem Hierarchy Standard or FHS? Within the FHS, briefly describe the contents of: 1. The root directory (/) 2. The following top-level directories: /bin /boot /dev /etc /home /lib /sbin /tmp /usr /varAnswer The FHS is a standard that describes how a Unix system should organize its directories, in particular, the top-level directories and selected second-level directories. Root directory:
Top-Level Directories:
Review Question #4: Within the FHS which directories contain general-use programs? Which directories contain system administration programs? Answer General-use programs:
System administration programs:
Review Question #5: What is a home directory? Within the FHS where do you find the home directories? What is the only userid whose home directory is in a different place? Why? Suppose your userid is weedly and you are an undergraduate student at a large university. Give two likely names for your home directory. Answer A home directory is the directory designated to hold the files for a particular userid. Whenever you log in your working directory is automatically set to be your home directory. Within the FHS home directories are found within /home. The only exception is root whose home directory is /root. On many systems the /home directory is in a secondary filesystem which is not available until it is mounted. The /root directory on the other hand is always part of the root filesystem and thus is always available. Likely names for the home directory for userid weedly are:
/home/weedly
Applying Your Knowledge #1: The following command will list all the subdirectories of the root directory: ls -F / | grep '/' Use this command to look at the names of the top-level directories on your system. Compare what you see to the basic layout of the Filesystem Hierarchy Standard. What are the differences? Answer Compare what you see to the directories listed in the answer for Review Question #3. Applying Your Knowledge #2: As we will discuss in Chapter 24 you can use the cd to change from one directory to another and ls to list the contents of a directory. For example to change to the /bin directory and list its contents you can use: cd /bin; ls Explore your system and find out where the following files are stored:
• Users' home directories
Hint: You may find the whereis program useful (see Chapter 25). Answer Start by thinking about the directory names you found when you answered the previous question. You can use whereis to find the location of a program and its man files. For example: whereis date Applying Your Knowledge #3: Enter the following command: cp /dev/tty tempfile Type several lines of text and then press ^D. What did you just do? How did it work? Hint: To clean up after yourself you should enter the following command to remove (delete) the file named tempfile: rm tempfile Answer The command copies data from the terminal (/dev/tty) to a file named tempfile. If tempfile does not exist it will be created. If it does exist it will be replaced. The rm command is necessary to remove tempfile when you are finished with it. For Further Thought #1: Unix defines a "file" a very general way. Give three advantages to such a system. Give three disadvantages. Answer Advantages: • Programs that read and write to standard Unix files are able to read from any source of input and write to any output target with modification. • When new types of I/O hardware are developed — for example new storage systems — it is possible to integrate them into the existing system. • Once programmers learn how to write programs to perform standard I/O they can access any type of I/O device. Disadvantages: • Because the Unix filesystem uses a one-size- fits all philosophy it is not easy to take advantage of any idiosyncratic characteristics an I/O device may have. Thus I/O with a specific device might be less efficient it would be if it had its own specialized interface. • It is confusing to treat all sources of input as if they were the same when conceptually they have nothing in common. For example music files on a CD are much different from information about current processes. • Requiring extra layers of abstraction (see Chapter 5) between the user/programs and I/O devices creates inefficiency. • Operations that might be simple are sometimes twisted into unnecessarily complex operations just so they can fit into the "system". For Further Thought #2: There is no uniformity as to how closely Unix systems must follow the Filesystem Hierarchy Standard. Some systems stick fairly close to the ideal; others are significantly different. Would it be a good or a bad idea to require all Unix systems to use the same basic filesystem hierarchy? Discuss the advantages and the disadvantages. Answer Requiring all Unix systems to adhere to the same filesystem hierarchy standard would be good as it would make for more uniformity. This in turn would make it easier for users and programmers to learn how to use Unix and to find their way around a new system. It would also make it easier to design more portable programs and tools. However such a system would be stifling as it would not leave enough flexibility for customizing systems to run under a large variety of conditions. The world of Unix has always been open to change and improvement (at least in principle). In such a world standardization works best when it is adopted voluntarily and when it can be changed as conditions change. Exercises: Introduction | Chapter list
© All contents Copyright 2024, Harley Hahn
|