I am new to UNIX and have a doubt about file size in UNIX (AIX). ls -ltr shows me fileA size as 59096. As per my knowledge this is in bytes ,so it is nearly = 0.06 MB However, a script which should zip files greater than 1MB, also zips this file:

find [dir] -type f -size +1M -exec gzip {} \;

Based on my testing it evaluates the same fileA size to be 115 MB and hence compresses the file.

Can some one please help. My aim is to zip all files above 1 MB.

  • 3
    What testing did you perform that gave you a file size of 115 MB? Also, what does 'ls -lh fileA' return? – schaiba Feb 15 '13 at 19:53
  • The find command should work. For me it lists only the files that are 1MiB + 1 Byte (1048577 bytes) or larger. – frostschutz Feb 15 '13 at 23:39
  • Need further details: Exact environment (distribution, version), programs involved? Everything up to date? – vonbrand Feb 16 '13 at 2:10
  • 1
    Are you sure you did "+1M" ? If you did "1M" instead it would find all the files sized 1B to 1M – Jasen Feb 16 '13 at 4:39
  • ls -lh is not supported. I get an error saying flag 'h' not found. To test i had four files, with the above code all 4 were listed. i changed my script from +1M to +100M and then +110M, all 4 were yet zipped. Around +115M the smallest file was not zipped and all other 3 were zipped. – Bhavna Feb 16 '13 at 4:43

AIX's find doesn't appear to support +1M.

From the man page,

-size n

Evaluates to the value True if the file is the specified n of blocks long (512 bytes per block). The file size is rounded up to the nearest block for comparison.

-size nc

Evaluates to the value True if the file is exactly the specified n of bytes long. Adding c to the end of the n variable indicates that the size of the file is measured in individual bytes not blocks.

You should be able to use,

find [dir] -type f -size +1048575c -exec gzip {} \;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.