Page 1 of 1

How to check existence of a file using shell script?

Posted: Sat Jan 21, 2017 4:26 am
by jeniffer
How to check existence of a file using shell script? How to check whether a file exists on the server

Re: How to check existence of a file using shell script?

Posted: Sat Jan 21, 2017 4:35 am
by Martin
Example : the below script will check the file /etc/redhat-release and output whether it exists or not.

#!/bin/bash

if [ -f /etc/redhat-release ]
then
echo "file exists"
else
echo"file doesn't exist"
fi


------------------------------
Martin N
Linux Support Engineer.
Nixtree Solutions
Managed Full Server Backups
https://www.nixtree.com/managed-backups.php
Follow us on : https://twitter.com/nixtree

Re: How to check existence of a file using shell script?

Posted: Tue Jan 24, 2017 10:40 am
by Ashlin
thanks for this