Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File size not trapped using bourne shell

Status
Not open for further replies.

myindi

Technical User
May 29, 2003
3
AU
Hi Gurus,


I have been having trouble finding where I'm wrong.

Problem:

I'm trying list all files exceeding 1.5G everything works fine if I move to bash, but I want to get this to work on bourne shell.

/twork > ls -al
total 12908196
drwxr-xr-x 2 root other 512 May 29 16:20 .
drwxr-xr-x 3 root other 512 May 29 12:43 ..
-rw-r--r-- 1 root other 3302859316 May 29 11:31 a
-rw-r--r-- 1 root other 1992294400 May 29 13:52 b
-rw-r--r-- 1 root other 1310564916 May 29 13:55 c
/work > ls -al|grep -v "^total"|grep -v "d"|awk '{print $5, $9}'|while read si fi
> do
> if [ $si -gt 1500000000 ]
> then
> echo $si size $fi file
> fi
> done
1992294400 size b file
< I expect file &quot;a&quot; to appear in the output ???? >

This is very simple straight forward but it doesn't trap the file &quot;a&quot;. It traps only file &quot;b&quot;.

Workaround:

When I change my shell to bash it works fine but I would like to stick to bourne shell.
/twork > bash
/twork> ls -al|grep -v &quot;^total&quot;|grep -v &quot;d&quot;|awk '{print $5, $9}'|while read si fi
> do
> if [ $si -gt 1500000000 ]
> then
> echo $si size $fi file
> fi
> done
3302859316 size b file
1992294400 size a file
/twork >

I have tried the following but none of the changes trappped file a.
if [ $si -gt 1500000000 ]
if [ &quot;${si} -gt 1500000000 ]


I appreciate any assistance.

Thanks






 
Your script seems to work OK for me if I replace the &quot;d&quot; in the first line with &quot;^d&quot; to only exclude directories and not any filename containing a d. Is this the problem, or are your files really called a and b? Cheers.
 
Thanks for your prompt reply.

My problem is when I use bourne shell the script won't detect the files exceeding 2G under my if statement.

When I use bash it works fine.

This is a long script and the rest coded using bourne shell & I'm compelled to stick to bourne shell.

 
Sorry, I haven't been able to replicate this problem on my Solaris system. What OS are you using, perhaps it's a limitation of ls for largefiles in bourne on it? Anyone else out there got any ideas?
 
You could do this ?

#!/bin/sh
find . -type f -ls | awk '!$7<1500000000'



Checkout: man find for description of -ls
Note: you may need to play with the values

Good Luck
Laurie.
 
or use the size options with the find command.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top