Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Bash script ,which puts all the files in order of size

I need help with a bash script. The problem is that I want to sort all the files in order of size, but I only need files, not folders,and to show me their size as well.
I have this code but folders also appear:

read -p "Enter the size of the top: " MARIMETOP
du  -a | sort -n -r | head -n $MARIMETOP | /usr/bin/awk 'BEGIN{ pref[1]="K";  pref[2]="M"; pref[3]="G";} { total = total + $1; x = $1; y = 1; while( x  > 1024 ) { x = (x + 1023)/1024; y++; }  printf("%g%s\t%s\n",int(x*10)/10,pref[y],$2); } END { y = 1; while(  total > 1024 ) { total = (total + 1023)/1024; y++; } ; }'

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This will print all regular files in the current directory and subdirectories sorted by size:

find . -type f -print0 | xargs -0 -n100000 ls -Sl

With the -n100000 flag this will handle at most 100000 files found by find.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading