file date vs. system date


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers file date vs. system date
# 1  
Data 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.
# 2  
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.
alwayslearningunix
# 3  
Power 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  
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.
# 5  
Computer

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.
Smilie
# 6  
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  
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?
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #766
Difficulty: Medium
Modern CPUs have multiple non-interacting on-chip caches.
True or False?

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

Compare date in .txt with system date and remove if it's lesser than system date

I m working on shell scripting and I m stuck where in my .txt file there is column as expiry date and I need to compare that date with system date and need to remove all the rows where expiry date is less than system date and create a new .txt with update. (1 Reply)
Discussion started by: Stuti
1 Replies

2. UNIX for Beginners Questions & Answers

Compare date in .txt with system date and remove if it's lesser than system date

Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt . I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies

3. SCO

Cannot use 'date -t' to set the system date and time

Hi! All, I am trying to reset the date and time since the change in time over the weekend. I cannot issue the command date -t 201703131330. The system gives me an error invalid option. This happens on my SCO OpenServer 5.0.7 and 5.0.6. Do anyone have an idea why? I even tried using... (6 Replies)
Discussion started by: trolley
6 Replies

4. Shell Programming and Scripting

Compare the system date with date from a text file

I get the date that's inside a text file and assigned it to a variable. When I grep the date from the file, I get this, Not After : Jul 28 14:09:57 2017 GMT So I only crop out the date, with this command echo $dateFile | cut -d ':' -f 2,4The result would be Jul 28 14:57 2017 GMT How do I... (3 Replies)
Discussion started by: Loc
3 Replies

5. Shell Programming and Scripting

Adding days to system date then compare to a date

Hi! I am trying to read a file and every line has a specific date as one of its fields. I want to take that date and compare it to the date today plus 6 days. while read line do date=substr($line, $datepos, 8) #date is expected to be YYYYMMDD if ; then ...proceed commands ... (1 Reply)
Discussion started by: kokoro
1 Replies

6. UNIX for Dummies Questions & Answers

Comparing Output Date to Current System Date

Hi Guys, Anyone who knows how to compare the current date with the a file containing a date, say for example I have a file that looks like this: Command was launched from partition 0. ------------------------------------------------ Executing command in server server6 Fri Dec 16... (7 Replies)
Discussion started by: rymnd_12345
7 Replies

7. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

8. Shell Programming and Scripting

how to get what date was 28 days ago of the current system date IN UNIX

Hi, Anybody knows how to get what date was 28 days ago of the current system date through UNIX script. Ex : - If today is 28th Mar 2010 then I have to delete the files which arrived on 1st Mar 2010, (15 Replies)
Discussion started by: kandi.reddy
15 Replies

9. Shell Programming and Scripting

Set system date to some date (Sunos)

I am testing a script and need to change the system date to Nov 30 2009. I cannot seem to find a way to do this other than TZ command but it does not seem to work correctly. I tried TZ=GMT+168 date but it is returning todays date Mon Dec 7 19:48:11 GMT 2009 ...instead of Nov 30 2009 I... (4 Replies)
Discussion started by: hanton
4 Replies

10. Shell Programming and Scripting

Compare date from db2 table to yesterday's Unix system date

I am currently running the following Korn shell script which works fine: #!/usr/bin/ksh count=`db2 -x "select count(*) from schema.tablename"` echo "count" I would like to add a "where" clause to the 2nd line that would allow me to get a record count of all the records from schema.tablename... (9 Replies)
Discussion started by: sasaliasim
9 Replies

Featured Tech Videos