0

I want to empty a folder called 'cur' across all accounts on my server. Which is setup with this format. I want cur to remain.

/home/ACCNAME/mail/cur/*

After trying to empty a single folder manually using

rm -f /home/ACCNAME/mail/cur/*

and being presented with 'Argument too long. I can be sure I cannot run this using wildcards across all accounts.

How would I do this process, if I wanted to use wildcard to repeat this process across all accounts

like this (but without Argument too long error)

rm -f /home/*/mail/cur*

Would something like that work?

Or does the first asterisk match everything after it, so in essence it would remove the entire home folder.

  • possible duplicate of [Argument list too long error for rm, cp, mv commands](http://stackoverflow.com/questions/11289551/argument-list-too-long-error-for-rm-cp-mv-commands) – Dana the Sane Jan 27 '15 at 03:05

1 Answers1

1

you can use xargs and find:

for x in /home/*/mail/cur/
do
    find $x -type f 2>/dev/null | xargs rm -f 
done
Rustam Gasanov
  • 15,290
  • 8
  • 59
  • 72
  • Since this is Linux and will have GNU `find` and `xargs`, you might prefer to use `-print0` with `find` and `-0` with `xargs`. Or you could avoid `xargs` altogether with `find "$x" -type f -exec rm -f {} +` or even `find "$x" -type f -delete`. All three mechanisms will handle any arbitrary file names. – Jonathan Leffler Jan 27 '15 at 04:05