Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
04-26-2006, 11:17 AM
|
#1
|
LQ Newbie
Registered: Apr 2006
Posts: 4
Rep:
|
Delete files in /var/spool/mqueue
RedHat 7.3
./spool/mqueue is 2.9 GB and the root parition is 100% full. In order to recover space until I can get to the root cause of the problem I want to delete the files in mqueue. I've stopped Sendmail and tried rm -rf * . . . which give the following error: bash:/bin/rm: Argument list too long. What steps should I take?
|
|
|
04-26-2006, 11:30 AM
|
#2
|
Senior Member
Registered: Feb 2004
Location: England
Distribution: Slackware 14.2
Posts: 1,492
Rep:
|
why are you using 3 dots (...)?
i would cd to the directory then type rm -rf *.
make sure you're in the correct directory though!
i.e not "/"
|
|
|
04-26-2006, 12:25 PM
|
#3
|
LQ Newbie
Registered: Apr 2006
Posts: 4
Original Poster
Rep:
|
cd var/spool/mqueue
rm -rf *
This did not work. Still giving error: bash:/bin/rm: Argument list too long message. Additionl suggestions would be appreciated.
|
|
|
04-26-2006, 12:58 PM
|
#4
|
Senior Member
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,508
Rep:
|
There are too many files on mqueue !
Go to a directory below and remove mqueue (rm -rf mqueue).
Before that, take note owner/permissions of mqueue (ls -ld mqueue) to be able to re-create it with the same permissions (chown, chmod).
Last edited by marozsas; 04-26-2006 at 01:24 PM.
|
|
|
04-27-2006, 07:17 AM
|
#5
|
LQ Newbie
Registered: Apr 2006
Posts: 5
Rep:
|
delete files at /var/spool/queue
try >/var/spool/mqueue
U might need to have permissions to do this.
Check if u have sudo access
|
|
|
02-01-2011, 08:05 PM
|
#6
|
LQ Newbie
Registered: Feb 2011
Posts: 1
Rep:
|
Too many files to handle that way
Although this question is an old one, this info may be handy for someone having the same issue;
The error message is happening because when the wildcard * is used with a command, Linux will go through the directory and build a list of the files it's going to delete. Since there's so many of them, it runs out of room to store the list of files.
One way around it is to use the find command with the -exec option. This will run a separate rm command for each file found by find, rather than trying to do them all at once.
find /var/spool/mqueue -type f -exec rm -f {} \;
-type f : searches for files only
-exec : do the following command. {} is where find will put the name of the find result to be acted on by the command.
rm -f : include the -f force option to stop it prompting you to remove every file
You could add other things to the find command , such as
find /var/spool/mqueue -type f -mtime +5 -exec rm -f {} \;
-mtime +5 will only delete message older than five days, so you don't need to delete the whole queue
Hope that helps someone out there.
|
|
1 members found this post helpful.
|
06-07-2012, 01:53 AM
|
#7
|
LQ Newbie
Registered: Jun 2012
Posts: 1
Rep: 
|
another way through shell script.........
You should change the directory to mqueue directory and apply the below script...
for i in `ls`
do
rm -f $i
done
|
|
|
02-09-2018, 09:10 AM
|
#8
|
LQ Newbie
Registered: Feb 2018
Posts: 1
Rep: 
|
System Administrator
This is very late but just for a knowledge purpose, i wanted to clear the mail queue (not everything) with the restriction in a form of REGEX that grep only certain hosts, my mail mqueue seems genuine however only certain hosts must be trim/removed so here how i achieved this -
for i in $(mailq | grep -B1 "\^[a\-zA\-Z0\-9\_\.\+\-]\+@\?(\|[a,b,c,d]host1\|[a-z]host2[0-9]\|host3[1-9]\|)\.domain\.on\.ca$" | grep -Eow '\w{14}' | sort -r | uniq); do /usr/local/bin/qtool.pl -C /etc/mail/sendmail.cf -d /var/spool/mqueue/$i; done
Which means grep the QID's which contains any user from hosts{1..3} followed up with my domain need to be removed from mqueue.
Hope this help who look something similar.
you can find qtool.pl from "https://www.cyberciti.biz/faq/linux-unix-bsd-clear-sendmail-queue/"
Thanks,
M
Last edited by mahir.kadri; 02-09-2018 at 09:13 AM.
Reason: Provide qtool.pl link
|
|
|
12-17-2018, 05:02 PM
|
#9
|
LQ Newbie
Registered: Dec 2018
Posts: 3
Rep: 
|
>> find /var/spool/mqueue -type
While this will work, it will be very slow to execute. The reason is that it will fork a new process for each and every file it will delete. Since there are a ton of them, it is very resource intensive to fork each and every time.
A better solution is to fork every once in a while with a long list of files to delete. That's precisely what the xargs(1) command is created for. Issue this command:
find /var/spool/mqueue -type f -print0 | xargs -0 rm -f
xargs is similar to the shell expanding the '*' into a long list of files, but it does it in such a way that it won't exceed the shell's command line buffer.
So by way of illustration:
Using wildcard expansion:
If a directory had files A thru Z
rm -f *
would expand to "rm -f A B C D E F G H I J K L M N O P Q R S U V W X Y Z"
Only one fork, but can't complete because two many files in the list.
(this is only for illustration. 26 files is no way will exceed the buffer limit of the shell)
Using find -exec:
find . -exec rm -f {} \;
Is the same as:
$ rm -f A
$ rm -f B
$ rm -f C
.
.
$ rm -f X
$ rm -f Y
$ rm -f Z
26 forks to accomplish task
Using find piped to xargs:
find /var/spool/mqueue -type f -print0 | xargs -0 rm -f
Is like:
rm -f A B C D E F G H I
rm -f J K L M N O P Q R
rm -f S T U V W Z Y Z
xargs knows the buffer limit that can be issued on the command line. In this illustration, it broke the list into 3 pieces so that it wouldn't exceed the shell's buffer limit. Only 3 forks to delete all files.
The -print0 and -0 switch to xargs will properly process filenames with spaces embedded in the filename.
|
|
|
12-21-2018, 02:09 AM
|
#10
|
Senior Member
Registered: Dec 2011
Location: Simplicity
Distribution: Mint/MATE
Posts: 3,051
|
-delete is the fastest!
Code:
find /var/spool/mqueue -type f -delete
|
|
|
12-21-2018, 02:51 AM
|
#11
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,498
|
do you know this thread is more than 10 years old?
by the way the fastest way is to remove the dir itself and create again. At least I think.
|
|
|
12-21-2018, 08:19 AM
|
#12
|
LQ Newbie
Registered: Dec 2018
Posts: 3
Rep: 
|
-delete not always available
Quote:
Originally Posted by MadeInGermany
-delete is the fastest!
Code:
find /var/spool/mqueue -type f -delete
|
Some versions of UNIX have a find(1) command that do not support the -delete option. Solaris is one example. I think the GNU project was the one that introduced that option. But it's still useful to know about the xargs(1) command, because then you can operate on a list of files even if there isn't an option in the find command itself. For example, find can find files with certain permissions, but you can't change them without using -exec or using xargs(1). Here is how you can add read rights to all html files:
find htdocs -name '*.html' -print0 | xargs -0 chmod a+r
|
|
|
All times are GMT -5. The time now is 02:00 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|