149-152.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 86 行

HTML
86
字号
<HTML>

<HEAD>

<TITLE>Linux Unleashed, Third Edition:Using the File System</TITLE>

<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=0672313723//-->

<!--TITLE=Linux Unleashed, Third Edition//-->

<!--AUTHOR=Tim Parker//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Sams//-->

<!--CHAPTER=8//-->

<!--PAGES=149-152//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch07/145-148.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="152-153.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 8<BR>Using the File System

</FONT></H2>

<P><I>by Ed Treijs and Tim Parker</I></P>

<DL>

<DT><B>In This Chapter</B>

<DT>&#149;&nbsp;&nbsp; Files: an overview

<DT>&#149;&nbsp;&nbsp; Directories: an overview

<DT>&#149;&nbsp;&nbsp; Navigating the Linux file system

<DT>&#149;&nbsp;&nbsp; Creating and deleting files

<DT>&#149;&nbsp;&nbsp; Removing files and directories

<DT>&#149;&nbsp;&nbsp; Important directories in the Linux file system 

</DL>

<P>To understand how Linux works and to use the system beyond a superficial level, you must be familiar with the Linux notion of files and the file system into which they are organized. If you&#146;ve worked with another operating system such as DOS or Windows, you&#146;ve already seen these concepts because both operating systems base their approach for files, directories, and file systems on UNIX. As you will see, there is a lot more flexibility in the way UNIX and Linux handle file systems than the rather strict and limited way both DOS and Windows manage them.

</P>

<H3><A NAME="Heading2"></A><FONT COLOR="#000077">Files: An Overview</FONT></H3>

<P>The most basic concept of a file&#151;and one you may already be familiar with from other computer systems&#151;defines a <I>file</I> as a distinct chunk of information that is found on your hard drive. <I>Distinct</I> means that there are many separate files, each with its own particular contents. To keep files from getting confused with one another, every file must have a unique identity. In Linux, you identify each file by its name and location. In each location or <I>directory,</I> there can be only one file by a particular name. So, for instance, if you create a file called <TT><B>novel</B></TT>, and you get a second great idea, either you will have to call it something different, such as <TT><B>novel2</B></TT>, or put it in a different directory to prevent <I>overwriting</I> the contents already in your original <TT><B>novel</B></TT>.</P>

<H4 ALIGN="LEFT"><A NAME="Heading3"></A><FONT COLOR="#000077">Common Types of Files</FONT></H4>

<P>Files can contain various types of information. The following three types will become the most familiar to you on a Linux system:

</P>

<DL>

<DD><B>&#149;</B>&nbsp;&nbsp;User data: Information that you create and update. The simplest user data is plain text or numbers. You will learn to create these simple files later in this chapter. More complicated user data files might have to be <I>interpreted</I> by another program to make sense. For instance, a spreadsheet file looks like gibberish if you look at it directly. To work with a spreadsheet, you have to start the spreadsheet program and read in the spreadsheet file.

<DD><B>&#149;</B>&nbsp;&nbsp;System data: Information, often in plain text form, that is read and used by the Linux system&#151;to keep track of which users are allowed on the system, for example. As a system administrator, you are responsible for changing system data files. For instance, when you create a new user, you modify the file <TT><B>/etc/passwd</B></TT>, which contains the user information. Ordinary users of the system are usually not concerned with system data files, except for their private startup files.

<DD><B>&#149;</B>&nbsp;&nbsp;Executable files: These files contain instructions that your computer can perform. This set of instructions is often called a <I>program</I>. When you tell the computer to perform them, you&#146;re telling it to <I>execute</I> the instructions given to it. To human eyes, executable files contain meaningless gibberish&#151;obviously your computer doesn&#146;t think the way you do! Creating or modifying executable files takes special tools. You learn how to use these programming tools in Part V, &#147;Linux for Programmers.&#148;

</DL>

<P>While we have decided there are three different types of files, it&#146;s important for you to realize that there is no difference between the type of files as far as the Linux file system is concerned. Each file is a chunk of data on the disk drives that contains information. What is inside each file is irrelevant to Linux until you try to use the file. The <TT><B>bash</B></TT> shell that we&#146;ve been using, for example, can run any executable file, but may not be able to figure out what kind of data is in the user or system data files. The contents of the file are relevant only to the application that uses them, not to Linux as an operating system. The only exception to this general statement are the system data files that Linux uses when starting and running the system. In this case, Linux knows how to read the contents of the files itself.</P>

<H4 ALIGN="LEFT"><A NAME="Heading4"></A><FONT COLOR="#000077">Filenames</FONT></H4>

<P>Linux allows filenames to be up to 256 characters long. These characters can be lower- and uppercase letters, numbers, and other characters, usually the hyphen (-), the underscore (_), and the period (.). While Linux allows you to use 256 characters in a filename, there are two things to bear in mind.

</P>

<P>First, not all the characters are significant. If you have two filenames both 250 characters long which differ only in the last (250<SUP>th</SUP>) character, to Linux the files have the same name. This is because Linux takes only the first 32 or 64 characters of the filename (depending on the version of Linux) as significant. The rest of the filename is there for your convenience, and Linux keeps track of the information, but usually doesn&#146;t consider the rest of the characters after the 33<SUP>rd</SUP> or 65<SUP>th</SUP> as important for its own uses.</P>

<P>Secondly, remember that you have to type all those long names. Sure, you can call a file by a name 256 characters long, but you also have to type it when you want access to the file (unless you use metacharacters or wildcards). Common sense indicates you should use reasonably short, descriptive filenames. If your file contains statistical data for January, you can call the file <TT><B>Jan_stats</B></TT> or simply <I>data_Jan</I>, which is a heck of a lot easier to type than the filename <TT><B>statistical_data_for_January</B></TT>. There&#146;s nothing to stop you using the long name, though.</P>

<P>Filenames don&#146;t normally include reserved <I>metacharacters</I> such as the asterisk, question mark, backslash, and space because these all have meaning to the shell. We met some metacharacters when we discussed wildcards in the previous chapter. Other metacharacters will be introduced in the Linux shell chapters. (It is possible to create files that have metacharacters in them but they tend to pose problems for the operating system and applications.)</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch07/145-148.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="152-153.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?