LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 10-02-2003, 10:21 AM   #1
rharvey@cox
Member
 
Registered: Aug 2003
Location: Victoria, Texas
Distribution: Gentoo
Posts: 63

Rep: Reputation: 15
question about rm command on Red Hat 9


I've run into a frustrating problem with the rm command on Red Hat 9. I have a directory with 41,000+ files that I would like to get rid of. When I employ the command:

rm -f *.*

I get this error message:

bash: /bin/rm: Argument list too long

What is the problem? Is it a hardware (RAM?) problem or is it something with Red Hat's modifying the rm command?

TIA

Bob
 
Old 10-02-2003, 11:42 AM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
That error has to do with the limitations of the length of things that can be entered into the shell. The *.* is expanded into a list of all 41,000 files, which is too many for bash to handle all at once.

A Google search turned up this article on the subject with some solutions. Also, you don't need to use *.*, you can use just plain *
 
Old 10-02-2003, 04:38 PM   #3
Medievalist
Member
 
Registered: Aug 2003
Distribution: Dead Rat
Posts: 191

Rep: Reputation: 56
Assuming the directory you want to delete is called "spooge" here are two solutions:

rm -rf /spooge

That's a recursive rm, so it'll kill everything below the named directory.

find /spooge -type f -exec rm -f {} \;

That's a find command that executes the rm -f command on every file it finds.

Either should work. The first form would probably be faster, and would work on links and subdirectories as well as files. The second form will ignore directories and links; it should just delete files.
 
Old 10-02-2003, 05:08 PM   #4
rharvey@cox
Member
 
Registered: Aug 2003
Location: Victoria, Texas
Distribution: Gentoo
Posts: 63

Original Poster
Rep: Reputation: 15
That's exactly what I needed! I figured it had something to do with changing parameters somehwere. I was hoping it was changing parameters at a higher level, like the menu somewhere, but I feel comfortable recompiling the kernel.

Thanks.

Bob
 
Old 10-02-2003, 05:55 PM   #5
rharvey@cox
Member
 
Registered: Aug 2003
Location: Victoria, Texas
Distribution: Gentoo
Posts: 63

Original Poster
Rep: Reputation: 15
Medievalist's method:

$ rm -rf /br

did not work for me. I'll try recompiling the kernel to see if that helps. Thanks for the suggestion, though.

Bob
 
Old 10-04-2003, 04:00 AM   #6
kbridger
LQ Newbie
 
Registered: Oct 2003
Posts: 14

Rep: Reputation: 0
rharvey,

What do you mean the 'rm -rf /br' didn't work?

If you typed that, then that means that your 'br' directory exists in the top most directory (/) i think you should leave the '/' out..

ie. if your directory is in

~/br (in your home account) then do this.

rm -rf ~/br

or if you prefer

cd ~
rm -rf br

Note no forward slash...

I'm just curious, how would recompiling your kernel help with this problem?

Cheers,
Karl
 
