LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help creating a Bash script (https://www.linuxquestions.org/questions/linux-newbie-8/help-creating-a-bash-script-102500/)

gothicreader 10-10-2003 12:33 PM

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!!

david_ross 10-10-2003 12:53 PM

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

gothicreader 10-10-2003 01:11 PM

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!

trickykid 10-10-2003 01:30 PM

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.

gothicreader 10-10-2003 01:36 PM

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.