Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
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

1 Answer 1

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 {} \;

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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