Hi,
I am writing the script for tomcat logs clean up ending with *.txt and *.log.
cleanup should be applied to logs older than 7 days logs same will be scheduled in cron.
after googling found below but it only help partially.
I can list out the files older than 7 days.
getting issue while combining the commands ,any best pointer can i have to the task?
If you are getting the list of files you want with one of the above, what would you prefer to happen next?
The second find command is selecting file in the current directory and below that are older than seven days, more correctly more than 7*24*60*60 seconds since last modified. The -exec ls -lrt {} \; section then attempts to give you the long (reversed time ordered) listing of each file. This is a one-at-a-time list, so the output will still be unsorted. Does this really matter?
You might do better with one of these:-
.... however if there are too many files to list in one go, this will break into multiple ls commands and the output will be sorted in chunks but still not entirely.
How about ORing in a second -name test using the -o operator (incl. parentheses)? Or, extend the ".log" pattern like [lt][ox][gt] (with the danger of false positives)?
You may have found ".log" files younger than 7 days as without grouping the -name tests using parentheses the -mtime will be valid for the ".txt" test only.
Hi,
Could someone help me that what the problem is in this code?
#!/bin/sh
FOLDER=/abc/datasource/checkstatus
TIMESTAMP=$(date +%s)
for filename in $(find $FOLDER -maxdepth 1 -type f -name "CHECK_STATUS*"); do
f1=$($filename -Eo "{4}+")
f2=$(date -d "$f1" +%s)
if... (11 Replies)
Hi,
I have multiple files in my log folder. e.g:
a_m1.log
b_1.log
c_1.log
d_1.log
b_2.log
c_2.log
d_2.log
e_m1.log
a_m2.log
e_m2.log
I need to keep latest 10 instances of each file.
I can write multiple find commands but looking if it is possible in one line.
m file are monthly... (4 Replies)
Hello all,
I want to list the files older than 10 days. Currently am using
find ./ -mtime +10 -exec ls -ltr {} \;
command. But I want to execute the same command in 16 directories at a time and want an output asking to remove those file?
Please help me to design the script.
regards,
Ajay (3 Replies)
Hi All,
Problem Statement:Find all log files under all file systems older than 2 days and zip them. Find all zip files older than 3days and remove them. Also this has to be set under cron.
I have a concerns here
find . -mtime +2 -iname "*.log" -exec gzip {}
Not sure if this will work as... (4 Replies)
Hi ,
I am a newbie!!!
I want to develop a script for deleting files older than x days from multiple paths. Now I could reach upto this piece of code which deletes files older than x days from a particular path. How do I enhance it to have an input from a .txt file or a .dat file? For eg:... (12 Replies)
To delete log files content older than 30 days and append the lastest date log file date in the respective logs
I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs
This is my script
cd... (2 Replies)
Hi
I want to find the total space used by the files which are older than x days
find ./ -type f -mtime +x-days -name "G00*" -exec du {} \; | awk '{total+=$1}END{print "TOTAL" total}'
Total prints as 17.20 MB ( total / 1024*2 )
But actual size of it will be around 18.5 GB... (1 Reply)
Hi All,
OS :- HP-UX wm5qa B.11.23 U ia64 1119805695 unlimited-user license
I need to search files older than 50 days. I've used following command in order to search desired files, I also discoverd, it's showing today's files as well. Do you have any clue with this ?
wmqa1> find .... (4 Replies)
What command arguments I can use in unix to list files older than 10 days in my current directory, but I don't want to list the hidden files.
find . -type f -mtime +15 -print will work but, it is listing all the hidden files., which I don't want. (4 Replies)
Script help, I need to delete files that are older than 7 days. I do that automatically but I know that a cron job can do the job for me. Any help is greatly appreciated, as you can see, I am a DOS or WINDOWS guy. Little on UNIX. Thanks (3 Replies)