Linux systems are always used as server. Many times we need to cleanup the server. I found nice solution for deleting older files and folders from server without any issue.
For deleting files or folder you can use following command:
rm -rf `find /home/purab/* -type d -mtime +90`
Above command will find all files and folders which are created 90 days ago and delete those folders and files.
Before running above command be careful about directory path. please directory path. rm -rf command is always dangerous.
Above We used find command for searching all files in folder.
-mtime is used to calculate time.
If you want to keep only 5 latest folders on server than you can use following command.
ls -dt /home/purab/*/ | tail -n +6 | xargs rm -rf
Above command has three parts.