UNIX command: mv - Objective: move files based on timestamp


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers UNIX command: mv - Objective: move files based on timestamp
# 1  
Old 03-09-2005
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.
# 2  
Old 03-09-2005
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.
# 3  
Old 03-09-2005
Tools

I came across examples of using the find command in the thread https://www.unix.com/unix-for-dummies-questions-and-answers/15222-ls-help.html?s=. 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 11:30 PM..
# 4  
Old 03-10-2005
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
# 5  
Old 07-11-2008
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.

https://www.unix.com/unix-dummies-que...ven-dates.html


With a bit of cleverness the year can be a parameter.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need help with UNIX command to get the latest file from list of files with timestamp

Hi All, I have list of files like below with name abcxyz.timestamp. I need a unix command to pick the latest file from the list of below files. Here in this case the lates file is abcxyz.20190304103200. I have used this unix command "ls abcxyz*|tail -1" but i heard that it is not the appropriate... (2 Replies)
Discussion started by: rakeshp
2 Replies

2. Shell Programming and Scripting

Script to keep todays files based on Timestamp

Hi i need to keep todays files based on timestamp and archive the remaining files ex: Managerial_Country_PRD_20150907.csv Managerial_Country_PRD_20150907.csv Managerial_Country_PRD_20150906.csv Managerial_Country_PRD_20150905.csv (6 Replies)
Discussion started by: ram1228
6 Replies

3. UNIX for Dummies Questions & Answers

Script to keep todays files based on Timestamp

Hi i need to keep todays files based on timestamp and archive the remaining files ex: Managerial_Country_PRD_20150907.csv Managerial_Country_PRD_20150906.csv Managerial_Country_PRD_20150905.csv (2 Replies)
Discussion started by: ram1228
2 Replies

4. UNIX for Dummies Questions & Answers

Display files based on particular file timestamp

Hi, I have requirement to list out files that are created after particular file. ex. I have below files in my directory. I want to display files created after /dirdat/CG1/cg004440 file. ./dirdat/CG1/cg004438 09/07/14 0:44:05 ./dirdat/CG1/cg004439 09/07/14 6:01:48 ... (3 Replies)
Discussion started by: tmalik79
3 Replies

5. UNIX for Dummies Questions & Answers

Move Multiple Files adding date timestamp before file type

There are files in a directory and I have to move multiple files adding datetimestamp before the file type. /Data/ abc.csv def.csv ghi.csv I have to move this files to archive directory adding datatimestamp before .csv /archive/ abc_YYYYMMDDHHMMSS.csv def_YYYYMMDDHHMMSS.csv... (7 Replies)
Discussion started by: eskay
7 Replies

6. Shell Programming and Scripting

sort the files based on timestamp and execute sorted files in order

Hi I have a requirement like below I need to sort the files based on the timestamp in the file name and run them in sorted order and then archive all the files which are one day old to temp directory My files looks like this PGABOLTXML1D_201108121235.xml... (1 Reply)
Discussion started by: saidutta123
1 Replies

7. Shell Programming and Scripting

copy files based on creation timestamp

Dear friends.. I have the below listing of files under a directory in unix -rw-r--r-- 1 abc abc 263349631 Jun 1 11:18 CDLD_20110603032055.xml -rw-r--r-- 1 abc abc 267918241 Jun 1 11:21 CDLD_20110603032104.xml -rw-r--r-- 1 abc abc 257672513 Jun 3 10:41... (5 Replies)
Discussion started by: sureshg_sampat
5 Replies

8. Shell Programming and Scripting

Unix Script To Move Files Based On Grep

I am looking for advice on how to write a script that will rename and/or move files to a different directory based upon the results of a grep. Let's say I have ten files in a directory. Some of them - not all - contain the text 'HELLO'. I would like to be able to grep the files for that text,... (3 Replies)
Discussion started by: rjhjr64
3 Replies

9. UNIX for Dummies Questions & Answers

Using find command for timestamp based search

Hi, I am writing a script where i need to list all the files that have a scecific timestamp. I get this time stamp from another file. Is it possible to do this with 'find' command? Please let me know your valuable inputs. Thanks Sunny. (1 Reply)
Discussion started by: sunny_03
1 Replies

10. UNIX for Advanced & Expert Users

Move client files using UNIX command.

Is there a way to move file on the client(PC) from the UNIX command? i.e. copy c:\file1 to d:\file1. I like to use it in my unix script. I could copy file between the client and unix server using the following: print "\033&oBreceive $DESTFILE from $SOURCEFILE ascii delete" I was wonderful if... (2 Replies)
Discussion started by: pputh
2 Replies
Login or Register to Ask a Question