1748119 Members
3373 Online
108758 Solutions
New Discussion

scripting question -

 
rveri-admin
Frequent Advisor

scripting question -

Hi ,

 

I am trying to check if files are present  inside the directory or not,  but getting error,  not sure if the syntax is correct,

 

 

if [ -f /home/myfiles/* ]
then
echo "files found "
else
echo "files not found"

##########################

 

 

can you guys advise, whats wrong  

Thanks,

 

 

 

3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: scripting question (empty directory)

-f only works on one file at a time.  You need to use something like:

if [ ! -z $( ls /home/myfiles 2> /dev/null ) ]; then

   echo "files found"

rveri-admin
Frequent Advisor

Re: scripting question -

Dennis,

Thanks,

what is the -z is stands for. is it checking for zero byte,

 

 

 

 

 

Dennis Handly
Acclaimed Contributor

Re: scripting question (empty directory)

>what is the -z is stands for. Is it checking for zero byte,

 

You can look at the man ages for test(1), ksh(1) or sh-posix(1).

This is if the string has zero length and "! -z" means not empty.