Re: How to remove empty maildir?
* Wu, Yue vano...@gmail.com [2009-09-24 09:24 +0800]: Thanks for all replies, mutt uses its own maildir so I have no issue about the two apps read/write the same maildirs at one time. I don't know sh, and I've tried the following sh script, but it doesn't work: #!/bin/sh DIR=~/temp/mails/* for d in ${DIR}; do if [ $(find d -type f | wc -l) -eq 0 ] ; then rm -r d fi done It says: y...@bsd ~ ./del_maildir.sh find: d: No such file or directory rm: d: No such file or directory y Without a '$' prefix, 'd' is interpreted as a string and not a variable. There are a few improvements I would make such as quoting variables and moving the glob (*) into the for statement. #! /bin/sh DIR=~/temp/mails for d in $DIR/* do if [ $(find $d -type f -print | wc -l) -eq 0 ] then rm -r $d fi done
Re: How to remove empty maildir?
* Wu, Yue on Thursday, September 24, 2009 at 09:24:35 +0800 On Wed, Sep 23, 2009 at 09:03:09AM -0500, Kyle Wheeler wrote: On Wednesday, September 23 at 09:45 PM, quoth Wu, Yue: The logic I need is: if maildir A has no mails(new/ tmp/ cur/ are empty) rm -r A endif Ahh. How about: if [ $(find A -type f | wc -l) -eq 0 ] ; then rm -r A rm -r $A fi Thanks for all replies, mutt uses its own maildir so I have no issue about the two apps read/write the same maildirs at one time. I don't know sh, and I've tried the following sh script, but it doesn't work: #!/bin/sh DIR=~/temp/mails/* for d in ${DIR}; do if [ $(find d -type f | wc -l) -eq 0 ] ; then rm -r d rm -r $d But I would be careful with rm while developing the script, perhaps do a echo $d first, to see what would be removed. fi done I also think this does not work with a nested hierarchy. Try this for a simple nested hierarchy: mailhier=~/temp/mails for md in `find $mailhier -type d \( -name cur -o -name new -o -name tmp -execdir pwd \; \) -prune`; do if [ `find $md -type f | wc -l` -eq 0 ]; then echo $md # rm -r $md fi done c -- \black\trash movie_C O W B O Y_ _C A N O E_ _C O M A_ Ein deutscher Western/A German Western --- http://www.blacktrash.org/underdogma/ccc.php
Re: How to remove empty maildir?
On Thu, Sep 24, 2009 at 08:26:53AM +0200, Christian Ebert wrote: * Wu, Yue on Thursday, September 24, 2009 at 09:24:35 +0800 I don't know sh, and I've tried the following sh script, but it doesn't work: #!/bin/sh DIR=~/temp/mails/* for d in ${DIR}; do if [ $(find d -type f | wc -l) -eq 0 ] ; then rm -r d rm -r $d But I would be careful with rm while developing the script, perhaps do a echo $d mutt owns the maildir at all, so I don't need to worry it :) first, to see what would be removed. fi done I also think this does not work with a nested hierarchy. Try this for a simple nested hierarchy: mailhier=~/temp/mails for md in `find $mailhier -type d \( -name cur -o -name new -o -name tmp -execdir pwd \; \) -prune`; do if [ `find $md -type f | wc -l` -eq 0 ]; then echo $md # rm -r $md fi done Thank you, I've take it down in my note for reference. James Michael's version seems more concise, so I will use that version :) -- Hi, Wu, Yue
Re: How to remove empty maildir?
On Thu, Sep 24, 2009 at 08:26:53AM +0200, Christian Ebert wrote: But I would be careful with rm while developing the script, perhaps do a echo $d I got some idea about handling the empty maildirs in mutt. Mutt should use some method to check if the maildir is empty or not, if so, then mutt can mask the empty ones automatically, so I can be away the no sense the boring empty maildirs and also don't need to worry about if the rmdir's solution is reliable or not. -- Hi, Wu, Yue
Re: How to remove empty maildir?
On 24-09-2009, at 09h 24'35, Wu, Yue wrote about Re: How to remove empty maildir? #!/bin/sh DIR=~/temp/mails/* for d in ${DIR}; do if [ $(find d -type f | wc -l) -eq 0 ] ; then rm -r d fi done #!/bin/sh DIR=~/temp/mails/* for d in ${DIR}; do if [ $(find $d -type f | wc -l) -eq 0 ] ; then rm -r $d fi done Ionel
Re: How to remove empty maildir?
On Thu, Sep 24, 2009 at 02:59:30PM +0800, Wu, Yue wrote: I got some idea about handling the empty maildirs in mutt. Mutt should use some method to check if the maildir is empty or not, if so, then mutt can mask the empty ones automatically, so I can be away the no sense the boring empty maildirs and also don't need to worry about if the rmdir's solution is reliable or not. I wonder where you got that idea from... ;-) http://www.mail-archive.com/mutt-users@mutt.org/msg39155.html -- Derek D. Martinhttp://www.pizzashack.org/ GPG Key ID: 0xDFBEAD02 -=-=-=-=- This message is posted from an invalid address. Replying to it will result in undeliverable mail due to spam prevention. Sorry for the inconvenience. pgpX2gBf6Jner.pgp Description: PGP signature
Re: How to remove empty maildir?
On Thu, Sep 24, 2009 at 11:57:38AM -0500, Derek Martin wrote: On Thu, Sep 24, 2009 at 02:59:30PM +0800, Wu, Yue wrote: I got some idea about handling the empty maildirs in mutt. Mutt should use some method to check if the maildir is empty or not, if so, then mutt can mask the empty ones automatically, so I can be away the no sense the boring empty maildirs and also don't need to worry about if the rmdir's solution is reliable or not. I wonder where you got that idea from... ;-) http://www.mail-archive.com/mutt-users@mutt.org/msg39155.html What a pity I can't reach the website... Could you show me the contents of archived mails please? -- Hi, Wu, Yue
How to remove empty maildir?
Hi, list, question is how to use some commands(i.g. shell commands) to remove the empty maildirs, i.e. no any file in maildirs' new/ cur/ and tmp/? -- Hi, Wu, Yue
Re: How to remove empty maildir?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 On Wednesday, September 23 at 08:16 PM, quoth Wu, Yue: Hi, list, question is how to use some commands(i.g. shell commands) to remove the empty maildirs, i.e. no any file in maildirs' new/ cur/ and tmp/? If you know it won't be re-created or delivered to while you're fussing with it, you can just use `rm -r maildirname` or even `rmdir maildirname/new maildirname/cur maildirname/tmp maildirname` ~Kyle - -- Science has proof without any certainty. Creationists have certainty without any proof. -- Ashley Montague -BEGIN PGP SIGNATURE- Comment: Thank you for using encryption! iQIcBAEBCAAGBQJKuiDeAAoJECuveozR/AWe3vUP/Rse15oRQ/ijWxXPoAGvFLZT HiBXQVbETRtzAMGnH7+HUSCdIZTTXeZU8P1iso1N1aThDMtahisgQXNVHejkVGGc GRb8nVGIbGXpLacQfsuWCDY/nzqXIBIkR4pYPkiKLm+898UNz/1bx0UTv7pC6Gn0 F62J2nDGvb02F42Xe6Of3uD4PbuaKwvwbWOqayqiicm3yAcWep+7yq0Z6+cUIQ1H 7JB++dP9TocVyVjFys9bvvEidsn24bPEzW0aZcp/o8JS8lKzHR0n6NxDkTRQ03sP 2b2bJqSz1dHZ3FsMo6uXT36Liv/tYArYi7senPCuHSO/snpfPstigJ3q+uWRv8vZ o2Ow1TEe6p/SKk+pWwRTWB9O/eKgkxHn2oWc9SZ2jCvBWgL6y6ZD91w2jh5HT4Yg aDvDrL/TGbZGC5PddC1MeBSmacqPOTuxQUSwXhX+F4yHRhh1X+F2nO539dy6RAet zXkVXYD/mPWs6ZEdTHB08ek0zzkKApzBEmivld6KlGGauJikLdN+ZxOoacX3GbAS IBMUmVz163bKZPu0CU3QZFbrhtUvIjhev+gwGWk2mMWxPZxTrFaH246Snq92hUkd Kw4jCJscxixuD1UB1PCzfpMJPUttP108/EqxMwAW/HZmfk5V8f9J+Ohn/wl6Sq/a zfCy7DDi7qpdDOhOn0Q+ =Z5eY -END PGP SIGNATURE-
Re: How to remove empty maildir?
On Wed, Sep 23, 2009 at 08:21:35AM -0500, Kyle Wheeler wrote: On Wednesday, September 23 at 08:16 PM, quoth Wu, Yue: Hi, list, question is how to use some commands(i.g. shell commands) to remove the empty maildirs, i.e. no any file in maildirs' new/ cur/ and tmp/? If you know it won't be re-created or delivered to while you're fussing with it, you can just use `rm -r maildirname` or even `rmdir maildirname/new maildirname/cur maildirname/tmp maildirname` Maybe I did not describe clearly. I'm sure them won't be re-created while I'm removing them. I just need a way to determine if a maildir is empty(it should has the empty new/ tmp/ cur/ respectively), then remove the empty maildir. `rm -r maildirname` doesn't help me to determine if the maildirname is empty. `rmdir maildirname/new maildirname/cur maildirname/new maildirname` isn't a rock way, because if one of a maildir's child dirs(new/ cur/ tmp) is lost, then mutt won't regonize the maildir mailboxes. The logic I need is: if maildir A has no mails(new/ tmp/ cur/ are empty) rm -r A endif -- Hi, Wu, Yue
Re: How to remove empty maildir?
On 23-09-2009, at 08h 21'35, Kyle Wheeler wrote about Re: How to remove empty maildir? On Wednesday, September 23 at 08:16 PM, quoth Wu, Yue: Hi, list, question is how to use some commands(i.g. shell commands) to remove the empty maildirs, i.e. no any file in maildirs' new/ cur/ and tmp/? If you know it won't be re-created or delivered to while you're fussing with it, you can just use `rm -r maildirname` or even `rmdir maildirname/new maildirname/cur maildirname/tmp maildirname` To remove all empty directories just type rm -rf `find -type d -empty` or find -type d -empty -exec \rm -fr {} \; at your (ba)sh prompt. Ionel
Re: How to remove empty maildir?
On Wed, Sep 23, 2009 at 09:45:47PM +0800, Wu, Yue wrote: The logic I need is: if maildir A has no mails(new/ tmp/ cur/ are empty) rm -r A endif From http://www.google.com/search?q=bash+test+empty+directory : http://www.cyberciti.biz/faq/linux-unix-shell-check-if-directory-empty/ -- Monte
Re: How to remove empty maildir?
On Wed, Sep 23, 2009 at 08:21:35AM -0500, Kyle Wheeler wrote: On Wednesday, September 23 at 08:16 PM, quoth Wu, Yue: Hi, list, question is how to use some commands(i.g. shell commands) to remove the empty maildirs, i.e. no any file in maildirs' new/ cur/ and tmp/? If you know it won't be re-created or delivered to while you're fussing with it, you can just use `rm -r maildirname` or even `rmdir maildirname/new maildirname/cur maildirname/tmp maildirname` That assumes you know its name, with maildir it's quite possible that it *won't* have the name you expect, it could well be a long name with the whole virtual directory/folder hierarchy prepended. -- Chris Green
Re: How to remove empty maildir?
On Wed, Sep 23, 2009 at 11:08:52AM -0300, Monte Stevens wrote: On Wed, Sep 23, 2009 at 09:45:47PM +0800, Wu, Yue wrote: The logic I need is: if maildir A has no mails(new/ tmp/ cur/ are empty) rm -r A endif From http://www.google.com/search?q=bash+test+empty+directory : http://www.cyberciti.biz/faq/linux-unix-shell-check-if-directory-empty/ There's no atomic way of checking if all three sub-directories are empty so, in the general case, some other process may come along and put something in one of the sub-directories after you have checked it but before you do the removal. OK, as long as you know no mail deliveries are going to happen you *can* check new/ tmp/ cur/ are empty and *then* remove the whole maildir. There is also, of course, the possibility that the hierarchy has maildirs within maildirs (is it allowed in 'classic' maildir?) and that adds a whole new set of problems and issues. It's easy with mbox! :-) -- Chris Green
Re: How to remove empty maildir?
On 23-09-2009, at 15h 21'53, Chris G wrote about Re: How to remove empty maildir? There's no atomic way of checking if all three sub-directories are empty so, in the general case, some other process may come along and put something in one of the sub-directories after you have checked it but before you do the removal. Not if you rename them before you do the check (not tested): for A in all-mailboxes ; do cd $A mv new new-$$ mv tmp tmp-$$ mv cur cur-$$ if [ `find ???-$$ -type f | wc -l` -eq '0' ]; then if [ -e new ] [ -e tmp ] [ -e cur ] ; then echo $A was empty but just right now some e-mail arrived. rmdir ???-$$ else echo $A is empty. rm -fr ../$A echo Ups, $A was empty! Now is gone... fi else echo $A has mail. mv new-$$ new mv tmp-$$ tmp mv cur-$$ cur fi done You can also turn off $sendmail when you do the check :-)) Ionel
Re: How to remove empty maildir?
On Wed, Sep 23, 2009 at 04:50:56PM +0200, Ionel Mugurel Ciobica wrote: On 23-09-2009, at 15h 21'53, Chris G wrote about Re: How to remove empty maildir? There's no atomic way of checking if all three sub-directories are empty so, in the general case, some other process may come along and put something in one of the sub-directories after you have checked it but before you do the removal. Not if you rename them before you do the check (not tested): The the 'other' application will either recreate them or fall in a heap, neither of which is particularly helpful. for A in all-mailboxes ; do cd $A mv new new-$$ mv tmp tmp-$$ mv cur cur-$$ if [ `find ???-$$ -type f | wc -l` -eq '0' ]; then if [ -e new ] [ -e tmp ] [ -e cur ] ; then echo $A was empty but just right now some e-mail arrived. rmdir ???-$$ else echo $A is empty. rm -fr ../$A echo Ups, $A was empty! Now is gone... fi else echo $A has mail. mv new-$$ new mv tmp-$$ tmp mv cur-$$ cur fi done You can also turn off $sendmail when you do the check :-)) I doubt if it's just sendmail you need to turn off. -- Chris Green
Re: How to remove empty maildir?
On Wed, Sep 23, 2009 at 09:03:09AM -0500, Kyle Wheeler wrote: On Wednesday, September 23 at 09:45 PM, quoth Wu, Yue: The logic I need is: if maildir A has no mails(new/ tmp/ cur/ are empty) rm -r A endif Ahh. How about: if [ $(find A -type f | wc -l) -eq 0 ] ; then rm -r A fi Thanks for all replies, mutt uses its own maildir so I have no issue about the two apps read/write the same maildirs at one time. I don't know sh, and I've tried the following sh script, but it doesn't work: #!/bin/sh DIR=~/temp/mails/* for d in ${DIR}; do if [ $(find d -type f | wc -l) -eq 0 ] ; then rm -r d fi done It says: y...@bsd ~ ./del_maildir.sh find: d: No such file or directory rm: d: No such file or directory y -- Hi, Wu, Yue