find command: various date ranges


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find command: various date ranges
# 1  
Old 10-24-2008
find command: various date ranges

Hi,

I have writtena script that will recursivly go into subdirecotries and report out what files there are in there that have not been accessed over various date ranges.

I do this using a number of find commands:
Code:
find . -path './.snapshot' -prune -o  -type f             -atime -8   
find . -path './.snapshot' -prune -o  -type f -atime +7   -atime -32  
find . -path './.snapshot' -prune -o  -type f -atime +31  -atime -187 
find . -path './.snapshot' -prune -o  -type f -atime +186 -atime -366 
find . -path './.snapshot' -prune -o  -type f -atime +365

I know this is highly inefficient - and it takes ages! Any suggestions on what I can do to speed this up?
As you can see I am having to ezxclude snapshots and am only interested in file sizes. For inforation, I then pipe this through an awk command to sum the total bytesand number of files.
# 2  
Old 10-24-2008
Are you on Linux?
# 3  
Old 10-24-2008
Ideally I'd be running this script on both Linux and Unix machines, but realise that this is going to make it harder, so trying to stick to Linux for now.

So in short - yes.
# 4  
Old 10-24-2008
I am not on Linux now - so I cannot give you a working answer in code form.
pseudo code:
use the stat command to produce the filename and the atime in epoch seconds
I think this is close to correct for the command I want - you can check it:
Code:
stat -c "%N %x" -t "%s" filename

This is what I need Linux to verify.
Code:
now=date "+%s"
find -path './snapshot' -prune -o -type f -exec stat -c "%x %N" -t "%s" {} | \
while read asecs filename
do
     daysago=$(( (now - asecs) / 86400  ))
     monthsago=$(( daysago / 30 ))
     echo "$daysago $monthsago $filename"
done | sort -n > outputfile

You now have a file you can work with using awk - atime in days before today, atime in months before today, and file name. The reason you do this is because you want to find all files just once. Repeating find over and over agsain on the same filesystem is a waste of time. And is why your code is slow.

Example: distribution of file ages in months order by months ago
Code:
awk ' { arr[$2]++ } END { for (i in arr) { print i, arr[i]} ' outputfile | sort -n

# 5  
Old 10-24-2008
Thanks. no time to check it right now - but will try on Monday.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grepping the data between 2 date ranges

Hi There, Good Day !! I have txt file containing data in the below format. There are many lines, here i have mentioned for example. cat remo.txt 2/3/2017 file1 3/4/2016 file2 6/6/2015 file5 1/1/2018 file3 4/3/2014 file4 - - - I need to grep the file names for given date rage... (11 Replies)
Discussion started by: kumar85shiv
11 Replies

2. UNIX for Beginners Questions & Answers

Search files between date ranges - Ctime usage

Hello, I am a noob and need some help. I am trying to find files created between a date range. For Example: These are files in directory. -rw-r--r-- 1 user staff 6 May 8 09:43 file1.txt -rw-r--r-- 1 user staff 6 May 8 09:43 file2.txt -rw-r--r-- 1 user... (8 Replies)
Discussion started by: r@v!7*7@
8 Replies

3. Programming

Derivation of values falling on date ranges

Hi Guys, I am having below tables used in oracle bal ID BALANCE BAL_DATE 1 -11.71 01-JAN-05 00.00.00 1 -405.71 02-JAN-05 00.00.00 1 -760.71 03-JAN-05 00.00.00 ref_table PRODUCT EFF_FROM_DATE EFF_TO_DATE TYPE MIN_AMT MAX_AMT CHARGE 12 01-JAN-05 00.00.00 01-JAN-06... (6 Replies)
Discussion started by: rohit_shinez
6 Replies

4. Shell Programming and Scripting

Compare colunmn and find value within a ranges

Dear All, sorry for open a new thread but the old one (https://www.unix.com/shell-programming-and-scripting/263430-find-values-within-range-output.html) is already marked as resolved but actually it doesn't work properly and the input file are a bit different. File 1: 1 195240910 + 2... (6 Replies)
Discussion started by: giuliangiuseppe
6 Replies

5. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

6. Shell Programming and Scripting

getting files between specific date ranges in solaris

hi ! how can i get files in a directory between certain date ranges ? say all files created/modified between Jan24 - Jan31 thanks (10 Replies)
Discussion started by: aliyesami
10 Replies

7. Linux

search on weblogic logs with date time ranges

Hi All, The developers want me to search and capture the weblogic log, you know this big logs of htmls. They want to me to have ranges on the date and time. Like from "2010-01-20 14:04:46,186" to "2010-01-20 15:00:12,490" I can only do this, cat /usr/local/bea/logs_prod1/debug.log... (1 Reply)
Discussion started by: itik
1 Replies

8. Shell Programming and Scripting

search on weblogic logs with date time ranges 2

Hi All, The developers want me to search and capture the weblogic log, you know this big logs of htmls. They want to me to have ranges on the date and time. Like from "2010-01-20 14:04:46,186" to "2010-01-20 15:00:12,490" I can only do this, cat /usr/local/bea/logs_prod1/debug.log |... (1 Reply)
Discussion started by: itik
1 Replies

9. Shell Programming and Scripting

date ranges

Hi, Please anyone help to achive this using perl or unix scripting . This is date in my table 20090224,based on the date need to check the files,If file exist for that date then increment by 1 for that date and check till max date 'i.e.20090301 and push those files . files1_20090224... (2 Replies)
Discussion started by: akil
2 Replies

10. Shell Programming and Scripting

Use date command to find last month

#!/usr/bin/ksh Does anyone have a good way to set a variable to last month? For example, today is 20070810. I would like to use the date command to set a variable to last months %m code, which is 07. If I pluck this months value (08) and user expr to do simple math on it, it returns 7 (not... (5 Replies)
Discussion started by: Cbish68
5 Replies
Login or Register to Ask a Question