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

Finding the ten largest size files from a given directory

Combine the du and sort commands to find large files that should be deleted or moved:

    $ du -ak SOURCE_DIR | sort -nrk 1 | head

The -a option makes du display the size of all the files and directories in the SOURCE_DIR. The first column of the output is the size. The -k option causes it to be displayed in kilobytes. The second column contains the file or folder name.

The -n option to sort performs a numerical sort. The -1 option specifies column 1 and the -r option reverses the sort order. The head command extracts the first ten lines from the output:

    $ du -ak /home/slynux | sort -nrk 1 | head -n 4
    50220 /home/slynux
    43296 /home/slynux/.mozilla
 43284 /home/slynux/.mozilla/firefox ...
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