Link to home
Start Free TrialLog in
Avatar of petro2
petro2

asked on

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  
Avatar of griessh
griessh
Flag of United States of America image

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
I guess we will see a few more universal suggestions soon.

======
Werner
ASKER CERTIFIED SOLUTION
Avatar of bira
bira

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bira
bira

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

  Regards
Avatar of petro2

ASKER

Does exactly what I need and exits correctly. thansk jq