Linux Sort du -h (human-readable) Output By Size

ht‮t‬ps://www.lautturi.com
Linux Sort du -h (human-readable) Output By Size

To sort the output of the "du -h" command by size in Linux, you can use the "sort" command and specify the "--human-numeric-sort" option. The "du -h" command displays the size of files and directories in a "human-readable" format, with units like "K", "M", "G", and "T" to indicate the size in kilobytes, megabytes, gigabytes, and terabytes, respectively. The "sort" command can sort the output of the "du -h" command based on the size of the files and directories.

To sort the output of the "du -h" command by size in Linux, follow these steps:

  1. Open a terminal window.

  2. Change to the directory you want to list the size of. For example:

cd /path/to/dir
  1. Use the "du -h" command to list the size of the files and directories in the current directory. For example:
du -h

This will display the size of the files and directories in a "human-readable" format.

  1. Pipe the output of the "du -h" command to the "sort" command and specify the "--human-numeric-sort" option. For example:
du -h | sort --human-numeric-sort

This will sort the output of the "du -h" command by size, with the largest files and directories appearing first.

With these steps, you should be able to sort the output of the "du -h" command by size in Linux. Consult the documentation of the "du" and "sort" commands for more information on these and other options.

Created Time:2017-10-30 10:17:38  Author:lautturi