Delete files created before specific date.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete files created before specific date.
# 1  
Old 05-05-2009
Lightbulb Delete files created before specific date.

There is a system logging a huge amount of data and we need to delete some of the older logs .I mean the files that are created before one week from today. Here is a listing of files that are sitting there:
/usr/WebSphere/AppServer/logs
# ls -l
-rw-r--r-- 1 root system 3740694 May 03 13:14 eFlow.log
-rw-r--r-- 1 root system 2863367 Feb 17 23:59 eFlow.log2009-02-17
-rw-r--r-- 1 root system 7089482 Feb 18 23:59 eFlow.log2009-02-18
-rw-r--r-- 1 root system 7092836 Feb 19 23:59 eFlow.log2009-02-19
-rw-r--r-- 1 root system 7066516 Feb 20 23:59 eFlow.log2009-02-20
-rw-r--r-- 1 root system 7565633 Feb 21 23:59 eFlow.log2009-02-21
-rw-r--r-- 1 root system 7208210 Feb 27 23:59 eFlow.log2009-02-27
-rw-r--r-- 1 root system 7923604 Feb 28 23:59 eFlow.log2009-02-28
-rw-r--r-- 1 root system 7092836 Mar 01 23:59 eFlow.log2009-03-01
-rw-r--r-- 1 root system 9994678 Mar 02 23:59 eFlow.log2009-03-02
-rw-r--r-- 1 root system 7542130 Mar 03 23:59 eFlow.log2009-03-03
-rw-r--r-- 1 root system 7091377 Mar 04 23:59 eFlow.log2009-03-04
-rw-r--r-- 1 root system 6249702 Mar 06 23:59 eFlow.log2009-03-06
-rw-r--r-- 1 root system 7046123 Mar 07 23:59 eFlow.log2009-03-07
-rw-r--r-- 1 root system 7085965 Mar 08 23:59 eFlow.log2009-03-08
-rw-r--r-- 1 root system 7088620 Mar 09 23:59 eFlow.log2009-03-09
-rw-r--r-- 1 root system 7088620 Mar 10 23:59 eFlow.log2009-03-10
-rw-r--r-- 1 root system 7077497 Mar 11 23:59 eFlow.log2009-03-11
-rw-r--r-- 1 root system 6585525 Mar 13 23:59 eFlow.log2009-03-13
-rw-r--r-- 1 root system 7027121 Mar 14 23:59 eFlow.log2009-03-14
-rw-r--r-- 1 root system 7087194 Mar 15 23:59 eFlow.log2009-03-15
-rw-r--r-- 1 root system 7087194 Mar 16 23:59 eFlow.log2009-03-16
-rw-r--r-- 1 root system 7082678 Mar 17 23:59 eFlow.log2009-03-17
-rw-r--r-- 1 root system 7087194 Mar 18 23:59 eFlow.log2009-03-18
-rw-r--r-- 1 root system 44349749 Mar 19 23:59 eFlow.log2009-03-19
-rw-r--r-- 1 root system 9859356 Mar 20 23:59 eFlow.log2009-03-20
-rw-r--r-- 1 root system 10412244 Mar 21 23:59 eFlow.log2009-03-21
-rw-r--r-- 1 root system 8315508 Mar 22 23:59 eFlow.log2009-03-22
-rw-r--r-- 1 root system 7092836 Mar 23 23:59 eFlow.log2009-03-23
-rw-r--r-- 1 root system 8212466 Mar 24 23:59 eFlow.log2009-03-24
-rw-r--r-- 1 root system 7637270 Mar 25 23:59 eFlow.log2009-03-25
-rw-r--r-- 1 root system 43091141 Mar 26 23:59 eFlow.log2009-03-26
-rw-r--r-- 1 root system 7350430 Mar 27 23:59 eFlow.log2009-03-27
-rw-r--r-- 1 root system 7062982 Mar 28 23:59 eFlow.log2009-03-28
-rw-r--r-- 1 root system 7092836 Mar 29 23:59 eFlow.log2009-03-29
-rw-r--r-- 1 root system 7598982 Mar 30 23:59 eFlow.log2009-03-30
-rw-r--r-- 1 root system 7358271 Mar 31 23:59 eFlow.log2009-03-31
-rw-r--r-- 1 root system 7088996 Apr 01 23:59 eFlow.log2009-04-01
-rw-r--r-- 1 root system 42804120 Apr 02 23:59 eFlow.log2009-04-02
-rw-r--r-- 1 root system 8162814 Apr 03 23:59 eFlow.log2009-04-03
-rw-r--r-- 1 root system 10470761 Apr 04 23:59 eFlow.log2009-04-04
-rw-r--r-- 1 root system 10512896 Apr 05 23:59 eFlow.log2009-04-05
-rw-r--r-- 1 root system 44687293 Apr 06 23:59 eFlow.log2009-04-06
-rw-r--r-- 1 root system 7090632 Apr 07 23:59 eFlow.log2009-04-07
-rw-r--r-- 1 root system 8356189 Apr 08 23:59 eFlow.log2009-04-08
-rw-r--r-- 1 root system 46229290 Apr 09 23:59 eFlow.log2009-04-09
-rw-r--r-- 1 root system 6170341 Apr 10 23:59 eFlow.log2009-04-10
-rw-r--r-- 1 root system 7048246 Apr 11 23:59 eFlow.log2009-04-11
-rw-r--r-- 1 root system 7091275 Apr 12 23:59 eFlow.log2009-04-12
-rw-r--r-- 1 root system 7092836 Apr 13 23:59 eFlow.log2009-04-13
-rw-r--r-- 1 root system 7250532 Apr 14 23:59 eFlow.log2009-04-14
-rw-r--r-- 1 root system 6723072 Apr 15 23:59 eFlow.log2009-04-15
-rw-r--r-- 1 root system 43798773 Apr 16 23:59 eFlow.log2009-04-16
-rw-r--r-- 1 root system 6626049 Apr 17 23:59 eFlow.log2009-04-17
-rw-r--r-- 1 root system 6658579 Apr 18 23:59 eFlow.log2009-04-18
-rw-r--r-- 1 root system 6721511 Apr 19 23:59 eFlow.log2009-04-19
-rw-r--r-- 1 root system 18957673 Apr 20 23:59 eFlow.log2009-04-20
-rw-r--r-- 1 root system 6721511 Apr 21 23:59 eFlow.log2009-04-21
-rw-r--r-- 1 root system 7717785 Apr 22 23:59 eFlow.log2009-04-22
-rw-r--r-- 1 root system 42807804 Apr 23 23:59 eFlow.log2009-04-23
-rw-r--r-- 1 root system 7029300 Apr 24 23:59 eFlow.log2009-04-24
-rw-r--r-- 1 root system 6677253 Apr 25 23:59 eFlow.log2009-04-25
-rw-r--r-- 1 root system 7184666 Apr 26 23:59 eFlow.log2009-04-26
-rw-r--r-- 1 root system 6835662 Apr 27 23:59 eFlow.log2009-04-27
-rw-r--r-- 1 root system 2408802 Apr 28 23:59 eFlow.log2009-04-28
-rw-r--r-- 1 root system 6774561 Apr 29 23:59 eFlow.log2009-04-29
-rw-r--r-- 1 root system 73019 Apr 30 00:18 eFlow.log2009-04-30
-rw-r--r-- 1 root system 39808025 May 02 23:59 eFlow.log2009-05-02
# 2  
Old 05-05-2009
To delete files older than 7 days

