Delete file less than 23hrs old
From command line, how do I delete a file less than 23 hrs old so a new file can come in? The file is a txt file
|
Quote:
Code:
find /some/path -name <pattern> -type f -mtime -1 -delete |
Perfectamuno!!! Thank you!!! Dang I love this site!! FAST REPLIES!!!!!!
|
Pattern of course is the file name right?
|
You will use 'find' to find files of a certain age. The paramaters -mmin (number of minutes) or -mtime (number of days) is what you will be looking for.
What you have LITERALLY asked for, is to find a file that is LESS than 23 Hours. Which means that this will find and delete the file if it were made in the last 1 minute, 2 minutes, 3 minutes, 4 minutes, 5 minutes and so on up until 23 hours and delete them. That can be done with this (change the 'ls' to 'rm' when you are certain it is deleteing what you want it to): Code:
find . -type f -name 'TESTING.txt' -mmin -1380 -exec ls {} \; |
Sorry, should have said less than 24 hours
|
No problem. Looks like tb0ne had you covered there. Take notice of the difference in the commands though. They might come in handy.
|
You all are AWESOME!!!!!!
|
Using -mmin and -mtime matches files modified at a certain time.
If you are continually updating this file, it will never become "older" as the modified time will always reflect the most recent change. In fact, you may discover if you download a file it will have a very old modified time (eg from March 2006) I believe there are some instances of recording the creation date, but these should be considered unreliable. In most cases, using the modified date as a match for "oldness" works fine, but you should be aware of what it is matching. Read the manual pages (as suggested) to fully understand the commands you are using. Code:
-mmin n |
I love this site!!!! OPTIONS OPTIONS OPTIONS!!!! You guys/gals are great!!! Thank you for all your help!!!
|
All times are GMT -5. The time now is 05:55 AM. |