Solved

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

Posted on 2001-08-24
6
265 Views
Last Modified: 2010-04-21
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  
0
Comment
Question by:petro2
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:griessh
ID: 6423615
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
 
LVL 11

Expert Comment

by:griessh
ID: 6423621
I guess we will see a few more universal suggestions soon.

======
Werner
0
 
LVL 6

Accepted Solution

by:
bira earned 300 total points
ID: 6423799
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:bira
ID: 6423801
0
 
LVL 6

Expert Comment

by:bira
ID: 6423803
I have places an cp ( copy command ) instead mv ( move )
for you to test.

  Regards
0
 

Author Comment

by:petro2
ID: 6423850
Does exactly what I need and exits correctly. thansk jq
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now