How to sort linux's 'du -sh' results by size
- User
How to sort linux's 'du -sh' results by size
Assistant
To sort the results of the
du -shcommand by size, you can use thesortcommand in combination withdu. Here's a step-by-step guide:- Use the
du -hs *command to display the size of all files in the current working directory. - Pipe the output of the
du -hs *command to thesort -hcommand to sort the files in ascending order according to their size.
The resulting command would be:
du -hs * | sort -hThis command will display the files in the current working directory sorted by size, with the smallest files appearing first. If you want to reverse the sorting order, you can use the
-rflag with thesortcommand:du -hs * | sort -hrThis command will display the files sorted by size, with the largest files appearing first.
- Use the
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.