Operating System - HP-UX
1855742 Members
7959 Online
104103 Solutions
New Discussion

file size zero - if condition !!

 
SOLVED
Go to solution
Whitehorse_1
Frequent Advisor

file size zero - if condition !!

admins,

how can I find files of size "zero" bytes using "if".,

if [ -? file1 ]; then
echo "This is a ZERO byte file"; fi

--WH
Reading is a good course medicine for deep sleep !!
5 REPLIES 5
Oviwan
Honored Contributor

Re: file size zero - if condition !!

Hey

check this: man test
-s file True if file exists and has a size greater than
zero.


Regards
Whitehorse_1
Frequent Advisor

Re: file size zero - if condition !!

Hi,,

I just require the opposite of wat you said, files with "ZERO size". "-s" finds non-zero files.

-- WH
Reading is a good course medicine for deep sleep !!
Dennis Handly
Acclaimed Contributor
Solution

Re: file size zero - if condition !!

>I just require the opposite of what you said

You reverse it with:
if [ ! -s file1 ]; then
OldSchool
Honored Contributor

Re: file size zero - if condition !!

Watch out for the "file doesn't exist gottcha when reversing the condition

! -s will PASS if

file *doesn't exist or file exist and is 0 bytes
Dennis Handly
Acclaimed Contributor

Re: file size zero - if condition !!

>OldSchool: Watch out for the "file doesn't exist gottcha

Ok:
if [ -f file1 -a ! -s file1 ]; then