Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi, I'm a newbie to scripting in Unix and I need help with the following.
I want to write a script that would retrieve the creation date/time of a file and compare that to the current date/time to determine how old the file has been created. I have no idea how to do this. Please help me...Thank you in advance.

How you will find creation date/time of a file. It is not necessary that the time you get with "ls -l" is the creation date/time.
If you want to compare that "ls -l"'s date/time with current date/time then it can be done.
Let us know.

Hi, I too am a 'newbie' at scripting. This is a problem that I have been stuck on for a while.
I have a script that is creating files from another system, and adding them into a specific directory. I would like to compare the creation date of a file with the current system date and delete it if it is older than 2 weeks old. I am not sure how this can be done, or if it can be done. Has anyone got any ideas??? Thanx

Hi, in order to compare date file with the current date, i use this
find [path] -daystart -[a/c/m]time [+/-]n
-atime n
File was last accessed n*24 hours ago.
-ctime n
File's status was last changed n*24 hours ago.
-mtime n
File's data was last modified n*24 hours ago
+ == >
- == <
n whitout sign === only this day before the current date
You can use it with redirection, or as a kind of filter usefull for remove file
rm -f $(find blabla), and in one command you have a solutionSorry for my bad english, i'am just a little french

Hi,
you can simply use the `test' command for your problem, it will return zero (true) if file1 is newer than file2 (therefore `-nt') and will return > 0 if not:
$> test file1 -nt file2
$> echo $?
1
$>You can use it in combination with an `if'-statement as well, good for batch scripting:
if [ file1 -nt file2 ]
then
echo "file1 is newer"
fiOr on the shell directly, optionally in a different notation:
$> test file1 -nt file2 && echo "file1 is newer"
$>or, other way round:
$> test file1 -nt file2 || echo "file1 is not newer"
file1 is not newer
$>Hope, I could give you a short introduction. try `man test' on your shell to get more info about the `test' command. Maybe you'll find a good documentation about `if' / `&&' / `||' and return code handling somewhere on the net.
Cheers,
Manuel

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |