LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-11-2013, 08:08 PM   #1
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
Find for files older than 12 hours


I know how to do a find for files that are older than one day with
-mtime +1
but is there a way to do it for files that are older than 12 hours? I need to do some mv's in a faster period than 1 day.
 
Old 06-11-2013, 08:11 PM   #2
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
-cmin 720

sorry! I must have scrolled too fast in man the first time
 
Old 06-11-2013, 08:43 PM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
If you use zsh instead of bash you don't need to use find at all for this job. For example, to find and mv all files recursively under the current directory that are older than 12 hours you would just do
Code:
mv **/*(.mh-12) /destination/path
More info on that can be found here: http://zsh.sourceforge.net/Doc/Relea...name-Expansion
 
1 members found this post helpful.
Old 06-12-2013, 09:40 AM   #4
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Very cool! didn't even know that existed.
 
Old 06-12-2013, 10:15 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Code:
touch -t 201306120500 rjo98.time
find /path/to/dir ! -newer rjo98.time
 
Old 06-13-2013, 10:44 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
gnu find now makes the above even easier, with it's -newerxy option.

Code:
find /startdir ! -newermt "-12 hours" -print
Use 'm' in the 'x' position to test for mtime, and 't' in the 'y' position to compare it against a given time stamp. The time stamp can be a relative string in the same way as date's -d option.
 
2 members found this post helpful.
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron Question - Delete files in a dir older than 48 hours? t3___ Linux - Newbie 5 10-11-2011 03:42 AM
[SOLVED] Delete regular files (not hidden files) with find + rm in one line older than 15 Virtuose Linux - Newbie 1 01-08-2011 05:24 PM
Deleting files older than 1 hours a4kata Linux - Newbie 2 09-08-2009 12:01 PM
find command : finding files that are created within last 24 hours Fond_of_Opensource Linux - Newbie 1 11-06-2006 03:47 AM
Deleting Files Older Than 2 Hours using Find? LinuxGeek Linux - Software 1 06-29-2005 06:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration