Sponsored Content
Operating Systems Linux Red Hat Delete files older than 1week(dates need to be calculate based on file name) Post 302999614 by RudiC on Friday 23rd of June 2017 09:26:37 AM
Old 06-23-2017
For a zero'th approximation, try
Code:
for FN in *.tps; do DAT=${FN#*-}; DAT=${DAT:0:8}; touch -d${DAT} $FN; done
touch -d$((DAT - 7)) REF
find . -newer REF
./tps-20170523210831497-45475.tps
./tps-20170519030152674-2586.tps
./tps-20170520120924116-26089.tps
./tps-20170521203131446-45475.tps
./tps-20170525004909816-45475.tps
./tps-20170524183206292-45475.tps
./tps-20170523223946192-45475.tps
./tps-20170522171753527-45475.tps
./tps-20170525171625377-45475.tps
./tps-20170524004838503-45475.tps
./tps-20170522180142517-45475.tps
./tps-20170519030525811-2586.tps

Please not that this is just a quick and dirty idea on how to proceed; it assumes the file sorted last is the newest one and the one to start calculating backwards from, it is not month end nor year end safe, and it requires shell arithmetic as provided by e.g. bash (recent).
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

delete files older than 7 days

can anyone tell me how I would write a script in ksh on AIX that will delete files in a directory older than 7 days? (1 Reply)
Discussion started by: lesstjm
1 Replies

2. UNIX for Dummies Questions & Answers

How can I delete files older than 7 days?

I will like to write a script that delete all files that are older than 7 days in a directory and it's subdirectories. Can any one help me out witht the magic command or script? Thanks in advance, Odogboly98:confused: (3 Replies)
Discussion started by: odogbolu98
3 Replies

3. Shell Programming and Scripting

how to delete the files which are the 30 min older...?

Hi all, i have a simple question that i want to find out the 30 minutes older files and delete those files from the particular location(Folder) Generally for this purpose used to retreive the files with "atime" command For example: find and delete the 2 days older log files use this below... (2 Replies)
Discussion started by: psiva_arul
2 Replies

4. Shell Programming and Scripting

Delete files older than 3 months.(read date from the name of the file)

Guys, My log files stored in the date format format below(log_20080714072942): TIMESTAMP=`date +%Y%m%d%H%M%S` LOG=/log/log_${TIMESTAMP}.log I'm looking for a shell script which deletes all files which is older than 3 months from today. Regards, Bhagat (3 Replies)
Discussion started by: bhagat.singh-j
3 Replies

5. UNIX for Dummies Questions & Answers

Delete files older than 30 days

This is driving me crazy. How can I delete files in a specifc directory that are over 30 days old? Thanks in advance. (3 Replies)
Discussion started by: tlphillips
3 Replies

6. Shell Programming and Scripting

Delete files older than today

is it -mtime +1 as i need all files older than today to be deleted (6 Replies)
Discussion started by: dinjo_jo
6 Replies

7. Shell Programming and Scripting

To delete files older than 24 hrs

I have to retain only 1 day files in my system an I have to delete all the other files which are older than 24 hrs. Please let me know the option I have to give in the find -mtime command. (3 Replies)
Discussion started by: rajesh8s
3 Replies

8. UNIX for Dummies Questions & Answers

How to delete all the files older than a date?

Hi, I need a command for deleting all the compress files *.Z that are older than the current date - 5 days. Basically I have a directory where daily I meet some back up files and I want to remove automatically the ones 5 days (or more) older than the current date. How can I write a 'rm' command... (1 Reply)
Discussion started by: Francy
1 Replies

9. Shell Programming and Scripting

List and Delete Files which are older than 7 days, but have white spaces in file name

I need to list and delete all files in current older which are olderthan 7 days. But my file names have white spaces. Before deleting I want to list all the files, so that I can verify.find . -type f -mtime +7 | xargs ls -l {} But the ls command is the working on the files which have white... (16 Replies)
Discussion started by: karumudi7
16 Replies
Moose::Cookbook::Basics::Recipe6(3)			User Contributed Perl Documentation		       Moose::Cookbook::Basics::Recipe6(3)

NAME
Moose::Cookbook::Basics::Recipe6 - The augment/inner example VERSION
version 2.0205 SYNOPSIS
package Document::Page; use Moose; has 'body' => ( is => 'rw', isa => 'Str', default => sub {''} ); sub create { my $self = shift; $self->open_page; inner(); $self->close_page; } sub append_body { my ( $self, $appendage ) = @_; $self->body( $self->body . $appendage ); } sub open_page { (shift)->append_body('<page>') } sub close_page { (shift)->append_body('</page>') } package Document::PageWithHeadersAndFooters; use Moose; extends 'Document::Page'; augment 'create' => sub { my $self = shift; $self->create_header; inner(); $self->create_footer; }; sub create_header { (shift)->append_body('<header/>') } sub create_footer { (shift)->append_body('<footer/>') } package TPSReport; use Moose; extends 'Document::PageWithHeadersAndFooters'; augment 'create' => sub { my $self = shift; $self->create_tps_report; inner(); }; sub create_tps_report { (shift)->append_body('<report type="tps"/>'); } # <page><header/><report type="tps"/><footer/></page> my $report_xml = TPSReport->new->create; DESCRIPTION
This recipe shows how the "augment" method modifier works. This modifier reverses the normal subclass to parent method resolution order. With an "augment" modifier the least specific method is called first. Each successive call to "inner" descends the inheritance tree, ending at the most specific subclass. The "augment" modifier lets you design a parent class that can be extended in a specific way. The parent provides generic wrapper functionality, and the subclasses fill in the details. In the example above, we've created a set of document classes, with the most specific being the "TPSReport" class. We start with the least specific class, "Document::Page". Its create method contains a call to "inner()": sub create { my $self = shift; $self->open_page; inner(); $self->close_page; } The "inner" function is exported by "Moose", and is like "super" for augmented methods. When "inner" is called, Moose finds the next method in the chain, which is the "augment" modifier in "Document::PageWithHeadersAndFooters". You'll note that we can call "inner" in our modifier: augment 'create' => sub { my $self = shift; $self->create_header; inner(); $self->create_footer; }; This finds the next most specific modifier, in the "TPSReport" class. Finally, in the "TPSReport" class, the chain comes to an end: augment 'create' => sub { my $self = shift; $self->create_tps_report; inner(); }; We do call the "inner" function one more time, but since there is no more specific subclass, this is a no-op. Making this call means we can easily subclass "TPSReport" in the future. CONCLUSION
The "augment" modifier is a powerful tool for creating a set of nested wrappers. It's not something you will need often, but when you do, it is very handy. AUTHOR
Stevan Little <stevan@iinteractive.com> COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Infinity Interactive, Inc.. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.12.5 2011-09-06 Moose::Cookbook::Basics::Recipe6(3)
All times are GMT -4. The time now is 09:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy