home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / docs / src / getfilesize < prev    next >
Text File  |  1997-01-24  |  829b  |  34 lines

  1. #!/bin/sh
  2. #
  3. # Print the size of a file in a "nice" way. Just call it with the name of
  4. # the file as parameter
  5. #
  6.  
  7. /bin/ls -l $1 | \
  8. gawk ' \
  9.     {                        \
  10.     size = $5;                \
  11.     if (size < 2000)                    \
  12.         print size " Bytes";            \
  13.     else if (size < 10000)              \
  14.     {                    \
  15.         size = int((size+51)*10/1024)/10;    \
  16.         print size " KB";               \
  17.     }                    \
  18.     else if (size < 100000)             \
  19.     {                    \
  20.         size = int((size+512)/1024);          \
  21.         print size " KB";               \
  22.     }                    \
  23.     else if (size < 10000000)           \
  24.     {                    \
  25.         size = int((size+51200)*10/(1024*1024))/10; \
  26.         print size " MB";               \
  27.     }                    \
  28.     else                    \
  29.     {                    \
  30.         size = int((size+512000)/(1024*1024));   \
  31.         print size " MB";               \
  32.     }                    \
  33. }'
  34.