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

📄 0296-0298.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 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="0291-0295.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0299-0301.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-296"><P>Page 296</P></A>









<P>The df (free disk space) command will gather and summarize some important

statistics about all currently mounted filesystems. The

df command is easy to use, for example:

</P>



<!-- CODE //-->

<PRE>

# df

Filesystem         1024-blocks  Used Available Capacity Mounted on

/dev/hda3             497699  443871    28124     94%   /

/dev/hda1             509856  469632    40224     92%   /mnt/dos

/dev/hdc1               3868    2596     1272     67%   /mnt/flash

/dev/hdb              644324  644324        0    100%   /mnt/cdrom

</PRE>

<!-- END CODE //-->



<P>This output shows four different filesystems on three different devices mounted

under Linux. The first is the root partition at the

/ directory on /dev/hda3; the second is a DOS partition under

/mnt/dos on /dev/hda1; the third is a flashcard under

/mnt/flash on /dev/hdc1; and the fourth is a CD-ROM, mounted under

/mnt/cdrom on /dev/dev/hdb. The df command also

lists the size of the storage device, how much has been used, how much is available, and

the current capacity of the device. Notice that the CD-ROM has no space left. This is

because it is mounted read-only, meaning you can't save or delete files on this device. The

command shown in the next example will let you know.

</P>



<P>One handy way to find out about the different filesystems you have mounted is to use

the mount command. This command is usually used during startup, and by the root

operator to mount and unmount filesystems, but you can use

mount to show what type of filesystems are in use, and how the filesystems are mounted, for example:

</P>



<!-- CODE //-->

<PRE>

# mount

/dev/hda3 on / type ext2 (rw)

/dev/hda1 on /mnt/dos type msdos (rw)

none on /proc type proc (rw)

/dev/hdc1 on /mnt/flash type msdos (rw)

/dev/hdb on /mnt/cdrom type iso9660 (ro)

</PRE>

<!-- END CODE //-->



<P>This shows that your root partition, on the / directory, is a Linux

ext2 filesystem mounted read-write, whereas

/mnt/dos and /mnt/flash contain DOS partitions, also read-write. (The

/proc filesystem is a special directory Linux uses for process reporting, such as

running applications, system state, and so on.)

Finally, mount reports that your CD-ROM is mounted as a read-only iso9660 filesystem.

</P>



<P>You can use this information from mount to get specific information with the

df command, by using the df command's -t, or filesystem, option, as follows:

</P>



<!-- CODE SNIP //-->

<PRE>

# df -t ext2

Filesystem         1024-blocks  Used Available Capacity Mounted on

/dev/hda3             497699  443873    28122     94%   /

</PRE>

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



<P>This tells df to just show information about any mounted Linux filesystems. You can

get a list of valid filesystems to specify with the

df command by looking at the mount manual page. The

mount command is covered in more detail in Hour 21, &quot;Handling Files.&quot; You can

see

</P>





<A NAME="PAGENUM-297"><P>Page 297</P></A>







<P>that by using the df and mount command, you can get reports on the type of mounted

devices, how the devices are mounted, and how much room you have left on each.

</P>



<H4><A NAME="ch20_ 7">

Getting Filesystem Disk Usage with the du Command

</A></H4>



<P>The du (disk usage) command conveniently summarizes how your disk is being used,

by reporting the amount of space required by each directory or specified path. Although

the du command has more than 20 command-line options, this section presents some of

the common ones, and leaves it up to you to experiment. You can use the

du command by itself, or specify a directory or path, for example:

</P>



<!-- CODE //-->

<PRE>

# du

904     ./book

12080   ./mail

1       ./.tin/.mailidx

1       ./.tin/.index

10      ./.tin

...

589     ./News

9       ./.index

7       ./.procmail

5       ./.ncftp

418     ./reading

778     ./documents

27199   .

</PRE>

<!-- END CODE //-->



<P>This report (for brevity, not all the directories are listed) shows the contents of a

home directory, with a total for 27,199 1-kilobyte blocks. If you find this hard to

understand, you can have du report the size in bytes, for example:

</P>



<!-- CODE //-->

<PRE>

# du -b

897606  ./book

12294410        ./mail

1024    ./.tin/.mailidx

1024    ./.tin/.index

9382    ./.tin

561715  ./News

4033    ./.index

4139    ./.procmail

2791    ./.ncftp

424037  ./reading

784216  ./documents

26785752        .

</PRE>

<!-- END CODE //-->



<P>If this is too much information for you, then you can use the

--summarize option to get the total in either kilobytes or bytes, as follows:

</P>



<!-- CODE SNIP //-->

<PRE>

# du -b --summarize

26786903        .

</PRE>

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



<P>The du command can also help you keep track of directories which, unattended,

sometimes grow out of control or use a lot of disk space. If you specify a path,

du will report on the

</P>





<A NAME="PAGENUM-298"><P>Page 298</P></A>





<P>

different size of the directories, pinpointing any that may contain too much

information, for example:

</P>

<!-- CODE //-->

<PRE>

# du --summarize -b /var/* | sort -nr

6474535 /var/lib

2336494 /var/log

868163  /var/catman

76362   /var/spool

14591   /var/dt

2385    /var/run

2048    /var/lock

2048    /var/local

1024    /var/tmp

1024    /var/preserve

1024    /var/nis

</PRE>

<!-- END CODE //-->



<P>Here I've combined the du command, which has been instructed to summarize the

number of bytes in each directory, with the sort command, which has been set to use a

numerical sort in reverse order. This one-liner, which uses pipes (discussed in Hour 6, &quot;Using

the Shell&quot;), will automatically print the largest directories at

the top of the output list. You can see that the

/var/log directory is getting pretty big. The

/var/lib directory will be large because it contains the

rpm databases (rpm is discussed in Hour 22, &quot;Red Hat Tools&quot;).

</P>



<P>Although the du command does not, like the df command, have a

-t option to specify which filesystem to report on, you can use the

-x option to exclude other filesystems. Or, you

can have du report on other filesystems by specifying a usage report at the

mount point. For example, du will merrily chug along and summarize how much room your

Windows directories take up:

</P>

<!-- CODE //-->

<PRE>

# du -b --summarize /mnt/dos/* | sort -nr

129486405       /mnt/dos/windows

23929345        /mnt/dos/msoffice

20811654        /mnt/dos/photoenf

7744046 /mnt/dos/tranxit

6828902 /mnt/dos/org2

6647520 /mnt/dos/laplink

5556496 /mnt/dos/acrobat3

4041127 /mnt/dos/pcdr

3753962 /mnt/dos/psp

3603469 /mnt/dos/insync

3176769 /mnt/dos/antvirus

2669335 /mnt/dos/airlite

2408920 /mnt/dos/winfax

...

</PRE>

<!-- END CODE //-->



<P>This (shortened) report shows that next to the operating system, the largest space is

taken up by certain applications. This information can be helpful in making a decision on

what applications to uninstall if you need more disk space.

</P>



<H4><A NAME="ch20_ 8">

Checking Symbolic Links with the stat Command

</A></H4>



<P><CENTER>

<a href="0291-0295.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0299-0301.html">Next</A>

</CENTER></P>











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

<!-- begin footer information -->









</body></html>

⌨️ 快捷键说明

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