1832859 Members
2999 Online
110048 Solutions
New Discussion

Re: find command

 
SOLVED
Go to solution
Mike Barron_3
Advisor

find command

I have a good question for everyone out there.

I am trying to find a way to list all files created in the last 24 hours in any given directory.

Anyone have any ideas?
5 REPLIES 5
MarkSyder
Honored Contributor

Re: find command

find . -mtime -1 -print

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: find command

This is really impossible, in spite of what you will be told. UNIX has no creation time (except by accident) associated with any file. The inode simply does not carry that bit of metadata. The closest thing is the 'ctime' -- change time (not the same as mtime - modification). Ctime refers to the last time that the file's mode or ownership was changed (e.g. chmod). If this happens to be the time of creation then it works -- but only by accident.

About as close as you are going to get:
find . -ctime -1
but it's far from perfect.
If it ain't broke, I can fix that.
Mike Barron_3
Advisor

Re: find command

Thanks for the info. I kinda figured that would be the case. I just thought maybe someone had some trick up their sleeves.

I guess I can write a script to do a long list of all file changed within the last 24 hours and then strip away anything that isn't "new"

Thanks again.
Sundar_7
Honored Contributor

Re: find command


touch a file with timestamp of exactly 24 hours before than ur current time

# touch -mt 200403080817 ref

# ls -lrt ref
rw-rw-r-- 1 root sys 407 Mar 8 08:17 ref

# find /dir -newerc ref -exec ls -ld {} \;

The above command will list the files with the inode modification time newer than that of file ref.

but note that this goes by the inode modification time. So even if the file permission is changed (or other system calls which modifies the inode data) , it will be included in the list.
Learn What to do ,How to do and more importantly When to do ?
RAC_1
Honored Contributor

Re: find command

Files have three time stapms associated with them.

ll -u -- access time
ll -c -- change time
ll -t -- modification time.

Now if you create a file and do not do any changes to it, ctime is still the creation time. But once a change is done to a file, you get only chnage time. so what you can do it is create a file change it's timestamp to as 24 hrs back and use find command with -newer option.

Anil
There is no substitute to HARDWORK