Does 'grep' update a file's access date/time?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Does 'grep' update a file's access date/time?
# 1  
Old 06-14-2013
Does 'grep' update a file's access date/time?

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!
# 2  
Old 06-14-2013
Yes, they would affect the access time, but not the modification time.
Code:
$ ls -lu file
-rw-r--r--  1 scott  staff  157 14 Jun 17:37 file
$ grep x file
$ ls -lu file
-rw-r--r--  1 scott  staff  157 14 Jun 19:03 file

# 3  
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:
# 4  
Old 06-14-2013
Of course, I hadn't considered mount options like "noatime". A very clear explanation, Don.
# 5  
Old 06-14-2013
I like to use "| xargs -n101" rather than "-exec {} +" as you get some pipeline parallelism: find does not stop while it is running rm.
# 6  
Old 06-18-2013
You also have to consider that a regular backup of the files will access them.

I have some replication software on a server and after the schedule, there is a pause waiting for some large outgoing file transfers and then the backup kicks in. On the data transmission logs for the replication software, we can see a vast I/O increase when the back is reading several million small files, and this information is replicated to the remote site.

Sorry if I'm the bearer of bad news.




Robin
Liverpool/Blackburn
UK
# 7  
Old 06-18-2013
Yes, it is less durable than the archive bit in Windows, and so of little use. Most practical apps use the date modified, to control backup and archiving. For casual use, "find -mtime -<days>" is good, but for precise set definition you need something like:
Code:
touch marker_new
sleep 1 # get out of new marker file's second
find ... -newer marker_last ! -newer marker_new | ...
mv -f marker_last marker_done # in case you need a rerun
mv marker_new marker_last

---------- Post updated at 12:19 PM ---------- Previous update was at 12:15 PM ----------

Yes, it is less durable than the archive bit in Windows, and so of little use. Most practical apps use the date modified, to control backup and archiving. For casual use, "find -mtime -<days>" is good, but for precise set definition you need something like:
Code:
touch marker_new
sleep 1 # get out of new marker file's second
find ... -newer marker_last ! -newer marker_new | ...
mv -f marker_last marker_done # in case you need a rerun
mv marker_new marker_last

You need to bracket your files with two dates in the past. If you start in th current second, you might miss files modified later in that second. A second is a long time for a modern computer ! Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question