Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Problems extracting some information

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-18-2012
Skirmish Skirmish is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 18 November 2012, 1:58 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Problems extracting some information

Hi there!

Well, I'm writing a script to obtain certain information about files. Specifically, I want to get the information about those files which last access were in the last 24 hours, so I'm doing something like this:


Code:
find <directory_name> -atime -1 -printf '%f %a\n'

I would also like to add some extra information to this result: I would like to obtain the date and time of the last modification of these files if that is also during the last 24 hours, so that I might use '%t' anywhere. The problem is that not all files were also modified during this time. How could I implement this condition in the code? I want a result like this:


Code:
<file_name1> <last_access_time1>
<file_name2> <last_access_time2> <last_modification_time2>
<file_name3> <last_access_time3>
<file_name4> <last_access_time4>
<file_name5> <last_access_time5> <last_modification_time5>
      ...               ...                        ...

where files 2 and 5 were modified within the last 24 hours. Is there a way to insert conditions to fulfill before printing the results? Or anything equivalent to get this behaviour?

Thanks in advance.
Regards.
Sponsored Links
    #2  
Old Unix and Linux 11-18-2012
msabhi's Unix or Linux Image
msabhi msabhi is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 2 November 2013, 1:26 AM EDT
Location: In books/UNIX.com
Posts: 177
Thanks: 16
Thanked 61 Times in 60 Posts

Code:
find . -name "*" -type f -mtime -1  -exec stat -c "{} %x %y" {} \;

---------- Post updated at 01:17 PM ---------- Previous update was at 01:15 PM ----------

And if you want those angles


Code:
find . -name "*" -type f -mtime -1  -exec stat -c "<{}> <%x> <%y>" {} \;

Sponsored Links
    #3  
Old Unix and Linux 11-18-2012
Skirmish Skirmish is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 18 November 2012, 1:58 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Yes, that shows me the last modification time and last access time, but only for the files accessed and modified within the last 24 hours. I would be also interested in those files accessed within the last 24 hours, but not modified...

Thank you for your answer anyway Linux
    #4  
Old Unix and Linux 11-18-2012
msabhi's Unix or Linux Image
msabhi msabhi is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 2 November 2013, 1:26 AM EDT
Location: In books/UNIX.com
Posts: 177
Thanks: 16
Thanked 61 Times in 60 Posts

Code:
 find . -name "*" -type f -atime -1 -a -mtime +1 -exec stat -c "<{}> <%x> <%y>" {} \;

Accessed in last 24 hours but not modified in last 24 hours
Sponsored Links
    #5  
Old Unix and Linux 11-18-2012
Skirmish Skirmish is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 18 November 2012, 1:58 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you so much for your help, msabhi Linux
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extracting relevant information from syslogs. lewk Shell Programming and Scripting 2 09-12-2012 07:04 AM
extracting information from multiple files houkto Shell Programming and Scripting 4 11-15-2011 02:51 PM
Problems with extracting information c0mrade Shell Programming and Scripting 0 11-17-2008 03:17 PM
Extracting information from text fields. spindoctor UNIX for Dummies Questions & Answers 24 06-09-2007 01:17 PM
Extracting information from a template Ernst Shell Programming and Scripting 4 03-07-2007 12:18 AM



All times are GMT -4. The time now is 12:10 PM.