LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-22-2016, 12:33 PM   #1
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Rep: Reputation: Disabled
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
 
Old 11-22-2016, 12:43 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,846

Rep: Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009Reputation: 8009
Quote:
Originally Posted by trickydba View Post
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
Read the man page on the find command.
Code:
find /some/path -name <pattern> -type f -mtime -1 -delete
...will delete a file less than 1 day old.
 
1 members found this post helpful.
Old 11-22-2016, 12:44 PM   #3
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Perfectamuno!!! Thank you!!! Dang I love this site!! FAST REPLIES!!!!!!
 
Old 11-22-2016, 12:45 PM   #4
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Pattern of course is the file name right?
 
Old 11-22-2016, 12:47 PM   #5
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
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 {} \;
Explained here: http://explainshell.com/explain?cmd=...+%7B%7D+%5C%3B
 
Old 11-22-2016, 12:52 PM   #6
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Sorry, should have said less than 24 hours
 
Old 11-22-2016, 12:54 PM   #7
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
No problem. Looks like tb0ne had you covered there. Take notice of the difference in the commands though. They might come in handy.
 
Old 11-22-2016, 12:54 PM   #8
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
You all are AWESOME!!!!!!
 
Old 11-22-2016, 09:44 PM   #9
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
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
              File's data was last modified n minutes ago.

       -mtime n
              File's  data was last modified n*24 hours ago.  See the comments for -atime to
              understand how rounding affects the interpretation of file modification times.
 
1 members found this post helpful.
Old 11-28-2016, 08:06 AM   #10
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I love this site!!!! OPTIONS OPTIONS OPTIONS!!!! You guys/gals are great!!! Thank you for all your help!!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Shell script to get name of file, delete original file, rename blank file chrisgti Linux - General 11 09-15-2012 02:49 AM
Create the file, write into that file but can't delete file in Linux pandunr Linux - Newbie 3 06-15-2011 08:45 AM
file from install ffmpeg conflicts w/file from package fmpeg-libs: which to delete? ybalazs Linux - Software 0 10-27-2009 01:21 AM
Upload file to ftp server -vsftp- but can not delete or change the file once uploaded murattas6 Linux - Server 2 06-26-2009 06:00 AM
Tried to delete file as root but it says I don't have permission to delete it! beejayzed Mandriva 23 03-12-2004 02:46 AM

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

All times are GMT -5. The time now is 01:24 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