LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices

Reply
 
Search this Thread
Old 10-22-2004, 05:50 AM   #1
imsajjadali
Member
 
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102

Rep: Reputation: 15
Delete/move/copy files of specific date


I want to delete files of specific date, how can I do it?
for example I have file list as
-rw-r----- 1 oracle oinstall 10484224 Oct 22 14:41 1_19390.dbf
-rw-r----- 1 oracle oinstall 10484224 Oct 22 14:42 1_19391.dbf
-rw-r----- 1 oracle oinstall 10484224 Oct 22 14:42 1_19392.dbf
-rw-r----- 1 oracle oinstall 10484224 Oct 22 14:43 1_19393.dbf
-rw-r----- 1 oracle oinstall 10484224 Oct 22 14:43 1_19394.dbf
-rw-r----- 1 oracle oinstall 10484224 Oct 22 14:43 1_19395.dbf
-rw-r----- 1 oracle oinstall 10484224 Oct 22 14:44 1_19396.dbf
-rw-r----- 1 oracle oinstall 10484224 Oct 22 14:44 1_19397.dbf
-rw-r----- 1 oracle oinstall 10484224 Oct 22 14:45 1_19398.dbf
-rw-r----- 1 oracle oinstall 10484224 Oct 22 14:46 1_19399.dbf

I want to delete files of dated Oct 22 2004.

It will be more helpfull if some body also tell me how to move and copy of specific date files.


Thanks in advance
Sajjad
 
Old 10-24-2004, 04:16 AM   #2
ugge
Senior Member
 
Registered: Dec 2000
Location: Gothenburg, SWEDEN
Distribution: OpenSUSE 10.3
Posts: 1,028

Rep: Reputation: 45
Using the find command and command pipes you can search out the files you like and then send them to the correct command.
Code:
find -mtime 2
This would find all files modified 2*24h=48h ago. This result can be piped to the rm command like this
Code:
find -mtime 2 | xargs rm
the xargs is necesary for rm to accept the listing as an argument list. There is also a built in exec function in find.
 
Old 10-25-2004, 12:38 AM   #3
imsajjadali
Member
 
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102

Original Poster
Rep: Reputation: 15
what -mtime mean?
 
Old 10-25-2004, 03:09 AM   #4
imsajjadali
Member
 
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102

Original Poster
Rep: Reputation: 15
The following error message generated on this command
[oracle@visionapps1 test]$ find -mtime 2 | xargs rm
rm: too few arguments
 
Old 10-25-2004, 08:05 AM   #5
ugge
Senior Member
 
Registered: Dec 2000
Location: Gothenburg, SWEDEN
Distribution: OpenSUSE 10.3
Posts: 1,028

Rep: Reputation: 45
Sorry forgot an important argument that goes right after find, it's the search path
Code:
find /usr/local/ -mtime 2
The -mtime is modified time.
There are at least three timestamps:
atime accessed
ctime changed
mtime modified
 
Old 10-25-2004, 11:49 PM   #6
imsajjadali
Member
 
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102

Original Poster
Rep: Reputation: 15
I did not get solution. I have folder /home/test/. this folder contains the number of files such as
a.txt
b.txt
c.txt
d.txt
.......

I just want system delete only those files from above given files which are created during last one day.

thanks
 
Old 10-26-2004, 07:59 AM   #7
ugge
Senior Member
 
Registered: Dec 2000
Location: Gothenburg, SWEDEN
Distribution: OpenSUSE 10.3
Posts: 1,028

