Home > front end >  Bash script ,which puts all the files in order of size
Bash script ,which puts all the files in order of size

Time:09-02

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  ; } ; }'

CodePudding user response:

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.

  • Related