I am interested in finding n biggest subdirectories (eg. 3) in my current directory AND THEN listing all the files from them. I am not interested in finding biggest files. I know there are a lot of solutions for finding biggest files and that's not what I want.
I have found my 3 biggest subdirectories with line:
$ du -hs */ | sort -rh | head -3
with result:
212K 04/
52K 02/
20K 03/
but somehow I am not able to list files from these directories (piping with ls did't work). Any suggestions how to do that?
Best Answer
You can use the results of your piped commands with a while loop:
As a one liner:
Thanks to steeldriver for suggesting the use of
read
in awhile
loop over afor
loop usingawk
, to handle filenames with spaces and special characters in a more robust manner.