file size check | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

file size check

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-18-2005
malaymaru malaymaru is offline
Registered User
 
Join Date: May 2005
Last Activity: 28 April 2008, 7:23 AM EDT
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old 10-19-2005
vino's Avatar
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 9 April 2013, 8:19 AM EDT
Location: Sydney, Down Under
Posts: 2,847
Thanks: 0
Thanked 12 Times in 12 Posts
-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
Sponsored Links
    #3  
Old 10-19-2005
malaymaru malaymaru is offline
Registered User
 
Join Date: May 2005
Last Activity: 28 April 2008, 7:23 AM EDT
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Hammer & Screwdriver

Thanks for your help vino.

malay
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
check the file size sandy1028 Shell Programming and Scripting 1 11-11-2010 06:16 AM
Check the file size - help sithara Shell Programming and Scripting 5 06-10-2010 10:52 AM
Check for file size is zero or not. Hangman2 Shell Programming and Scripting 3 04-14-2009 04:08 PM
How to check the file size in a dir bsathishmca Shell Programming and Scripting 6 10-02-2008 10:26 AM
Check file size alnita UNIX for Dummies Questions & Answers 6 06-20-2005 02:34 PM



All times are GMT -4. The time now is 01:56 AM.