1829717 Members
1971 Online
109992 Solutions
New Discussion

deleting files by timing

 
Henry Chua
Super Advisor

deleting files by timing

Hi Guys,

I am doing some housekeeping on my over cluddered filesystem. I was just wondering is there anyway I can delete away files by their time.. say files before "20:54:50" of the day?

thank u..
Henry
6 REPLIES 6
Alex Lavrov.
Honored Contributor

Re: deleting files by timing

In "find" command you can specify how old should be the files you want to find (man find). You can write a simple script that calculates how old are the files (according to the momen the script being run) and then delete all the files that find outputs.

You can read in man fo "find" command how to define the time window.

I don't give a damn for a man that can only spell a word one way. (M. Twain)
Norman_21
Honored Contributor

Re: deleting files by timing

Hello

Here is a document if you have access to knowledgebase:
http://www1.itrc.hp.com/service/cki/docDisplay.do?docLocale=en_US&docId=200000067131091

http://www1.itrc.hp.com/service/cki/docDisplay.do?docLocale=en_US&docId=200000068500492

An example to remove files older than a week:
find /qti/archive -name :qtiarch*dbf.: -mtime +7 -exec rm {} \; -print

Hope this help
"Attitudes are contagious, is yours worth catching"/ My first point was given by SEP on January 31, 2003
Indira Aramandla
Honored Contributor

Re: deleting files by timing

Hi Henry,

You can use find with mtime patameter to find the files that are older than a specified time and delete them.

Eg:- find /directory_name_path -name "arch*log" -mtime +3 -exec rm {} \;

will delete all the archive logs older than 3 days.

You could use the -newer option as well.

For other options have a lokk at man find.

IA.
Never give up, Keep Trying
Mobeen_1
Esteemed Contributor

Re: deleting files by timing

Henry,
As many have mentioned in the previous posts, use -mtime qualifier with the find command to do this.

Addtional help you could look at man find

rgds
Mobeen
Peter Godron
Honored Contributor

Re: deleting files by timing

Henry,
if you want to remove files before a certain time AND DATE.

touch -t [[CC]YY]MMDDhhmm[.SS] file.mark
then use the find command with:
-newer file.mark

Regards

Gordon  Morrison
Trusted Contributor

Re: deleting files by timing

I suggest using Peter's touch command, then using
find . ! -newer file.mark
The "!" says "Not newer than"
What does this button do?