How to find 开发者_JAVA百科the files that are created in the last hour in unix
If the dir to search is srch_dir
then either
$ find srch_dir -cmin -60 # change time
or
$ find srch_dir -mmin -60 # modification time
or
$ find srch_dir -amin -60 # access time
shows files whose metadata has been changed (ctime
), the file contents itself have been modified (mtime
), or accessed (atime
) in the last hour, respectively.
ctime
is non-unintuitive and warrants further explanation:
ctime
: Unlikemtime
, which is only related to the contents inside a file, changed timestamp indicates the last time some metadata of a file was changed.ctime
refers to the last time when a file’s metadata. For example, if permission settings of a file were modified,ctime
will indicate it.
UNIX filesystems (generally) don't store creation times. Instead, there are only access time, (data) modification time, and (inode) change time.
That being said, find
has -atime
-mtime
-ctime
predicates:
$ man 1 find ... -ctime n The primary shall evaluate as true if the time of last change of file status information subtracted from the initialization time, divided by 86400 (with any remainder discarded), is n. ...
Thus find -ctime 0
finds everything for which the inode has changed (e.g. includes file creation, but also counts link count and permissions and filesize change) less than an hour ago.
check out this link and then help yourself out.
the basic code is
#create a temp. file
echo "hi " > t.tmp
# set the file time to 2 hours ago
touch -t 200405121120 t.tmp
# then check for files
find /admin//dump -type f -newer t.tmp -print -exec ls -lt {} \; | pg
find ./ -cTime -1 -type f
OR
find ./ -cmin -60 -type f
sudo find / -Bmin 60
From the man
page:
-Bmin n
True if the difference between the time of a file's inode creation and the time
find
was started, rounded up to the next full minute, is n minutes.
Obviously, you may want to set up a bit differently, but this primary seems the best solution for searching for any file created in the last N minutes.
Check out this link for more details.
To find files which are created in last one hour in current directory, you can use -amin
find . -amin -60 -type f
This will find files which are created with in last 1 hour.
精彩评论