0351-0354.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 476 行
HTML
476 行
<HTML>
<HEAD>
<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:GNU Project Utilities</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=0672311739 //-->
<!-- TITLE=RED HAT LINUX 2ND EDITION //-->
<!-- AUTHOR=DAVID PITTS ET AL //-->
<!-- PUBLISHER=MACMILLAN //-->
<!-- IMPRINT=SAMS PUBLISHING //-->
<!-- PUBLICATION DATE=1998 //-->
<!-- CHAPTER=17 //-->
<!-- PAGES=0351-0372 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="../ch16/0348-0350.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0355-0357.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-351"><P>Page 351</P></A>
<H3><A NAME="ch17_ 1">
CHAPTER 17
</A></H3>
<H2>
GNU Project Utilities
</H2>
<P>
<B>by Sriranga R. Veeraraghavan</B>
</P>
<H3><A NAME="ch17_ 2">
IN THIS CHAPTER
</A></H3>
<UL>
<LI> File Utilities
<LI> Find Utilities
<LI> Shell Utilities
<LI> Text Utilities
</UL>
<A NAME="PAGENUM-352"><P>Page 352</P></A>
<P>GNU (which stands for "GNU's not UNIX") is a
UNIX-compatible software system that is being developed by Richard Stallman. The GNU project utilities are the GNU
implementation of familiar UNIX programs like mv,
cp, and ls.
</P>
<P>The GNU versions of these programs generally run faster, provide more options, have
fewer arbitrary limits, and are generally POSIX.2-compliant.
</P>
<P>The GNU project utilities are distributed in several parts. The
bin utilities, diff utilities, and shar (shell archive) utilities are primarily used in development work. The most frequently
used utilities are the file utilities, find utilities, shell utilities, and text utilities; these are covered
in this chapter.
</P>
<P>The true power of the GNU project utilities is that they enable a user to
break down complex tasks and solve them piece by piece, quickly and easily.
</P>
<H3><A NAME="ch17_ 3">
File Utilities
</A></H3>
<P>This section covers the major GNU file management utilities. The following is a complete
list of the programs included in the GNU file utilities distribution:
</P>
<TABLE WIDTH="360">
<TR><TD>
chgrp
</TD><TD>
ls
</TD></TR>
<TR><TD>
chown
</TD><TD>
mkdir
</TD></TR>
<TR><TD>
chmod
</TD><TD>
mvdir
</TD></TR>
<TR><TD>
cp
</TD><TD>
mkfifo
</TD></TR>
<TR><TD>
dd
</TD><TD>
mknod
</TD></TR>
<TR><TD>
df
</TD><TD>
mv
</TD></TR>
<TR><TD>
du
</TD><TD>
rm
</TD></TR>
<TR><TD>
install
</TD><TD>
rmdir
</TD></TR>
<TR><TD>
ln
</TD><TD>
sync
</TD></TR>
<TR><TD>
dir
</TD><TD>
touch
</TD></TR>
<TR><TD>
vdir
</TD></TR>
</TABLE>
<H4>
Listing Directory Contents
</H4>
<P>The GNU file utilities include three programs for listing directory contents and
information about files: ls, dir, and vdir. The biggest difference between these three programs is in
their default behavior; dir is equivalent to ls -C, and
vdir is equivalent to ls -l.
</P>
<P>The default behavior of ls (invoked with no arguments) is to list the contents of the
current directory. If a directory is given as an argument, then its contents are listed nonrecursively
(files starting with a period (.) are omitted). For filename arguments, just the name of the file
is printed. By default, the output is listed alphabetically.
</P>
<A NAME="PAGENUM-353"><P>Page 353</P></A>
<P>The GNU version of ls supports all the standard options and also introduces the major
feature of color-coding files.
</P>
<P>The variable $LS_COLOR (or $LS_COLOUR) is used to determine the color scheme. If
$LS_COLOR is not set, the color scheme is determined from the system default stored in the file
/etc/DIR_COLORS. This variable can be set by hand, but it is much easier to have the program
dircolors set it by issuing the following command:
</P>
<!-- CODE SNIP //-->
<PRE>
eval `dircolors`
</PRE>
<!-- END CODE SNIP //-->
<P>To aid in customizing the color scheme,
dircolors supports a -p option that prints out the default configuration. Redirecting the output to a file creates a valid
dircolors init file. So,
</P>
<!-- CODE SNIP //-->
<PRE>
dircolors -p > .dircolorsrc
</PRE>
<!-- END CODE SNIP //-->
<P>will create a file .dircolorsrc, which can be customized. After the file
.dircolorsrc is customized, $LS_COLORS can be set by issuing the following command:
</P>
<!-- CODE SNIP //-->
<PRE>
eval `dircolors .dircolorsrc`
</PRE>
<!-- END CODE SNIP //-->
<P>Putting this line in an init file (.profile or
.cshrc) and then having the alias
</P>
<!-- CODE SNIP //-->
<PRE>
alias ls="ls --colors" (sh,bash,ksh)
alias ls "ls --colors" (csh,tcsh)
</PRE>
<!-- END CODE SNIP //-->
<P>will ensure that the custom color scheme is used for
ls.
</P>
<P>Listing 17.1 is an excerpt from a .dircolorsrc file that implements bold text for
directories and normal text for all other types of files. If any of these file types are left out, default
values are substituted for them. The comments describe the different color values that can be used.
</P>
<P>Listing 17.1. Excerpt from a .dircolorsrc file.
</P>
<!-- CODE //-->
<PRE>
# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
NORMAL 00 # global default
FILE 00 # normal file
DIR 01 # directory
LINK 00 # symbolic link
FIFO 00 # pipe
SOCK 00 # socket
BLK 00 # block device driver
CHR 00 # character device driver
ORPHAN 00 # symlink to nonexistent file
EXEC 00 # executables
</PRE>
<!-- END CODE //-->
<A NAME="PAGENUM-354"><P>Page 354</P></A>
<P>To implement colors, simply specify the scheme as
</P>
<!-- CODE SNIP //-->
<PRE>
FILE_TYPE attribute codes;text codes;background codes
</PRE>
<!-- END CODE SNIP //-->
<P>This line indicates all links are red with a white background:
</P>
<!-- CODE SNIP //-->
<PRE>
LINK 00;31;47
</PRE>
<!-- END CODE SNIP //-->
<P>Another feature of the --color option is that files with extensions can also be colorized.
For example, to make all .jpg files underlined, put the line
</P>
<!-- CODE SNIP //-->
<PRE>
.jpg 04
</PRE>
<!-- END CODE SNIP //-->
<P>into the .dircolors file. Any file extension can be used. Some people like to have archive
files (.uu, .tar, .tar.gz, .gz, .Z, .z, .tgz) in one color and picture files
(.jpg, .jpeg, .gif) in another.
</P>
<H4><A NAME="ch17_ 4">
File Operations
</A></H4>
<P>The next set of commands in the file utilities are the utilities that are used for basic file
operations, such as copying and moving files.
</P>
<P>The file operations commands like cp, mv, rm, and
ln are familiar to all UNIX users. The GNU versions of these commands support all the standard options along with a few additional
options for safety and convenience. These options are as follows:
</P>
<TABLE WIDTH="360">
<TR><TD>
-b or --backup
</TD><TD>
Makes backups of files that are about to
be overwritten or removed. Without this option,
the original versions are destroyed. (Not available
in rm.)
</TD></TR>
<TR><TD>
-s suffix or --suffix=suffix
</TD><TD>
Appends suffix to each backup file made if
a backup option is specified. (Not available in rm.)
</TD></TR>
<TR><TD>
-v or --verbose
</TD><TD>
Prints out the filename before acting
upon it.
</TD></TR>
</TABLE>
<P>In terms of safety, the backup options are like the
-i option (interactive mode); they frequently prevent mishaps.
</P>
<P>By default, the suffix for the backups is the tilde
(~), but this can easily be changed by setting the variable
$SIMPLE_BACKUP_SUFFIX. Setting this variable also avoids having to give the
-s option each time.
</P>
<P>Another command that is useful for copying files is
the install command. It is frequently used to install compiled programs and is familiar to programmers who use
make, but it also can be useful for the casual user because it can be used to make copies of files and set attributes
for those files.
</P>
<P><CENTER>
<a href="../ch16/0348-0350.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0355-0357.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?