I am trying to write a shell script but I only want it to run if there are no files with a specific name found on the server. I know how to check for a specif file which would be done like this:
if [ -f /path/to/file ]
then
echo The file already exists
else
touch /path/to/file
fi
The above requires that I know the path to the file however. The script I am creating is supposed to search the server to see if a file with that name already exists and if it doesn't, run the commands and preferably, if the file does exist, display it's location but I can't figure out how this would be done.
I can use find to specify the file like so:
find / -name "filename"
Which either comes up with results or nothing, which is expected. What I want to happen is if find has no results then I want it to run a command and if it does have results, display those results. Here's some pseudo code of what I want it to do:
if [ find / -name "filename" > 0 ]
then
echo The file already exists at (location)
else
create the file
fi
Hopefully that makes sense.