It can often be useful to remove files that are unnecessary, such as log files, backup files, etc, when it is not already done automatically. Fortunately there is a very simple command to do just that.
Using the find command, it is possible to find the files in the folder you want to clean out and remove them. The following command scans the folder /home/myuser/myfolder/ for files older than 30 days and then executes rm, to remove those files.
find /home/myuser/myfolder/* -mtime +30 -exec rm {} \;
If you want to be cautions, you can use the following commands to test it out:
To see what find pulls up, you can run this.
find /home/myuser/myfolder/* -mtime +30
If you want to make certain the exec command is given the right parameters, you can run it through ls.
find /home/myuser/myfolder/* -mtime +30 -exec ls -l {} \;
[amazon_link asins=’1593273894,0596005954,151738043X,1430219971,B0043D2DY6′ template=’ProductCarousel’ store=’openmindspace-20′ marketplace=’US’ link_id=’2a76a978-d376-11e6-80ff-31f3f7a3df6d’]