Linux-如何查找在过去12小时内没有find命令更改的文件 [英] Linux - How to find files changed in last 12 hours without find command

查看:64
本文介绍了Linux-如何查找在过去12小时内没有find命令更改的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要查找最近12个小时内修改过的文件.但是,目录很大,因此使用常规的find命令花费的时间太长.

I need to find files modified in the last 12 hours. However, the directory is quite large so using the usual find command takes way too long.

有人有更快的想法吗?我在想类似列出文件的方法,然后使用head获得前20名,然后仅检查那些文件.但是我不确定.

Anyone have any ideas doing this quicker? I was thinking something like listing the files, then using head to get the top 20 and then check those files only. But I'm not sure.

有帮助吗?

更新:由于选择了答案,我们发现您实际上可以在不使用find命令的情况下找到文件.技巧是给文件名加上时间戳,然后使用以下代码获取最新的文件名:

UPDATE: Thanks to the help of the chosen answer, we have figured out that you can actually find a file without using the find command. The trick is to timestamp the file names, then use the following code to get the latest one:

ls -1/directory/files*.txt |排序-nr |头-1

推荐答案

文件修改时间存储在其inode中.因此,无论您使用什么命令,都必须读取该目录中所有文件的inode.您可以创建自己的脚本来检查mtime,但这不会更快.

The file modification time is stored in its inode. So whatever command you use has to read inodes for all files in that directory. You can make your own script for checking the mtime, but it won't be faster.

列出目录内容(仅文件名)非常快,请尝试使用 ls -1 ( ls减一个),但是使用诸如mtime之类的文件属性列出目录速度很慢: ls -l <​​/code>( ls减去小L ).

Listing the directory contents (filenames only) is really fast, try with ls -1 (ls minus one).But listing it with file attributes like mtime is slow: ls -l (ls minus little L).

文件系统以随机"顺序读取目录中的文件列表(该顺序取决于许多因素,但是是静态的).因此,您不能使用X个文件后停止等操作. ls -t 列出了按mtime排序的文件,但必须读取所有文件的mtime才能对其进行排序.

The file list in directory is read in "random" order by the filesystem (the order depends on many things, but is static). So you can't use something like stopping after X number of files. ls -t lists the files sorted by mtime, but it has to read the mtime of all files in order to sort them.

这篇关于Linux-如何查找在过去12小时内没有find命令更改的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