LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-22-2007, 12:05 AM   #1
marsguy
Member
 
Registered: Nov 2004
Distribution: Red Hat Enterprise & SuSe 10
Posts: 77

Rep: Reputation: 15
ow do I delete all files which were created on a specific date


Hello

I have a simple question!

How do I delete all files which were created on a specific date?

Thanks in advance
 
Old 03-22-2007, 01:21 AM   #2
johngreenwood
Member
 
Registered: Nov 2006
Location: Lancashire, United Kingdom
Distribution: Slackware 13
Posts: 243

Rep: Reputation: 31
I do not have an answer for you, but I do have this. Probably not very helpful but here it is anyway.

I made a short script that did this:
Code:
if [ $* = `ls -l | cut -b 28-37` ]
then echo "yes"
else echo "no"
that was basically it, when I ran it in a directory with a file created for a test, using todays date as it appears with the ls -l command, it returned yes. On another file it returned no. BUT, the position of the date is not always in the same location so if it was a script to remove files, it probably wouldn't get them all. Also you would probably have to use a for loop. I don't know, I am very new to this.

Someone will probably show up with an instant way to do it, or a really cool script to do it. I just thought this may help, another command to look at (I think) is sed, which I haven't learned yet.

Good luck.
 
Old 03-22-2007, 04:25 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by marsguy
Hello

I have a simple question!

How do I delete all files which were created on a specific date?

Thanks in advance
Something like this?

Code:
#!/bin/bash
timediff=`echo '('  \`date +"%s"\` - \`date --date="$*" +"%s"\` ')/3600/24'| bc`  
find . -type f -mtime $timediff -exec echo rm -rf {} \;
Save as some file name and invoke like so:
Code:
somefilename "DD Mon YYYY"

When you're sure it finds the right ones remove the
echo behind the exec :}


Cheers,
Tink
 
Old 03-23-2007, 05:03 AM   #4
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Rep: Reputation: Disabled
With Konqueror (sort by date) and two or three clicks
 
Old 03-23-2007, 01:58 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by JZL240I-U
With Konqueror (sort by date) and two or three clicks :p ;)
And konqueror will scan the subdirectories, too?
I have to ask because I don't use it.


Cheers,
Tink
 
Old 03-23-2007, 02:28 PM   #6
Jordi
LQ Newbie
 
Registered: Mar 2007
Location: Barcelona
Distribution: CentOS
Posts: 11

Rep: Reputation: 0
Tinkster's answer it's a good solution.

[off_topic_mode]

The FreeBSD's ls command has an specific option for do that:

-U Use time when file was created for sorting or printing.

It's a pitty than Linux ls has not this useful option.
Maybe we should send some feedback to ls mantainers and developers for request that feature.

[/off_toppic_mode]
 
Old 03-23-2007, 02:41 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by Jordi
Tinkster's answer it's a good solution.
Thanks :}

Quote:
[off_topic_mode]

The FreeBSD's ls command has an specific option for do that:

-U Use time when file was created for sorting or printing.

It's a pitty than Linux ls has not this useful option.
Maybe we should send some feedback to ls mantainers and developers for request that feature.

[/off_toppic_mode]
Code:
ls -ltc

Cheers,
Tink
 
Old 03-25-2007, 12:39 AM   #8
marsguy
Member
 
Registered: Nov 2004
Distribution: Red Hat Enterprise & SuSe 10
Posts: 77

Original Poster
Rep: Reputation: 15
Thanks everyone for helping me

I really appreciate it
 
Old 03-26-2007, 03:52 AM   #9
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Rep: Reputation: Disabled
Quote:
Originally Posted by Tinkster
And konqueror will scan the subdirectories, too?...
Not normally, no. But it is so versatile, that there might be a mode to achieve that too.

I never tried, because for recursive tasks I use the command line...
 
Old 08-21-2007, 08:15 AM   #10
mjp053000
LQ Newbie
 
Registered: Jun 2006
Distribution: RHEL, SLES, Fedora, Ubuntu
Posts: 14

Rep: Reputation: 0
delete files by date range

I have had some success using the following to delete files by date.

#these commands set up the date range

touch -d'2004-01-01 00:00:00' 2004-Jan
touch -d'2004-05-31 23:59:59' 2004-May

#this will actually delete the files

find /some/dir -newer 2004-Jan -not -newer 2004-May -exec rm -rf {} \;

you can also use ls, mv, etc... in place of rm
hope this helps.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete/move/copy files of specific date imsajjadali Red Hat 26 11-07-2013 11:34 PM
Automatically set permissions of new files created within a specific folder Lorian Linux - Desktop 2 03-03-2007 03:17 PM
Date interrogation for files created chunky Linux - General 2 08-03-2004 03:31 PM
If I delete files are new ones created?? BajaNick Linux - Software 1 07-06-2004 11:07 PM
Copying files from a specific date dman65 Linux - Software 3 09-22-2003 10:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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