Solved

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

Posted on 2001-08-24
6
264 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
Comment Utility
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
Comment Utility
I guess we will see a few more universal suggestions soon.

======
Werner
0
 
LVL 6

Accepted Solution

by:
bira earned 300 total points
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 6

Expert Comment

by:bira
Comment Utility
0
 
LVL 6

Expert Comment

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

  Regards
0
 

Author Comment

by:petro2
Comment Utility
Does exactly what I need and exits correctly. thansk jq
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

744 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

12 Experts available now in Live!

Get 1:1 Help Now