Thursday, May 16, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 2953  / 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
;