<?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: scripting to move files to specific date in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979849#M99609</link>
    <description>I think this should do it.&lt;BR /&gt;Write the following into a file and keep it in /Inarchive , goto Inacrchive and execute this.&lt;BR /&gt;I have put the echo for mkdir and mv currently so that you can test if it works to your satisfaction and then you cabn remove the echo.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;find . -mtime +90 -type f | xargs ls -ld | awk '{print $6,$8,$NF}' &amp;gt; files.dat&lt;BR /&gt;grep ":" files.dat | awk '{print $1}' | sort -u | while read month &lt;BR /&gt;do&lt;BR /&gt;     year=$(date +%y)&lt;BR /&gt;     if test ! -d ../inarchive.$year$month &lt;BR /&gt;      then&lt;BR /&gt;         echo mkdir ../inarchive.$year$month&lt;BR /&gt;     fi&lt;BR /&gt;     files=$(grep "$month ..:" files.dat | awk '{print $NF}')&lt;BR /&gt;     echo mv $files ../inarchive.$year$month&lt;BR /&gt;done&lt;BR /&gt;grep -v ":" files.dat | awk '{print $1,$2}' | sort -u | while read month year&lt;BR /&gt;do&lt;BR /&gt;     year=$(echo $year | cut -c 3-4)&lt;BR /&gt;     if test ! -d ../inarchive.$year$month &lt;BR /&gt;      then&lt;BR /&gt;         echo mkdir ../inarchive.$year$month&lt;BR /&gt;     fi&lt;BR /&gt;     files=$(grep "$month ..$year" files.dat | awk '{print $NF}')&lt;BR /&gt;     echo mv $files ../inarchive.$year$month&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Ninad</description>
    <pubDate>Fri, 19 May 2006 04:26:10 GMT</pubDate>
    <dc:creator>Ninad_1</dc:creator>
    <dc:date>2006-05-19T04:26:10Z</dc:date>
    <item>
      <title>scripting to move files to specific date</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979844#M99604</link>
      <description>Hello all,&lt;BR /&gt;&lt;BR /&gt;I am attempting to write a script that searches an archive directory - finds files over 3 months old and create another directory then move the files to the specific month.&lt;BR /&gt;&lt;BR /&gt;ie.&lt;BR /&gt;&lt;BR /&gt;files listed in the directory will have dates such as march 1-31 feb 1-28/29 Jan 1 etc etc&lt;BR /&gt;&lt;BR /&gt;so I do a find /Inarchive -mtime + 90 -exec ls -l {} \;&lt;BR /&gt;&lt;BR /&gt;gives me my list then I wan to move these files to a specific date directory which is one dir up the tree with the original dirname then date ../Inarchive.yymm but this directory will need to be create from the script.&lt;BR /&gt;&lt;BR /&gt;I have some idea's by creating lots of variables but am open to suggestions.&lt;BR /&gt;&lt;BR /&gt;Thanks for you help chaps.&lt;BR /&gt;&lt;BR /&gt;Mr L.</description>
      <pubDate>Fri, 19 May 2006 03:37:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979844#M99604</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2006-05-19T03:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: scripting to move files to specific date</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979845#M99605</link>
      <description>You mean to say dir where files will be copied should have certain name and that dir be created on the fly? For exmaple if you move files for 2nd feb, dir will have name 2-FEB or something similar?</description>
      <pubDate>Fri, 19 May 2006 03:52:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979845#M99605</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2006-05-19T03:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: scripting to move files to specific date</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979846#M99606</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Use this way to get the month &amp;amp; date for the files that are being moved.&lt;BR /&gt;&lt;BR /&gt;NDATE=$(find /tmp -mtime +20 -exec ls -l {} \; |awk '{print $6 $7}')&lt;BR /&gt;&lt;BR /&gt;I assume that you run this script once every day.&lt;BR /&gt;&lt;BR /&gt;The 1st time you may get old files too.&lt;BR /&gt;&lt;BR /&gt;Chan</description>
      <pubDate>Fri, 19 May 2006 04:02:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979846#M99606</guid>
      <dc:creator>Chan 007</dc:creator>
      <dc:date>2006-05-19T04:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: scripting to move files to specific date</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979847#M99607</link>
      <description>Mr L,&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;cd lnarchive&lt;BR /&gt;for a in `find . -mtime + 90 -type f`&lt;BR /&gt;do&lt;BR /&gt;month=`ll $a | awk -F' ' '{print $6}'`&lt;BR /&gt;file=`ll $a | awk -F' ' '{print  $9}'`&lt;BR /&gt;if [ ! -d $month ]&lt;BR /&gt;then&lt;BR /&gt;echo "mkdir ../lnarchive.$month"&lt;BR /&gt;echo "mv $file ../$month/$file"&lt;BR /&gt;else&lt;BR /&gt;echo "mv $file ../$month/$file"&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;This script pulls out the filedate month and then check if the directoryy exists.&lt;BR /&gt;&lt;BR /&gt;If you are happy with the test run, remove the echo parts of the mkdir and mv lines.</description>
      <pubDate>Fri, 19 May 2006 04:15:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979847#M99607</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-05-19T04:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: scripting to move files to specific date</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979848#M99608</link>
      <description>Mr L,&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;cd lnarchive&lt;BR /&gt;for a in `find . -mtime + 90 -type f`&lt;BR /&gt;do&lt;BR /&gt;month=`ll $a | awk -F' ' '{print $6}'`&lt;BR /&gt;file=`ll $a | awk -F' ' '{print  $9}'`&lt;BR /&gt;if [ ! -d $month ]&lt;BR /&gt;then&lt;BR /&gt;echo "mkdir ../lnarchive.$month"&lt;BR /&gt;echo "mv $file ../lnarchive.$month/$file"&lt;BR /&gt;else&lt;BR /&gt;echo "mv $file ../lnarchive.$month/$file"&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;This script pulls out the filedate month and then check if the directoryy exists.&lt;BR /&gt;&lt;BR /&gt;If you are happy with the test run, remove the echo parts of the mkdir and mv lines.</description>
      <pubDate>Fri, 19 May 2006 04:16:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979848#M99608</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-05-19T04:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: scripting to move files to specific date</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979849#M99609</link>
      <description>I think this should do it.&lt;BR /&gt;Write the following into a file and keep it in /Inarchive , goto Inacrchive and execute this.&lt;BR /&gt;I have put the echo for mkdir and mv currently so that you can test if it works to your satisfaction and then you cabn remove the echo.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;find . -mtime +90 -type f | xargs ls -ld | awk '{print $6,$8,$NF}' &amp;gt; files.dat&lt;BR /&gt;grep ":" files.dat | awk '{print $1}' | sort -u | while read month &lt;BR /&gt;do&lt;BR /&gt;     year=$(date +%y)&lt;BR /&gt;     if test ! -d ../inarchive.$year$month &lt;BR /&gt;      then&lt;BR /&gt;         echo mkdir ../inarchive.$year$month&lt;BR /&gt;     fi&lt;BR /&gt;     files=$(grep "$month ..:" files.dat | awk '{print $NF}')&lt;BR /&gt;     echo mv $files ../inarchive.$year$month&lt;BR /&gt;done&lt;BR /&gt;grep -v ":" files.dat | awk '{print $1,$2}' | sort -u | while read month year&lt;BR /&gt;do&lt;BR /&gt;     year=$(echo $year | cut -c 3-4)&lt;BR /&gt;     if test ! -d ../inarchive.$year$month &lt;BR /&gt;      then&lt;BR /&gt;         echo mkdir ../inarchive.$year$month&lt;BR /&gt;     fi&lt;BR /&gt;     files=$(grep "$month ..$year" files.dat | awk '{print $NF}')&lt;BR /&gt;     echo mv $files ../inarchive.$year$month&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Ninad</description>
      <pubDate>Fri, 19 May 2006 04:26:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979849#M99609</guid>
      <dc:creator>Ninad_1</dc:creator>
      <dc:date>2006-05-19T04:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: scripting to move files to specific date</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979850#M99610</link>
      <description>Thats great guys, the script will be run every month via cron for this filesystem however I will use the syntax to create an archive policy and script for every directory on the server.&lt;BR /&gt;&lt;BR /&gt;Thanks a million!</description>
      <pubDate>Fri, 19 May 2006 06:10:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-to-move-files-to-specific-date/m-p/4979850#M99610</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2006-05-19T06:10:33Z</dc:date>
    </item>
  </channel>
</rss>

