📄 ch01_15.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 1] 1.15 Filenames </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:31:14Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch01_01.htm"TITLE="1. Introduction"><LINKREL="prev"HREF="ch01_14.htm"TITLE="1.14 The Kernel and Daemons "><LINKREL="next"HREF="ch01_16.htm"TITLE="1.16 Wildcards "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_14.htm"TITLE="1.14 The Kernel and Daemons "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 1.14 The Kernel and Daemons "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 1<BR>Introduction</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_16.htm"TITLE="1.16 Wildcards "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 1.16 Wildcards "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1011">1.15 Filenames </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-1386"></A><ACLASS="indexterm"NAME="AUTOID-1389"></A>Like all operating systems, UNIX files have names: words (sequences ofcharacters, whatever) that let you identify a file. Older versions ofUNIX had some restrictions on the length of a filename (14characters), but modern versions have removed these restrictions forall practical purposes. Sooner or later you will run into alimit, but if so, you are probably being unnecessarilyverbose.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-1392"></A>Technically, a filename can be made from almost any group ofcharacters (including non-printing characters) except a slash(<CODECLASS="literal">/</CODE>). However, you should avoid filenames containing mostpunctuation marks and all non-printing characters. These will usuallybe a pain.To be safe, limit your filenames to the following characters:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-1399"></A><BCLASS="emphasis.bold">Uppercase and lowercase characters.</B> UNIX is <EMCLASS="emphasis">always</EM> case-sensitive.That is, uppercase and lowercase letters are always different (unlikeDOS and VAX/VMS, which consider uppercase and lowercase letters thesame). Therefore, <EMCLASS="emphasis">myfile</EM> and <EMCLASS="emphasis">Myfile</EM> are different files.It is usually a bad idea to have files whose names differ only intheir capitalization, but that's your decision.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-1407"></A><ACLASS="indexterm"NAME="AUTOID-1409"></A><BCLASS="emphasis.bold">Underscores (</B><CODECLASS="userinput"><B>_</B></CODE><BCLASS="emphasis.bold">).</B>Underscores are handy for separating"words" in a filename to make them more readable. For example,<EMCLASS="emphasis">my_long_filename</EM> is easier to read than<EMCLASS="emphasis">mylongfilename</EM>.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-1418"></A><BCLASS="emphasis.bold">Periods (</B><CODECLASS="userinput"><B>.</B></CODE><BCLASS="emphasis.bold">).</B>Periods are used by some programs (such as the Ccompiler) to separate filenames from<SPANCLASS="link">filename extensions (<ACLASS="linkend"HREF="ch01_17.htm"TITLE="Filename Extensions ">1.17</A>)</SPAN>.Extensions are used by these programsto recognize the type of file to be processed, but they are nottreated specially by the shell, the kernel, or other UNIX programs.</P><PCLASS="para">Filenames that begin with a period are treated specially by theshell:<SPANCLASS="link">wildcards won't match (<ACLASS="linkend"HREF="ch01_16.htm"TITLE="Wildcards ">1.16</A>)</SPAN>them unless you include the period(like <CODECLASS="literal">.*</CODE>). The <EMCLASS="emphasis">ls</EM> command, which lists your files, ignoresfiles whose names begin with a period unless you give it a specialoption(<SPANCLASS="link"><EMCLASS="emphasis">ls -a</EM> (<ACLASS="linkend"HREF="ch16_11.htm"TITLE="Showing Hidden Files with ls -A and -a ">16.11</A>)</SPAN>).Special configuration files are often"hidden" in directories by beginning their names with aperiod.</P></LI><LICLASS="listitem"><PCLASS="para"><BCLASS="emphasis.bold">Certain other punctuation.</B>About the only other punctuation mark<ACLASS="indexterm"NAME="AUTOID-1434"></A><ACLASS="indexterm"NAME="AUTOID-1436"></A>that is always safe is the comma (<CODECLASS="literal">,</CODE>)-although it isn't part of thePOSIX-portable character set. The other punctuation marksmay have special meanings in one situation or another. Stay away fromthem, or you will create filenames that are inconvenient to work with.</P></LI></UL><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-1440"></A>I'm so dead-set against using weird, non-printingcharacters in filenames that Iwon't even tell you how to do it. I will give you some<SPANCLASS="link">special techniques for deleting files with weird names (<ACLASS="linkend"HREF="ch23_11.htm"TITLE="Deleting Files with Odd Names ">23.11</A>)</SPAN>,in case you create some by accident.</P><PCLASS="para">Some things to be aware of:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-1448"></A>UNIX does not have any concept of a file <EMCLASS="emphasis">version</EM>. There aresome<SPANCLASS="link">revision control programs (<ACLASS="linkend"HREF="ch20_12.htm"TITLE="Protecting Files with SCCS or RCS ">20.12</A>)</SPAN>that implement their own notion of aversion, but there is nothing analogous to VAX/VMS's version number.If you are editing a file, don't count on UNIX to save your previousversions - you can make<SPANCLASS="link">scripts to do this (<ACLASS="linkend"HREF="ch44_11.htm"TITLE="Set Exit Status of a Shell (Script) ">44.11</A>)</SPAN>though, if you want to; theGNU Emacs editoralso<SPANCLASS="link">makes backups (<ACLASS="linkend"HREF="ch32_04.htm"TITLE="Backup and Auto-Save Files ">32.4</A>)</SPAN>.</P></LI><LICLASS="listitem"><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-1457"></A>Once you delete a file in UNIX,<SPANCLASS="link">it is gone forever (<ACLASS="linkend"HREF="ch23_02.htm"TITLE="rm and Its Dangers ">23.2</A>)</SPAN>.You can't get itback without restoring it from a tape. Be careful when you deletefiles. Later, we'll show you<SPANCLASS="link">programs (<ACLASS="linkend"HREF="ch23_08.htm"TITLE="Safe Delete: Pros and Cons ">23.8</A>, <ACLASS="linkend"HREF="ch23_09.htm"TITLE="delete: Protecting Files from Accidental Deletion ">23.9</A>)</SPAN>that will give youa "grace period" between the time you delete a file and the time it actuallydisappears.</P></LI></UL><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_14.htm"TITLE="1.14 The Kernel and Daemons "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 1.14 The Kernel and Daemons "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_16.htm"TITLE="1.16 Wildcards "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 1.16 Wildcards "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">1.14 The Kernel and Daemons </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">1.16 Wildcards </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -