LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Closed Thread
  Search this Thread
Old 01-23-2012, 12:39 AM   #1
ankitpandey
Member
 
Registered: Jan 2012
Location: Mumbai
Posts: 63

Rep: Reputation: Disabled
Unhappy How to delete files in slot of 1000 leaving 7 days of history


Hey all,

I want to create a script which can delete the files older than 7 days but in a slot of 1000. As i have millions of file to delete which i need to perform 1000 files in one slot then next 1000 files and so on. The start state should be 7 days before the present date. I tried deleting all the files after 7 days but it has thrown the below error so want to do it in slot of 1000 files.

error : /usr/bin/find: arg list too long
usage: rm [-fiRr] file ...

Please suggest on this.

Thanks,
Ankit
 
Old 01-23-2012, 02:11 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
xargs is generally a safe way to do this sort of thing, as rm is invoked individually for each file passed to it.

find /path -type f -mtime +7 -print0 | xargs -0 rm

http://en.wikipedia.org/wiki/Xargs
 
1 members found this post helpful.
Old 01-23-2012, 12:11 PM   #3
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

Continue here: http://www.linuxquestions.org/questi...-files-924788/
 
  


Closed Thread



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
delete files when it's older 30 days Madison00 Linux - Newbie 8 01-07-2011 02:07 AM
How to make Google Chrome to delete history after x days? Mr. Alex Linux - Software 3 11-20-2010 01:02 PM
[SOLVED] Delete old files older than 7 days anon091 Linux - Newbie 3 09-18-2009 01:15 PM
Script help - delete files older than 45 days but exclude the system files jojothedogboy Linux - Software 3 06-13-2008 03:43 PM
Delete files older then 30 days stefaandk *BSD 1 01-07-2008 08:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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