How to move files older than certain time?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to move files older than certain time?
# 1  
Old 11-04-2016
How to move files older than certain time?

If there are 100 files created in a directory /data/ today from 2:00 AM to 10:00 AM

I need to move files older than 3:00 AM to a new directory /hold/

How to do that?

Also, if I have to move files between 3:00 AM to 9:00 AM, how to achieve that
# 2  
Old 11-04-2016
Did you consider the find command? Applying the -mmin twice to enclose the desired period, or the -newer test accordingly.
# 3  
Old 11-04-2016
How do I give the date?

Code:
find /data/ -type f -newer 11042016103500

Files are like

Code:
	1.5M (1612002)	Fri Nov 04 10:33:32 CDT 2016	887.txt 
	1.5M (1612002)	Fri Nov 04 10:33:32 CDT 2016	889.txt 
	1.6M (1652434)	Fri Nov 04 10:33:31 CDT 2016	877.txt 
	1.6M (1652434)	Fri Nov 04 10:33:31 CDT 2016	878.txt 
	1.8M (1837570)	Fri Nov 04 10:33:31 CDT 2016	879.txt 
	1.8M (1837570)	Fri Nov 04 10:33:31 CDT 2016	880.txt 
	1.7M (1748194)	Fri Nov 04 10:33:31 CDT 2016	881.txt


Last edited by Scrutinizer; 11-11-2016 at 06:32 AM.. Reason: code tags
# 4  
Old 11-11-2016
Quote:
Originally Posted by eskay
How do I give the date?

find /data/ -type f -newer 11042016103500
Did you consider to read the man-page for find?
Quote:
-newer file

File was modified more recently than file. If file is a symbolic link and the -H option or the -L
option is in effect, the modification time of the file it points to is always used.

BTW, there is no way you can reliably find out the creation date of a file. All discussions in this thread refer to the last modification time of the file (which in your case is probably sufficient).

Last edited by rbatte1; 11-14-2016 at 07:35 AM.. Reason: Changed Orange italic text into a QUOTE
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Total size utilizes by the files older than a time span

Through find command I identified the files older that 1 year. I need the overall size utilizes by these 1 year older files. Please share me the command to identify it .Thanks Please post in an adequate technical forum! (3 Replies)
Discussion started by: Sang
3 Replies

2. Shell Programming and Scripting

Process 2 lists at the same time and move files.

I have this while loop, that works but is quite slow to process though. I'm hopping there might be a faster/better way to find what I'm looking for. I have 2 lists of numbers, and want to only find files where a file name has both values present. each list has about 100 values. while... (10 Replies)
Discussion started by: whegra
10 Replies

3. Shell Programming and Scripting

How to move the files older than x days with similar directory structure?

Hello, I need to move all the files inside /XYZ (has multi-depth sub directories) that are older than 14 days to/ABC directory but with retaining the SAME directory structure. for example: /XYZ/1/2/3/A/b.txt should be moved as /ABC/1/2/3/A/b.txt I know about find /XYZ -type f -mtime +14... (3 Replies)
Discussion started by: prvnrk
3 Replies

4. Shell Programming and Scripting

Move log files with date and delete older than 3 weeks

I have written a script which generate one logfile on every sunday and thursday I want to move the older log files into /tmp directory befor generating new one so i used mv command like mv usr/sbin/appl/logfile.txt usr/sbin/appl/tmp 2) But when i move this file to /tmp it will... (1 Reply)
Discussion started by: Nakul_sh
1 Replies

5. UNIX for Advanced & Expert Users

HPUX move files older than 30 days

Hello, I have a script which finds files in a directory that are older than 30 days and moves them to the specified directory. The problem is I don't know why it works the way it does? Code: find . -name '*.sql' ! -mtime -30 -exec mv '{}' /dataload/archivelogs \; I was under the... (4 Replies)
Discussion started by: pure_jax
4 Replies

6. UNIX for Dummies Questions & Answers

move files older than 2 days to another folder

Hi I am facing problem in using this command, mv `find /export/june/PURGEDATA*.txt -mtime +2 -exec ls {} \;` june/archive/ mv: Insufficient arguments (1) Usage: mv f1 f2 mv f1 ... fn d1 mv d1 d2 Thank you in advance (2 Replies)
Discussion started by: vishwakar
2 Replies

7. Shell Programming and Scripting

files older than a certain time

I know how to find files, which are newer than a specific time. touch -t 201103300650 dummy find /path/to/files -type f -newer dummy -exec ls -l {} \; Is there a way to find files, which are older than a specific time? (2 Replies)
Discussion started by: BeefStu
2 Replies

8. Shell Programming and Scripting

Shell script to move certain files on scheduled time

Hi Friends, I want a shell script which will move certain .jar files from a specified location (say /publish/content) to (/publish/archive) on every saturday morning 6 am. One more thing to add is that before moving files it must check free space at (/publish/archive), if it is more than 60 %... (7 Replies)
Discussion started by: abhishek27
7 Replies

9. Shell Programming and Scripting

Finding files older than the current date and time and renaming and moving

Hi, I have a very urgent requirement here. I have to find all files in the specified directory but not in the sub directories(The directory name is stored in a variable) which are older than the current date as well as current time and rename it as filename_yyyymmddhhmmss.ext and move it into a... (7 Replies)
Discussion started by: ragavhere
7 Replies

10. UNIX for Dummies Questions & Answers

Archiving and move files in the same time

Hi All, I have tried so many command but none work like i wanted. I would like archive which i assume it will move the files and archive it somewhere. for example: if i have a folder and files: /home/blah/test /home/blah/hello /home/blah/foo/bar i would like to archive folder... (6 Replies)
Discussion started by: c00kie88
6 Replies
Login or Register to Ask a Question