Operating System - HP-UX
1748019 Members
4789 Online
108757 Solutions
New Discussion юеВ

Re: How to find recently created file.

 
SOLVED
Go to solution
Chitta
Frequent Advisor

How to find recently created file.

Hi,

Can any one help me to find recently created file in a mount point. that i have to pass in a script to as a input.
I tried with "find /u02/backup/script/ -type f -newer /u02/backup/script/"

But no expected out put. Earli response would be appericated>

Regs,
Chitta
7 REPLIES 7
Mark McDonald_2
Trusted Contributor
Solution

Re: How to find recently created file.

ll -rt /u02/backups/script/* | tail -1

will give you the newest file in the directory
Mark McDonald_2
Trusted Contributor

Re: How to find recently created file.

Sorry - should have said "ls" not "ll" for passing to a script.
Dennis Handly
Acclaimed Contributor

Re: How to find recently created file.

You are trying to find files that have been modified after the directory script/ was modified. Why are you trying to use that directory as the reference file?
James R. Ferguson
Acclaimed Contributor

Re: How to find recently created file.

Hi:

There is no such thing as a file _creation_ timestamp in UNIX. The _last_modification_ timestamp or 'mtime' is the closest you have. When a file is first created, the 'mtime' represents the creation time but any update of the file or directory contents thereafter alters the 'mtime' to be current time.

Hence, finding a file in a directory with the most recent 'mtime' may only reflect that that file was more recently updated than any other, not necessarily that it is newly present.

Regards!

...JRF...
Suraj K Sankari
Honored Contributor

Re: How to find recently created file.

Hi,
Frist create a file into /tmp

# touch -amt /tmp/abc

find files that are newer than /tmp/abc

# find /tmp -xdev -type f -newer /tmp/abc -exec ls -l {} \;

find files that are newer than /tmp/abc

Suraj

Dennis Handly
Acclaimed Contributor

Re: How to find recently created file.

>Suraj: First create a file into /tmp
>touch -amt /tmp/abc

To create a reference file, you must either do it in the past at the time you need, or you need to specify the time:
touch -t [[CC]YY]MMDDhhmm[.SS] /tmp/abc
Chitta
Frequent Advisor

Re: How to find recently created file.

Solution