find $PATH -mtime +7 -type f -exec rm -f {} \;
# 3  
Old 05-05-2009
the whole contents of the shell script file

Many thanks man.Smilie
Please help me again . I don't know what is the whole contents of the shell script file .
The path of the files that I want to delete is :
/usr/WebSphere/AppServer/logs
Thanks again.
# 4  
Old 05-05-2009
replace $PATH with your path.

Quote:
find /usr/WebSphere/AppServer/logs -mtime +7 -type f -exec rm -f {} \;
# 5  
Old 05-05-2009
you can also use xargs. This will improve performance when dealing with large number of files.

Code:
find /usr/WebSphere/AppServer/logs -type f -name "*.log* -mtime +7 -print | xargs rm -f


cheers,
Devaraj Takhellambam
# 6  
Old 05-05-2009
just to correct the typo in devtakh's solution ...

Quote:
find /usr/WebSphere/AppServer/logs -type f -name "*.log*" -mtime +7 -print | xargs rm -f
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Delete all files created in specific year

I have more than 200K files created in year 2017 under directory having size of 50GB. I want to all these files in one shot. Is there any faster option available with find command to delete all these file ? (6 Replies)
Discussion started by: sp23029
6 Replies

2. Shell Programming and Scripting

Files created on specific time

Hello Gurus, I am facing one issue to get a file for a specific time. There are about 300 files created between 6.30 pm to 7.15 pm everyday. Now I wanted only the file which is created on 6.45pm. No other files required. I have used "find" command to get the files, but not getting the expected... (3 Replies)
Discussion started by: pokhraj_d
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

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

5. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

6. UNIX Desktop Questions & Answers

How to delete files from a specific date?

Guys, I am wondering how to remove files for a specific date in a directory? for instance when I do ls -l , i see many files. And i want to delete files for date May 15: 58252015 May 10 03:45 my_05102012.log 58252015 May 15 06:45 my_05152012.log Thanks (8 Replies)
Discussion started by: DallasT
8 Replies

7. Shell Programming and Scripting

Showing files that were created at a certain Date

Guys i am having a bit of a trouble finding the creation date of a file. What i have to do is to redirect the output of a command (which i believed was ls -l but this command shows only the Modification time) into a file, which will contain all the files that were created on a certain date, for... (2 Replies)
Discussion started by: jimas13
2 Replies

8. Shell Programming and Scripting

print out date of files last created??

Hello everyone, I have this script here: use Time::Local; opendir (D, $ARGV) or die "Cant open"; foreach $file (readdir D) { $path = "$ARGV/$file"; next if ! -T $path; $last_mod = (stat $path); ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime ($last_mod); printf "%-15s:... (4 Replies)
Discussion started by: new bie
4 Replies

9. Filesystems, Disks and Memory

How to list files with specific created date

Hi, Would like to ask, which command is used to list all the files for specific date (says 1st May) and its size, for all files (including its subdirectory), in a mounted NFS disk to HP-UX. I would like to check for the total files came into my disk on 1st May. Very much appreciating your... (2 Replies)
Discussion started by: Draculla
2 Replies

10. Shell Programming and Scripting

List files created between specific date and time

Hi I need to write a script to list files in a directory created within specific date and time for eg list files created between Apr 25 2007 11:00 to Apr 26 2007 18:00. and then i have to count them Any suggestions pls ? (3 Replies)
Discussion started by: jazjit
3 Replies
Login or Register to Ask a Question