How to sort linux's 'du -sh' results by size
- User
How to sort linux's 'du -sh' results by size
Assistant
The
ducommand in Linux does not have a built-in option to sort the results by size. However, you can use thesortcommand to sort the output ofdu -shby size.Here's an example of how to do it:
codedu -sh * | sort -n -k 1This will sort the output of
du -shby the first column (the size of each file or directory), in numerical order (from smallest to largest).The
-noption tellssortto use numerical values for sorting, and the-k 1option tells it to sort based on the first column.You can also use the
-hoption withsortto make it display the output in a more human-readable format, like this:codedu -sh * | sort -n -k 1 -hThis will sort the output of
du -shby size, and display the output in a more human-readable format, with the largest file or directory at the top.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.