Книга: 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).

Оглавление книги


Генерация: 6.807. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз