user2648727
user2648727

Reputation:

Argument Too Long - Using RM and Wildcard

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.

Upvotes: 0

Views: 922

Answers (1)

Potter_nsit
Potter_nsit

Reputation: 96

you can use xargs and find:

for x in /home/*/mail/cur/
do
    find $x -type f 2>/dev/null | xargs rm -f 
done

Upvotes: 1

Related Questions