If you would like to cleaning old or no longer used files from your server or instances, using the command below able to remove the files older than number of days. You can use the find command  to search for files that are older than a certain number of days, and then use the -delete option to delete those files or directories.

Delete Old Files:

The below command is used to delete files in the current directory and all subdirectories that are older than 30 days:
 

$ find . -type f -mtime +30 -delete


"find -type f" command to search for all files that have a modification time (-mtime) of more than 30 days ago,

"."  located to the current directoy

"-delete" Delete the files or directories

Delete Old Directory Recursively:

" -exec" option to delete and also to have print the file name which is being deleted.

$ find /location/to/dir -type f -mtime +30 -exec rm {} \; -print


Delete Old Directory Recursively:

Searching all the directories under /var/log modified before 90 days using the command below.


find /location/to/dir -type d -mtime +30 

find /location/to/dir -type d -mtime +30 -exec rm -rf {} \;