Skip to Content
Linux Shell Scripting Cookbook - Third Edition
book

Linux Shell Scripting Cookbook - Third Edition

by Clif Flynt, Sarath Lakshman, Shantanu Tushar
May 2017
Beginner
552 pages
28h 47m
English
Packt Publishing
Content preview from Linux Shell Scripting Cookbook - Third Edition

How to do it...

To find the disk space used by a file (or files), use the following command:

    $ du  FILENAME1 FILENAME2 ..

Consider this example:

    $ du file.txt

To obtain the disk usage for all files inside a directory, along with the individual disk usage for each file shown in each line, use this command:

    $ du -a DIRECTORY

The -a option outputs results for all files in the specified directory or directories recursively.

Running du DIRECTORY will output a similar result, but it will show only the size consumed by subdirectories. However, this does not show the disk usage for each of the files. For printing the disk usage by files, -a is mandatory.

Consider this example:

    $  du -a test
    4  test/output.txt
    4  test/process_log.sh
 4 test/pcpu.sh ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Linux Shell Scripting - Second Edition

Mastering Linux Shell Scripting - Second Edition

Mokhtar Ebrahim, Andrew Mallett

Publisher Resources

ISBN: 9781785881985