1

I have a set of client folders on a server. Each client has backups inside a "backup" directory like so;

~/backups/<CLIENT_NAME>/{daily, weekly, monthly}/{databases, directories, logs}

I'd like to find a way to search every client folder and remove files older than a specific time. Can I do this without doing a find for each client? So far I have to do 3 find for each client, and there's dozens.

find ~/backups/<CLIENT_NAME>/daily/{directories,databases,logs} -mtime +6 -exec rm -rf {} \;
find ~/backups/<CLIENT_NAME>/weekly/{directories,databases,logs} -mtime +27 -exec rm -rf {} \;
find ~/backups/<CLIENT_NAME>/monthly/{directories,databases,logs} -mtime +31 -exec rm -rf {} \;
  • You could replace <CLIENT_NAME> by {client1,client2,...clientN}, but then you'd risk overflowing the command line buffer. Just do a loop for clients. With a few dozens of clients the difference in efficiency would be too small to measure. Start worrying about that when you have >100k directories. – Satō Katsura Oct 27 '16 at 10:02
  • unfortunately I need to keep the CLIENT_NAME as they are, but thank you – eekfonky Oct 27 '16 at 10:03
  • Without giving away too much info, why do you need to keep the name the way it is? – I_GNU_it_all_along Oct 27 '16 at 10:11
  • Because they come from an rsync that creates the CLIENT_NAME based on the source server $HOSTNAME. That and the boss says so :-) – eekfonky Oct 27 '16 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.