The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How can i copy files by date last modifed range? geauxsaints UNIX for Advanced & Expert Users 4 05-25-2008 08:06 AM
How to display files that have been modifed between a given date range prathima UNIX for Dummies Questions & Answers 1 04-02-2008 08:24 AM
Sorting Files by date and moving files in date order rebel64 Shell Programming and Scripting 2 03-11-2008 08:45 AM
Search files between a date range zcanji Shell Programming and Scripting 4 09-05-2007 12:38 AM
cp only files in certain date range ee7klt UNIX for Dummies Questions & Answers 1 06-27-2005 06:35 PM

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-16-2002
Registered User
 

Join Date: Jul 2001
Posts: 62
Question Moving Files within a particular date range

Hi,
Can someone please help me with this.

Actually i want to move files from one directory to another directory , But I just want to move files of a specific data range.

For ex:
This is my directory which contains all fine.
/home/Rooh
Then there is a long listing of files.
suppose this directory contains files from feb 01 , march01, april 01.
But I just want to move files of Feb 01 to another Directory for ex:
/home/abd/FILESFEB_01

How can I do this.
I have tried alot but somehow I am unable to get the output I want.
I have also tried with -mtime but doesn't give me the desired output.
Your Help will be highly appreciated.
Thanks.
ROOH
Forum Sponsor
  #2 (permalink)  
Old 03-16-2002
Kelam_Magnus's Avatar
Unix does a body good.
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
use grep and for loop

Off the top of my head here is one longhanded way is to use grep.


Do a long listing of your directory that has files you want to move. Then determine the modify dates of those files. Now use grep here

Do:

ls -la |grep -e "Mar 1" -e "Mar 2" -e "Mar 3" > some.file

Now do a for loop to move them

for name in `cat some.file` # backtics here
do
mv $name /some/other/directory
done 2> /some/error.log # I always use an error log just in case


Of course you will possibly need to cleanup the "some.file" before running the for loop.

This is a crude way to do it but I think that it will work well.


Enjoy!
My Brain is your brain...

__________________
My brain is your brain
  #3 (permalink)  
Old 03-17-2002
Registered User
 

Join Date: Sep 2001
Posts: 36
The following script should do the job if Feb01 file stands for files with mtime "Feb" (I mean, +20...today is 18th March 2002)

mv `find . -mtime +20` urfolder

Note: change the number in mtime as per your requirement...
  #4 (permalink)  
Old 03-18-2002
Registered User
 

Join Date: Mar 2002
Posts: 8
This will move files by month, and will only work if there is no white-space in the file's name.

ls -go |sed '/^d/ d' |awk '{ if ( $4 == "Feb" ) print $7 } |xargs -i mv {} /home/abd/FILESFEB_01/

Sometimes usernames can bleed over to group IDs in a long listing, which would mess up the awk statement. So use option g and o to remove the owner and group columns.

sed is there to remove the directories from the listing.

awk statement will check the month column to see if it's equal, in this case, to Feb. If it is, it'll print the file name (again, file names with white-space won't work).

Finally pass it to xargs. If you're not familiar with xargs, read up on it... very useful in the right situations.
__________________
Potatoes grow in the ground.
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:00 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0