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
Purge files based on timestamp avl in file name sureshg_sampat Shell Programming and Scripting 3 02-29-2008 07:28 AM
Using find command for timestamp based search sunny_03 UNIX for Dummies Questions & Answers 1 02-12-2008 01:38 AM
how to move files into different folders based on filename italia5 UNIX for Dummies Questions & Answers 7 08-23-2006 07:04 AM
Move client files using UNIX command. pputh UNIX for Advanced & Expert Users 2 12-19-2003 01:23 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-09-2005
Registered User
 

Join Date: Mar 2005
Posts: 34
Stumble this Post!
UNIX command: mv - Objective: move files based on timestamp

I was wondering if there was a command to move files from one directory to another subdirectory based on the timestamp, i.e. moving from directory A files that have a timestamp of before the year 2005 into directory B. Directory B is a subdirectory located in directory A. I was advised to concatenate commands mv and find ... printed out the "man find" manual but it didn't make much sense. I also tried googling around but was not able to come upon any sites that talked about either moving files based on the timestamp, or concatenating the mv and find commands.

Please help!

Thanks.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-09-2005
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Stumble this Post!
Please use the search function on this site to locate threads that will help you answer your question. You will no doubt see many links on the use of find. Also, please see the FAQ section on this site as there is a FAQ regarding the use of find. Finally, please take a moment to read the rules of the board.
Reply With Quote
  #3 (permalink)  
Old 03-09-2005
Registered User
 

Join Date: Mar 2005
Posts: 34
Stumble this Post!
Cool

I came across examples of using the find command in the thread ls Help. It looks like probably some variation of a find / -mtime -63 will be included in the command. But how do I concatenate the mv command with the find? I tried searching for "concatenate commands" and "combine commands" in the forum but didn't come up with something that will assist me in this regard. Is there some sort of syntax that's to be followed when telling UNIX to move files that are older than x days old, in the above-example, 63 days old?
--- Edit ---
I tried executing mv * /DestinationDirectory/ | find / -mtime -63 but it started to go through the entire mount or something. I saw directories UNIX was checking that I didn't even want it to go through.
I was in the directory that I wanted to move the files for that were older than sixty days when I typed pwd to make sure I was in the right location.

Last edited by HLee1981; 03-09-2005 at 07:30 PM.
Reply With Quote
  #4 (permalink)  
Old 03-10-2005
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Stumble this Post!
You will need to use xargs or exec to process what find "finds". As an example: find / -name '*junk*' -exec mv * /new-dir/ {} \;

Here is a thread with a solution to your problem
Reply With Quote
  #5 (permalink)  
Old 07-11-2008
Registered User
 

Join Date: Mar 2008
Posts: 64
Stumble this Post!
You can confine your search to one year by using find with the "-newer" and "! -newer" against files you create with a specific date using "touch".

See this thread but consider setting the "-newer" file to the last minute of the previous year and the "! -newer" to the first minute of the following year.

files between any two given dates


With a bit of cleverness the year can be a parameter.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:51 PM.


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