Cobra Forum

Linux => New to Ubuntu => Topic started by: mahesh on Sep 21, 2023, 07:06 AM

Title: How to delete every folder named "derek" except "/home/derek" more than one week
Post by: mahesh on Sep 21, 2023, 07:06 AM
Howdy folks,

I have a nasty habit of leaving "to be deleted" files strewn about my server in folders named derek.

I use WinSCP's explorer interface a lot and to minimise having instances and tabs open while actually using it like a file explorer (deleting large bodies of small documents, etc.), I don't like to have it clog up the pipes with multiple connections to manage several deletion processes occurring simultaneously. So I prefer to just select a bunch of files over SFTP and drag them into a new folder called "derek" that I then resolve to return to delete later. I'm sure you see the obvious flaw in my extremely lazy plan.

So, once you're all finished cringing at my attempt to manage a remote ubuntu server by using WinSCP like it's Windows Explorer and KiTTY like it's PowerShell, (I'm *very* much in a transitional period and would like more freedom to tinker around and make mistakes without filling up my drive with loose files when something I experiment with fails and I put off cleaning up the residual files due to the multiconnection issue in WinSCP), I'd like help in creating a spider that really likes to eat people named derek.

I would like to be talked through the steps needed to create a service that starts upon booting the server that monitors for any directory named "derek", then deletes every instance of every directory named "derek" currently over a week old, with the sole exception of the directory at "/home/derek", which, of course, should be immune to the sweeping process. I'd like this to recur weekly, indefinitely, silently, and automatically upon starting the server. If, upon boot, it has run within the last week, I would like it to skip the search and terminate or something along those lines.

I have SSH access, SFTP, and also I have Cockpit set up with the terminal there, so I'm covered for access. I hope this is enough information for us to get started figuring out what steps I need to take, really this is more an orienteering challenge than anything, I think, so with a bit of friendly guidance and prescience that I'm *very* new to linux, having spent my whole life using Windows exclusively, and so my foundational knowledge is extremely limited.


TL;DR:

I would like a silent, auto-starting, weekly janitor spider that crawls through my entire server for folders named "derek" older than one week, unless the path is equal to "/home/derek" relative to root (so it would delete /home/derek/derek but not /home/derek). It also needs to not trigger a search every time I restart the server--only if it's been at least a week since its last hunt.

TIA for your assistance,
Maia

nb. I call the folder "derek" because it takes less time than it does to type "delete".