Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding file with a specific time_stamp 1

Status
Not open for further replies.

annanathan

Programmer
May 1, 2002
24
0
0
CA
Hi All,

Does anyone know how to Remove all the files in a particular directory if their last time modified was yesterday at 8:30am? (or any specific time stamp )

Any help is appreacited.
Thank you.
 
man find Vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Hi annanathan,

try this command:

find your_search_dir -mtime -1 -exec ls -la {} \; | grep 08:30

-mtime -1 means you are only interested in files that were modified in the last 24 hours.

mrjazz [pc2]
 
Hi annanathan again,

just found a problem with the -exec ls -al part [sad].

This small script works in Bourne or Korn shell

LIST=`find your_search_path -mtime -1 -ls | grep 08:30 | awk ´{ print $11 }´`

for file in $LIST
do
rm $file
done

mrjazz
 
Hi mrjazz,

what does awk '{print $11}' mean? what is $11?

thank you.
 
Hi,

$11 means the field #11 of output for &quot;ls -al&quot; (the name of the file).

To complete the Mrjazz solution's, i think you can try :

find your_search_path -mtime -1 -type f -ls | grep 08:30 | awk ´{print $11 }´ | xargs rm

Regards,

Gilles
 
Thank you all for you help... but I have one more question...

The above examples remove the files of the day stamp of 08:30 exact of yesterday's files, right! What if I want to remove all files prior to that time stamp? let's say remove all the files in a particular directory prior to yesterday 08:30 (not exactly 08:30, but before that)

Thank you in advance.
Annanathan
 
A possible solution :

find your_search_path -mtime -1 -type f -ls | sed 's/://g' | awk '$10 < your-hour_without_: {print $11}' | xargs rm

It workes but,surely, there's abetter way to do it.

Bye,

Gilles
 
I'm very new to unix scripting, so I might sound dum, but I have another question:

what does sed 's/://g' do?

i tried the man page, but it doesn't help me much...

Thank you.
 
sed 's/://g' means that you will substitue (&quot;s&quot;) each &quot;:&quot; with ...nothing (/://)in each line (g).

Gilles
 
Thank you....

Everyone has been of real help, especially gillou and mrjazz. I got my script to work thanks to you.
 
Just a minor correction. The g in 's/://g' means do the substitution for every occurrence of : on a line. Without the g sed will only do the first substitution on every line. CaKiwi
 
Just joined tek-tips .. good stuff. Am back-reading some of the postings and figured I would step in on this one. When I have to find (and/or delete) files after a certain date/TIME, 'touch' a start file and find from that point:

% touch 0708083002 start_here
% find /start/path !-newer start_here -exec rm {} \;

check the man page for touch as formats vary. In my example I touched &quot;start_here&quot; and set the date to Jul 08, 2002 08:30. The find command the finds all files that are older (actually = &quot;not newer&quot;) than the set date of my start file.

WMj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top