Shell Script – Check the existence of files which have common file name

Except checking whether the folder is empty or not, i would also like to know whether the *.log files are removed. Here is another example.

# Read a folder path from user input and check if
# there is any .log file

# Read the folder location
# "\c" means keep the cursor on the same line
echo "Please input the folder location: \c"
read _folder

# Quit if the folder does not exist
if [ ! -e $_folder ]; then
        echo 'Sorry, folder does not exist.'
        exit 1

# Check if the folder contains any .log files
if [ -z "$(find $_folder -name \*.log -print)" ]; then
        echo "$_folder does not have any log files"
        echo "$_folder contains log files"

Done =)

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.