<?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: commands (or script) to capture specific files. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/commands-or-script-to-capture-specific-files/m-p/2777512#M76360</link>
    <description>Hiya!&lt;BR /&gt;&lt;BR /&gt;First, the grep statement you use would not work, as it expects a stdin or file arguement.&lt;BR /&gt;&lt;BR /&gt;A find would be a good start:&lt;BR /&gt;&lt;BR /&gt;find /&lt;BR /&gt;&lt;BR /&gt;But then to get the 2001 bit you'd need to add:&lt;BR /&gt;&lt;BR /&gt;find / -exec ls -ld {} \; | grep 2001&lt;BR /&gt;&lt;BR /&gt;Better performance would be:&lt;BR /&gt;&lt;BR /&gt;find / | xargs ls -ld | grep 2001&lt;BR /&gt;&lt;BR /&gt;Then you want to trim off the file names&lt;BR /&gt;&lt;BR /&gt;find / | xargs ls -ld | grep 2001 | awk '{print $9}'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Then to move enclose the above in grav quotes:&lt;BR /&gt;&lt;BR /&gt;mv `above command` /your/destination/dir&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HOWEVER - DO NOT do this from /, as a lot of system files are 2001 dated. Start it off with &lt;BR /&gt;&lt;BR /&gt;find /your/file/directory&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Cheers!&lt;BR /&gt;James&lt;BR /&gt;&lt;BR /&gt;If it's hard, you're doing it wrong.&lt;BR /&gt;</description>
    <pubDate>Thu, 01 Aug 2002 11:46:05 GMT</pubDate>
    <dc:creator>James Beamish-White</dc:creator>
    <dc:date>2002-08-01T11:46:05Z</dc:date>
    <item>
      <title>commands (or script) to capture specific files.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/commands-or-script-to-capture-specific-files/m-p/2777511#M76359</link>
      <description>Greetings fellow SA's,&lt;BR /&gt;   As scripting is not a strong point for me, I need some help from you learned people. I want to use a series of commands (or need a script)&lt;BR /&gt;to capture files/directories that were creatred in the year 2001 for archival. I want to move them to a directory called: 2001_files&lt;BR /&gt;I was going to use the following at the command line from within the appropriate directory (for this eg the dir is /data/abcdef):&lt;BR /&gt;grep '2001' | mv -i * /data/abcedf/2001_files&lt;BR /&gt;  Can anyone tell me if this is the best way to do it, if not can you suggest a way?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;To</description>
      <pubDate>Thu, 01 Aug 2002 11:36:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/commands-or-script-to-capture-specific-files/m-p/2777511#M76359</guid>
      <dc:creator>Thomas J Dicks</dc:creator>
      <dc:date>2002-08-01T11:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: commands (or script) to capture specific files.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/commands-or-script-to-capture-specific-files/m-p/2777512#M76360</link>
      <description>Hiya!&lt;BR /&gt;&lt;BR /&gt;First, the grep statement you use would not work, as it expects a stdin or file arguement.&lt;BR /&gt;&lt;BR /&gt;A find would be a good start:&lt;BR /&gt;&lt;BR /&gt;find /&lt;BR /&gt;&lt;BR /&gt;But then to get the 2001 bit you'd need to add:&lt;BR /&gt;&lt;BR /&gt;find / -exec ls -ld {} \; | grep 2001&lt;BR /&gt;&lt;BR /&gt;Better performance would be:&lt;BR /&gt;&lt;BR /&gt;find / | xargs ls -ld | grep 2001&lt;BR /&gt;&lt;BR /&gt;Then you want to trim off the file names&lt;BR /&gt;&lt;BR /&gt;find / | xargs ls -ld | grep 2001 | awk '{print $9}'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Then to move enclose the above in grav quotes:&lt;BR /&gt;&lt;BR /&gt;mv `above command` /your/destination/dir&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HOWEVER - DO NOT do this from /, as a lot of system files are 2001 dated. Start it off with &lt;BR /&gt;&lt;BR /&gt;find /your/file/directory&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Cheers!&lt;BR /&gt;James&lt;BR /&gt;&lt;BR /&gt;If it's hard, you're doing it wrong.&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Aug 2002 11:46:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/commands-or-script-to-capture-specific-files/m-p/2777512#M76360</guid>
      <dc:creator>James Beamish-White</dc:creator>
      <dc:date>2002-08-01T11:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: commands (or script) to capture specific files.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/commands-or-script-to-capture-specific-files/m-p/2777513#M76361</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;DIR=/data/abcdef&lt;BR /&gt;DESTDIR=/data/abcedf/2001_files &lt;BR /&gt;&lt;BR /&gt;ll $DIR | while read LINE&lt;BR /&gt;do&lt;BR /&gt;  date=`echo $LINE|awk '{print $8}'`&lt;BR /&gt;  file=`echo $LINE|awk '{print $9}'`&lt;BR /&gt;  &lt;BR /&gt;  if [ $date = "2001" ]&lt;BR /&gt;  then&lt;BR /&gt;    mv "$DIR/$file" $DESTDIR&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;One way of many and probably more eleagant solutions, bu it works&lt;BR /&gt;&lt;BR /&gt;Good luck &lt;BR /&gt;&lt;BR /&gt;Chris&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Aug 2002 12:06:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/commands-or-script-to-capture-specific-files/m-p/2777513#M76361</guid>
      <dc:creator>Christopher McCray_1</dc:creator>
      <dc:date>2002-08-01T12:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: commands (or script) to capture specific files.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/commands-or-script-to-capture-specific-files/m-p/2777514#M76362</link>
      <description>I have two options, the best one would be find with newer and -atime option. First select the oldest file which was created on 2001, then:&lt;BR /&gt;# find . \( -newer filename -a -atime +210 \) -exec ll {} \;&lt;BR /&gt;&lt;BR /&gt;This will list the files whiche were created after 'filename' and which were not accessed for last 210 days (approx. 2002 Jan). if you find the list is correct, then replace ll with 'mv' command.&lt;BR /&gt;&lt;BR /&gt;you can also check a simple command:&lt;BR /&gt;# cd dir&lt;BR /&gt;# ls -la | grep 2001 | mv ...</description>
      <pubDate>Thu, 01 Aug 2002 12:18:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/commands-or-script-to-capture-specific-files/m-p/2777514#M76362</guid>
      <dc:creator>Sajid_1</dc:creator>
      <dc:date>2002-08-01T12:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: commands (or script) to capture specific files.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/commands-or-script-to-capture-specific-files/m-p/2777515#M76363</link>
      <description>Thomas,&lt;BR /&gt;&lt;BR /&gt;This should work as well.&lt;BR /&gt;&lt;BR /&gt;----- script starts ------&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;find /data/abcedf -type f | xargs ll | while read $LINE&lt;BR /&gt;do&lt;BR /&gt;     if [ `echo $LINE | awk '{print $8}'` = 2001 ]; then&lt;BR /&gt;      mv `echo $LINE | awk '{print $9}'` /data/abcedf/2001_files&lt;BR /&gt;     fi&lt;BR /&gt;done&lt;BR /&gt;------ script ends ------&lt;BR /&gt;Hai</description>
      <pubDate>Thu, 01 Aug 2002 12:28:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/commands-or-script-to-capture-specific-files/m-p/2777515#M76363</guid>
      <dc:creator>Hai Nguyen_1</dc:creator>
      <dc:date>2002-08-01T12:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: commands (or script) to capture specific files.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/commands-or-script-to-capture-specific-files/m-p/2777516#M76364</link>
      <description>if you really had your heart set on using grep then you could try - &lt;BR /&gt;&lt;BR /&gt;for FILE in $(ll |grep " 2001 "|tr -s " "|cut -d" " -f9)&lt;BR /&gt;do&lt;BR /&gt;mv $FILE /data/abcdef/2001_files&lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;Or to ensure that the file is not actually a directory -&lt;BR /&gt;&lt;BR /&gt;for FILE in $(ll |grep " 2001 "|tr -s " "|cut -d" " -f9)&lt;BR /&gt;do&lt;BR /&gt;if [ -f $FILE ]&lt;BR /&gt;then&lt;BR /&gt;mv $FILE /data/abcdef/2001_files&lt;BR /&gt;fi&lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;Then again as already mentioned find may be better and theres an option to find called -mtime which would locate files more than a specified number of days ago - eg&lt;BR /&gt;&lt;BR /&gt;find /data/abcdef -mtime +365&lt;BR /&gt;&lt;BR /&gt;You could do something like this then - &lt;BR /&gt;&lt;BR /&gt;DAY=$(date +%j)&lt;BR /&gt;for FILE in $(find /data/abcdef -mtime +$DAY)&lt;BR /&gt;do&lt;BR /&gt;mv $FILE /data/abcdef/2001_files&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;This would find all files older than the current year.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Aug 2002 12:52:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/commands-or-script-to-capture-specific-files/m-p/2777516#M76364</guid>
      <dc:creator>Nick Wickens</dc:creator>
      <dc:date>2002-08-01T12:52:40Z</dc:date>
    </item>
  </channel>
</rss>

