LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-14-2010, 02:24 AM   #1
m.mandar123
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Rep: Reputation: 0
problem with rm -rf


Hi Friends,

i am trying to delete temp files using rm -rf but i am getting this error "bash: /usr/bin/rm: Arg list too long" can someone help me plz?


Regards,
B-)
 
Old 04-14-2010, 02:31 AM   #2
Sayan Acharjee
Member
 
Registered: Feb 2010
Location: Chennai, India
Distribution: Manjaro
Posts: 616

Rep: Reputation: 64
Quote:
Originally Posted by m.mandar123 View Post
Hi Friends,

i am trying to delete temp files using rm -rf but i am getting this error "bash: /usr/bin/rm: Arg list too long" can someone help me plz?


Regards,
B-)
Hi,
Can you please post the full command that resulting that error.
 
Old 04-14-2010, 02:38 AM   #3
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
You probably are using pattern along with the rm command which is resulting in to list of files which is more that rm expects.
 
Old 04-14-2010, 04:14 AM   #4
m.mandar123
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Hi
Thank you for the quick reply

i am trying to delete this types of files "XmlHelper18467xml"

using rm -rf * . but it shows /usr/bin/rm: Arg list too long
message.
 
Old 04-14-2010, 04:21 AM   #5
Sayan Acharjee
Member
 
Registered: Feb 2010
Location: Chennai, India
Distribution: Manjaro
Posts: 616

Rep: Reputation: 64
Quote:
Originally Posted by m.mandar123 View Post
Hi
Thank you for the quick reply

i am trying to delete this types of files "XmlHelper18467xml"

using rm -rf * . but it shows /usr/bin/rm: Arg list too long
message.
Why you are putting a dot after the command? Just run rm -rf * you need to be in the temp directory in order to delete the files with that command.
 
Old 04-14-2010, 04:26 AM   #6
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
How many files are there in the directory?

rm -rf * will eat up everything !!

You should use a pattern to remove set of files.
something like
Code:
rm -rf XmlHelper18467*
 
Old 04-14-2010, 04:27 AM   #7
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
use the find command and it's -exec option to delete the files
Code:
find ./ -exec rm \{\} \;
{} gets replaced with the filename found. ; is the marker of the end of the command. It's escaped with \ cause else the shell would interpret the chars. You could also do

Code:
find ./ -exec 'rm {};'
Just be warned that with this command all files in the current directory are deleted!
 
Old 04-14-2010, 04:29 AM   #8
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by m.mandar123 View Post
Hi
Thank you for the quick reply

i am trying to delete this types of files "XmlHelper18467xml"

using rm -rf * . but it shows /usr/bin/rm: Arg list too long
message.
You're exceeding the maximum number of arguments which rm can take. You'll need to be a bit more creative here. I'd suggest using find and rm as such:
Code:
find ./ -exec rm "{}" +
Just to be clear, this will recusively delete all files in the directory you run the command from. If you only want to delete files in the current directory, but not thsoe in subdirectories, you'll need:
Code:
find ./ -maxdepth 1 -exec rm "{}" +
The + at the end of the command means that more than one file is passed to the rm command, rather than when you use ;, when for each file found, rm is called every time. Using the + makes the process significanly faster.

Last edited by pwc101; 04-14-2010 at 04:30 AM.
 
Old 04-14-2010, 04:32 AM   #9
m.mandar123
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Hi
i am trying to delete cd /var/tmp
as per your reply i am using the same command but getting the same error.


bash-2.05# rm -rf *
bash: /usr/bin/rm: Arg list too long
 
Old 04-14-2010, 04:34 AM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by m.mandar123 View Post
i am trying to delete temp files using rm -rf but i am getting this error "bash: /usr/bin/rm: Arg list too long"
That's because the argument list is too long

There is a set amount of space, configured into the kernel when it was built. It is shared by the environment variables and command arguments which are passed to a new process to execute a command.

The easy way around it may be to limit the number of file names that you are passing to rm, like
Code:
rm -fr a*
rm -fr b*
etc.
The alternative is to use the xargs command to run the rm command. xargs is designed to "batch up" the arguments it reads from stdin and repeatedly run the command it is given with few enough of them that it does not run into the "arg list too long" problem. Examples here.
 
Old 04-14-2010, 05:12 AM   #11
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Hope this helps
http://www.cyberciti.biz/faq/rm-ls-c...oo-long-error/
 
Old 04-14-2010, 05:33 AM   #12
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,072

Rep: Reputation: 384Reputation: 384Reputation: 384Reputation: 384
Pipe it onto xargs, but be careful and double check your current location before doing so. No need to say how dangerous rm -rf is.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Solved Problem Second GCC-Pass(or gettext sanity check problem) hoes Linux From Scratch 0 09-04-2005 10:20 AM
Sound Card problem(every time i install linux i have diffirent hardware problem) jacka1l Linux - Newbie 7 08-11-2005 06:10 AM
Lan configuration problem - NFS boot problem - RX&TX packets errors 242VDM242 Linux - Networking 4 11-25-2004 01:35 PM
Internet and LAN access is unstable-is this a hardware problem or a software problem? soren625 Linux - Networking 1 06-07-2004 06:43 AM
perl problem? apache problem? cgi problem? WorldBuilder Linux - Software 1 09-17-2003 07:45 PM


All times are GMT -5. The time now is 07:40 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration