Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

file size check

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 10-19-2005
vino's Unix or Linux Image
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 12 March 2015, 5:33 AM EDT
Location: Sydney, Down Under
Posts: 2,848
Thanks: 0
Thanked 13 Times in 13 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 Unix and Linux 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 10:37 PM.