Linux Check File Exist or not – Shell Script

The following script used to check the specified file present or not in shell script

#!/bin/bash
#########################################################################################
# This Shell script used to find the specificed
file exixts or not on particular location #########################################################################################

filePath="/home/file-path"
fileName="$filePath/filename.txt"
if [ -f "$fileName" ]
then
echo "$fileName found"
else
echo "$fileName not found"
fi

To check multiple file on same if condtion

filePath="/home/file-path"
fileName="$filePath/filename.txt"
fileName2="$filePath/filename2.txt"
if [ -f "$fileName" ] && [ -f "$fileName2" ]
then
echo "$fileName found"
else
echo "$fileName not found"
fi

Advertisements

About Lekshmana Perumal M

Proud be an Indian, passion to teaching & learn, love mathematics, enjoy with family & friends, job to code. Care about child education, Indian culture
This entry was posted in linux and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s