moving files one at a time by oldest time to youngest time

I would like to move all the files in a directory, one at a time in 20 second internals with the files with the oldest date/time 1st and continue until finished. I know I can do the whole directory by
mv `ls /DIR/FILE*` /DIR2/

thanks  
petro2Asked:
Who is Participating?
 
biraConnect With a Mentor Commented:
Hi


   My suggestion is

     for i in `ls -ltr|awk '{print $9}'`
   do
      a=`ls -l |grep $i|cut -c1-1`
      if [ "$a" != "d" ] ; then
            echo "Processing $i ..."
            cp $i /destination_dir
             sleep 20
      fi
    done
0
 
griesshCommented:
ls -tr gives you the files sorted by time in reverse order (oldest first), just check the man pages for 'ls'.

In ksh I would do something like this:

ls -tr | while read -r line
do
if [ -f $line ] ; then
<your move>
sleep 20
fi
done

The if ... just makes sure that it is a file and not a directory ...

======
Werner
0
 
griesshCommented:
I guess we will see a few more universal suggestions soon.

======
Werner
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
biraCommented:
0
 
biraCommented:
I have places an cp ( copy command ) instead mv ( move )
for you to test.

  Regards
0
 
petro2Author Commented:
Does exactly what I need and exits correctly. thansk jq
0
All Courses

From novice to tech pro — start learning today.