1828631 Members
8542 Online
109983 Solutions
New Discussion

help on date of file

 
SOLVED
Go to solution
Pando
Regular Advisor

help on date of file

Dear Gurus,

I would like to ask on how to move my files that is 3 days old from the time it is created whether it is accessed or not. Is this possible is a one line command format or in a script?
Maximum points for all correct replies.
Thanks!
8 REPLIES 8
Pando
Regular Advisor

Re: help on date of file

Opps sorry for that...What i meant was is this possible in a one line command format?
or is there a script out there available for me to use? Thanks again!
Ninad_1
Honored Contributor

Re: help on date of file

Hi Pando,

I think this is the same question for which you started a thread.
Your problem statement is not very clear.
You say - a file which is 3 days old from the time it is created. If a file is created on date x how can it be 3 days older than x ?
Now if you mean you want to find files which were created 3 days or more ago than today - you have a valid question.
In that case I would like to reiterate what I said to your earlier post - you cannot determine in Unix if a file was created at so and so time [ or so many days ago ] what you can find is if a file was modified x days ago or not.
So you can find files which were modified 3 days or more ago and havent been modified in last 3 days ; but you will not be able to find out a file which was created x days ago but has been modified in the last 3 days as Unix maintains only modification time and access times - not creation times of files

Hope this clarifies.

Regards,
Ninad
spex
Honored Contributor

Re: help on date of file

Pando,

Not sure if I'm interpreting your question correctly. If you want to move any files in /foo/dir1 that have not be accessed in more than 3 days to /foo/dir2, you could do:

find /foo/dir1 -type f -atime +3 -exec mv {} /foo/dir2 \;

As Ninad said, HP-UX does not store a file's creation time. The closest thing to this is the last modification time of a file's inode, but many activities will cause this time to be updated (file created, mode changed, etc.). 'ls -lc' will give you a long listing sorted by last inode modification time.

PCS
Robert-Jan Goossens_1
Honored Contributor

Re: help on date of file

Frank de Vries
Respected Contributor

Re: help on date of file

Hi

I usually use modify time as basis.
And for safety I tar them first using
xargs.

(I found the -exec not usefull when moving,
it is okay when rm or grep)

Anyway here it is:
1) Find . -print -type f -mtime +3 | xargs
tar -cvf new.tar ; mv new.tar /newpath

Nice , safe and clean.
Plus you can output to a log to
see what happened afterwards
(mv is rather silent)

You can check the tar at new
destination with tar -tvf new.tar

Keep cooking:)
Look before you leap
Pando
Regular Advisor

Re: help on date of file

Hi All,

Sorry that vague question. When you do an ll command, i see on my screen the following:

# ll
-rw-rw-r-- 1 idsdb users 2644 May 29 11:05 E-BC-0619-0826.xml
-rw-rw-r-- 1 idsdb users 2641 May 29 11:05 E-BC-0619-0830.xml

The above list a date and time stamp (May 29 11:05). Is this the creation date and time?

What i really want to do is that 3 days after May 29 11:05 (that's should be Jun 1 11:06), these files will be move to an archive directory.

I hope this clarifies my inquiries.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: help on date of file

No those or not they creation timestamps. Those are the last modification times of those files and if that happens to be when the files were created then you know the creation only by accident. UNIX has no notion of a creation time of a file.

Now to move files that have not been modified in more than 3 days, you should create a cron job that runs everyday at some
preferred time and run a script something like this:

#!/usr/bin/sh

SRCDIR=/xxx/yyy
DESTDIR=XXX/YYY.save

cd ${SRCSRC}
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
find . -type f -mtime +3 -exec mv {} ${DESTDIR}/ \;
STAT=${?}
else
echo "Can't cd to ${SRCDIR}; status ${STAT}." >&2
fi
exit ${STAT}
If it ain't broke, I can fix that.
Pando
Regular Advisor

Re: help on date of file

Dear A. Clay Stephenson,

Thanks for that wonderful insight. The code helps me a lot! Thanks!