Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 2955  / 2 Years ago, tue, august 9, 2022, 11:41:28

How to find and delete older files (older than 7 days) in a folder using a bash script? It's a folder in a server which contain automatic backups. Need to delete old ones automatically so there's space for new ones.


More From » bash

 Answers
7
#!/bin/bash
ssh user@machine "find /path/to/files/ -mtime +7 -exec rm {} ;"


name the script as some_file_name.sh and give execute permissions.



 chmod +x file_name.sh


Run it as ./file_name.sh or bash file_name.sh


[#34393] Wednesday, August 10, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
amacal

Total Points: 457
Total Questions: 102
Total Answers: 116

Location: Thailand
Member since Thu, Apr 22, 2021
3 Years ago
amacal questions
Thu, Aug 11, 22, 17:35, 2 Years ago
Thu, Apr 13, 23, 18:00, 1 Year ago
Sat, Oct 22, 22, 09:15, 2 Years ago
;