Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort du -h output? [closed]

Tags:

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?

like image 292
Pablo Avatar asked Mar 01 '12 03:03

Pablo


People also ask

How do you sort du command output?

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.

What units does du output?

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.

How does the du command work?

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.

What does the du command do it shows the disk file size it shows disk usage it shows the details of the currently logged in user none of these?

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.


1 Answers

Have you tried sort -h -r instead? My Linux is RHEL 6.1. sort version 8.4.

like image 145
Crend King Avatar answered Sep 21 '22 07:09

Crend King