LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   deleting millions of files at once (https://www.linuxquestions.org/questions/linux-software-2/deleting-millions-of-files-at-once-323734/)

Red Squirrel 05-15-2005 12:20 PM

deleting millions of files at once
 
I have this folder with probably over 1 million small files, suprised it did not crash the filesystem due to the inode limit, but anyway, when I do a rm to delete them all, it errors out with -bash: /bin/rm: Argument list too long. Is there a quick way (other then formatting) to delete all these?

btmiller 05-15-2005 12:25 PM

Assuming you want the folder and all its files gone:

rm -rf /path/to/folder

The reason you get argument list to long is that the shell expands wildcards like *. You can delete a few files at a time with rm [a-c]* for all file beginning with a, b, or c, which may put you under the limit.

As always, with rm and wildcards, be very very careful. Linux does not have an undelete.

Komakino 05-15-2005 02:03 PM

go to the folder, do:

for i in `ls`; do rm $i; done

but ONLY do it in the folder!!

Red Squirrel 05-15-2005 02:58 PM

Thanks that for loop one worked. Never thought of doing that. Well would not have known how anyway. :P

Speaking of not being an undelete in linux, is there any utility you can get to restore files? or does deleting in linux actually destroy the file, unlike windows? Would be handy to have in case I ever goof up or something.

RedDwarf 05-15-2005 03:24 PM

Last time I deleted something I should not (stupid console emulator from Konqueror!!!!) I found that in ext2 filesystems files can be restored, but in ext3 isn't possible because......well, bacause something i don't remember :p

trickykid 05-15-2005 03:44 PM

Quote:

Originally posted by Komakino
go to the folder, do:

for i in `ls`; do rm $i; done

but ONLY do it in the folder!!

You can also do a large listings for removals by piping to xargs.. ;)

Red Squirrel 05-15-2005 03:59 PM

Quote:

Originally posted by RedDwarf
Last time I deleted something I should not (stupid console emulator from Konqueror!!!!) I found that in ext2 filesystems files can be restored, but in ext3 isn't possible because......well, bacause something i don't remember :p
Yeah I figured, because of the journaling, it overrites quickly. Which sucks since beleive it or not I just just pulled it off on a folder while doing a cleanup. Typed the wrong folder name. :cry: Good thing it's stuff I can get back though. I was wondering why it was taking so long then suddently relized I typed the wrong folder. I must of hit CTRL+C at least 20 times. :p


All times are GMT -5. The time now is 05:42 AM.