Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-14-2010, 06:11 AM   #1
LQ Newbie
Registered: Oct 2010
Posts: 12

Rep: Reputation: 0
Question Deleting million files

Hi all,

There are millions of files in many directories. Wherenver i try rm * or find or use xargs, they say 'argument list too long' and exit.

How can i deleted files in a directory with so many files without deleting the directory itself.
Old 11-14-2010, 06:43 AM   #2
LQ Guru
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
You didn't post any commands.


find directory -type f -print0 | xargs -0 rm -f
directory is the top directory you want to clear of files.
1 members found this post helpful.
Old 11-14-2010, 06:44 AM   #3
Registered: Mar 2010
Location: Switzerland
Distribution: Slackware
Posts: 97

Rep: Reputation: 13
Did you try out

find -type f -print0 | xargs -0 rm
in that directory?

Edit: too slow
1 members found this post helpful.
Old 11-14-2010, 06:48 AM   #4
Simon Bridge
LQ Guru
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Its the -r option in rm that is giving the problem.
You use find to delete the files one at a time.

find . -name 'spam-*' | xargs rm

You can set the find command options to go recursively through directories.

In case that is what you've already tried, a more careful approach:
... you should be able to modify the script for your files.

Last edited by Simon Bridge; 11-14-2010 at 06:50 AM.
1 members found this post helpful.


delete, files

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
LXer: What's the best way to move 60 million files from one Windows server to another? - Linux LXer Syndicated Linux News 0 09-25-2010 05:50 AM
maximum files per directory for optimal access speed when having 13 million files andrew777 Linux - Server 3 04-27-2009 03:30 PM
LXer: Wikimedia to Sloan: Thanks a million, thanks a million, thanks a million LXer Syndicated Linux News 0 03-26-2008 03:50 PM
3 million files in a DIR swiswire Debian 3 09-02-2007 02:30 AM
10 million files on Linux? dcabbar Linux - General 11 07-12-2005 12:38 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:41 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration