⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 317-320.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Special Edition Using Linux, Fourth Edition:Managing Files and Directories</TITLE>

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

 -->




<!--ISBN=0789717468//-->

<!--TITLE=Special Edition Using Linux, Fourth Edition//-->

<!--AUTHOR=Jack Tackett//-->

<!--AUTHOR=Jr.//-->

<!--AUTHOR=Steve Burnett//-->

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

<!--IMPRINT=Que//-->

<!--CHAPTER=17//-->

<!--PAGES=317-320//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch16/314-316.html">Previous</A></TD>

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

<TD><A HREF="320-323.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 17<BR>Managing Files and Directories

</FONT></H2>

<P><I>by Jack Tackett</I></P>

<DL>

<DT><B><BIG>I</BIG>n this chapter

</B><DT>Listing Files

<DT>Organizing Files

<DT>Copying Files

<DT>Moving and Renaming Files

<DT>Removing Files or Directories

<DT>Viewing the Contents of a File

<DT>Searching for Files

<DT>Changing File Time and Date Stamps

<DT>Compressing Files

</DL>

<P>The vast majority of Linux commands manipulate files and directories. Indeed, Linux shell scripts are particularly adept at manipulating files and directories. File manipulations that are difficult in a conventional language (even in C) are made easy from within a shell, largely because of the rich selection of file-manipulation commands available in Linux.

</P>

<P>File-manipulation commands can be grouped roughly into two categories:</P>

<DL>

<DD><B>&#149;</B>&nbsp;&nbsp;Commands that manipulate files as objects

<DD><B>&#149;</B>&nbsp;&nbsp;Commands that manipulate the contents of files

</DL>

<P>This chapter concentrates on commands that manipulate files as objects&#151;commands that move, rename, copy, delete, locate, and change the attributes of files and directories. This chapter also takes a quick look at commands that manipulate the contents of files.

</P>

<H3><A NAME="Heading2"></A><FONT COLOR="#000077">Listing Files</FONT></H3>

<P>The basic command to list files is <TT>ls</TT>. The way <TT>ls</TT> displays files depends on how you use the command. If you use the <TT>ls</TT> command in a pipe, every file is displayed on a line by itself. This is also the default for some versions of UNIX, such as SCO UNIX. Other versions of UNIX list files in several columns. For most uses, the columnar format is more convenient; systems that list files one per row often have an alternative command, usually <TT>lc</TT>, for lists in column format.</P>

<P>The <TT>ls</TT> command&#146;s behavior is modified with the use of flags that take the form <TT>-abcd</TT>. In general, versions of the <TT>ls</TT> command fall into two categories: versions of <TT>ls</TT> derived from Linux System V and those derived from Berkeley. Because the Berkeley Linux systems are slowly giving way to Linux System V, this chapter concentrates on the flags used by System V. If you&#146;re in doubt about which version of <TT>ls</TT> you have, consult the manuals for your system or try the command <TT>man ls</TT>.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>Most man pages for commands in this chapter are no longer being maintained and may be inaccurate or incomplete under Red Hat Linux because the system is moved to more graphical-based systems such as HTML and Texinfo. However, for the time being, this information is accurate for this release of Red Hat Linux 4.0. <HR></FONT>

</BLOCKQUOTE>

<P>Flags used with the <TT>ls</TT> command can be concatenated or listed separately. This means that the following commands are effectively identical:</P>

<!-- CODE SNIP //-->

<PRE>

ls -l &#150;F

</PRE>

<!-- END CODE SNIP //-->

<P>and

</P>

<!-- CODE SNIP //-->

<PRE>

ls -lF

</PRE>

<!-- END CODE SNIP //-->

<P>Table 17.1 lists in alphabetical order several of the flags used with <TT>ls</TT> and their uses.</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 17.1</B> Flags for the <TT>ls</TT> Command

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH WIDTH="20%" ALIGN="LEFT">Flag

<TH WIDTH="80%" ALIGN="LEFT">Description

<TR>

<TD COLSPAN="2"><HR>

<TR>

<TD VALIGN="TOP"><TT>-a</TT>

<TD>Lists all entries. In the absence of this or the <TT>-A</TT> option, entries whose names begin with a period (.) aren&#146;t listed. Linux has a way of &#147;hiding&#148; files; all files that begin with a period by default aren&#146;t listed because they&#146;re generally files used to customize applications. For example, .profile is used to customize the Bourne and Korn shells, and .mailrc is used to customize your system-wide e-mail configuration file. Because almost every major command you use has a startup file, your home directory looks cluttered if the <TT>ls</TT> command lists all those startup files by default. If you want to see them, use the <TT>-a</TT> flag.

