find and delete files matching a regex pattern
On my servers, i create alot of js and css files that are automatically generated as caches. They become obsolete as often as the codebase changes (which is very often), so finding and deleting them all every so often is a good idea. They all conform to the same pattern:
- they are all in folders called "raw"
- they all either have a .js and a .css extension
- Their names are md5() hashes of their contents.
This command lists the files:
find -L /var/www/domains/ -regextype posix-extended -iregex '.*/raw/[a-f0-9]{32}\.(js|css)'
Print the number of matches
find -L /var/www/domains/ -regextype posix-extended -iregex '.*/raw/[a-f0-9]{32}\.(js|css)' | wc -l
delete them:
find -L /var/www/domains/ -regextype posix-extended -iregex '.*/raw/[a-f0-9]{32}\.(js|css)' -delete
Written by Sean Macdonald
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#