Red HatThis forum is for the discussion of Red Hat Linux.
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.
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.
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?
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 *
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.
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.
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.
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!
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.
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?
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.
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:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.