What Is mtime In Linux and Find Command?
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.
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.
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.
$ ls -l
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.
$ 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.
$ 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.
$ find /home -mtime +12