The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Search files between a date range zcanji Shell Programming and Scripting 7 05-27-2009 12:31 PM
How can i copy files by date last modifed range? geauxsaints UNIX for Advanced & Expert Users 4 05-25-2008 11: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 11:24 AM
Sorting Files by date and moving files in date order rebel64 Shell Programming and Scripting 2 03-11-2008 12:45 PM
cp only files in certain date range ee7klt UNIX for Dummies Questions & Answers 1 06-27-2005 09:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-16-2002
rooh rooh is offline
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
  #2 (permalink)  
Old 03-16-2002
Kelam_Magnus's Avatar
Kelam_Magnus Kelam_Magnus is offline Forum Advisor  
Registered User
  
 

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...

  #3 (permalink)  
Old 03-18-2002
inpavan inpavan is offline
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
halfling halfling is offline
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0