shell script to check if file is present or not in a directory

Open your favorite editor and create a script as below,


#get the name of file to check if its present or not in pwd

if [ ! -f $FILE_TO_CHECK ]
echo "file $FILE_TO_CHECK does not exits"
echo "file $FILE_TO_CHECK is present"

Now, lets say you want to search myfile.pdf in a big list of files in a directory, then cd to that directory, copy this script there, and run the script as,

 $ bash myfile.pdf 

Leave a Comment