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 longI tried using findfind /home/*/mail/new/ -mindepth 1 -deleteBut 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 thisfor f in /home/*/mail/new/*.*~; do        # if it is a file, delete it    if [  -f $f ]    then        rm $f    fidonePlease 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.
Remove everything within directory using for loop
files;directory;for;loop device;dot files
The problem is that /home/*/mail/new/* expands to too many file names. The simplest solution is to delete the directory instead:rm -rf /home/*/mail/new/Alternatively, use your find command. It should work, it will just be slower. Or, if you need the new directories use a loop to find them, delete and recreate them:for d in /home/*/mail/new/; do    rm -rf $d && mkdir $ddoneThe loop you were trying to write (but don't use this, it is very slow and inefficient) is something like:for f in /home/*/mail/new/* /home/*/mail/new/.*; do    rm -rf $fdoneNo need to test for files if you want to delete everything, just use rm -rf and both directories and files can be deleted by the same command. It will complain about not being ab;e to delete . and .. but you can ignore that. Or, if you want to be super clean and avoid the errors, you can do this in bash:shopt -s dotglobfor f in /home/*/mail/new/*; do        rm -rf $fdone