Three month old specific files deletion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Three month old specific files deletion
# 1  
Old 09-10-2014
Three month old specific files deletion

Hi,

I need to delete 3 month old files in my logpath. This path contains several logs and other important files

The file names are be like this

sl_details.env
tomcatfiles_03062014.log
application_zur_03.062014.log

I need to delete only tomcatfiles logs. I wrote this command.

can some one confirm is it good or any best is there

Code:
find . -type f -name "tomcatfiles*log" -mtime +90 ! -name "*.gz" | xargs gzip -9v

# 2  
Old 09-10-2014
Hello Nag_sathi,

Following command may help you in same. It will delete the files older than 90 days with name

Code:
find . -type f -mtime +90 -name "tomcatfiles*.log" | xargs rm -rf

Also please use only find to double check that all files which you are getting as output are good to delete.

Here is an example I tried in my server.

Code:
ls -ltr | grep tomcat
-rw-r--r-- 1 Singh01 Singh01                0 Dec 12  2013 tomcat_13.log
-rw-r--r-- 1 Singh01 Singh01                0 Dec 12  2013 tomcat_12.log
 
find . -mtime +90 -name "*.log"
./tomcat_13.log
./tomcat_12.log
 
find . -mtime +90 -name "*.log" | xargs rm -rf
 
ls -ltr | grep tomcat
<NO Result now>


Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 09-10-2014
Quote:
Originally Posted by RavinderSingh13
Hello Nag_sathi,

Following command may help you in same. It will delete the files older than 90 days with name

Code:
find . -type f -mtime +90 -name "tomcatfiles*.log" | xargs rm -rf

Also please use only find to double check that all files which you are getting as output are good to delete.

... ... ...

Thanks,
R. Singh
There is no need to start up xargs for this. The following does the same thing without invoking xargs:
Code:
find . -type f -mtime +90 -name 'tomcatfiles*.log' -exec rm -f {} \;

These 2 Users Gave Thanks to Don Cragun For This Post:
# 4  
Old 09-10-2014
Quote:
Originally Posted by nag_sathi
I need to delete 3 month old files in my logpath.
Please specify what exactly you mean by "3 month old":

exactly 3 months/90 days?
3 months/90 days and older?
3 months / 90 days and younger?

The command you wrote:

Code:
find .  -mtime +90

selects the second variant (90 days and older), which might not be what you want.

If you want to specify an exact timeframe (only files older than a certain point in time and younger than a certain other point in time) you can use two reference files with the "-newer" clause:

Code:
find /some/path -newer referencefile1 ! -newer referencefile2

You can create these reference files with "touch" and give them the timestamp you need.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 5  
Old 09-10-2014
Better to use -exec operator.

First use this for verification:
find . -type f -mtime +90 -name 'tomcatfiles*.log' -exec ls {} \;

And then this for deletion:
find . -type f -mtime +90 -name 'tomcatfiles*.log' -exec rm -f {} \;

Last edited by Corona688; 09-10-2014 at 04:32 AM..
This User Gave Thanks to dinesh1178 For This Post:
# 6  
Old 09-10-2014
Hi All,

Thanks for the response.

If i want to zip only log files and omit all existing zipped files,other files.

is the below work

Code:
find . -type f -name "tomcatfiles*log" -mtime +90 ! -name "*.gz" | xargs gzip -9v

# 7  
Old 09-10-2014
Hi,

Specifying "tomcatfiles*log" will only find files that start "tomcatfiles" and end "log" so the exclusion of the ".gz" files is superfluous also you should use the "-exec" switch within find.

So the command would look like;

Code:
find . -type f -mtime +90 -name "tomcatfiles*.log" -exec gzip -9v {} \;

Regards

Dave

Last edited by gull04; 09-10-2014 at 09:20 AM.. Reason: Wrong Quotes
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Deletion of strings depending of the value in a specific column

Happy new year guys! I have a new question for you! Ubuntum, Bash version: 4.3.46 BashI have a csv file, composed from several columns. INPUT x1 x2 x3 x4 x5 as 10 32 T 3 sd 50 7 B 48 af 18 98 D 25 fe 75 55 P 15 I want to cancel the strings where the x2 and/or x3 values are <=10... (6 Replies)
Discussion started by: echo manolis
6 Replies

2. Shell Programming and Scripting

Need last month files after 10th of every month

Hi, I need all file names in a folder which has date >= 10th of last month, Example : files in folder AUTO_F1_20140610.TXT BUTO_F1_20140616.TXT CUTO_F1_20140603.TXT FA_AUTO_06012014.TXT LA_AUTO_06112014.TXT MA_AUTO_06212014.TXT ZA_AUTO_06232014.TXT Output: AUTO_F1_20140610.TXT... (9 Replies)
Discussion started by: nani1984
9 Replies

3. Shell Programming and Scripting

Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All, I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer. Any ideas would be appreciated! (5 Replies)
Discussion started by: pnara2
5 Replies

4. Shell Programming and Scripting

Fake deletion of files

Hi, This is possibly an odd request to do with permissions as I seem to have tied myself up with these! I have the following directory (see below) that contains files that the 'usergrp' user needs to be able to 'delete' files from. drwxr-s--- 2 usergrp usergrp 512 16 Feb 14:37... (2 Replies)
Discussion started by: Peejay
2 Replies

5. UNIX for Advanced & Expert Users

find files modified in a specific month

hello i need a way to list files modified in a specific month and move them to a specific directry , i mean somthing like : find . -modifiedtime "May" -print -exec /usr/bin/mv newdirectory thank u (1 Reply)
Discussion started by: omer_ome
1 Replies

6. Solaris

find files modified in a specific month

hello i need a way to list files modified in a specific month and move them to a specific directry , i mean somthing like : find . -modifiedtime "May" -print -exec /usr/bin/mv newdirectory thank u (1 Reply)
Discussion started by: omer_ome
1 Replies

7. HP-UX

find files modified in a specific month

hello i need a way to list files modified in a specific month and move them to a specific directry , i mean somthing like : find . -modifiedtime "May" -print -exec /usr/bin/mv newdirectory thank u (1 Reply)
Discussion started by: omer_ome
1 Replies

8. UNIX for Dummies Questions & Answers

Deletion of log files.

We have log files dating back to 2004. I need to write an interative script that will request the user for how many months he needs to keep the log files and remove all the remaing log files after that month. Supposing we are now in June 2006 , if teh user request to keep log file for the last 3... (1 Reply)
Discussion started by: Geeta
1 Replies

9. Shell Programming and Scripting

backup files for a specific month

i am having a problem with writing a shell script to back up files for a specific month. the month and year are specified as paramters. so a backup of all the files modified during the specified month have to be made. for example if specify 200406 as my parameter, it should back up files that have... (3 Replies)
Discussion started by: problems
3 Replies

10. Shell Programming and Scripting

Regarding deletion of old files

Hi, I have a list of directories which contain old files that are to be deleted. I put the list of all directories in a txt file and it is being read by a script Iam searching for the files older than 60 days using mtime and then deleting it But all the files are getting deleted... (3 Replies)
Discussion started by: Chidvilas
3 Replies
Login or Register to Ask a Question