LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-15-2005, 12:20 PM   #1
Red Squirrel
Senior Member
 
Registered: Dec 2003
Distribution: Mint 20.1 on workstation, Debian 11 on servers
Posts: 1,336

Rep: Reputation: 54
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?
 
Old 05-15-2005, 12:25 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
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.
 
Old 05-15-2005, 02:03 PM   #3
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
go to the folder, do:

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

but ONLY do it in the folder!!
 
Old 05-15-2005, 02:58 PM   #4
Red Squirrel
Senior Member
 
Registered: Dec 2003
Distribution: Mint 20.1 on workstation, Debian 11 on servers
Posts: 1,336

Original Poster
Rep: Reputation: 54
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.
 
Old 05-15-2005, 03:24 PM   #5
RedDwarf
LQ Newbie
 
Registered: Aug 2004
Posts: 25

Rep: Reputation: 15
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
 
Old 05-15-2005, 03:44 PM   #6
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
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..

Last edited by trickykid; 05-15-2005 at 04:05 PM.
 
Old 05-15-2005, 03:59 PM   #7
Red Squirrel
Senior Member
 
Registered: Dec 2003
Distribution: Mint 20.1 on workstation, Debian 11 on servers
Posts: 1,336

Original Poster
Rep: Reputation: 54
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
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. 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.
 
  


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
Deleting files in C monil Programming 4 03-13-2005 10:33 AM
Deleting tmp files satimis Fedora 6 10-31-2004 08:59 PM
Deleting files! a_priebe47 Slackware 6 10-17-2004 09:58 PM
Deleting files ShakyJake Linux - Newbie 12 05-08-2003 03:07 PM
Deleting files Tingle Linux - Newbie 4 01-16-2003 04:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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