HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

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
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.

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

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