1

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

0

1 Answer 1

1

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 
2
  • I used your command and the script stared giving correct output. What's wrong with my implementation? Commented Oct 25, 2012 at 2:30
  • $somepath what path you are giving here? And what error you are getting? Commented Oct 25, 2012 at 4:57

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.