bash script: find and remove files

This bash script will find all the files matching the pattern *foo.txt.

#!/usr/bin/bash
for f in $(find -type f -name '*foo.txt')
do
    echo "removing ${f}."
    rm "${f}"
done

Use -iname for case-insensitive, which will even match hidden files (files with a leading dot).
The -type f means only find regular files.

Tags: ,

Leave a Reply