Register
It is currently Sun Dec 21, 2014 7:02 am

Selecting files or folder older or newer than x minutes


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Tue Jan 21, 2014 9:42 am   

Joined: Tue Jan 21, 2014 9:26 am
Posts: 2
First we Need a helper file

Code:
# Create helper file for > 5 min
helperFile1()
{
   echo -e "INFO  : Create helper-file $HELPER1 for folders older than 5 min on $SRC"
   touch -t `date -d "-5 minutes" +"%Y%m%d%H%M"` $HELPER1
   #echo -e "DEBUG : Helper file created $HELPER1"
}

helperFile1


after creating a helper file we can work with files or folders older than 5 min

Code:
# check for new folders  in $SRC
if [ "$(ls -A $SRCDIR)" ]; then
   echo -e "INFO  : $SRC Is not Empty"

   echo -e "INFO  : Find all folder older than 5 min and move from $SRC to $DEST"
   
      for i in `find . -type d ! -newer $HELPER1`;do
          mv $i $DESTDIR
      done


to find newer files use
Code:
for i in `find . -type d -newer $HELPER1`;

instead of
Quote:
for i in `find . -type d ! -newer $HELPER1`;


Last edited by timetraxx on Wed Jan 22, 2014 1:50 am, edited 1 time in total.

Top
 Profile  
 PostPosted: Tue Jan 21, 2014 10:04 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
hi,

``for'' loop is useless, and may break if filename contains an IFS character.

instead, use -exec, or -execdir find's option.


Top
 Profile  
 PostPosted: Wed Jan 22, 2014 1:48 am   

Joined: Tue Jan 21, 2014 9:26 am
Posts: 2
Hi Watael,

thank you for your comment This explanation is important.
I know the "issue" about "for" loop and the IFS.
IFS typically includes the space, tab, and the newline. But in my Case there are no IFS Character.

cheers


Top
 Profile  
 PostPosted: Fri Jan 31, 2014 3:26 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 673
Location: Des Moines, Iowa
Pretty interesting solution :) I like it.


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP