Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically Expire or Remove Files Uploaded to our FTP Site

Status
Not open for further replies.

stevenriz

IS-IT--Management
May 21, 2001
1,069
Hi everyone, we have now multiple internal people transferring files to our FTP site for their various contacts to logon and download. Is there any way to automatically expire those files so they don't stay there forever taking up space? If people don't clean up after themselves, we will quickly run out of space. Any suggestions? thanks!
Steve
 
You could have a cron job that runs every day. This command would get rid of files over five 5 days old:

cd /ftpdirectory
find . -mtime +5 | xargs rm
 
To handle subdirectories they may create, I would enhance that with:

Code:
cd /ftpdirectory
find . -type f -mtime +5 | xargs rm 
find . -type d -mtime +5 | xargs rmdir

Annihilannic.
 
At least gnu-find has the ability to delete files and directories as well with an uniform command (called '-delete' for no obvious reason) :)
Code:
find /ftpdirectory -mtime +5 -delete

And you don't need xargs, with it's probable problems with blanks and newlines.

If your find does not contain -delete, use
Code:
find /ftpdirectory -mtime +5 -type f -exec rm {} \;
and
Code:
find /ftpdirectory -mtime +5 -type d -exec rmdir {} \;

don't visit my homepage:
 
True about xargs, an important consideration when it's a "public" destination that will probably contain evil filenames.

find ... -print0 | xargs -0 rm is a good workaround, but again that's a GNU-ish extension... xargs is only of real benefit if you are going to be removing thousands of files and performance is a concern.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top