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


Reply
  Search this Thread
Old 12-25-2009, 08:40 AM   #1
smaxey
LQ Newbie
 
Registered: Dec 2009
Posts: 2

Rep: Reputation: 0
Using find with file name and mtime to remove files gets Arg list too long error


I need to delete all *.trc files that are older than 30 days and I am getting a "Argument list too long" error. There are other files that should not be deleted which is why I am using the "*.trc" and newer files need to be kept as well. I have seen other postings but they do not cover both of the conditions. Below are 2 of the many attempts at doing this but I cannot get this to work. Any help would be greatly appreciated.

Thanks

find *.trc -mtime +31 -print| xargs rm -f {}
find *.trc -mtime +31 -print -exec rm -f {} \;
 
Old 12-25-2009, 08:53 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

You are not using find correctly. It should be:

find <start location> <other options>

The start location is missing and you do not specify you are looking for files named *.trc

Try this: find . -name "*.trc" -mtime +31

If that works, add the remove part: find . -name "*.trc" -mtime +31 -exec rm -f {} \;

The . (dot) tells find to start from where you type the command, you can also use a hard path (/home/user/ for instance).

Hope this helps
 
Old 12-30-2009, 01:26 PM   #3
smaxey
LQ Newbie
 
Registered: Dec 2009
Posts: 2

Original Poster
Rep: Reputation: 0
druuna,

Thank you for replying, I had tried find . -name "*.trc" -mtime +31 as well as the others examples and got the "Argument list too long" error. I can get it to work if I use only one of the conditions but not both. I know I could get the list of files and loop through them and delete the files but I was trying to get this to work if possible. Thanks again for replying.
 
Old 12-30-2009, 05:34 PM   #4
wolfgangsz
LQ Newbie
 
Registered: Dec 2009
Location: Birmingham, UK
Distribution: Debian, Fedora, ...
Posts: 7

Rep: Reputation: 0
Hi smaxey,

your reply is a little confusing, as the combination of matching both file name AND timestamp should actually return fewer results compared to running find with each match on its own.
Have you actually checked the result of running the find without the -exec option to see whether it matches your expectations?
Have you read the manpage for find?
 
  


Reply

Tags
linux



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
How to find a file and just list the found files? thomas2004ch Linux - Newbie 4 08-07-2009 04:54 AM
have long file list; want to find word matches(package deletion purposes) lxquestions000019 Linux - Newbie 2 07-13-2009 04:28 AM
using find to compare file mtime with another file's mtime TheFueley Linux - Newbie 1 12-23-2008 08:06 PM
Combines 16000 files into 1 single file > error tb: /bin/cat: Argument list too long guanyu Linux - General 4 02-09-2007 12:33 AM
how to remove long-windows-filename files based on exlusion list adamrosspayne Linux - Newbie 3 06-23-2006 02:25 AM

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

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