LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-22-2009, 08:26 AM   #1
fatz2000
LQ Newbie
 
Registered: Dec 2009
Location: London, UK
Posts: 2

Rep: Reputation: 0
Delete all files of certain date.


Hi

I'm trying to remove files and directories of a specific date. I have several backup files which are created on the same day, which I have to delete all together.

I'm running this command to get the date of the oldest file, then using
this date delete all files with this date ignoring the time.

Code:
ls -lastr *.bkf | head -1 | awk ' { printf "%s %2s\n",$7,$8 } '
This gives an output of Month Day
If I assign this to a variable in a csh or echo the above between two `
The padding space seems to be removed in the string.
For example
Code:
Dec  3
becomes
Code:
Dec 3
and therefore doesnt match the ls -lastr command for example-

Code:
4196384 -rwxrw-rw-   1 ftp   wheel  4294980608 Dec  3 06:12 B2D000001.bkf
I'm a bit of a newbie in scripting and I'm sure theres either a
simple syntax change or a much better way of doing this.

Any help much appreciated (I'm losing my hair over this one..)

Last edited by fatz2000; 12-22-2009 at 08:41 AM. Reason: typo
 
Old 12-22-2009, 08:33 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
delete all files that are 14 days old:

find /where/ever/ -daystart -mtime 14 -delete
 
Old 12-22-2009, 09:06 AM   #3
fatz2000
LQ Newbie
 
Registered: Dec 2009
Location: London, UK
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for that, however I am after deleting files of a specific date, ie the oldest set of files.

Unless you can determine how old the oldest file is to delete using mtime
 
  


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
Delete files based on current date -1 Winanjaya Linux - Newbie 3 06-23-2008 04:38 AM
ow do I delete all files which were created on a specific date marsguy Linux - General 9 08-21-2007 08:15 AM
delete files by date noir911 Programming 4 10-04-2006 07:42 AM
Delete files based on date stefaandk Linux - General 3 06-17-2005 02:20 AM
delete files date wise hardeep_ubhi Linux - General 1 11-16-2004 02:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:18 AM.

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