<?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: script to move files by month in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968866#M95458</link>
    <description>Hi:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I know find and mtime will identify all files from 90days however this may not capture all files.&lt;BR /&gt;&lt;BR /&gt;Why not?  The 'find' options offer '-mtime' as well as '-newer'.  With '-mtime' you have the ability to specify exactly, greater than or less than.  With '-newer' you can specify ranges of time by creating two reference files and comparing greater than one and not greater than the second.&lt;BR /&gt;&lt;BR /&gt;Of course, limit all of your 'find' selections to files only ('-type f') and don't cross mountpoints ('-xdev').&lt;BR /&gt;&lt;BR /&gt;See the 'find' manpages for more information.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Mon, 26 Mar 2007 07:25:19 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2007-03-26T07:25:19Z</dc:date>
    <item>
      <title>script to move files by month</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968863#M95455</link>
      <description>Hi guys,&lt;BR /&gt;&lt;BR /&gt;I am working on a script that will move and comppress files that are from 3 months ago.&lt;BR /&gt;&lt;BR /&gt;what I need is a solution to find all files in a directory that are from say december which is 3 months previous.  I know find and mtime will identify all files from 90days however this may not capture all files.&lt;BR /&gt;&lt;BR /&gt;any help would be great&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Mon, 26 Mar 2007 07:14:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968863#M95455</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2007-03-26T07:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files by month</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968864#M95456</link>
      <description>How about using touch to create a reference file of a certain date and then using the -newer option to move anything older than that?&lt;BR /&gt;&lt;BR /&gt;Something like:&lt;BR /&gt;&lt;BR /&gt;touch ref_file mmddyy, etc.&lt;BR /&gt;find /start_dir ! -newer ref_file&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Mon, 26 Mar 2007 07:21:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968864#M95456</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2007-03-26T07:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files by month</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968865#M95457</link>
      <description>I should also add that you need to consult the man pages for exact syntax for the touch and find commands.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Mon, 26 Mar 2007 07:24:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968865#M95457</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2007-03-26T07:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files by month</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968866#M95458</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I know find and mtime will identify all files from 90days however this may not capture all files.&lt;BR /&gt;&lt;BR /&gt;Why not?  The 'find' options offer '-mtime' as well as '-newer'.  With '-mtime' you have the ability to specify exactly, greater than or less than.  With '-newer' you can specify ranges of time by creating two reference files and comparing greater than one and not greater than the second.&lt;BR /&gt;&lt;BR /&gt;Of course, limit all of your 'find' selections to files only ('-type f') and don't cross mountpoints ('-xdev').&lt;BR /&gt;&lt;BR /&gt;See the 'find' manpages for more information.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 26 Mar 2007 07:25:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968866#M95458</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-03-26T07:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files by month</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968867#M95459</link>
      <description>Thanks Pete but I am looking to automate the move so the script can work out all files in the directory that where created in December.&lt;BR /&gt;&lt;BR /&gt;how can I make the script determine all files from december?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Mon, 26 Mar 2007 07:25:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968867#M95459</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2007-03-26T07:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files by month</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968868#M95460</link>
      <description>Hi (again) Lawrenzo:&lt;BR /&gt;&lt;BR /&gt;There is no such thing in Unix as a creation date, only a modification date that coincidently equals a creation timestamp because there was one and only one instantiation.&lt;BR /&gt;&lt;BR /&gt;That said, this should work sufficiently well:&lt;BR /&gt;&lt;BR /&gt;# touch -mt 200612010000 /tmp/ref1&lt;BR /&gt;# touch -mt 200612312359 /tmp/ref2&lt;BR /&gt;&lt;BR /&gt;# find /path -xdev -type f -newer /tmp/ref1 -a ! -newer /tmp/ref2&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 26 Mar 2007 07:30:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968868#M95460</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-03-26T07:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files by month</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968869#M95461</link>
      <description>I have reopened this thread because I require an automated solution within a script, can someone advise ....&lt;BR /&gt;&lt;BR /&gt;Basically I have a directory with 3 months of data in, at month 4 I have to cat the files to one large file and gzip, then when a file is required I have the code that extracts the data and recreates the original file ( Thanks JRF )&lt;BR /&gt;&lt;BR /&gt;The problem I am having is determining how to create the archive file archive.mprcout.&amp;lt;0701&amp;gt; ie:&lt;BR /&gt;&lt;BR /&gt;would I be best to setup a load of variables to determine the month&lt;BR /&gt;&lt;BR /&gt;date=`date +%m`&lt;BR /&gt;&lt;BR /&gt;if [ $date -eq 04 ] ; then&lt;BR /&gt;      date=01&lt;BR /&gt;elif [ $date -eq 05 ] ; then&lt;BR /&gt;      date=02&lt;BR /&gt;etc&lt;BR /&gt;etc&lt;BR /&gt;&lt;BR /&gt;then the time stamp on the files will eqaul a letter string ie Jan therefore to match all files with Jan and concatenate to archive.mprcout.&amp;lt;0701&amp;gt; I would:&lt;BR /&gt;&lt;BR /&gt;date=`date +%m`&lt;BR /&gt;&lt;BR /&gt;if [ $date -eq 04 ] ; then&lt;BR /&gt;      date=01&lt;BR /&gt;      month=Jan&lt;BR /&gt;elif [ $date -eq 05 ] ; then&lt;BR /&gt;      date=02&lt;BR /&gt;      month=feb&lt;BR /&gt;etc&lt;BR /&gt;etc&lt;BR /&gt;&lt;BR /&gt;again is there a simpler method to achieve this&amp;gt;&lt;BR /&gt;&lt;BR /&gt;many thanks&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Tue, 03 Apr 2007 05:44:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968869#M95461</guid>
      <dc:creator>lawrenzo</dc:creator>
      <dc:date>2007-04-03T05:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files by month</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968870#M95462</link>
      <description>Just use math, notably the modulus operator % !&lt;BR /&gt;&lt;BR /&gt;The alternative is to subtract and if zero or less re-add 12.&lt;BR /&gt;(Or add 8 (12-4) and subtract 12 when gt 12)&lt;BR /&gt;&lt;BR /&gt;$ current=05&lt;BR /&gt;$ let  backup=$current+12-4&lt;BR /&gt;$# yes, you can use +8, but this is more clear.&lt;BR /&gt;$ echo $backup&lt;BR /&gt;13&lt;BR /&gt;$ let backup=$backup%12&lt;BR /&gt;$ echo $backup&lt;BR /&gt;1&lt;BR /&gt;$ zbackup=$(printf  "%02d"  $backup)&lt;BR /&gt;$ echo $zbackup&lt;BR /&gt;01&lt;BR /&gt;&lt;BR /&gt;I suppose you can also use typeset to force the formatting.&lt;BR /&gt;&lt;BR /&gt;Personnaly i would use proper date math (perl?) and not muck with the year/month transitions myself&lt;BR /&gt;&lt;BR /&gt;Also... you may want to consider to retain your refrence files in a fixed location such that you know what was done last. Then recalculate just 1 endpoint, and mv ref2 ref1. &lt;BR /&gt;&lt;BR /&gt;Finally.. what if magically a 5 month old file shows up?  Do you want it captured? In the current cycle seperate. If it can go to the current cycle then just use olde reference file, not the newer.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Hein van den Heuvel&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 03 Apr 2007 06:32:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968870#M95462</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-04-03T06:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files by month</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968871#M95463</link>
      <description>On the typeset suggestion...&lt;BR /&gt;&lt;BR /&gt;$ WINDOW=3&lt;BR /&gt;$ YEAR=$(date +%Y)&lt;BR /&gt;$ let MONTH=$(date +%m)-$WINDOW&lt;BR /&gt;$ if [ $MONTH -le 1 ];  then let MONTH=$MONTH+12; let YEAR=$YEAR-1; fi&lt;BR /&gt;$ typeset -Z2 ZMONTH=$MONTH&lt;BR /&gt;$ NAME=${YEAR}${MONTH}&lt;BR /&gt;$ echo $NAME&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 03 Apr 2007 09:04:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968871#M95463</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-04-03T09:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files by month</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968872#M95464</link>
      <description>correction&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; $ if [ $MONTH -le 1 ]; &lt;BR /&gt;&lt;BR /&gt;That should of course be -lt 1&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Hein.&lt;BR /&gt;[ 0 point for this ]&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Apr 2007 06:17:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968872#M95464</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-04-04T06:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files by month</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968873#M95465</link>
      <description>logrotate provides this ability as well&lt;BR /&gt;&lt;A href="http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/logrotate-2.5/" target="_blank"&gt;http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/logrotate-2.5/&lt;/A&gt;  Maybe you can leverage from it.&lt;BR /&gt;&lt;BR /&gt;Logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Apr 2007 08:29:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files-by-month/m-p/3968873#M95465</guid>
      <dc:creator>Cheryl Griffin</dc:creator>
      <dc:date>2007-04-04T08:29:31Z</dc:date>
    </item>
  </channel>
</rss>

