Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!think.com!mintaka!spdcc!merk!millipore!lampert From: lampert@millipore.com (Jeff Lampert) Newsgroups: comp.unix.misc Subject: Arg list too long error? Here's a work-around. Summary: rm * produces arg list too long error if there are too many files. Keywords: find Message-ID: <1990Nov14.192707.1099@millipore.com> Date: 14 Nov 90 19:27:07 GMT Sender: lampert@millipore.com Organization: Millipore Corporation Lines: 42 I had an application run wild and create thousands of zero length files on my Sequent UNIX box a few days ago. All the files were in one sub-directory and began with the characters SRW. "No big deal", I thought. "I'll just cd to that directory and 'rm SRW*'" Unfortunately, when I tried that, I got the error 'Arg list too long'. When the shell tried to parse the asterisk, there were too many filenames to fit in the argument list. What was I to do? The filenames were similar to 'SRW634534872'. I could issue the command 'rm SRW63453487*', then 'rm SRW63453486*', etc. Or I could also write the directory list to a file, then have a shell script delete the files from the directory list. (Keep in mind that 'ls SRW*' also produces the 'Arg list too long' error for the same reason.) Well, here's a neat work-around that I found. Since I'm new to UNIX, I don't know how well known this is, but I hope it helps someone other than me... The 'find' command does'nt seem to have the 'Arg list' limitation. It also has the feature of being able to execute a command on the files that it finds. So, by giving the command: find . -name "SRW*" -exec rm {} \; I was able to delete all the SRW files. By adding -print, you can see the files being worked on: find . -name "SRW*" -print -exec rm {} \; Keep in mind that find works recursively, and that the above command will remove all files "SRW*" in the sub-directories below the current one!!! This may be what you want, or not. Be careful. One last example: To change file protection on all files in a directory, and all files beneath that directory, cd /dirname find . -name "*" -print -exec chmod 700 {} \; Hope this helps. Any better ways? Please E-Mail me. Any way to aviod recursion? Again, please let me know... lampert@millipore.com