Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-21-2008, 08:06 AM   #1
LQ Newbie
Registered: Feb 2008
Posts: 1

Rep: Reputation: 0
Removing directory that is too large to use find and xargs

I have a server that uses files to handle sessions under php, with quite a long session life time (about a month). I didn't look at it for a while (a couple of months), when sessions stopped working properly.

The session folder was over 1 gig. I tried a couple of ways of dealing with it:

rm -rf session (from the directory above) - doesn't seem to do anything after 10 hours sitting there with httpd off. Should I wait longer?

within the directory:

find . -name * | xargs rm -f

find gives the error, argument list too long (note not rm, it's find that's crapping out).

This is a CentOS installation, and unlink as superuser isn't allowed.

The naming convention for the session is pretty predictable so I could write a looping script to handle the find in smaller batches, but I was just wondering if there was a simpler way to do this.
Old 02-21-2008, 08:11 AM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
Your find command isn't correct. You need to put double quotes aroung the asterisk. Since you want to match every file, "find ./ -type f" would be better. You still want to limit the number of arguments that xargs uses. Use the -L argument for that. Also, you might want to separate arguments with nulls. That will eliminate the problem of a filename containing evil characters.

find ./ -type f -print0 | xargs -0 -L 1000 rm

Last edited by jschiwal; 02-21-2008 at 08:16 AM.


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: Using 'ls' and 'xargs' to manage large numbers of files LXer Syndicated Linux News 0 02-15-2007 07:16 AM
clarification on find + xargs rm command dtra Linux - General 2 05-17-2006 06:56 AM
Help me to understand this command: find...| grep -e ... | xargs rm -f ROBERT483599 Red Hat 2 02-14-2006 09:21 AM
du on specific files from find command (use xargs?) fireman949 Linux - Software 2 07-10-2005 02:42 AM
error with find . | xargs cbonar Linux - Newbie 7 12-09-2004 12:22 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:14 AM.

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
Open Source Consulting | Domain Registration