How to check existence of a file using shell script?

Discussions related with hosting control panels used, which include cPanel, Plesk, Directadmin etc..

Moderator: Staff

Post Reply
jeniffer
Posts: 0
Joined: Wed Sep 21, 2016 3:23 pm

How to check existence of a file using shell script?

Post by jeniffer »

How to check existence of a file using shell script? How to check whether a file exists on the server


Martin
Posts: 36
Joined: Fri Sep 16, 2016 10:34 am

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

Post 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


Ashlin
Posts: 0
Joined: Fri Sep 16, 2016 10:10 am

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

Post by Ashlin »

thanks for this


If you are looking for assistance in server management, please get in touch with our support.
Post Reply