How to sort by size using the du command

The default options of the linux du command are not sorted according to the size of the disk.

If you want to display the results of du according to the disk usage size, you need to use the pipe and sort commands.

In the following example, we will use the du command to display the file and directory disk usage in the current directory, and then use the sort command through the pipeline to sort the results.

➜  ~ du -d 1 | sort -n -r
  • du -d 1 : Only the disk usage of the current level of directories and files is displayed
  • sort -n -r : Sort in reverse order according to value

Add a Comment

Your email address will not be published. Required fields are marked *