6

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?

9

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)

  • Wouldn't it be section*-*.html so they can continue to delete the section2* and so on files as well? – Terrance Jul 12 at 14:09
  • 1
    @Terrance The OP wants the effect that running rm section1-*.html would have if the shell were able to pass such a long argument list to an external command. – Eliah Kagan Jul 12 at 14:14
  • @Terrance I see what you mean. I think they mentioned that to clarify that there were other files in the directory that should not be deleted, or perhaps because they may sometimes want to delete files associated with a specific other section. But it may be that they really do want to delete all the sections, and had tried matching just the section 1 files with the hope that the argument list would be short enough for the command to succeed. – Eliah Kagan Jul 12 at 14:22
  • 1
    @EliahKagan hopefully once the OP understands what the issue is and how to address it, they can decide themselves how "wild" they want to go with the wildcard matching. – steeldriver Jul 12 at 14:42
  • @EliahKagan That makes sense and I see what you mean. Sometimes trying to think logically this early in the morning for me hurts my brain. =) – Terrance Jul 12 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.