📄 unx05.htm
字号:
<PRE>NAME
cat - concatenate and print files
SYNOPSIS
cat [<B>-u</B>] [<B>-s</B>] [<B>-v</B> [[<B>-t</B>] [<B>-e</B>]] <I>file . . .</I>
DESCRIPTION
cat reads each <I>file</I> in sequence and writes it on the standard output.
Thus
cat file
prints the contents of file on your terminal, and
cat file1 file2 >file3
concatenates <B>file1</B> and <B>file2</B>, and writes the results in <B>file3</B>. If
no input file is given, or if the argument - is encountered, <B>cat</B> reads from
the standard input. <B>cat </B>processes supplementary code set characters
according to the locale specified in the <B>LC_CTYPE</B> environment variable [see
LANG on environ(5)].
The following options apply to <B>cat</B>:
<B>-u</B> The output is not buffered. (The default is buffered output.)
<B>-s</B> <B>cat</B> is silent about non-existent files.
<B>-v</B> Causes non-printing characters (with the exception of tabs,
new-lines, and form-feeds) to be printed visibly. <B>ASCII</B> control characters
(octal 000 - 037) are printed as ^n, where n is the corresponding <B>ASCII</B>
character in the range octal 100 - 137 (@, A, B, C, . . ., X, Y, Z,
[, \, ], ^, and _); the DEL character (octal 0177) is printed <B>^?</B>. Other
non-printable characters are printed as <B>M-</B>x, where x is the <B>ASCII</B>
character specified by the low-order seven bits. All supplementary code
set characters are considered to be printable.
The following options may be used with the <B>-v</B> option:
<B>-t</B> Causes tabs to be printed as <B>^I</B>'s and formfeeds to be printed
as <B>^L</B>'s.
<B>-e</B> Causes a <B>$</B> character to be printed at the end of each line
(prior to the new-line).
The <B>-t</B> and <B>-e</B> options are ignored if the <B>-v</B> option is not specified.
FILES
/usr/lib/locale/<I>locale</I>/LC_MESSAGES/uxcore.abi
language-specific message file [See <B>LANG</B> on <B>environ</B>(5).]
SEE ALSO
<B>cp</B>(1), <B>pg</B>(1), <B>pr</B>(1)
The <B>NAME</B> section gives the name of the command and a brief description of
what it does.
The <B>SYNOPSIS</B> section shows the command's syntax by listing all possible
options and arguments. Arguments to <B>cat</B> are the names of one or more files. The
fact that <I>file</I> is written in italic type means that <I>file</I> is merely a
placeholder for the name of an actual file. The <B>cat</B> command has three options
and one of them has two "sub-options". The brackets around options indicate
that they are optional. For example, the command could be any one of the
following:
cat file
cat -u file
cat -s file
cat -u -s file (or cat -s -u file)
cat -us file (or cat -su file)
cat -v file
cat -v -t file (or cat -vt file)
cat -v -e file (or cat -ve file)
cat -v -t -e file (or cat -vte file)
cat -u -v -t file (or cat -uvt file)
and so on. With three options and two suboptions, there are many possible
combinations. Note that the order of writing the options doesn't matter and
options can be combined so that only one dash (-) need be written. While these
are generally true, there are some Unix commands that require a particular
order, some that do not permit combinations and even a few that require a
specific order and deny any combinations.
The <B>DESCRIPTION</B> section is the heart of the manual page. It describes each
option and argument, and frequently contains one or more examples. However, its
explanations are frequently sprinked with referenced to other commands, so that
in general it is difficult to learn about a command from its man page.
The <B>FILES</B> section lists other files that are used or related to the
command.
The <B>SEE ALSO</B> section lists related commands. The numbers in parentheses
refer to the section of the manual in which the command will be found. Among
the most important are:
Section 1 - User Commands
Section 1C - Basic Networking Commands
Section 1M - Administration Commands
Section 2 - System Calls
Section 3 - BSD Routines
Section 3C - C Library Functions
Section 3M - Math Library Functions
Section 3S - Standard I/O Functions
Section 4 - File Formats
Section 5 - Miscellaneous
Section 6 - (not included)
Section 7 - Special Files
Section 8 - System Maintenance Procedures</PRE>
<P>As a user or adminstrator, you will be most interested in section 1 (which contains 1, 1C and 1M). Programmers will be interested in 2, 3 and possibly 4.
<BR></P>
<P>Some man pages have the following additional sections:
<BR></P>
<P>The NOTES section is self-explanatory.
<BR></P>
<P>The DIAGNOSTICS sections contains explanations of error messages that the command may cause to be displayed. Not enough commands have a DIAGNOSTICS section!
<BR></P>
<P>The WARNINGS section describes anything that may limit the use of a command.
<BR></P>
<P>The BUGS section tells of known problems that have not been fixed in the current version of the command.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I15" NAME="I15">
<FONT SIZE=4><B>Finding Information About Disk Utilization with </B><B><I>du</I></B><B> and </B><B><I>df</I></B>
<BR></FONT></A></CENTER></H3>
<P>Occasionally, a user needs to know how much disk space his or her files occupy—perhaps the system administrator has sent e-mail requesting that the user is approaching some sort of limit. Frequently, the system administrator needs the same
information for all users or on all parts of one or more disks, and frequently needs information on the overall utilization in all file systems. UNIX provides two commands that report that information: du and df.
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I16" NAME="I16">
<FONT SIZE=3><B>Summarizing Disk Usage with </B><B><I>du</I></B>
<BR></FONT></A></CENTER></H4>
<P>The du command reports the number of disk blocks used for each directory and subdirectory, and the files found there. It has an option to display the number of blocks of just the "top level" directory.
<BR></P>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> A block is the smallest piece of a disk that can be allocated to a file. Frequently, the size of a block is 512 bytes (but the size depends on things that the system administrator did when setting up
the disks). A file that is 1 byte long and a file that is 511 bytes long each occupies one block. A 513 byte file and a 1,023 byte file each occupies two blocks. That is, every 512 bytes of a file occupy a disk block, plus one block for the last piece that
less than 512 bytes.
<BR></NOTE>
<HR ALIGN=CENTER>
<P>Here are some sample executions. First, issue the command to display what you have in the directory hierarchy, from the current directory on down:
<BR></P>
<PRE>$ ls -lR
total 259
drwxr-xr-x 2 pjh other 48 Oct 17 1990 unixbin
-rw-r—r— 1 pjh root 130137 May 10 1993 vpix.img
./unixbin:
total 16
-rw-rw-rw- 1 pjh other 7576 Apr 8 1993 rununix.exe</PRE>
<P>The current directory has one regular file (vpix.img) and one directory file (unixbin), and the subdirectory has one regular file (rununix.exe).
<BR></P>
<P>Now find out the total disk usage:
<BR></P>
<PRE>$ du -s
274 .</PRE>
<P>That's 274 blocks, or somewhere between 13,312 and 13,823 bytes.
<BR></P>
<P>Use the following command to find out how many blocks are in the subdirectory:
<BR></P>
<PRE>$ du
17 ./unixbin
274 .</PRE>
<P>Then find out how many blocks each file has:
<BR></P>
<PRE>$ du -a
16 ./unixbin/rununix.exe
17 ./unixbin
256 ./vpix.img
274 .</PRE>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> The total for a directory or directory hierarchy includes the blocks that the directory files themselves occupy.
<BR></NOTE>
<HR ALIGN=CENTER>
<H4 ALIGN="CENTER">
<CENTER><A ID="I17" NAME="I17">
<FONT SIZE=3><B>Reporting Blocks and Files with </B><B><I>df</I></B>
<BR></FONT></A></CENTER></H4>
<P>The df command helps the system administrator maintain the file systems on the disks. The command displays information about mounted and unmounted resources, types of file systems, and numbers of inodes. It also deals with special devices rather than
easily identifiable directory paths. Most of these terms have little meaning to the ordinary user, but they are discussed in Chapter 35. However, if a user wants to see what's going on with the disk's file systems, the system permits it.
<BR></P>
<P>Multiple options are available with df. In this section, you'll see some of these options demonstrated and explained. But first, here is a typical result that you get when you invoke df with no options:
<BR></P>
<PRE>$ df
/ (/dev/root ): 381964 blocks 58845 files
/proc (/proc ): 0 blocks 128 files
/dev/fd (/dev/fd ): 0 blocks 0 files
/stand (/dev/dsk/c0t0d0sa): 12643 blocks 194 files
/var (/dev/dsk/c0t0d0sb): 961502 blocks 64499 files
/tmp (/dev/dsk/c0t0d0sd): 191308 blocks 24560 files
/usr (/dev/dsk/c0t1d0s3): 772900 blocks 53842 files
/home (/dev/dsk/c0t1d0s4): 923256 blocks 63303 files
/.NetWare (/.NetWare ): 0 blocks 499 files</PRE>
<P>The first column is the path name of the file system. This system's special device name appears in the second column. The third column reports the number of disk blocks available on each disk partition. Finally, the last column displays the number of
files that can be added to each partition. When setting up a new disk, the system administrator partitions it into file systems and allocates several blocks and inodes (or files) to each file system according to how that partition will be used. For
details, see Chapter 35, "File System Administration."
<BR></P>
<P>The -b option shows the free space in kilobytes rather than blocks:
<BR></P>
<PRE>$ df -b
Filesystem avail
/dev/root 190982
/proc 0
/dev/fd 0
/dev/dsk/c0t0d0sa 6321
/dev/dsk/c0t0d0sb 480751
/dev/dsk/c0t0d0sd 95654
/dev/dsk/c0t1d0s3 386450
/dev/dsk/c0t1d0s4 461628
/.NetWare 0</PRE>
<P>The -k option shows some details about allocated space—how much has been used and how much is available—in kilobytes:
<BR></P>
<PRE>$ df -k
filesystem kbytes used avail capacity mounted on
/dev/root 316416 125434 190982 40% /
/proc 0 0 0 0% /proc
/dev/fd 0 0 0 0% /dev/fd
/dev/dsk/c0t0d0sa 10240 3918 6321 38% /stand
/dev/dsk/c0t0d0sb 509952 29201 480751 6% /var
/dev/dsk/c0t0d0sd 102368 6714 95654 7% /tmp
/dev/dsk/c0t1d0s3 512000 125550 386450 25% /usr
/dev/dsk/c0t1d0s4 512976 51348 461628 10% /home
/.NetWare 0 0 0 0% /.NetWare</PRE>
<P>If you are curious about file systems, the -n option tells you the name of the file system type used for each partition. (Again, see Chapter 35 for details.)
<BR></P>
<PRE>$ df -n
/ : vxfs
/proc : proc
/dev/fd : fdfs
/stand : bfs
/var : vxfs
/tmp : vxfs
/usr : vxfs
/home : vxfs
/.NetWare : nucam</PRE>
<P>Finally, the -t option shows used blocks and files, and the total allocation for each file system:
<BR></P>
<PRE>$ df -t
/ (/dev/root ): 381964 blocks 58845 files
total: 632832 blocks 65520 files
/proc (/proc ): 0 blocks 128 files
total: 0 blocks 202 files
/dev/fd (/dev/fd ): 0 blocks 0 files
total: 0 blocks 50 files
/stand (/dev/dsk/c0t0d0sa): 12643 blocks 194 files
total: 20480 blocks 200 files
/var (/dev/dsk/c0t0d0sb): 961502 blocks 64499 files
total: 1019904 blocks 65536 files
/tmp (/dev/dsk/c0t0d0sd): 191308 blocks 24560 files
total: 204736 blocks 24576 files
/usr (/dev/dsk/c0t1d0s3): 772900 blocks 53842 files
total: 1024000 blocks 65536 files
/home (/dev/dsk/c0t1d0s4): 923256 blocks 63303 files
total: 1025952 blocks 65536 files
/.NetWare (/.NetWare ): 0 blocks 499 files
total: 0 blocks 500 files</PRE>
<H3 ALIGN="CENTER">
<CENTER><A ID="I18" NAME="I18">
<FONT SIZE=4><B>Summary</B>
<BR></FONT></A></CENTER></H3>
<P>UNIX provides several small programs that you can use to quickly obtain information that you frequently need. These programs include the following:
<BR></P>
<UL>
<LI>bc, dc—calculator programs
<BR>
<BR></LI>
<LI>date and cal—to display time and date
<BR>
<BR></LI>
<LI>finger, who and id—provide user information
<BR>
<BR></LI>
<LI>man and apropos—explains commands
<BR>
<BR></LI>
<LI>su—"switch user"
<BR>
<BR></LI>
<LI>du and df—display information about disk contents
<BR>
<BR></LI></UL>
<P>These commands are rather specialized commands that, in general, retrieve information about different parts of the system: users, files, directories, clock, and so on. The basis of information storage in UNIX is the file, so Chapter 6, "Popular
File Tools," explores the somewhat more specialized commands for working with files—particularly text files.</P>
<P><A HREF="unx04.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="index.htm"><IMG SRC="blutoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="unx06.htm"><IMG SRC="blunext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>
<A HREF="index.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Home"></A>
</P></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -