Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a shell script which was written for Mac OSX and now ported to a linux machine. I don't have access to a linux machine currently( I will be setting up a virtual machine soon) Some statements in the shell script are failing, which is expected. I have a find command statement used for finding files sizes greater than 1MB:

oversize=`find "$somePath" -maxdepth 1 -size +1048576c -iname "*.gz" -print0 | xargs -0 ls -l | wc -l`    
oversize=$((oversize * 1))
if [ $oversize -eq 0 ];then
  echo "OK"
else  
  echo "Limit exceeded"

fi

Any idea if something is wrong with this statement ? It flagged a file whose size was 1045400 bytes

share|improve this question

I have a find command statement used for finding files sizes greater than 1MB:

For that use -size +1M

oversize=`find -maxdepth 2 -size +1M -exec ls -lh {} \; | wc -l`
oversize=$((oversize * 1))
echo size of oversize = $oversize
if [ $oversize -eq 0 ];then
  echo "OK"
else  
  echo "Limit exceeded"

fi

It 's giving the output

size of oversize = 96

Limit exceeded

That is true right?

update

See here for me its giving correct output

[max@localhost ~]$ find Downloads/ -maxdepth 1 -size +1048576c -name "*.pdf" -print0 | xargs -0 ls -l | wc -l
9
[max@localhost ~]$ find Downloads/ -maxdepth 1 -size +1048576c -name "*.pdf" -print0 | xargs -0 ls -l
-rw-rw-r-- 1 max max  1443224 Oct 11 17:04 Downloads/------.pdf
-rw-rw-r-- 1 max max  1330293 Sep 29 15:27 Downloads/-------.pdf
-rw-rw-r-- 1 max max 12825921 Oct  1 18:49 Downloads/--------.pdf
-rw-rw-r-- 1 max max  8197602 Sep 29 15:46 Downloads/--------.pdf
-rw-rw-r-- 1 max max  1604859 Oct 11 17:23 Downloads/------.pdf
-rw-rw-r-- 1 max max  2792931 Oct 24 11:27 Downloads/--------.pdf
-rw-rw-r-- 1 max max  5382152 Oct  9 14:52 Downloads/----------.pdf
-rw-rw-r-- 1 max max  1113609 Sep 29 15:46 Downloads/--------.pdf
-rw-rw-r-- 1 max max  9198710 Sep 29 15:40 Downloads/---------.pdf
share|improve this answer
    
I used your command and the script stared giving correct output. What's wrong with my implementation? – smokinguns Oct 25 '12 at 2:30
    
$somepath what path you are giving here? And what error you are getting? – max Oct 25 '12 at 4:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .