Computing.Net > Forums > Unix > Comparing file sizes in korn script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Comparing file sizes in korn script

Reply to Message Icon

Name: Ian
Date: January 17, 2002 at 09:52:03 Pacific
Comment:

I'm trying to write a shell script to monitor certain files and display a warning when they reach a certain size. The idea being to give a warning BEFORE the ulimit is hit! I've fallen at the first hurdle however, how can you RELIABLY get JUST the file size? I'm trying variations along the following lines:

ls -l filename|cut -d" " -f5

However on my Unixware 2.1.3 (and on 7) system the cut seems to give different results depending on the file listed. Presumably there are different numbers of spaces in the resulting line?

My other option is to use "cut -c35-41". However, being really pedantic, I'd like the script not to be platform specific so I can't rely on the character positions.

Any ideas?



Sponsored Link
Ads by Google

Response Number 1
Name: wpatte
Date: January 17, 2002 at 10:49:17 Pacific
Reply:

Try this ....

ls -l "filename" | awk '{print $5}'


0

Response Number 2
Name: James Boothe
Date: January 17, 2002 at 12:11:26 Pacific
Reply:

Correct on the varying number of spaces. The cut command is using each space as a field delimiter, so a bunch of spaces makes for a bunch of null fields.

By default, awk delimites each field with any amount of whitespace. I check a directory for large files with:

ls -l | awk '$5>999999'

And the read command uses whitespace, by default, as its delimiter:

ls -l fname | read x x x x fsize remainder
echo $fsize


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Comparing file sizes in korn script

Array size in shell script? www.computing.net/answers/unix/array-size-in-shell-script/5761.html

Changing shell in Korn script www.computing.net/answers/unix/changing-shell-in-korn-script/4747.html

Compare two variables in shell script www.computing.net/answers/unix/compare-two-variables-in-shell-script-/3611.html