LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-01-2009, 07:11 AM   #1
kumar_eee
LQ Newbie
 
Registered: Dec 2008
Posts: 10

Rep: Reputation: 0
How to get the files which are 6 months older?.


I would like to get the list of files which are 6 months older.

Any help would be appreciated..
 
Old 09-01-2009, 07:28 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Welcome to LinuxQuestions!

Take a look at
Code:
man find
and in particular the -mtime predicate. Note that the numeric argument of -mtime expresses the time in hours. It's up to you to compute the proper conversion hour/month.
 
Old 09-01-2009, 07:29 AM   #3
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Rep: Reputation: 36
you wold have to use the find command with -ctime option i guess.
 
Old 09-01-2009, 07:33 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by kdelover View Post
with -ctime option i guess.
That's another valid option. It all depends on what time the OP is referring to (among change, access and modification times).
 
Old 09-01-2009, 07:36 AM   #5
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Rep: Reputation: 36
just wondering what would give teh desired result? -atime,-mtime or ,-ctime?This looks like homework Q to me
 
Old 09-01-2009, 08:01 AM   #6
kumar_eee
LQ Newbie
 
Registered: Dec 2008
Posts: 10

Original Poster
Rep: Reputation: 0
find command is not working..

Any example pls..
 
Old 09-01-2009, 08:08 AM   #7
kumar_eee
LQ Newbie
 
Registered: Dec 2008
Posts: 10

Original Poster
Rep: Reputation: 0
I'm using csh.. I think find command work with bash it seems..

The following command is working fine in bash.
"find renameCDL -name rename*.* -mtime +10"

How does it differs from csh?.
 
Old 09-01-2009, 08:09 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by kumar_eee View Post
find command is not working..

Any example pls..
It would be easy if you post the command you've tried and the error messages you've got. Also, what about the atime, ctime and mtime issue explained above? Do you know the difference among them? And finally, is this homework?
 
Old 09-01-2009, 08:12 AM   #9
kumar_eee
LQ Newbie
 
Registered: Dec 2008
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
It would be easy if you post the command you've tried and the error messages you've got. Also, what about the atime, ctime and mtime issue explained above? Do you know the difference among them? And finally, is this homework?
I'm sorry.. Please find the command & Error message below.

Command : "find /user/kumark/renameCDL -name *"

Error:
find: paths must precede expression
Usage: find [path...] [expression]
 
Old 09-01-2009, 08:13 AM   #10
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by kumar_eee View Post
I'm using csh.. I think find command work with bash it seems..

The following command is working fine in bash.
"find renameCDL -name rename*.* -mtime +10"

How does it differs from csh?.
Ok. Just seen this one. Please, disregard the irrelevant parts of my previous post. The find command does not differ among shells. It may differ if we're talking about GNU find and non-GNU find.

The line of code you posted above is almost correct, except for the -name part. Indeed, you have to protect the asterisks from the shell expansion to let the find command interpret them in the correct way. You can use either single quotes or escapes, as in:
Code:
find renameCDL -name rename\*.\* -mtime +10
find renameCDL -name 'rename*.*' -mtime +10
Edit: just seen your very last one. Answer is the same: try to protect wildcards from shell expansion as suggested above

Last edited by colucix; 09-01-2009 at 08:14 AM.
 
Old 09-01-2009, 08:24 AM   #11
kumar_eee
LQ Newbie
 
Registered: Dec 2008
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
Ok. Just seen this one. Please, disregard the irrelevant parts of my previous post. The find command does not differ among shells. It may differ if we're talking about GNU find and non-GNU find.

The line of code you posted above is almost correct, except for the -name part. Indeed, you have to protect the asterisks from the shell expansion to let the find command interpret them in the correct way. You can use either single quotes or escapes, as in:
Code:
find renameCDL -name rename\*.\* -mtime +10
find renameCDL -name 'rename*.*' -mtime +10
Edit: just seen your very last one. Answer is the same: try to protect wildcards from shell expansion as suggested above
its working now. Thanks...
One more thing, I want to get the size of the directory which is 6 months older.

I just want to delete the files/directories which are 6 months older & exceeds 1GB.
 
Old 09-01-2009, 08:31 AM   #12
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by kumar_eee View Post
One more thing, I want to get the size of the directory which is 6 months older.

I just want to delete the files/directories which are 6 months older & exceeds 1GB.
You have to go through the manual page again. I admit that it is very long to read, but I strongly suggest to try or eventually look for some tutorial online. Anyway, for the size part check the -size predicate. For the delete part check -exec.

Just an advice: do not actually delete anything until you're extremely confident with the results of the find command. To test the deleting part, I usually put a echo in front of the rm command, so that the actual commands we're going to execute are displayed on the terminal and I can check them. For example:
Code:
find blah blah blah -exec echo rm {} \;
the code above will just echo the complete rm commands without executing them. After careful checking, remove the echo and run again.
 
  


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
Script help - delete files older than 45 days but exclude the system files jojothedogboy Linux - Software 3 06-13-2008 03:43 PM
Help to Delete older Files on asterisk n33d Linux - Server 3 06-05-2008 08:20 PM
Delete files older then 30 days stefaandk *BSD 1 01-07-2008 08:31 PM
How to move files older than 30 days gfem AIX 8 11-08-2006 04:58 AM
delete files older then a month? Red Squirrel Linux - Software 1 10-05-2005 10:54 PM


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