'rm' (delete) thousands of files selectively
I created a cache system in my web server which stores the HTML files of each webpage, instead of dynamic producing them. As a consequence, I have 50,000+ files within a directory in a Linux server. They are labelled: section1-xxx.html
, section2-xxx.html
, and so on.
Now, I have problems when I try to selectively delete some of them. When I run rm section1-*.html
, the shell warns me that they are too many files. Any tip to manage to delete them?
Solution 1:
Either
find . -maxdepth 1 -name 'section1-*.html' -delete
(test it first with -print
in place of -delete
) or
printf '%s\0' ./section1-*.html | xargs -r0 rm
(test it first with echo
in place of rm
)