find is the Unix/Linux command line utility used for searching files across the file system. Sometimes we need to search files modified in last few days. Assume you have modified multiple files in your application and forgot to keep track of the modified files. In that case, find command provides you an option to search files based on their modification. You can also search the files modified before X days.
-mtime option with the find command to search files based on modification time followed by the number of days. Number of days can be used in two formats.
- Use + with number of days to search file modified older that X days
- Use – with number of days to search file modified in last X days
The below examples will help you to understand the search for files based on modification time.
Find files modified in last X days
Use below command to search all files and directories modified in last 30 days. Here dot (.) is used to search in current directory. And
-30 defines to search files modified in last 30 day. Change this number with your search requirements.
find . -mtime -30
You can also customize search based on file type. Use -type followed with -f (file) or -d (directory). Below command will search for files only.
find . -type f -mtime -30
Find files modified before X days
The below command will search all files and directories modified before 30 days. Here dot (.) is used to search in current directory. And
+30 defines to search files modified before 30 day. Change this number with your search preferences.
find . -mtime +30
Customize search pattern to search for files only using
-type f. Or use
-type d to search for directories.
find . -type f -mtime +30
This tutorial helps you to find files based on modification days.
The post How To Find Files Modified in Last 30 Days in Linux appeared first on TecAdmin.