Date range command (and delete)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Date range command (and delete)
# 1  
Old 11-12-2010
Date range command (and delete)

Hello. Newbie here....

I basically have a directory with tens of thousands (literally) subdirectories and need to delete those that are older than 2008 (hundreds) with all their contents. I've looked through all the RM parameters and still can't quite figure out how to specify the data range and then pipe it to a directory remove command. COuld some kind soul please help?

MTIA!!!!
# 2  
Old 11-12-2010
Suppose you want to find flat files from 2008. First, touch a pair of files, mark2008 to "2008-01-01 00:00:00" and to "2009-01-01 00:00:00", and then
Code:
 
find ... -type f -newer mark2008 ! -newer mark2009 |xargs -n999 rm -f

I suppose for complete accuracy, the time stamps should be 1 second less, like mark2007/8end to "2007/8-12-31-23:59:59"! Smilie
# 3  
Old 11-13-2010
Please be cautious of DGPickett solution because it does not match your requirement.
However because it does not delete directories it is less harmful than if it did delete them.
# 4  
Old 11-14-2010
If the old directories are to be deleted, that is usually more manual, and easier if there is a date component in some directory name. As you say, removing directories that are just old is perilous. For instance, configuration or software installed and found satisfactory for a long time are now in old directories. If this gets to be a pain, manually, you might want to consider your design from a file and directory life cycle point of view.
# 5  
Old 11-15-2010
I agree with DGPickett.
It is remarkably difficult to write a cleanup script which makes decisions based on a directory timestamp. This is because deleting files or subdirectories changes the directory timestamp. Also it is common to have a subdirectory with a timestamp newer than the parent directory.
# 6  
Old 11-15-2010
In good old MULTICS, there were no hard links, just soft, but because of that, any mod. timestamp rippled up the tree to the root, so you could date the whole subtree under any directory. Backups were very easy. That is one of the tradeoffs with the inode / UNIX file system. In UNIX, a file can be in many directories, so none 'owns' it.
# 7  
Old 11-16-2010
Off topic. DEC RSX11/M had the same concept.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to delete row in csv file on date range?

I want to delete row in csv file , which row value from 2009-10-01 to 2011-06-03 using script.my csv row data look like: 2009-10-01 2011-03-30 2011-03-31 2011-04-01 2011-06-03 2011-06-30 2011-07-01 2011-09-28 ... (7 Replies)
Discussion started by: rakibul639
7 Replies

2. Shell Programming and Scripting

Date range

Dear all, how can I select in the file below only the files created between Aug 14 2014 and Feb 03 2015? EZA2284I -rw-r--r-- 1 30 8 356954 Aug 15 2014 file1 EZA2284I -rw-rw-r-- 1 30 8 251396 Feb 05 12:53 file2 EZA2284I -rw-rw-r-- 1 30 8 ... (3 Replies)
Discussion started by: simomuc
3 Replies

3. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

4. Shell Programming and Scripting

Date listing in a date range

Solaris 10 ksh88 Sorry for re-hashing some of this, but I can't find a proper solution in the forums. Starting with /a/archive containing (on and on date formatted directories) 20060313 20080518 20100725 20121015 20060314 20080519 ... (1 Reply)
Discussion started by: moesplace
1 Replies

5. Shell Programming and Scripting

Delete lines falling in a range

Hi All, I have a file which contains lakhs of records 0136812368126 03000 Statement 1237129372189 02321 JIT 0136812368126 05000 terminal 1237129372189 05001 Utilise Is there an option to delete all lines which fall within the range 05000 to 05999? I tried... (6 Replies)
Discussion started by: swasid
6 Replies

6. Shell Programming and Scripting

sed delete range

Hi I would like to delete ranges of text from an html file; In the sentence; aqua>Stroomprobleem in Hengelo verholpen <a href="107-01.html"><font color=yellow>107</a> With several sentences like this in that file, where the text between <a href a> varies, so it needs to be deleted in the... (2 Replies)
Discussion started by: mdop
2 Replies

7. Shell Programming and Scripting

delete rows between closest pattern or range

Hi I am having some problom deleting the lines between two specific lines in a file. need to delete lines between two closest lines. i.e need to find the closest range or pattern in a file with repeating patterns. Sample Input: WARNING <some text in n number of lines> ERROR:2597... (10 Replies)
Discussion started by: sudheer1984
10 Replies

8. Shell Programming and Scripting

Grep a string in a range and delete the line

Hi, i need to delete a lines after searching a particular string but this searching should only happen after the 4th line.. basically imagine a file like this From: abcd.yahoo.com To: cdeb.yahoo.com Subject: hi all sdfsd sadasd asdasd dfsdf From: abcd.yahoo.com To:... (3 Replies)
Discussion started by: depakjan
3 Replies

9. UNIX for Dummies Questions & Answers

How to list file names in a certain date range using ls command?

Hi experts, I Need to print file names in a certain date range using ls:confused:. Please help me with any sample script. Thanks a lot in advance. Regards, Satish (4 Replies)
Discussion started by: satish.vutti
4 Replies

10. Shell Programming and Scripting

Get date range between 2 date input

Hi Experts, I have files name report_20090416 report_20090417 report_20090418 report_20090420 report_20090421 I have 2 input from user From Date: 20090417 To Date: 20090420 and I need to grep only those line in between. Output should be report_20090417 report_20090418... (3 Replies)
Discussion started by: tanit
3 Replies
Login or Register to Ask a Question