Operating System - HP-UX
1826340 Members
4721 Online
109692 Solutions
New Discussion

How do I check whether a file exists using Shell Script ?

 
SOLVED
Go to solution
Praveen Hari
Advisor

How do I check whether a file exists using Shell Script ?

How do I check whether a file exists in current directory and in a particular directory ?
e.g.
I like to see whether a file called a.txt exists in current directory ?
I like to see whether a file called a.txt exists in ..\temp directory ?

Thanks
1 REPLY 1
Steven E. Protter
Exalted Contributor
Solution

Re: How do I check whether a file exists using Shell Script ?

if [ -f $file]
then
#take action because the file exists
fi

-s if the file is bigger than 0 bytes
-r if the file is readable
-w if the file is writable
-x if the file is executable

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com