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

Displaying the grand total sum of disk usage

The -c option will calculate the total size used by files or directories, as well as display individual file sizes:

    $ du -c FILENAME1 FILENAME2..
    du -c process_log.sh pcpu.sh
    4  process_log.sh
    4  pcpu.sh
    8  total

Alternatively, use it like one of these:

    $ du  -c DIRECTORY
    $ du -c test/
    16  test/
    16  total

Or:

    $ du -c *.txt
    # Wildcards

The -c option can be used with options such as -a and -h to produce the usual output, with an extra line containing the total size.

The -s option (summarize), will print the grand total as the output. The -h flag can be used with it to print in a human-readable format:

    $ du -sh /usr/bin
    256M   /usr/bin
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