<TR>

<TD VALIGN="TOP"><TT>-A</TT>

<TD>Same as <TT>-a</TT>, except that . and .. aren&#146;t listed. (Recall from Chapter 16, &#147;Understanding the File and Directory System,&#148; that . is a pseudonym for the current directory, and .. is a pseudonym for the parent directory.) Because these filenames begin with a period, the <TT>-a</TT> flag lists them. If you don&#146;t want to see these pseudonyms, use the <TT>-A</TT> flag instead.

<TR>

<TD VALIGN="TOP"><TT>-b</TT>

<TD>Forces printing of nongraphic characters to be in octal \ddd notation. <TT>-b</TT> is more useful than the <TT>-q</TT> flag because it allows you to figure out what the characters are.

<TR>

<TD VALIGN="TOP"><TT>-c</TT>

<TD>Uses time of last edit (or last mode change) for sorting or printing. Linux maintains three time and date stamps on every file: the file creation date, the date of last access, and the date of last modification. Normally, files are listed in <I>ASCII order</I> (which is the same as alphabetical order except that capitals are sorted before lowercase letters).

<TR>

<TD VALIGN="TOP"><TT>-C</TT>

<TD>Forces multicolumn output with entries sorted down the columns. This is the default format of <TT>ls</TT> when output is to a terminal.

<TR>

<TD VALIGN="TOP"><TT>-d filename</TT>

<TD>If the argument is a directory, this flag lists only its name (not its contents); often used with the <TT>-l</TT> flag to get the status of a directory. Normally, the contents of a directory are listed if a directory name is explicitly listed or implied with the use of a wildcard. Thus, the simple command <TT>ls</TT> lists just the directory names themselves, but <TT>ls *</TT> lists files, directories, and the contents of any directories encountered in the current directory.

<TR>

<TD VALIGN="TOP"><TT>-F</TT>

<TD>Marks directories with a trailing slash (/), marks executable files with a trailing asterisk (*), marks symbolic links with a trailing at sign (@), marks FIFOs with a trailing bar (|), and marks sockets with a trailing equal sign (=).

<TR>

<TD VALIGN="TOP"><TT>-i</TT>

<TD>Prints each file&#146;s inode number (<I>inodes</I> are described in Chapter 16, &#147;Understanding the File and Directory System&#148;) in the first column of the report. If you list linked files, notice that both files have the same inode number.

<TR>

<TD VALIGN="TOP"><TT>-l</TT>

<TD>Lists directory entries in long format, giving mode, number of links, owner, size in bytes, and time of last modification for each file. If the file is a special file, the size field instead contains the major and minor device numbers. If the time of last modification is greater than six months ago, the month, date, and year are shown; otherwise, only the date and time are shown. If the file is a symbolic link, the path name of the linked-to file is printed, preceded by the characters -&gt;. You can combine <TT>-l</TT> with other options, such as <TT>-n</TT>, to show user and group ID numbers instead of names.

<TR>

<TD VALIGN="TOP"><TT>-n</TT>

<TD>Lists the user and group ID numbers, instead of names, associated with each file and directory. Usually, only the names are listed. If you&#146;re setting up networking products, such as TCP/IP, it&#146;s useful to know ID numbers when you&#146;re setting up permissions across several systems.

<TR>

<TD VALIGN="TOP"><TT>-q</TT>

<TD>Displays nongraphic characters in filenames as the character ?. For <TT>ls</TT>, this is the default action when output is to a terminal. If a file has accidentally been created with nonprintable characters, the <TT>-q</TT> flag displays the file.

<TR>

<TD VALIGN="TOP"><TT>-r</TT>

<TD>Reverses the sort order to show files in reverse alphabetical or oldest-file-first order, as appropriate.

<TR>

<TD VALIGN="TOP"><TT>-s</TT>

<TD>Gives the size of each file, including any indirect blocks used to map the file, in kilobytes. If the environment variable <TT>POSIX_CORRECT</TT> is defined, the block size is 512 bytes.

<TR>

<TD VALIGN="TOP"><TT>-t</TT>

<TD>Sorts by time modified (latest first) instead of by name. If you want to see the oldest file first, use the <TT>-rt</TT> combination.

<TR>

<TD VALIGN="TOP"><TT>-u</TT>

<TD>Uses time of last access, instead of last modification, for sorting (with the <TT>-t</TT> option) or printing (with the <TT>-l</TT> option).

<TR>

<TD VALIGN="TOP"><TT>-x</TT>

<TD>Forces multicolumn output with entries sorted across instead of down the page.

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch16/314-316.html">Previous</A></TD>

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

<TD><A HREF="320-323.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





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

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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