The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unix script to check whether particular file exists and to find its size Balachandar Shell Programming and Scripting 9 02-04-2008 11:56 PM
Check backup file size on backup tape ayhanne UNIX for Dummies Questions & Answers 0 10-25-2007 08:41 AM
Perl FTP - check file size rahulrathod Shell Programming and Scripting 1 02-20-2007 06:21 AM
Check file size and remove files srivsn Shell Programming and Scripting 1 04-12-2006 10:53 PM
Check file size alnita UNIX for Dummies Questions & Answers 6 06-20-2005 11:34 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-18-2005
Registered User
 

Join Date: May 2005
Posts: 54
file size check

How can I perform size check of any character file(which switch)?
For example: I have to perform certain actions if file size is not zero. How can I do that?

Is this syntax fine?

if test ! -z $filename
then

fi
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-18-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,639
-z $filename checks whether the string contained in the variable $filename is of length zero or not.

If you understand string functions in c/c++, -z $filename is the same is as the function if (strlen(filename) == 0)

To check whether the file has a size greater than 0, use the construct
Code:
[ -s "$filename" ]
vino
Reply With Quote
  #3 (permalink)  
Old 10-18-2005
Registered User
 

Join Date: May 2005
Posts: 54
Wink

Thanks for your help vino.

malay
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0