I am trying to remove large amount of mails (mostly mail delivery failed) from my server using
rm -rf /home/*/mail/new/*
And I am getting -bash: /usr/bin/rm: Argument list too long
I tried using find
find /home/*/mail/new/ -mindepth 1 -delete
But after 20 minutes it looks like it's not doing anything.
How do I use for loop to delete everything (directories, files, dotfiles) within /home/*/mail/new/
Something like this
for f in /home/*/mail/new/*.*~; do
# if it is a file, delete it
if [ -f $f ]
then
rm "$f"
fi
done
Please help me rewrite this command to delete files AND folders and everything within /home/*/mail/new/
EDIT: My question is unique because it's about doing that in FOR loop.
find
command looks fine. If you want to show what it's, doing use-print -delete
– jordanm Feb 28 '17 at 19:47for
has better performance than find. – Luka Feb 28 '17 at 19:50find
should be orders of magnitude faster. – terdon Feb 28 '17 at 19:56for d in /home/*; do rm -rf "/home/$d/mail/....
and even sections of filenames from there. – Jeff Schaller Feb 28 '17 at 20:55