how to match then delete files with regex through commandline?
matched files have 4 digits then .tmp eg
something0001.tmp
something-else-0090.tmp
something-6548.tmp
but not
something001.tmp
somethingelse99.tmp
tried various versions of
find . -type f -regex '.*\d{4}.tmp' -exec rm -rf {} \;
RegExr testing ok for matches, but ssh syntax is eluding me and am sure the regex is at fault.
find is using by default Emacs syntax of regex. This means that there is nothing like \d or {4}. You if you want to achieve this result, you need to use (also escape the second dot .).
find . -type f -regex '.*[0-9][0-9][0-9][0-9]\.tmp' -exec rm -rf {} \;
or use different -regextype option which supports your regex syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With