Re: Lots of files - how to select newest 10K files
- From: Unruh <unruh-spam@xxxxxxxxxxxxxx>
- Date: Sat, 09 Feb 2008 16:35:23 GMT
CptDondo <yan@xxxxxxxxxxxxxxxx> writes:
On Fri, 08 Feb 2008 07:58:58 -0700, Douglas Mayne wrote:
This sounds a bit like a contrived homework-style problem.
Your problem seems some arbitrary collection of files until 10,000 files
have been selected. I can see that there is a case where some new files
will never be selected. For example, if more that 10,000 files are
created on the interval. That makes this look like a contrived
homework-style problem. I suppose that the contents of the four reports
presented above could be tweaked until the requirement is met and that
satisfy your selection criteria.
Well, it's not homework but it is a bit contrived.
Visit http://www.seiner.com and look at the lizardcam and the snakecam.
The crittercams run at 12FPS but motion only saves the frames when it
detects motion. The result is that every I have a directory with
thousands of time-stamped jpg images.
I have a script that runs every hour, which creates a flash video from
the last 24 hours' worth of images, and deletes anything older than that.
In a typical 24 hour period, the lizard is active for about an hour,
which, with my ~ 4:1 speedup, creates about 10-15 minutes of video.
Great.
The snake is only active a few minutes a day; after feeding it may not
move at all for a day or two. So the videos are uniformly boring and
short. Then, when she gets hungry, she will be very active and create a
few minutes of video whenever she hunts.
The snakecam is the problem. I want to end up with at least 10-15
minutes of snake video, which means that I have to keep about 10,000
frames even if it means keeping the previous day's activity. But when
she's 'hunting' she can move a lot and easily exceed 10K frames in a day.
Thus my problem. I want to have enough frames to create a movie of about
10 minutes even if it means using yesterday's footage, but if she moves
enough to create 20K frames in a 24 period I want to show that too.
Ah, finally you explain your problem
ls -t .|awk 'BEGIN{i=0} {file[i]=$0;i++} END{if(i>10000) for (j=10000;j<i;j++) print file[j]}'|xargs rm
might work.
This assumes that all of the snake files are in a single directory without
any others. This command erases all the oldest files greater than 10000 the
10000th.
ls -t .
lists all of the files in the current directory in temporal order, newest
first. The awk command numbers the files, and then if there are more than
10000 of them erases those that are oldest. However you want more, you want
to keep all of todays if there are more than 10000. So, do something like
export NTODAY=`find . -mtime -1 |wc -w`
if [ $NTODAY -gt 10000 ]; then
find . -mtime +1|xargs rm
else
ls -t .|awk 'BEGIN{i=0} {file[i]=$0;i++} END{if(i>10000) for (j=10000;j<i;j++) printf( "%s ", file[j])}'|xargs rm
fi
That will leave you with either all of todays (ie the past 24 hours), or up to 10000 whichever is
greater. and erase all the rest.
Note that I have not particularly tested this so use at your own risk.
.
- Follow-Ups:
- Re: Lots of files - how to select newest 10K files
- From: CptDondo
- Re: Lots of files - how to select newest 10K files
- References:
- Lots of files - how to select newest 10K files
- From: CptDondo
- Re: Lots of files - how to select newest 10K files
- From: Douglas Mayne
- Re: Lots of files - how to select newest 10K files
- From: CptDondo
- Lots of files - how to select newest 10K files
- Prev by Date: Re: Which video format?
- Next by Date: Re: chronic CentOS md5sum error
- Previous by thread: Re: Lots of files - how to select newest 10K files
- Next by thread: Re: Lots of files - how to select newest 10K files
- Index(es):
Relevant Pages
|
Loading