Linux operating system and related technologies and tools provide modification time of the files, folders, executables etc. mtime
is an attribute used by files, directories and different type of files like text, binary etc. In this tutorial, we will learn how to use mtime
attribute with Linux find
and related commands.
Linux操作系统以及相关技术和工具提供了文件,文件夹,可执行文件等的修改时间mtime
是文件,目录和不同类型的文件(如文本,二进制文件等)使用的属性。在本教程中,我们将学习如何使用带Linux find
和相关命令的mtime
属性。
修改时间(mtime) (Modification Time (mtime))
Files and folders are modified in different time during the usage of Linux system. This modification time is stored by the file system like ext3, ext4, btrfs, fat, ntfs etc. Modification time is used for different purposes like backup, change management etc.
在使用Linux系统期间,文件和文件夹会在不同的时间修改。 此修改时间由文件系统(例如ext3,ext4,btrfs,fat,ntfs等)存储。修改时间用于不同目的,例如备份,更改管理等。
列表修改时间(mtime) (List Modification Time (mtime))
As modification time is stored by the file system we can list the modification time of the files and folders. We will use regular ls
command with the -l
option which will list modification time.
由于修改时间是由文件系统存储的,因此我们可以列出文件和文件夹的修改时间。 我们将使用带有-l
选项的常规ls
命令,该命令将列出修改时间。
$ ls -l
根据mtime查找命令 (Find Command According To mtime)
find
command is used to search and find files and directories according to their modification time. We will use -mtime
option with the find command. We can provide the time we want to search. In this example, we will search files and folders in the directory/etc
those modified in the last 24 hour.
find
命令用于根据修改时间搜索和查找文件和目录。 我们将在find命令中使用-mtime
选项。 我们可以提供想要搜索的时间。 在此示例中,我们将在/etc
目录中搜索最近24小时内修改过的文件和文件夹。
$ sudo find /etc -mtime -24
查找更少然后指定的修改时间(Find Less Then Specified Modification Time)
If we want to find files those modified after given time we will use -
with the time value. For example to find files and folders those modified before 12 hours we will use -12
. In this example, we will list files and folders those modified at most 4 hours ago.
如果我们要查找在给定时间后修改的文件,我们将使用-
和时间值。 例如,要查找在12小时之前修改过的文件和文件夹,我们将使用-12
。 在此示例中,我们将列出最多4个小时前修改过的文件和文件夹。
$ find /home -mtime -4
查找更多然后指定的修改时间(Find More Then Specified Modification Time)
We can also find files and folders those modified before the specified time. For example, if we want to list files and folders those modified 6
hours and before we will use +6
. In this example, we will list files and folders those are modified before 12 hours.
我们还可以找到在指定时间之前修改过的文件和文件夹。 例如,如果我们要列出经过6
小时或更长时间修改的文件和文件夹,我们将使用+6
。 在此示例中,我们将列出在12小时之前修改过的文件和文件夹。
$ find /home -mtime +12
翻译自: https://www.poftut.com/what-is-mtime-in-linux-and-find-command/