How to create a simple shell script to backup

Hello - I am in process of deleting many files which are older than 4 weeks.

For example I am inside:

/subsystem/prod/

Files are with various extentions, but anything older than 4 weeks should be deleted.

What would be the most simplest script to acheive this?

Use this with caution !!

find /subsystem/prod/ -type f -mtime +28 -exec rm {} \;

You can use find command as below

find /subsystem/prod/ -type f -mtime +28 -exec rm -rf {} \;

This will delete all the files more than 28 days old. I am afraid there is no option available for weeks as time unit.

P.S. Be cautious as this will also delete the files in subdirectories as well.

So by using this command, it will also delete files old in subsystem and ALSO in prod?

Is there a way to just define "prod" - otherwise it wont work..

It will only delete the files in /subsystem/prod and it's subdirectories

You may have a look on the man page of find to find the options you need.

-maxdepth N

will limit to N levels deep in the subdirectories