Computing.Net > Forums > Unix > file size check

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.

file size check

Reply to Message Icon

Name: Aki
Date: September 22, 2003 at 03:46:27 Pacific
OS: solaris
CPU/Ram: 320
Comment:

Hi,
Can some one please tell me how can I compare size of the file. I am currently reading file, size and du utilites. But I am not sure how to go about it. I want to compare a file size to check whether it is an empty file, if it is then I want to take up some action. Can some one please tell me which is the way to go.
Thanks.
Aki



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: September 22, 2003 at 05:19:03 Pacific
Reply:

if [ -f filename -a ! -s filename ] ; then
echo "The file exists and is empty"
fi

or

if [ -f filename -a `ls -l filename | awk '{ print $5 }' -eq 0 ] ; then


0

Response Number 2
Name: David Perry
Date: September 22, 2003 at 05:20:09 Pacific
Reply:

Sorry. I missed the closing back tick. This should have been:

if [ -f filename -a `ls -l filename | awk '{ print $5 }'` -eq 0 ] ; then


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: file size check

Comparing file sizes in korn script www.computing.net/answers/unix/comparing-file-sizes-in-korn-script/2776.html

FTP File Size Problem from UNIX to www.computing.net/answers/unix/ftp-file-size-problem-from-unix-to/4240.html

matching file sizes ? www.computing.net/answers/unix/matching-file-sizes-/3485.html