Monday, 8 June 2020

Check if a file exists with wildcard in shell script

The simplest should be to rely on ls return value (it returns non-zero when the files do not exist):

if ls /path/to/your/files* 1> /dev/null 2>&1; then
    echo "files do exist"
else
    echo "files do not exist"
fi

No comments:

Post a Comment

How to check if a file contains a specific string using Bash

 In case if you want to check whether file does not contain a specific string, you can do it as follows. if ! grep -q SomeString "$File...