<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Checking if file is older than 1 week in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879420#M99018</link>
    <description># find &lt;DIR&gt; -xdev -type f -mtime +168&lt;/DIR&gt;</description>
    <pubDate>Thu, 12 Oct 2006 16:35:52 GMT</pubDate>
    <dc:creator>Sandman!</dc:creator>
    <dc:date>2006-10-12T16:35:52Z</dc:date>
    <item>
      <title>Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879417#M99015</link>
      <description>I know I can compare a file to the time stamp on another file, but is there a simpler way in ksh?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Oct 2006 16:24:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879417#M99015</guid>
      <dc:creator>dictum9</dc:creator>
      <dc:date>2006-10-12T16:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879418#M99016</link>
      <description># find /dir -type f -mtime +7&lt;BR /&gt;&lt;BR /&gt;will find files older that have not been modified in 7 days.&lt;BR /&gt;&lt;BR /&gt;If mtime doesn't do what you want try -atime or -ctime.&lt;BR /&gt;&lt;BR /&gt;Have a look at 'man find' for information on these options.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Oct 2006 16:30:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879418#M99016</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2006-10-12T16:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879419#M99017</link>
      <description># find &lt;DIR&gt; -type f -mtime +168&lt;/DIR&gt;</description>
      <pubDate>Thu, 12 Oct 2006 16:35:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879419#M99017</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-10-12T16:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879420#M99018</link>
      <description># find &lt;DIR&gt; -xdev -type f -mtime +168&lt;/DIR&gt;</description>
      <pubDate>Thu, 12 Oct 2006 16:35:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879420#M99018</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-10-12T16:35:52Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879421#M99019</link>
      <description>Sorry for the double-posting and the flawed command...change that to:&lt;BR /&gt;&lt;BR /&gt;# find &lt;DIR&gt; -xdev -type f -mtime +7&lt;BR /&gt;&lt;/DIR&gt;</description>
      <pubDate>Thu, 12 Oct 2006 16:38:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879421#M99019</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-10-12T16:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879422#M99020</link>
      <description>All this is good, but I forgot to say I want to do this within a ksh script. &lt;BR /&gt;&lt;BR /&gt;Someting like&lt;BR /&gt;&lt;BR /&gt;if [[ $file ]]; then&lt;BR /&gt;&lt;BR /&gt;fi</description>
      <pubDate>Thu, 12 Oct 2006 16:43:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879422#M99020</guid>
      <dc:creator>dictum9</dc:creator>
      <dc:date>2006-10-12T16:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879423#M99021</link>
      <description>I know you can do file1 -nt file2 # true if file1 is newer than file2&lt;BR /&gt;&lt;BR /&gt;and I can create file2 and then set its time stamp, but it seems awfully complicated. A simpler way?</description>
      <pubDate>Thu, 12 Oct 2006 16:44:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879423#M99021</guid>
      <dc:creator>dictum9</dc:creator>
      <dc:date>2006-10-12T16:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879424#M99022</link>
      <description>Another question, how do I check that a file does NOT exist?&lt;BR /&gt;&lt;BR /&gt;I know I can do:&lt;BR /&gt;&lt;BR /&gt;if [[ -f $file ]] then&lt;BR /&gt;...&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;but where do I put the "!" negation symbol?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Oct 2006 16:49:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879424#M99022</guid>
      <dc:creator>dictum9</dc:creator>
      <dc:date>2006-10-12T16:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879425#M99023</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;# if [[ ! -f $file ]] ...&lt;BR /&gt;&lt;BR /&gt;...negates the test for presence...&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 12 Oct 2006 16:58:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879425#M99023</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-10-12T16:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879426#M99024</link>
      <description>Thank you (and sorry for multiple feedback, I didn't read the posts too closely)</description>
      <pubDate>Thu, 12 Oct 2006 17:00:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879426#M99024</guid>
      <dc:creator>dictum9</dc:creator>
      <dc:date>2006-10-12T17:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879427#M99025</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;By the way, all you need to do to create a file with a timestamp of your choosing is to 'touch' the file:&lt;BR /&gt;&lt;BR /&gt;# touch -amt 2006100500.00 myfile&lt;BR /&gt;&lt;BR /&gt;...would create "myfile" or update the timestamp of "myfile" to set its both its 'atime' and 'mtime' to October 5, 2006 at 00:00:00 hours.  If you don't want to alter a timestamp of an existing file but only want to create one if it *doesn't* exist, add the '-c' swithch to the 'touch':&lt;BR /&gt;&lt;BR /&gt;# touch -camt 2006100500.00 myfile&lt;BR /&gt;&lt;BR /&gt;Look at the manpages for 'touch' for more information.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 12 Oct 2006 17:07:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879427#M99025</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-10-12T17:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879428#M99026</link>
      <description>&lt;!--!*#--&gt;Hi:&lt;BR /&gt;&lt;BR /&gt;It occurs to me that your "concern" is having to create and cleanup a temporary file to which you can compare another file's age.&lt;BR /&gt;&lt;BR /&gt;My first choice would be a one-line Perl snippet, but since you would like to keep things in shell only, consider something like this:&lt;BR /&gt;&lt;BR /&gt;# cat .fileage&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;MYT=${1}&lt;BR /&gt;MYF=${2}&lt;BR /&gt;REF=/var/tmp/${0##*/}.${$}&lt;BR /&gt;&lt;BR /&gt;if [ ${#} -ne 2 ]; then&lt;BR /&gt;    echo "Usage: timestamp file"&lt;BR /&gt;    exit 2&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;[ ! -f ${MYF} ] &amp;amp;&amp;amp; { echo "${MYF} doesn't exist"; exit 2; }&lt;BR /&gt;&lt;BR /&gt;trap 'rm -f ${REF}' EXIT&lt;BR /&gt;&lt;BR /&gt;touch -amt ${MYT} ${REF} || exit 1&lt;BR /&gt;&lt;BR /&gt;if [ ${MYF} -nt ${REF} ]; then&lt;BR /&gt;    echo "${MYF} is newer than ${MYT}"&lt;BR /&gt;else&lt;BR /&gt;    echo "${MYF} isn't newer than ${MYT}"&lt;BR /&gt;fi&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;...run, passnig a timestamp value and the name of a file for comparison of its age; e.g.:&lt;BR /&gt;&lt;BR /&gt;# ./fileage 200510131001 /etc/hosts&lt;BR /&gt;/etc/hosts is newer than 200510131001&lt;BR /&gt;&lt;BR /&gt;# .fileage 10131001 /etc/hosts&lt;BR /&gt;/etc/hosts isn't newer than 10131001&lt;BR /&gt;&lt;BR /&gt;The script creates a reference file for comparison purposes, but uses a 'trap' to cleanup (remove) the file.  This simplifies coding.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 13 Oct 2006 09:16:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879428#M99026</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-10-13T09:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879429#M99027</link>
      <description>I like Perl better, how would it look in Perl?</description>
      <pubDate>Fri, 13 Oct 2006 11:21:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879429#M99027</guid>
      <dc:creator>dictum9</dc:creator>
      <dc:date>2006-10-13T11:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879430#M99028</link>
      <description>P.S. &lt;BR /&gt;Thanks, the ksh is really good stuff too, I will implement it.&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Oct 2006 11:22:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879430#M99028</guid>
      <dc:creator>dictum9</dc:creator>
      <dc:date>2006-10-13T11:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Checking if file is older than 1 week</title>
      <link>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879431#M99029</link>
      <description>&lt;!--!*#--&gt;HI:&lt;BR /&gt;&lt;BR /&gt;OK, in Perl we have the '-M' file test operator to ascertain the number of days since modification.  We also have '-A' and '-C' for access and inode change times, if you want.&lt;BR /&gt;&lt;BR /&gt;Again, since your original question was about a shell script, and since I suggested that at the least you could add a snippet of Perl to the shell for your purposes, here's a different variation --- without any temporary files:&lt;BR /&gt;&lt;BR /&gt;# cat .fileage2&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;MYT=${1}         &lt;BR /&gt;MYF=${2}&lt;BR /&gt;&lt;BR /&gt;if [ ${#} -ne 2 ]; then&lt;BR /&gt;    echo "Usage: days file"&lt;BR /&gt;    exit 2&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;[ ! -f ${MYF} ] &amp;amp;&amp;amp; { echo "${MYF} doesn't exist"; exit 2; }&lt;BR /&gt;&lt;BR /&gt;R=`perl -e '$x=(@ARGV &amp;amp;&amp;amp; -f $ARGV[1] &amp;amp;&amp;amp; -M $ARGV[1] &amp;gt; $ARGV[0]) ? 1:0;print $x' &lt;BR /&gt;${MYT} ${MYF}`&lt;BR /&gt;&lt;BR /&gt;if [ ${R} -eq 1 ]; then&lt;BR /&gt;    echo "${MYF} is older than ${MYT} days"  &lt;BR /&gt;else&lt;BR /&gt;    echo "${MYF} is too young"&lt;BR /&gt;fi&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;...run this one ...passnig the number of days and the name of a file for comparison of its age; e.g.:&lt;BR /&gt;&lt;BR /&gt;# .fileage2 100 /etc/hosts&lt;BR /&gt;/etc/hosts is older than 100 days&lt;BR /&gt;&lt;BR /&gt;To integrate the Perl code into the shell, I elected to pass two arguments to Perl; the number of days and the file's name.  The code returns a one (1) or a zero (0) which can be captured by the shell and handled there.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 13 Oct 2006 11:53:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/checking-if-file-is-older-than-1-week/m-p/3879431#M99029</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-10-13T11:53:13Z</dc:date>
    </item>
  </channel>
</rss>

