Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-10-2003, 01:33 PM   #1
LQ Newbie
Registered: Oct 2003
Posts: 5

Rep: Reputation: 0
Question 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.


if files are 45 days or older, delete for user's or groups directories.

Old 10-10-2003, 01:53 PM   #2
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 67
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
Old 10-10-2003, 02:11 PM   #3
LQ Newbie
Registered: Oct 2003
Posts: 5

Original Poster
Rep: Reputation: 0
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?

Old 10-10-2003, 02:30 PM   #4
LQ Guru
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 259Reputation: 259Reputation: 259
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.
Old 10-10-2003, 02:36 PM   #5
LQ Newbie
Registered: Oct 2003
Posts: 5

Original Poster
Rep: Reputation: 0
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!!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem creating BASH script with files that have whitespace scattaneo Linux - General 2 11-06-2004 06:40 PM
Bash script to do copying and ISO image creating, etc. satimis Programming 2 09-19-2004 10:47 PM
Creating switches in a bash script Moto_Jon Programming 2 07-28-2004 07:06 PM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 11:23 PM
need help creating a bash script zibertron Linux - General 3 01-31-2003 10:23 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:54 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration