Bash script for ubuntu to remove files older than 30 days

I'm not a programmer but one of our dept's has an SFTP server that they would like files older than 30 days to be deleted. The folders are in /home/clientname

Can anyone point me in the direction of a script that could cycle through the /home folder and certain sub directories for files older than 30 days and delete them? I could put the script in a cron job so it could run daily, weekly or monthly.

We are using ubuntu 64bit server version 10.10

thank you.
LVL 2
msidnamAsked:
Who is Participating?
 
woolmilkporcConnect With a Mentor Commented:
find /home/clientname -type f -mtime +30 | xargs rm

If there are several clients put their names into a textfile called "clients.txt" (one name per line) and run

while read clientname
 do
    find /home/$clientname -type f -mtime +30 | xargs rm
 done < clients.txt

For a "dry run" replace

xargs rm

with

xargs echo rm

This will display the rm commands, but not execute them.

To be really sure that the command is going to do the right things you can also run:

find /home/clientname -type f -mtime +30 -ls

This will produce a detailed listing of the selected files, but not run any further commands.
0
 
msidnamAuthor Commented:
Excellent thank you. I will try tomorrow morning when i get in the office. I will report results.
0
 
msidnamAuthor Commented:
This is great. thank you. I'm going to post something in exchange forum if you know power shell too :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.