You can use the
find
command to find all files that have been modified after a certain number of days.
For example, to find all files in the current directory that have been modified since yesterday (24 hours ago) use:
find . -maxdepth 1 -mtime -1 -ls
examples
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
Search for file with a specific name in a set of files (-name)
find . -name test.file
searches in the current working directory for a file named "test.file"
find /etc -name test.conf
searches in /etc for a file named "test.conf"
---------------------------------------------------------------------------------
Search for a file and if found, execute a command
find /etc -name test.conf -exec chmod 775 {} \;
searches in /etc for a file named "test.conf" and if found, executes 'chmod 755' on that file
---------------------------------------------------------------------------------
Search for a string in files that match criteria
find . -name \*.log -exec grep "error" {} \;
searches in the current working directory for all files ending in ".log" and then executes grep on those files to find the string "error"
---------------------------------------------------------------------------------
search multiple directories
find /etc /usr -name \*.log
searches /etc/ and /usr for any files ending in ".log"
---------------------------------------------------------------------------------
search for files older than a certain time and remove
find . -name \*.log -mtime +10 -exec rm {} \;
searches in the current working directory for all files ending in ".log" and last modified over 10 days ago and removes those files
---------------------------------------------------------------------------------
Search for files that have not been accessed in a certain time and remove
(with prompting)
find /apps -atime +30 -ok rm {} \;
searches in the /apps directory for all files that have not been accessed in over 10 days and prompts the user before removing those files
---------------------------------------------------------------------------------
search for files by access and modify time, and long list them
find /apps \(-mtime +10 -o -atime +20\) -exec ls -l {} \;
searches in the /apps directory for all files that have not been accessed in over 20 days or not modified in over 10 days and long lists those files
---------------------------------------------------------------------------------
remove core files larger than a certain size
find /apps -type f -size +104857600c -name core -exec rm {} \;
searches in the /apps directory for files (-type f) named "core" that are larger than 100mb (104857600 bytes = 100mb) and removes them
---------------------------------------------------------------------------------