du --max-depth=1 -h /media/downloads/ | sort -g -r
This will not ofcourse sort regarding G, M, K suffixes... Is there any way to solve it as one-line bash command?
Using the du and sort Commands We can use du and sort commands to list and sort files according to their size: $ du -ah --max-depth=1 | sort -h 451M ./dir2 751M ./dir1 1.2G ./file4.
Usage notes du computes file space in units of 512 bytes. The actual disk space that is used by files and directories might be more, since some systems allocate space in units of some multiple of a sector. On UNIX System V, it is usually two sectors; on UNIX Version 7, it is one sector.
The du command is a standard Linux/Unix command that allows a user to gain disk usage information quickly. It is best applied to specific directories and allows many variations for customizing the output to meet your needs. As with most commands, the user can take advantage of many options or flags.
As you are dealing with LINUX, there exists a command line utility for this also which is du command that estimates and displays the disk space used by files. So, in simple words du command-line utility helps you to find out the disk usage of set of files or a directory.
Have you tried sort -h -r
instead? My Linux is RHEL 6.1. sort
version 8.4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With