Help creating a Bash script
For starters, I'm a newbie in Linux. So, I've pretty much worked my way in creating a Linux server to use as an FTP server. Everything so far is functioning as it's suppose to.
I've set up quotas for users and groups. However, I would like to run a cron job to run a script that would go in and view files that are 45 days older than the system date. In which case, it would delete the files in everyones home directory that meet that criteria. So, I thought I ask the experts and maybe you guys can help me create a script that would do just that. Requirements: if files are 45 days or older, delete for user's or groups directories. Thanks!! |
Welcome to LQ.
Try something like this: find /home -type f -mtime +45 -exec rm -f {} \; To make sure it will only delete the files you want - try to run the find first: find /home -type f -mtime +45 |
Before I put this in place. I have another question. I several folders created under /home, however I just want the actual files within those directories to be removed. Can the command you provided me do it?
Thanks! |
Lets break down david's suggestion:
find /home -type f -mtime +45 -exec rm -f {} \; find = the command issued to start the search /home = the directory and all subdirectories to search in -type f = the types it will search specifically for, f stands for files so it will disregard directories -mtime +45 = the age of the files it will look for -exec rm-rf = once it finds all the files in /home and beyond that are older than 45 days, it will remove them. Hope that helps you understand what david presented you with and possibly use. But I would take his suggestion in running that second command, to make sure it will find the files that are older than 45 days, etc, to be for sure to test. |
Thanks trickykid.......I've saved this command for my document library for future use.
Yeah, I did try the second command line first.....good thing too I had some files I didn't want to delete!! |
All times are GMT -5. The time now is 06:15 PM. |