Rep: Reputation: 45
The ctime option most closely describes your request
The man page for find says like this about the ctime option.
Quote:
-ctime n
File's status was last changed n*24 hours ago.
This means last time the metadata (information about the data file) was changed. That could be creation of the file, file moved, file name changed, attributes changed on file...
(Correct me if that wasn't a correct explanation.)
 
Old 11-02-2004, 04:36 AM   #8
imsajjadali
Member
 
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102

Original Poster
Rep: Reputation: 15
but I have unabled to delete the files of last five days
 
Old 11-02-2004, 04:46 AM   #9
imsajjadali
Member
 
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102

Original Poster
Rep: Reputation: 15
can any body tell me how I can delete the files of specific dates????
 
Old 11-14-2007, 06:16 PM   #10
ggarron
LQ Newbie
 
Registered: Nov 2007
Location: Bolivia
Distribution: Arch Linux
Posts: 11
Blog Entries: 1

Rep: Reputation: 2
Deleting files of specific dates

you may use this

find -mtime 2 -type f -exec rm {} \;

this way should work

Guillermo Garron
Linux Operating System

Last edited by ggarron; 11-14-2007 at 06:34 PM.
 
Old 11-16-2007, 04:32 PM   #11
trebek
Member
 
Registered: Feb 2005
Location: Costa Rica
Distribution: Ubuntu, gOS, Debian & Slack 12
Posts: 426

Rep: Reputation: 30
Quote:
Originally Posted by ggarron View Post
you may use this

find -mtime 2 -type f -exec rm {} \;

this way should work

Guillermo Garron
Linux Operating System
Ok, i got here by searching, so i didn't have to open a new thread to ask my very similar question.

I need to move files in a mounted remote directory, to a local directory, right? I need to move the files that are from yesterday alone. So, if a file was created yesterday, that file needs to be moved. So basically i need to find the files that have a date 'yesterday' and move them over. Just out of being a Sammy Sosa, i guess i could do something like:
find /sourcedirectory -mtime 1 | mv /destination/directory

I hope i didn't make a big mess out of my explanation.

Thanks in advance for the help.
 
Old 11-20-2007, 05:19 AM   #12
Verve1986
LQ Newbie
 
Registered: Nov 2007
Posts: 6

Rep: Reputation: 0
Quote:
Originally Posted by trebek View Post
Ok, i got here by searching, so i didn't have to open a new thread to ask my very similar question.

I need to move files in a mounted remote directory, to a local directory, right? I need to move the files that are from yesterday alone. So, if a file was created yesterday, that file needs to be moved. So basically i need to find the files that have a date 'yesterday' and move them over. Just out of being a Sammy Sosa, i guess i could do something like:
find /sourcedirectory -mtime 1 | mv /destination/directory

I hope i didn't make a big mess out of my explanation.

Thanks in advance for the help.

use the -exec option of find and type

find /sourcedirectory -mtime 1 -exec mv "{}" /destination/directory/ \;

this will work as you wanted.

Last edited by Verve1986; 11-20-2007 at 05:28 AM.
 
Old 11-20-2007, 01:19 PM   #13
trebek
Member
 
Registered: Feb 2005
Location: Costa Rica
Distribution: Ubuntu, gOS, Debian & Slack 12
Posts: 426

Rep: Reputation: 30
What does "{}" mean? Should i put something in between those brackets? And many thanks for the prompt answer!!!

Last edited by trebek; 11-20-2007 at 01:22 PM.
 
Old 11-20-2007, 04:58 PM   #14
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 151Reputation: 151
From the man page for find:
Code:
The  string `{}' is replaced by the current file name being processed
 
Old 11-20-2007, 07:49 PM   #15
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,251

Rep: Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026Reputation: 2026
For grabbing files of a given date, using just basic shell cmds:
Code:
for file in `ls`
do
    day=`ls -lt $file|cut -d' ' -f6`
    if [[ $day = "2007-11-21" ]]
    then
        echo "$file matched"
    fi
done
If you have to use the date format in the OP, you'd also have to fool around with the date cmd or substring options to match the relevant bits
 
  


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
Delete files for a particular changed date recursively? qwertyme Linux - Newbie 5 01-23-2009 10:41 AM
Delete files based on date stefaandk Linux - General 3 06-17-2005 02:20 AM
Copy files after a certain date davholla Linux - General 2 03-17-2005 09:29 AM
delete files date wise hardeep_ubhi Linux - General 1 11-16-2004 02:07 AM
Copying files from a specific date dman65 Linux - Software 3 09-22-2003 10:16 AM


All times are GMT -5. The time now is 09:24 AM.

Main Menu
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