How To Find Last Modified File In Unix
This tutorial explains how to discover last modified files in Linux using different commands and co-ordinate to custom needs.
After reading this tutorial you lot'll know how to execute the following tasks:
- How to find files modified in a specific day range
- How to discover last modified specific file type (due east.g mp4, png)
- Finding files modified earlier / later Ten minutes
- How to find files modified in a specific appointment
- Finding modified files recursively
- Search omitting files or directories
- Find files by admission engagement
Finding concluding mean solar day modified files in Linux:
To start, let's search files modified less than a day ago. To observe files modified a day ago you lot can use the commands detect and newermt used in the following example.
The find control is used to search files. The newermt command compares files timestamp with the argument passed, in this case "1 mean solar day ago". And so, the ls command is passed to list the files.
$ find /dwelling house/linuxhint -newermt "one day ago" -ls
To find concluding day modified files, you can also use the mtime command together with observe. By specifying the option 0 as in the example beneath, mtime volition return all files modified in the last 24 hours.
$ observe /home/linuxhint -mtime 0
Notice Last Modified Specific File Blazon in Linux:
You can utilize a wildcard to limit your search to a specific file type. In the following example, detect and newermt are instructed to listing all mp4 files modified a day agone.
cc lang="fustigate" width="100%" superlative="100%" escaped="true" theme="blackboard"]$ observe /home/linuxhint/*.mp4 -newermt "1 day ago" -ls[/cc
In the following example, find and newermt are used to find all .png images less than xv days old.
$ notice /home/linuxhint/Desktop/*.png -newermt "fifteen day ago" -ls
Finding Last Hour Modified Files in Linux:
The following example combines the find command with the mmin command. We can apply the mmin command to specify minutes. In the example below, the find and mmin commands will print all files nether the /root directory, whose modifications are less than threescore minutes old.
Contrary to the previous example in which files modified in the by 60 minutes were found. Yous tin can as well apply +mmin to search files modified after X minutes. For example, the following command will show files modified 60 minutes ago or more.
Finding Files Modified on a Specific Appointment in Linux:
You can use the ls command to list files including their modification date by adding the -lt flag as shown in the case beneath. The flag -l is used to format the output as a log. The flag -t is used to list last modified files, newer first.
So you can combine ls -lt with grep to print all files which were modified on a specific appointment.
$ ls -lt /habitation/linuxhint | grep 'Jun 11'
Find Terminal Modified Files Recursively:
Previous examples are useful to detect last modified files
The control beneath tin be used to print terminal modified files recursively.
$ find -printf "%TY-%Tm-%Td %TT %p\due north" | sort -n
Search File by Date Omitting Files or Directories:
Reverse to the previous instance, you can search files omitting directories. For this purpose, you need to implement the -blazon flag with the option f (file) as shown in the following example. Equally a upshot, you'll see only concluding files and no directories.
$ observe /root -type f -newermt "2021-06-10"
You tin besides search directories only and the output will omit files. For this, just replace the f with a d afterward the -type flag.
$ find /root -type d -newermt "2021-06-x"
Find Files by Admission Engagement:
You also may want to find unmodified files past access appointment. For this purpose, you can employ the atime command. Information technology is like to the mtime command explained before, merely instead of identifying files by modification, it can display files past access. With this command you lot tin learn the final accessed files and directories in the system.
The post-obit command shows all files accessed in the past 10 days.
$ find /root -atime -10 -type f
Like the previous command, you can also utilize the d option to show just directories:
$ discover /root -atime -10 -type d
If you lot don't specify a blazon, atime will show all files and directories:
In the following example, find and atime are used to find files and directories with modification older than 20 days.
Every bit with previous examples, y'all can also limit the listing to files or directories with the -type flag.
$ find /dwelling -atime +20 -blazon f
Conclusion:
As you tin see, Linux offers dissimilar methods to find files according to modification time. Whatever Linux user level can easily learn those methods to search files with a single command. Finding files by modification or access inside a system is office of the basic noesis a Linux user needs.
I hope this tutorial was useful. Keep post-obit Linux Hint for more Linux tips and tutorials.
Source: https://linuxhint.com/find-last-modified-files-in-linux/
Posted by: keatonhalk1956.blogspot.com
0 Response to "How To Find Last Modified File In Unix"
Post a Comment