📄 0299-0301.html
字号:
<HTML>
<HEAD>
<TITLE>Developer.com - Online Reference Library - 0672311623:SAMS TEACH YOURSELF LINUX IN 24 HOURS:Basic System Administration</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=0672311623 //-->
<!-- TITLE=SAMS TEACH YOURSELF LINUX IN 24 HOURS //-->
<!-- AUTHOR=BILL BALL, STEPHEN SMOOGEN //-->
<!-- PUBLISHER=MACMILLAN //-->
<!-- IMPRINT=SAMS //-->
<!-- PUBLICATION DATE=1998 //-->
<!-- CHAPTER=20 //-->
<!-- PAGES=0291-0312 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0296-0298.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0302-0304.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-299"><P>Page 299</P></A>
<P>The stat command will give you a lot of information about a file or directory. Much of
this information is technical, but you may find the
stat command useful for checking symbolic links. The
stat command does not have any command-line options, but you can
specify directories or filenames, for example:
</P>
<!-- CODE //-->
<PRE>
# stat .
File: "."
Size: 2048 Filetype: Directory
Mode: (0775/drwxrwxr-x) Uid: ( 500/ bball) Gid: ( 500/ bball)
Device: 3,3 Inode: 91932 Links: 19
Access: Wed Nov 19 17:29:42 1997(00000.00:04:46)
Modify: Wed Nov 19 16:52:12 1997(00000.00:42:16)
Change: Wed Nov 19 16:52:12 1997(00000.00:42:16)
</PRE>
<!-- END CODE //-->
<P>You can see that the stat command shows who the file or directory belongs to, along
with permissions, and other information. If you want to use
stat to check symbolic links, you can try
</P>
<!-- CODE SNIP //-->
<PRE>
# touch file1
# ln -s file1 file2
# rm file1
rm: remove `file1'? y
# stat file2
Can't stat file2
</PRE>
<!-- END CODE SNIP //-->
<P>As a beginning sysadmin, you can use this knowledge to devise an even better
approach to help stat look at file directories recursively. There are a number of ways to do this.
Here's one handy command line you can use to check all the symbolic links in your
Linux filesystem:
</P>
<!-- CODE SNIP //-->
<PRE>
# find / -xdev | xargs stat | fgrep "Can't stat"
</PRE>
<!-- END CODE SNIP //-->
<P>This command line uses the find command to feed pathnames to the
stat command (through the xargs command), and then the
fgrep command to print all matches when stat can't find
a symbolic link. As you become a more proficient sysadmin, you'll devise your own bag
of tricks to help diagnose your system.
</P>
<H4><A NAME="ch20_ 9">
Saving Disk Space
</A></H4>
<P>This section gives you some tips on saving disk space. Part of being a sysadmin
is maintaining the health of your filesystem, and performing cleanup operations
occasionally to free up disk space. Once you've found some techniques or approaches that work for
your system and the way you work on your system, you'll find that you can routinely trim
and recover megabytes of disk space.
</P>
<P>One good way to save disk space is not to install a lot of software. For example, how
many different word processors do you need? How many graphics programs do you need? If
you find a capable program, delete others that do the same thing. Make sure to read Hour
22
</P>
<A NAME="PAGENUM-300"><P>Page 300</P></A>
<P>
to see how the rpm command can help you free up disk space and customize your
Linux installation by deleting packages of programs and supporting software.
</P>
<P>You can often trim the size of your directories by looking for less often used programs,
or collections of graphics or text you don't need. You've already seen one way to
find directories that may be candidates for cleanup. But you should also consider some
other file types that may more obviously be deleted.
</P>
<P>For example, some Linux programs create backup files with the tilde prefix. You can
search for these as follows:
</P>
<!-- CODE SNIP //-->
<PRE>
# find / -name ~* -xdev
</PRE>
<!-- END CODE SNIP //-->
<P>Once you feel comfortable with the results, you can pipe the filenames into the
rm command, using the xargs command to build a cleanup command line (although you
can also use the find command's -exec command-line option):
</P>
<!-- CODE SNIP //-->
<PRE>
# find / -name ~* -xdev | xargs rm -f
</PRE>
<!-- END CODE SNIP //-->
<P>You should also search for files named core. These are
core dumps, or dumps of program memory created if a program abnormally aborts. Some of these files can be huge,
for example:
</P>
<!-- CODE SNIP //-->
<PRE>
# ls -l /usr/lib/rhs/glint/core
-rw------ 1 root root 10768384 Sep 16 15:26 /usr/lib/rhs/glint/core
</PRE>
<!-- END CODE SNIP //-->
<P>You can use the bash or pdksh shells' ulimit
command to limit the size of these core files. To see the current allowable size of core files, use the
ulimit command's -c option, for example:
</P>
<!-- CODE SNIP //-->
<PRE>
# ulimit -c
1000000
</PRE>
<!-- END CODE SNIP //-->
<P>This doesn't mean that core dumps are limited to 1MB, but 1,000,000 512-byte
blocks! You can limit the size of core files with the
-c option, as in
</P>
<!-- CODE SNIP //-->
<PRE>
# ulimit -c 1000
</PRE>
<!-- END CODE SNIP //-->
<P>This sets the maximum size of core files to 512,000 bytes. If you're using the csh
shell, use
</P>
<!-- CODE SNIP //-->
<PRE>
# limit coredumpsize 1000
</PRE>
<!-- END CODE SNIP //-->
<P>Limiting the size of these files is one way to can save disk space in the future.
Other candidates for removal include
<TABLE>
<TR><TD>
*.bak, *.BAK
</TD><TD>
Backup files
</TD></TR><TR><TD>
*.o
</TD><TD>
Compiled object files from compiling operations
</TD></TR><TR><TD>
#*
</TD><TD>
Backup files
</TD></TR><TR><TD>
*.1, *.2, *.3
</TD><TD>
File extensions for system log files under the
/var/log directory.
</TD></TR></TABLE>
<A NAME="PAGENUM-301"><P>Page 301</P></A>
<BLOCKQUOTE>
Some logs can grow quite large, and unless you really need
them, they should be deleted.
</BLOCKQUOTE>
<P>
<CENTER>
<TABLE BGCOLOR="#FFFF99">
<TR><TD><B>
CAUTION
</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
Be careful about deleting files with file-number extensions, such as
.1, across your system: you will delete a lot of libraries and manual pages if you
automate a search-and-destroy mission starting at the root, or
/, directory!
</BLOCKQUOTE></TD></TR>
</TABLE></CENTER>
</P>
<P>If you feel uncomfortable with letting the find command run through your file system
and deleting files, just have the command generate a report of candidate files as follows:
</P>
<!-- CODE SNIP //-->
<PRE>
# find / \( -name core -o -name *.o \) -xdev > deletelist.txt
</PRE>
<!-- END CODE SNIP //-->
<P>Note that you can also set this command to run unattended, at regular intervals, and
have the report emailed to you as an automatic reminder. See Hour 24, "Scheduling,"
for details.
</P>
<P>If you experiment with your own combination of commands, you'll soon come up with
your own customized reports and cleanup actions. You now know how to get information
about your drive space. You'll also learn about managing disk space, using quotas (software
limits on hard drive usage) in the "Managing User Access" section. For now, you'll learn how
to find out more about what's going on in your computer's memory when you run Linux.
</P>
<H3><A NAME="ch20_ 10">
Getting Memory Information
</A></H3>
<P>Although the industry trend has been to offer more hard drive space and more
memory for less money, many people don't like to outlay more cash to expand their systems.
The good news is that Linux is very efficient at using memory, because even a 16MB
system provides enough room (with an equal amount of swap space) to run X11 and most
programs well. The bad news is that programs are getting larger all the time, especially with
feature creep, in which more and more functions creep into programs. This section
introduces you to some programs you may find helpful in understanding your system's memory,
and gives you some tips on conserving memory.
</P>
<H4><A NAME="ch20_ 11">
Memory Reporting with the free Command
</A></H4>
<P>The free command shows breakdowns of the amounts and totals of free and used
memory, including your swapfile usage. This command has several command-line options, but
is easy to run and understand, for example:
</P>
<P><CENTER>
<a href="0296-0298.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0302-0304.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -