<?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 in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990986#M100447</link>
    <description>Thank you everyone - got there in the end!&lt;BR /&gt;&lt;BR /&gt;James thanks for the suggestion however the business have request the archive directories this was.&lt;BR /&gt;&lt;BR /&gt;I like your idea however it wouldn't work for what is required as there are over 3000 files daily that sometimes require a search etc etc.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Chris.</description>
    <pubDate>Tue, 18 Jul 2006 02:54:44 GMT</pubDate>
    <dc:creator>lawrenzo_1</dc:creator>
    <dc:date>2006-07-18T02:54:44Z</dc:date>
    <item>
      <title>script to move files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990973#M100434</link>
      <description>i am trying to write a function that checks the date of files in a directory and if the files are not equal to today then create the dir:&lt;BR /&gt;&lt;BR /&gt;set -x&lt;BR /&gt;for i in `ls -l |awk '{print $6,$7}' |uniq`&lt;BR /&gt;do&lt;BR /&gt;if [ $i != $TODAY ] ; then&lt;BR /&gt;DIR=$($i |sed s/' '//)&lt;BR /&gt;mkdir $DIR&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;+ ls -l&lt;BR /&gt;+ uniq&lt;BR /&gt;+ awk {print $6,$7}&lt;BR /&gt;+ [ 06 != 20 Jul ]&lt;BR /&gt;+ + sed s/ //&lt;BR /&gt;+ 06&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;how can i parse "06 Jun" into [ $i != $TODAY ]as one string?&lt;BR /&gt;&lt;BR /&gt;Manyb Thanks&lt;BR /&gt;</description>
      <pubDate>Fri, 14 Jul 2006 07:48:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990973#M100434</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2006-07-14T07:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990974#M100435</link>
      <description>I don't see where you set TODAY. Setting it as such, should do the trick for you:&lt;BR /&gt;&lt;BR /&gt;TODAY=$(date +"%d %b")</description>
      <pubDate>Fri, 14 Jul 2006 08:35:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990974#M100435</guid>
      <dc:creator>Jeff_Traigle</dc:creator>
      <dc:date>2006-07-14T08:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990975#M100436</link>
      <description>Hi,&lt;BR /&gt;try with this:&lt;BR /&gt;&lt;BR /&gt;ls -l |awk '{print $6,$7}' |uniq|while read i&lt;BR /&gt;do&lt;BR /&gt;echo $i&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Enrico</description>
      <pubDate>Fri, 14 Jul 2006 09:15:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990975#M100436</guid>
      <dc:creator>Enrico P.</dc:creator>
      <dc:date>2006-07-14T09:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990976#M100437</link>
      <description>If you want exclude the directory from the ls command:&lt;BR /&gt;&lt;BR /&gt;ls -l |grep -v ^d|awk '{print $6,$7}' |uniq|while read i&lt;BR /&gt;do&lt;BR /&gt;if [ $i != $TODAY ] ; then&lt;BR /&gt;DIR=$($i |sed s/' '//)&lt;BR /&gt;mkdir $DIR&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Enrico</description>
      <pubDate>Fri, 14 Jul 2006 09:24:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990976#M100437</guid>
      <dc:creator>Enrico P.</dc:creator>
      <dc:date>2006-07-14T09:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990977#M100438</link>
      <description>And you need to quote the variables in the:&lt;BR /&gt;&lt;BR /&gt;if [ "$i" != "$TODAY" ] &lt;BR /&gt;&lt;BR /&gt;Sorry&lt;BR /&gt;Enrico</description>
      <pubDate>Fri, 14 Jul 2006 09:36:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990977#M100438</guid>
      <dc:creator>Enrico P.</dc:creator>
      <dc:date>2006-07-14T09:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990978#M100439</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;If I understand you correctly, you need something like that:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;TODAY=$(date +%d%b)&lt;BR /&gt;/bin/ls -lt  |grep -v ^d |while read FN; do&lt;BR /&gt;DATE=$(echo $FN|awk '{printf("%02d%s\n",$7,$6)}')&lt;BR /&gt;if [ "$DATE" != $TODAY ]; then&lt;BR /&gt;  if [ ! -d $DATE ] ; then&lt;BR /&gt;    mkdir $DATE&lt;BR /&gt;  fi&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;This works if all files in the current directory have been created on this year, otherwise you have to lok at $8, which is either year or HH:MM, but these are details.&lt;BR /&gt;&lt;BR /&gt;HTH</description>
      <pubDate>Fri, 14 Jul 2006 10:52:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990978#M100439</guid>
      <dc:creator>Victor Fridyev</dc:creator>
      <dc:date>2006-07-14T10:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990979#M100440</link>
      <description>&lt;!--!*#--&gt;Hi Lawrenzo,&lt;BR /&gt;&lt;BR /&gt;Change the awk statement on the for-loop line so that it outputs a string w/o any embedded spaces. This also helps in compacting code since you don't need the sed statement anymore, which basically removes embedded spaces in $i, and make sure $TODAY contains the same date format as $i. Here's your code with the suggested modifications.&lt;BR /&gt;&lt;BR /&gt;change -&amp;gt; awk '{print $6,$7}'&lt;BR /&gt;to -&amp;gt; awk '{print $6$7}'&lt;BR /&gt;&lt;BR /&gt;remove -&amp;gt; DIR=$($i |sed s/' '//)&lt;BR /&gt;&lt;BR /&gt;set -x&lt;BR /&gt;TODAY=$(date +"%b%d")&lt;BR /&gt;for i in `ls -l |awk '{print $6$7}' |uniq`&lt;BR /&gt;do&lt;BR /&gt;   if [ $i != $TODAY ]; then&lt;BR /&gt;      mkdir $i&lt;BR /&gt;   fi&lt;BR /&gt;done</description>
      <pubDate>Fri, 14 Jul 2006 12:10:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990979#M100440</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-07-14T12:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990980#M100441</link>
      <description>ok thats great to start my script off the main challenge I have here:&lt;BR /&gt;&lt;BR /&gt;I want to list all files in the directory - if the directory doesn't exist create it, then move the relevant date files to the directory&lt;BR /&gt;&lt;BR /&gt;if the directory does exist just move the files there.&lt;BR /&gt;&lt;BR /&gt;TY</description>
      <pubDate>Mon, 17 Jul 2006 06:58:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990980#M100441</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2006-07-17T06:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990981#M100442</link>
      <description>Hi Lawrenzo:&lt;BR /&gt;&lt;BR /&gt;I'd archive this way:&lt;BR /&gt;&lt;BR /&gt;# touch -amt 07170000 /tmp/myref #...today&lt;BR /&gt;# mkdir /tmp/myarchive&lt;BR /&gt;# cd /tmp/myarchive&lt;BR /&gt;# find /path ! -newer /tmp/me|cpio -padmxv .&lt;BR /&gt;&lt;BR /&gt;...This will find all files (and directories) that have been modified *before* today and copy then to your archive directory.  A listing of the files copied is automatically generated.  Modification and access times of the files are preserved.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Mon, 17 Jul 2006 07:17:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990981#M100442</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-07-17T07:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990982#M100443</link>
      <description>ok getting there now here is the function within the script &lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;&lt;BR /&gt;DIR=/usr/dump/JDE/data/out/ARCHIVE&lt;BR /&gt;LOGFILE=/sysadmin/logs/mvdata_JDE.log&lt;BR /&gt;REMOVE=/usr/dump/JDE/toberemoved&lt;BR /&gt;TODAY=$(date +"%d %b")&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;        for a in `find $DIR -ctime 1 -type f`&lt;BR /&gt;        do&lt;BR /&gt;&lt;BR /&gt;month=`ls -l $a | awk -F' ' '{print $6$7}'`&lt;BR /&gt;file=`ls -l $a | awk -F' ' '{print $9}'`&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;                if [ ! -d $month ] ; then&lt;BR /&gt;&lt;BR /&gt;                        mkdir /usr/dump/JDE/data/out/ARCHIVE/$month&lt;BR /&gt;                        mv $file /usr/dump/JDE/data/out/ARCHIVE/$month&lt;BR /&gt;&lt;BR /&gt;                else&lt;BR /&gt;                        mv $file /usr/dump/JDE/data/out/ARCHIVE/$month&lt;BR /&gt;                fi&lt;BR /&gt;        done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;this will create the directory and move the file.&lt;BR /&gt;&lt;BR /&gt;The issue I have now is when the script runs the second day it still attempts to move all files that where moved the previous day.&lt;BR /&gt;&lt;BR /&gt;how can i get find just to search the directory /usr/dump/JDE/data/out/ARCHIVE and not /usr/dump/JDE/data/out/ARCHIVE/day.mnth&lt;BR /&gt;&lt;BR /&gt;thanks</description>
      <pubDate>Mon, 17 Jul 2006 10:34:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990982#M100443</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2006-07-17T10:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990983#M100444</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;the easiest thing would be to keep the monthly archive outside the find tree:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;M_ARCHIVE=${DIR}-bymonth&lt;BR /&gt;&lt;BR /&gt;[ -d $M_ARCHIVE ] || mkdir $M_ARCHIVE&lt;BR /&gt;&lt;BR /&gt;for a in `find $DIR -ctime 1 -type f`&lt;BR /&gt;do&lt;BR /&gt; ...&lt;BR /&gt;   [ -d $M_ARCHIVE/$month ] || mkdir $M_ARCHIVE/$month&lt;BR /&gt;   mv $file $M_ARCHIVE/$month&lt;BR /&gt; ...&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Mon, 17 Jul 2006 11:19:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990983#M100444</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-07-17T11:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990984#M100445</link>
      <description>Hi (again) Lawrenzo:&lt;BR /&gt;&lt;BR /&gt;You are using the 'ctime' or last change time for a file's inode.  The 'ctime' changes whenever ownership, permissions are changed or whenever a file is renamed.&lt;BR /&gt;&lt;BR /&gt;Using 'ctime' tracks metadata changes.  If you truly want to find files based on *modification* of their data, you need to use 'mtime'.&lt;BR /&gt;&lt;BR /&gt;The manpages for 'stat(2)' will clarify things for you.&lt;BR /&gt;&lt;BR /&gt;BTW, I still suggest the 'cpio' method I posted above for your archiving needs.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 17 Jul 2006 11:47:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990984#M100445</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-07-17T11:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990985#M100446</link>
      <description>Modify the find command to exclude the other dir as follows:&lt;BR /&gt;&lt;BR /&gt;find $DIR ! -path "/usr/dump/JDE/data/out/ARCHIVE/day.mnth/*" -ctime 1 -type f&lt;BR /&gt;&lt;BR /&gt;~hope it helps</description>
      <pubDate>Mon, 17 Jul 2006 11:57:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990985#M100446</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-07-17T11:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: script to move files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990986#M100447</link>
      <description>Thank you everyone - got there in the end!&lt;BR /&gt;&lt;BR /&gt;James thanks for the suggestion however the business have request the archive directories this was.&lt;BR /&gt;&lt;BR /&gt;I like your idea however it wouldn't work for what is required as there are over 3000 files daily that sometimes require a search etc etc.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Chris.</description>
      <pubDate>Tue, 18 Jul 2006 02:54:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-move-files/m-p/4990986#M100447</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2006-07-18T02:54:44Z</dc:date>
    </item>
  </channel>
</rss>

