First, let us find out the files older than X days, for example 30 days.
To do, so, just run:
$ find . -mtime +30 -print
The above command will find and display the older files which are older than 30 day in the current working directorys.
If you want to search files in a specific directory, just replace the dot with the folder path. For example, to find out the files which are older than 30 days in /home/de/Downloads directory, just run:
$ find /home/de/Downloads -mtime +30 -print
Now, run any one of the following command to delete the files which are not required anymore. Again, I warn you that these commands will delete the files immediately once you hit ENTER button. Please be cautious and double check before running these commands.
$ find <Path_To_Old_Files> -type f -mtime +30| xargs rm -f
Or,
$ find <Path_To_Old_Files> -mtime +30 -exec rm -f {} \;
Or,
$ find <Path_To_Old_Files> -mtime +30 -delete;
This article is contributed by Neha. If you like dEexams.com and would like to contribute, you can write your article here or mail your article to admin@deexams.com . See your article appearing on the dEexams.com main page and help others to learn.