LinuxQuestions.org
Review your favorite Linux distribution.
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, 01: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, 02: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, 05:25 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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, 06:03 AM   #4
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 13.1 / 12.3_64-KDE, Ubuntu 14.04, Fedora 20, Mint 17, Chakra
Posts: 3,689

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

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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, 03: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, 03:41 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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, 01: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, 04:52 AM   #9
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 13.1 / 12.3_64-KDE, Ubuntu 14.04, Fedora 20, Mint 17, Chakra
Posts: 3,689

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, 09: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


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 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-08-2013 12:34 AM
Automatically set permissions of new files created within a specific folder Lorian Linux - Desktop 2 03-03-2007 04:17 PM
Date interrogation for files created chunky Linux - General 2 08-03-2004 04:31 PM
If I delete files are new ones created?? BajaNick Linux - Software 1 07-07-2004 12:07 AM
Copying files from a specific date dman65 Linux - Software 3 09-22-2003 11:16 AM


All times are GMT -5. The time now is 08:50 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration