LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 04-26-2006, 11:17 AM   #1
HLisD1
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Rep: Reputation: 0
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?
 
Old 04-26-2006, 11:30 AM   #2
satinet
Senior Member
 
Registered: Feb 2004
Location: England
Distribution: Slackware 14.2
Posts: 1,492

Rep: Reputation: 50
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 "/"
 
Old 04-26-2006, 12:25 PM   #3
HLisD1
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
Old 04-26-2006, 12:58 PM   #4
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,508
Blog Entries: 2

Rep: Reputation: 68
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.
 
Old 04-27-2006, 07:17 AM   #5
nishidwivedi
LQ Newbie
 
Registered: Apr 2006
Posts: 5

Rep: Reputation: 0
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
 
Old 02-01-2011, 08:05 PM   #6
L1ttl3J1m
LQ Newbie
 
Registered: Feb 2011
Posts: 1

Rep: Reputation: 1
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.
Old 06-07-2012, 01:53 AM   #7
ervkjain
LQ Newbie
 
Registered: Jun 2012
Posts: 1

Rep: Reputation: Disabled
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
 
Old 02-09-2018, 09:10 AM   #8
mahir.kadri
LQ Newbie
 
Registered: Feb 2018
Posts: 1

Rep: Reputation: Disabled
Lightbulb 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
 
Old 12-17-2018, 05:02 PM   #9
younda
LQ Newbie
 
Registered: Dec 2018
Posts: 3

Rep: Reputation: Disabled
Wink

>> 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.
 
Old 12-21-2018, 02:09 AM   #10
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Distribution: Mint/MATE
Posts: 3,051

Rep: Reputation: 1321Reputation: 1321Reputation: 1321Reputation: 1321Reputation: 1321Reputation: 1321Reputation: 1321Reputation: 1321Reputation: 1321Reputation: 1321
-delete is the fastest!
Code:
find /var/spool/mqueue -type f -delete
 
Old 12-21-2018, 02:51 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,498

Rep: Reputation: 8055Reputation: 8055Reputation: 8055Reputation: 8055Reputation: 8055Reputation: 8055Reputation: 8055Reputation: 8055Reputation: 8055Reputation: 8055Reputation: 8055
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.
 
Old 12-21-2018, 08:19 AM   #12
younda
LQ Newbie
 
Registered: Dec 2018
Posts: 3

Rep: Reputation: Disabled
-delete not always available

Quote:
Originally Posted by MadeInGermany View Post
-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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/usr/spool and /var/spool davidsrsb Slackware 1 04-06-2006 05:57 AM
/var/spool/mqueue/ is empty, but Sendmail keeps on sending messages guarriman Linux - Software 1 02-20-2006 04:46 AM
Printing from Mozilla creates 200Mb files in /var/spool/cups mikeyt_333 Linux - Software 3 05-23-2004 12:47 PM
What is /var/spool/mqueue?? WorldBuilder Linux - General 4 05-07-2003 02:32 PM
How to Lock Files (/etc/passwd /var/spool/[user] Larry James Programming 3 12-04-2000 11:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration