Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix find average file size

Tags:

unix

size

People also ask

How do you find the average file size in Linux?

If you just need the average size in bytes, you can use find . -type f -exec stat -f%z {} +|awk '{s+=$0}END{print s/NR}' .

How do I check the size of a file in Unix?

don't worry we have a got a UNIX command to do that for you and command is "df" which displays the size of the file system in UNIX. You can run "df" UNIX command with the current directory or any specified directory.

How do you determine a file size?

Locate the file or folder whose size you would like to view. Click the file or folder. Press Command + I on your keyboard. A window opens and shows the size of the file or folder.

How do I check the size of a file in KB in Unix?

Using the ls Command –l – displays a list of files and directories in long format and shows the sizes in bytes. –h – scales file sizes and directory sizes into KB, MB, GB, or TB when the file or directory size is larger than 1024 bytes. –s – displays a list of the files and directories and shows the sizes in blocks.


I found something here:
http://vivekjain10.blogspot.com/2008/02/average-file-size-within-directory.html

To calculate the average file size within a directory on a Linux system, following command can be used:

ls -l | gawk '{sum += $5; n++;} END {print sum/n;}'

A short, general and recursion-friendly variation of Ernstsson's answer:

find ./ -ls | awk '{sum += $7; n++;} END {print sum/n;}'

Or, for example, if you want to impede files above 100 KB from stewing the average:

find ./ -size -100000c -ls | awk '{sum += $7; n++;} END {print sum/n;}'

Use wc -c * to get the size of all the files and ls | wc -l to get the number of files. Then just divide one by the other.


du -sh . # gives the total space used by the directory

find . -type f | wc -l # count the number of files

devide the first by the second. If you want a one liner, here it is:

echo $(( `du -sb | tr '.' ' '` / `find . -type f | wc -l` ))