The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compare date from db2 table to yesterday's Unix system date sasaliasim Shell Programming and Scripting 8 04-24-2008 03:04 AM
Perl: Extracting date from file name and comparing with current date MKNENI Shell Programming and Scripting 4 03-26-2008 12:01 PM
parsing a system log file via the 'date' command cjones Shell Programming and Scripting 5 05-10-2007 09:26 AM
Changing Creation Date to a Prespecified Date of a File In Unix monkfan UNIX for Dummies Questions & Answers 4 11-28-2006 03:15 AM
need to create a file with its name having system date hamsa Shell Programming and Scripting 11 10-18-2006 01:48 AM

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-02-2001
ober5861's Avatar
Registered User
 

Join Date: Jul 2001
Location: Gettysburg, PA
Posts: 116
Unhappy file date vs. system date

Hey all,

I know there was a post on here at one point about how to get file properties such as create time and such, but I've searched high and low without success.

What I need to do is create a script that runs daily that will expire or remove files that are older than 1 month, or possibly a number of days, within a directory. I think I understand how to make the script run daily using the crontab.. but any help regarding how to check dates and remove the files accordingly would be greatly appreciated.

Thanks.
Forum Sponsor
  #2 (permalink)  
Old 08-02-2001
alwayslearningunix
Guest
 

Posts: n/a
The find command with the mtime or ctime flags will do this for you:

find /search/path -mtime +30 -exec rm -i {} \;

I put the -i flag here to prompt you for each file removed (linux defaults to this as I remember) - probably a better approach would be to copy them all to another directory and then only delete them once you are sure you want to get rid of them all.

+30 in this examples indicates 30 days or older.

You can put this all in your script.

Regards.
  #3 (permalink)  
Old 09-10-2001
Registered User
 

Join Date: Jul 2001
Location: Malaysia
Posts: 20
Red face confusing about -ctime

I "man find" but do not understand.
May I know when we will use -ctime instead of -mtime?

and why must put a ";" at last? I found if i just enter this command, it will also work:

find /at/path/dir -mtime +3
  #4 (permalink)  
Old 09-10-2001
patvdv's Avatar
Registered User
 

Join Date: Jul 2001
Location: Belgium
Posts: 83
ctime

You can also use:

find /search/path -mtime +30 | xargs rm -i

ctime indicates inode data change: ie. when you do chmod. chown on the file or when the file size changes. Not the contents of the file.
__________________
Patrick Van der Veken - UNIX consultant (c) 2001 - 2001 http://www.baanboard.com - http://www.ux-core.com
'True strength lies in gentleness' - Irish proverb
  #5 (permalink)  
Old 09-11-2001
Registered User
 

Join Date: Jul 2001
Location: Malaysia
Posts: 20
Talking

I know the symbols represents something like this:

| xargs = and execute arguments
and -exec = execute command

Patvdv, thank you very much!!!!!
Now i understand what is inode change.
  #6 (permalink)  
Old 09-11-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,318
I'd like to offer my thoughts on ctime verses mtime. Sorry, but this will be a little verbose.

First, if you change the contents of a file you change the mtime of a file. Since this is a change to the inode, ctime is updated as well. The mtime is bit like the date on a letter and ctime is a bit like the postmark on the envelope.

You can set mtime to anything you want via the utime() system call or the touch command. Doing so sets the ctime and you cannot reset ctime.

If you restored last year's payroll records from tape, you might want to set the mtime back to the end of last year. But the ctime will reliably still indicate when the last change to the file occurred. This is how your backup program will know that it must back up the file. The ctime is really used by backup program. But an application program that prints out a payroll listing would use mtime.
  #7 (permalink)  
Old 09-11-2001
patvdv's Avatar
Registered User
 

Join Date: Jul 2001
Location: Belgium
Posts: 83
Q

Mmm, let's picture this: you change exactly 1 character in an ASCII text file, thus not changing the file size. Does this change the ctime as well? I always thought not?
__________________
Patrick Van der Veken - UNIX consultant (c) 2001 - 2001 http://www.baanboard.com - http://www.ux-core.com
'True strength lies in gentleness' - Irish proverb
Google UNIX.COM
Closed Thread

Tags
linux, mtime

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0