Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Does 'grep' update a file's access date/time? Post 302821405 by Don Cragun on Friday 14th of June 2013 01:14:46 PM
Old 06-14-2013
Duplicate info deleted.

----------------

Based on Scott's following comment, I have restored the original content of this message:

Quote:
Originally Posted by Scottie1954
I've got a job that finds and removes trace files based upon an access time of more than seven days (I've also tried a modify date).

Code:
find TABC*[0-9][0-9] -atime +7 -exec rm +

Code:
find TABC*[0-9][0-9] -mtime +7 -exec rm +

Whether I use -atime or -mtime, the process seems to work sporadically. Sometimes it removes the files as expected. Other times it won't "find" them at all. These files contain lots of data that I frequently grep/awk/head/tail through, so I am wondering if any of those commands would update my file's access date/time values, and thus render my find inaccurate.

Thank you!
As long as you aren't using some mount option that skips timestamp updates, any successful attempt to read data from a file will mark the access timestamp for that file for update. Sometime between when that timestamp is marked for update and the next time you successfully stat() the file, the access timestamp will be set to the current time.

Find will stat() every filename in the current directory that matches the filename matching pattern TABC*[0-9][0-9] and, if any of those filenames name a directory, any files in those directories recursively). All of the commands you specified (awk, grep, head, and tail) will attempt to read a file (and if successful, will mark the access timestamp for those files for update).
PS
Your find statement is missing an operand for rm. You probably meant:
Code:
find TABC*[0-9][0-9] -mtime +7 -exec rm {} +


Last edited by Don Cragun; 06-14-2013 at 02:51 PM..
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

file access inode update

When is a file "accessed" according to UNIX? For example: gzipping a file will not change the access time. (1 Reply)
Discussion started by: dangral
1 Replies

2. Shell Programming and Scripting

grep time and date

Hi, I have a file which is a result of a script running every two minutes. What I wanted to do is to grep a specific date and time (hour and minute) from the file and then count the occurance of 201. I need to get the result of occurance of 201 every 5 minutes. What should I include in my... (8 Replies)
Discussion started by: ayhanne
8 Replies

3. Shell Programming and Scripting

Processing a log file based on date/time input and the date/time on the log file

Hi, I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies

4. Shell Programming and Scripting

grep to show date/time of file the string was found in.

I've seen several examples of grep showing the filename the string was found in, but what I really need is grep to show the file details in long format (like ls -l would). scenario is: grep mobile_number todays_files This will show me the string I'm after & which files they turn up in, but... (2 Replies)
Discussion started by: woodstock
2 Replies

5. Shell Programming and Scripting

Show date/time with tail|grep command

Hi, I have a log file without date/time, and I want that everytime tail|grep find something it displays the date/time and the line. I have tried something like this command but without any luck to display the date/time: tail -F catalina.out | sed "s/^/`date `/" | egrep ... (6 Replies)
Discussion started by: julugu
6 Replies

6. Shell Programming and Scripting

grep - date & time range

Hi, I need to search email files by date & time range in email files. The timezone is not important. Can someone plz advise how i can do this ? For e.g A user can specify only A single date A date range date & time range Below is part of the email file. (4 Replies)
Discussion started by: coolatt
4 Replies

7. Shell Programming and Scripting

how to update date part with new increment date time

hi experts, my requirement is like this i need to develop a shell script to update date part with new incremental date time in file some 'X' which is kept at some server location incrementing every two hours.as i am new to this scripting i need support from u people,thanx in advance (1 Reply)
Discussion started by: amanmro
1 Replies

8. Shell Programming and Scripting

Grep the Content of a LOG File which has latest Date and Time

Hi All, Need a small help. I have a log file which keeps updating for every Minute with multiple number of lines. I just want to grep few properties which has latest Date and Time to it. How do i do it? I wanted to grep a property by name "Reloading cache with a maximum of" from the... (4 Replies)
Discussion started by: nvindraneel
4 Replies

9. UNIX Desktop Questions & Answers

grep a range of time & date

how can i grep a range? i have a text file with the following text: result.log.00:2012/01/02 12:00:07.422 LOG STARTED HERE N6Kashya29MemoryShieldScheduler_AO_IMPLE, pid=8662/8658, config=(alertThreshold=10,alertLevel=0,killThreshold=7200,coreThreshold=0,full=1), deltaTime=0,... (1 Reply)
Discussion started by: boaz733
1 Replies

10. Shell Programming and Scripting

Access log field - using awk to pull date/time

hey guys. the following line is a line taken from apache's access_log 10.10.10.10 - jdoe "GET /images/down.gif HTTP/1.1" 304 I'm concerned about the field that has the date and time in it. if assuming the delimiter in the file is a space, then the fourth field will always have the date... (5 Replies)
Discussion started by: SkySmart
5 Replies
All times are GMT -4. The time now is 03:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy