Unix Blog

Monday, November 15, 2010

Check file existence

You check file existence using test command.

if test ! -s "dirname/filename"
then
 echo "File does not exist"
else
 echo "File exists"
fi

Here is the alternative way to check file existence. You can also check for multiple files

if [ -f dirname/filename1 ] && [ -f dirname/filename2 ]
then
 echo "File exists"
else
 echo "File does not exist"
fi

posted by Jayanthi Krishnamurthy @ 2:15 PM   0 Comments

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home

Newer›  ‹Older

About Me

Name: Jayanthi Krishnamurthy

View my complete profile

Posts

  • Check file existence

Older Posts Newer Posts

Archives

Subscribe to
Posts [Atom]