Книга: Fedora™ Unleashed, 2008 edition
Printing Disk Use with du
Printing Disk Use with du
The du
command prints the size of each file and directory that is inside the current directory. Its most basic use is as easy as it gets:
$ du
That query outputs a long list of directories and how much space their files take up. You can modify that with the -a parameter, which instructs du to print the size of individual files and directories. Another useful parameter is -h, which makes du use human-readable sizes like 18M (18MB) rather than 17532 (the same number in bytes, unrounded). The final useful basic option is -c
, which prints the total size of files.
So, using du
, you can get a printout of the size of each file in your home directory, in human-readable format, and with a summary at the end, like this:
$ du -ahc /home/paul
Two advanced parameters deal with filenames you want excluded from your count. The first is --exclude
, which enables you to specify a pattern that should be used to exclude files. This pattern is a standard shell file-matching pattern as opposed to a regular expression, which means you can use ?
to match a single character or *
to match 0 or many characters. You can specify multiple --exclude
parameters to exclude several patterns. For example:
$ du --exclude="*.xml" --exclude="*.xsl"
Of course, typing numerous --exclude
parameters repeatedly is a waste of time, so you can use -X
to specify a file that has the list of patterns you want excluded. The file should look like this:
*.xml
*.xsl
That is, each pattern you want excluded should be on a line by itself. If that file were called xml_exclude.txt
, you could use it in place of the previous example like this:
$ du -X xml_exclude.txt
You can make your exclusion file as long as you need, or you can just specify multiple -X
parameters.
TIP
Running du
in a directory where several files are hard-linked to the same inode counts the size of the file only once. If you want to count each hard link separately for some reason, use the -l
parameter (lowercase L).
- Printing the Contents of a File with cat
- Changing Directories with cd
- Changing File Access Permissions with chmod
- Copying Files with cp
- Printing Disk Use with du
- Finding Files by Searching with find
- Searches for a String in Input with grep
- Paging Through Output with less
- Creating Links Between Files with ln
- Finding Files from an Index with locate
- Listing Files in the Current Directory with ls
- Reading Manual Pages with man
- Making Directories with mkdir
- Moving Files with mv
- Listing Processes with ps
- Deleting Files and Directories with rm
- Printing the Last Lines of a File with tail
- Printing Resource Usage with top
- Printing the Location of a Command with which
- Making Directories with mkdir
- Conventions used in this document
- Chapter 15. Graphical User Interfaces for Iptables
- Terms used in this document
- What NAT is used for and basic terms and expressions
- Раздел uses
- Using Double Quotes to Resolve Variables in Strings with Embedded Spaces
- User-land setup
- Compiling the user-land applications
- User specified chains
- User-land states
- Drawbacks with restore