| Red Hat This forum is for the discussion of Red Hat Linux. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
10-22-2004, 05:50 AM
|
#1
|
|
Member
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102
Rep:
|
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
|
|
|
|
10-24-2004, 04:16 AM
|
#2
|
|
Senior Member
Registered: Dec 2000
Location: Gothenburg, SWEDEN
Distribution: OpenSUSE 10.3
Posts: 1,028
Rep:
|
Using the find command and command pipes you can search out the files you like and then send them to the correct command.
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.
|
|
|
|
10-25-2004, 12:38 AM
|
#3
|
|
Member
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102
Original Poster
Rep:
|
what -mtime mean?
|
|
|
|
10-25-2004, 03:09 AM
|
#4
|
|
Member
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102
Original Poster
Rep:
|
The following error message generated on this command
[oracle@visionapps1 test]$ find -mtime 2 | xargs rm
rm: too few arguments
|
|
|
|
10-25-2004, 08:05 AM
|
#5
|
|
Senior Member
Registered: Dec 2000
Location: Gothenburg, SWEDEN
Distribution: OpenSUSE 10.3
Posts: 1,028
Rep:
|
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
|
|
|
|
10-25-2004, 11:49 PM
|
#6
|
|
Member
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102
Original Poster
Rep:
|
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
|
|
|
|
10-26-2004, 07:59 AM
|
#7
|
|
Senior Member
Registered: Dec 2000
Location: Gothenburg, SWEDEN
Distribution: OpenSUSE 10.3
Posts: 1,028
Rep:
|
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.)
|
|
|
|
11-02-2004, 04:36 AM
|
#8
|
|
Member
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102
Original Poster
Rep:
|
but I have unabled to delete the files of last five days
|
|
|
|
11-02-2004, 04:46 AM
|
#9
|
|
Member
Registered: Jan 2004
Location: Faisalabad-Pakistan
Distribution: Red Hat Linux 2.1 Advance Server
Posts: 102
Original Poster
Rep:
|
can any body tell me how I can delete the files of specific dates????
|
|
|
|
11-14-2007, 06:16 PM
|
#10
|
|
LQ Newbie
Registered: Nov 2007
Location: Bolivia
Distribution: Arch Linux
Posts: 11
Rep:
|
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.
|
|
|
|
11-16-2007, 04:32 PM
|
#11
|
|
Member
Registered: Feb 2005
Location: Costa Rica
Distribution: Ubuntu, gOS, Debian & Slack 12
Posts: 426
Rep:
|
Quote:
Originally Posted by ggarron
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.
|
|
|
|
11-20-2007, 05:19 AM
|
#12
|
|
LQ Newbie
Registered: Nov 2007
Posts: 6
Rep:
|
Quote:
Originally Posted by trebek
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.
|
|
|
|
11-20-2007, 01:19 PM
|
#13
|
|
Member
Registered: Feb 2005
Location: Costa Rica
Distribution: Ubuntu, gOS, Debian & Slack 12
Posts: 426
Rep:
|
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.
|
|
|
|
11-20-2007, 04:58 PM
|
#14
|
|
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 13.37
Posts: 4,082
Rep: 
|
From the man page for find:
Code:
The string `{}' is replaced by the current file name being processed
|
|
|
|
11-20-2007, 07:49 PM
|
#15
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 14,938
|
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
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:43 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|