Old 10-04-2003, 09:36 AM   #7
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
I don't think recompiling the kernel would make any difference. The limitation you're encountering is in bash (or whichever shell you're using); the kernel has nothing to do with it, AFAIK. Recompiling the kernel is not the solution to everything It's rarely the only solution to anything, for that matter.
 
Old 10-04-2003, 03:54 PM   #8
rharvey@cox
Member
 
Registered: Aug 2003
Location: Victoria, Texas
Distribution: Gentoo
Posts: 63

Original Poster
Rep: Reputation: 15
Thanks folks. I just read your replies here at home. The problem is at work. I'll retry Karl's suggestion Monday or Tuesday when I get back to the office. I haven't had time to recompile the kernel yet, either!

Bob
 
Old 10-06-2003, 08:38 AM   #9
Medievalist
Member
 
Registered: Aug 2003
Distribution: Dead Rat
Posts: 191

Rep: Reputation: 56
The command

rm file1 file2 file3

removes (deletes) files named file1, file2, and file3. The rm command will accept about 256 characters in its command line, I think (that's from vague memories - if you need to know, read the C source code).

Recompiling the kernel will NOT increase the number of characters the rm command can accept as input.

The command

rm *

will be interpreted by the command shell (usually bash, the Bourne-Again SHell on linux boxen) and the asterisk will be replaced by the names of all the files in the current directory. Then the shell invokes the rm command using the line created by replacing the asterisk. The rm command never receives the asterisk as input, only the shell does.

The shell has a limit on the number of characters per line both before and after the asterisk is expanded; I think (again, if you want accuracy, read the C source for bash) the limit is around 1024 characters.

Recompiling the kernel will NOT increase the number of characters the shell can accept in a single line.

You've said the rm -rf didn't work - please post the error message that was returned so we can see what the problem is, and we'll go from there.
 
Old 10-09-2003, 06:14 PM   #10
rharvey@cox
Member
 
Registered: Aug 2003
Location: Victoria, Texas
Distribution: Gentoo
Posts: 63

Original Poster
Rep: Reputation: 15
OK, I've had some success with the command rm -rf br (for the directory br) from the directory that contains br. The problem is I don't want to remove the entire directory, just the files.

As for the the shell question and accepting characters, can I switch to another shell (Korn, Tckl) and delete the 41,000+ files?

Thanks for the help

Bob
 
Old 10-10-2003, 04:19 AM   #11
mr_segfault
Member
 
Registered: Oct 2003
Location: Australia
Distribution: Redhat 9
Posts: 95

Rep: Reputation: 15
You could use the find command (but be careful, you dont want to make a mistake with it!)
Code:
find br -exec rm {} \;
Now this will search for all files from the dir br and execute the command after the -exec (in this case 'rm') and replace the '{}'s with the file name of the found file..

You may want to run the following, and inspect the output before running the command above. If it looks like it lists all the files you want to delete then go ahead and run the real command, note this is recursive also, so all files below br will be deleted.
Code:
find br -exec echo {} \;
You will need to type it exactly as I have here, the \; is very important also..

This will infact attempt to do a 'rm br' but will fail with an error message: 'rm: cannot remove 'tmp' : Is a directory' so therefor only the files within and recursivly down will be deleted but all directories will be intact.

I hope this helps!

Cheers
 
Old 10-10-2003, 07:56 AM   #12
Medievalist
Member
 
Registered: Aug 2003
Distribution: Dead Rat
Posts: 191

Rep: Reputation: 56
Quote:
OK, I've had some success with the command rm -rf br (for the directory br) from the directory that contains br. The problem is I don't want to remove the entire directory, just the files.
Well, the directory is easy to recreate, you know; if you want a directory named "/usr/br" and owned by user "smedley" in group "deadly" with reasonably strong protections you can do:

mkdir /usr/br
chown smedley:deadly /usr/br
chmod u=rwx,g=rx,o /usr/br

Quote:
As for the the shell question and accepting characters, can I switch to another shell (Korn, Tckl) and delete the 41,000+ files?
No. All the shells have some sort of limitations on their command line lengths, but it really doesn't matter, because the "rm" command has a shorter limit. rm is not a shell primitive, it's a unix/linux command utility.

Either use the recursive rm and recreate the directory afterwards, or use a recursive find. The find command I gave in a previous post specifically works on files only and will not delete the directory. Here's another one that should do what you want, IFF the directory in question is named /tmp/br.

find /tmp/br/ -mindepth 1 -exec rm -f {} \;

That one deletes everything below /tmp/br, including links and directories or other special files, but not /tmp/br itself.

Last edited by Medievalist; 10-10-2003 at 07:58 AM.
 
Old 10-13-2003, 07:49 AM   #13
rharvey@cox
Member
 
Registered: Aug 2003
Location: Victoria, Texas
Distribution: Gentoo
Posts: 63

Original Poster
Rep: Reputation: 15
Thanks mr_segfault and Medievalist. The problem is now solved. The expression

find br -exec rm {} \;

works as advertised. I looked up the find command in the man pages and actually understand what I'm doing!

Once again, many thanks.

Bob
 
Old 10-14-2003, 03:59 AM   #14
B1TW1SE
LQ Newbie
 
Registered: Mar 2002
Location: Midlands, UK
Distribution: RedHat 9, Slackware 9.1, Fedora core 2
Posts: 23

Rep: Reputation: 15
Thankyou, Thankyou, Thankyou, Thankyou, Thankyou, Thankyou, Thankyou, Thankyou, Thankyou, Thankyou,

I have been using RH 9 at home for a few months now, and I have been banging my head trying to get ls to do a search of all sub folders for a file.

And now I learn that there is a find command! And before you ask, I'm not simple or anything. I've just been brought up on DOS where
Code:
dir *.but /s
worked fine for that sort of thing.

Thanks guys.
 
Old 10-19-2003, 05:51 PM   #15
lenlutz
Member
 
Registered: May 2003
Location: philadelhpia pa
Posts: 92

Rep: Reputation: 15
for i in *
do
/bin/rm $i
done
 
  


Reply



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
what command to install red hat? aoeshang Linux - Newbie 19 07-09-2005 11:35 AM
Red Hat 9 to Red Hat EL Mozilla Migration Question rharvey@cox Linux - Software 2 01-13-2004 06:43 PM
Red Hat 8.0 equivalent command photowriters Linux - Networking 2 12-29-2003 09:11 AM
Red Hat 7.0 problem with ps command fweaver Linux - Software 15 02-27-2003 02:29 PM
Red Hat 7.2 command j0ck Linux - General 2 11-21-2002 12:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 01:02 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