From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96079336919649.tru64-unix-managers.marc@archive.invalid> From: "Altamiro M. Diniz" Date: Fri, 25 Feb 2000 11:10:40 +0000 To: tru64-unix-managers Subject: SUMMARY: removing a lot of old files X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96079336919649 My original message: > Hi all, > > inside a sub-directory there are xxxx.dat.old (more than 100k) files > that I have to remove. > > I mustn't remove the subdir. > > Searching in the archieve, I found the following suggestions: > # find ./ -type f -exec rm {} \; > answer: /usr/bin/find: arg list too long > > and > # ls | xargs -i rm -f {} > answer: /usr/bin/ls: arg list too long > > I tried these and some variants commands but... not success :-( > > TIA, First of all, sorry for post twice but at first time I received a msg due my S/MIME Cipher so I understood my msg was not read. I received 21 messages about this subject. Many thanks to all you :-) This list is great! The problem was to remove *only* those xxxxxx.dat.old files. The large amount of files was not considered for all readers. So, it was not possible to use wildcards: this cause an arg list overflow. There are 2 possible solutions for the problem (St. Suika Fenderson Roberts and John J. Francini), marked as WORKS in the original replies. Again, thanks a lot for the replies. ---------------------------------------------------------------- Dr. Tom Blinn, 603-884-0646 Are you a total UNIX newbie? "cd" into the directory and then do an "rm *".. ---------------------------------------------------------------- mc.vialatte What do you mean by "not success" ? Have you simply tried : rm -f * or rm -f *.dat.old ---------------------------------------------------------------- Gwen Pettigrew why not just cd to the sub directory and do rm *.dat.old You might want to check that hasn't been aliased to rm -i first. ( check you login scriptd for what ever shell you use) ---------------------------------------------------------------- Finn Rasmussen If I understand you correct, use the command: rm *.dat.old inside the subdir. This will delete all files whos name ends in ".dat.old" --------------------------------------------------------------- Nikola Milutinovic What is the error message? ---------------------------------------------------------------- Paul Crittenden Can't you go into that sub-directory and do a rm *.dat.old? ---------------------------------------------------------------- John Losey If you want them all gone, and they are all of the format xxxx.dat.old, then use: (from inside the directory) rm ????.dat.old ---------------------------------------------------------------- Dave Paper you might want to try ls -1 | xargs -i rm -f {} though, that's strange that find and ls give you an error. They shouldn't. Try something like echo * | xargs -i rm -f {} if that fails. ---------------------------------------------------------------- Joerg Bruehe 1) These commands will remove _all_ files, please check if that is what you want. 2) The easiest way will be to remove the subdirectory and then to re-create it: cd parent ; rm -fr subdir ; mkdir subdir possibly followed by chown, chgrp, chmod for the subdir 3) The commands you typed should also work, and IMHO the error messages do not fit the commands. Please double-check whether you really did find ./ and ls or you called find ./* and ls * You must not use the '*' here because it makes the shell expand all file names, and that causes the arg list overflow. 4) In such a full directory, you might also do rm -f a* rm -f b* and so on, because that restricts the file names expanded (and hence the arg list) to those starting with 'a', then with 'b' and so on; repeat that for all starting characters. You might get a book or tutorial on shells and shell programming telling you how to avoid such an overflow. >>>>>>>>>>>>>>>> WORKS <<<<<<<<<<<<<<<<<<< ---------------------------------------------------------------- St. Suika Fenderson Roberts find /path/to/subdir/ -name \*.dat.old -exec ls -l \{\} \; should list them all nicely, to make sure you are only chosing the ones to be removed, then find /path/to/subdir -name \*.dat.old -exec rm \{\} \; will remove them. ---------------------------------------------------------------- Jerome M Berkman Those should work. I don't see why "ls" wouldn't unless you started "ls * | ...". Try: % ls > /tmp/names % xargs -i rm -f {} < /tmp/names If the "ls" doesn't work, maybe you have it aliased in a funny way or are using a weird shell. You could write a short Perl program to scan the directory and remove all files, but that shouldn't be necessary. ---------------------------------------------------------------- George Gallen what happens if you just do a "rm *.dat.old"? since all the files end in .dat.old You do have delete rights? possibly why it didn't work? if you want to clear all the files, then just do a "rm *" this will NOT remove subdirectories. but you must execute it from within the subdirectory you want cleared (same with the above statement). >>>>>>>>>>>>>>>> WORKS <<<<<<<<<<<<<<<<<<< ---------------------------------------------------------------- John J. Francini # cd dir-with-all-the-files # find . -name "*.dat.old" -exec rm {} \; Note that the quotation marks around *.dat.old are required to keep the shell from expanding the wildcard. ---------------------------------------------------------------- Gary George How about: ls | xargs -n 10 rm -f {} (And then go for coffee.) ---------------------------------------------------------------- Cyndi Smith Here's what I have in my root crontab to clean out /var/tmp, maybe a variation would work: find /var/tmp -type f -atime +2 -exec /usr/bin/rm -f {} \; perhaps what you need would be: # find ./ -type f -exec /usr/bin/rm -f {} \; maybe it need the path to rm specified. The other comment I make is the I use gnu's find. Also, are there any files in that subdirectory that you need to keep? If not, why not just cd into that directory, then # /usr/bin/rm -f * or # /usr/bin/rm -f ????.dat.old if you want to be more specific. ---------------------------------------------------------------- Piotr Konieczny Try: 1) for i in `find . -type f`; do rm $i; done 2) for i in a b c d e f ... z; do rm $i*; done 3) for i in a b c d e f ... z; do for j in a b c d ... z; do rm $i$j*; done; done ---------------------------------------------------------------- Udo de Boer try find . wsithout the slash. ---------------------------------------------------------------- Thomas M. Payerle That is very odd. Are you sure you did not include a * anywhere? Check your aliases for find, rm, ls, and xargs? ls * will expand to ls file1 file2 file3 .... file100001, etc. and can very well overflow the arg list, but plain ls doesn't have any args. Can you do a plain ls on the directory? If so, an uglier alternative to the suggestions shown (and tried) is ls > temp.file Then edit temp.file (may need to use sed, or split -l 1000, etc because of size) and simply change each line to read rm file1 rm file2 and run as shell script. But doubt will work if others failed. Have you considered mv'ing the directory, creating an empty one, xfer any files not to be deleted, and delete the renamed directory? (Not sure how stringent the not delete directory requirement is)? ---------------------------------------------------------------- alan The find example fails because the command line generated is longer than the exec(2) family of system calls support. I'm not sure why the ls fails, since an ls by itself only opens the current directory and runs through listing the files. I'd use: find . -type f -print | xargs rm -f ---------------------------------------------------------------- Craig Cole Try sending through a for loop so that it takes the files one at a time: for i in `ls` do echo removing $i rm $i done don't bother with the "echo" line if you don't want any output to the screen. I just like to make sure the command is doing what I think it's doing. ---------------------------------------------------------------- Jim Belonis If the filenames have some way you can select a subset, you might be able to do it by parts e.g. by deleting all that start with 'a', then all that start with 'b' etc. You can ls -1 > some_filename then select filenames from the file one at a time or a bunch at a time (to the limits of the rm command-line) using a short shell script. -- Altamiro M. Diniz