In Linux, the “mtime” (modification time) is the time when the content of any file is modified. This is stored as a timestamp in the file’s inode (index node), a data structure containing details about the file, such as its permissions, size, owner, etc.
This tutorial describes various methods to find “mtime” in Linux. The supported content of this guide is as follows:
- Using the stat Command
- Using the ls Command
- Using the find Command
- Bonus Tip: Find Modified Files of the Last 24 Hours
Let’s start with the “stat” command.
Method 1: Using the stat Command to Find mtime in Linux
The “mtime” is updated whenever the file’s content is modified. To find the modification time (mtime) of a file “file.txt” in Linux, you can use the “stat” command:
$ stat file.txt
The output displays the information about the “file.txt”, including the modification date “2022-12-27” and time “23:55:28”.
Method 2: Using the ls command to Find mtime in Linux
Users can use the “ls” command to display the modification time of a file with the help of the “-l” option. It displays the “long format” of the specified file, including permission, modification date, and time:
$ ls -l file.txt
The output displays the information about the file in a long format, having a modification time of “23:55”.
Let’s carry out another method to find mtime in Linux.
Method 3: Using the find command to Find mtime in Linux
We can use the “find” command to search files with the criteria of modification time. For instance, find those files which are modified 20 days ago:
$ find /usr -mtime -20 -ls
Note: The find command has many options for searching based on modification time, so you can use it to find files modified within a specific time range or at a specific time.
These are all possible methods to find “mtime” in Linux.
Conclusion
In Linux, the “stat”, “ls” and “find” commands are used to find the “mtime” of files in Linux. These commands display the updated modification time when the file’s content is changed. Additionally, the “find” command has multiple options to display the list of directories and subdirectories within a specific time. This guide has demonstrated various methods to find “mtime” in Linux.