How to Compare Directory Size Using find and du Commands?

Viewed 23

find -name "test*" | xargs du

I'm pretty new to bash scripting, but I need to essentially find a list of directories, with similar directory names (test1,test2,test3,etc.), with an arbitrary number them, and then find the largest of the few and remove the rest. I'm struggling to come up with a solution as to how to pipe the command I listed above into something that can determine the largest file by looking at the size and then returning the file name to be removed. I so far am able to display the directories I'm looking for and their sizes, I'm just unsure how to complete the final half of what I need to do so any advice would be of great help!

0 Answers
Related