I am trying to write bash script wich can cleanup my whoole server from spam emails that already are present in my client's folders. I would need this script to do,

Check recursively directory /var/qmail/mailnames/* for array of keywords if files with keyword has been found go two levels up to and move files there.

I have started to write something like this, but it will not work as i need. First thing is that i get Argument list too log.

grep -lir 'discount' /var/qmail/mailanmes/* | xargs mv -t /var/qmail/

The problem is with your globbing pattern. /var/qmail/mailanmes/* expands to too long a command line. What you should do is:

find /var/qmail/mailnames -regex '.*discount.*' -print0 | xargs -0 mv -t /var/qmail

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.