Unix questions - Testing file size and file exist?

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > March 2005 > Testing file size and file exist?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Testing file size and file exist?
Matt Benson

2005-03-16, 6:02 pm

I want to perform a couple of statements if either the file does not exist OR the file size of a given file
is equal 0. Currently the best solution I can imagine is something like:


if [! -e myfile.dat ]; then
echo "File not existing or file size = 0"
do_something
else
filesize=`wc -c myfile.dat`
echo "filesize=$filesize"
if [ $filesize = 0 ]; then
echo "File not existing or file size = 0"
do_something
fi
fi

The first problem I encounter is that the back ticks are NOT recognized by the shell interpreter.
filesize contains blank after the wc command. Why?

Is there a filesize testing without back quotes instructions?

Secondly, I feel that there is a (much) shorter way of doing this.
Has someone a better idea?

Thx
Matt

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com