How to delete older files using a bash script?

Tags:

Answer: 1

8 hours ago

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.

Added by: Madisen Kerluke IV

Answer: 2

31 hours ago

#!/bin/bash
ssh [email protected] "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

Added by: Tate Corkery

Answer: 3

5 hours ago

Using the below command, first confirm the file list:

find . -mtime +7

If the list is correct, using below the files can be deleted.

find . -mtime +7 -exec rm '{}' \;
Added by: Sarina Dooley

Answer: 4

12 hours ago

For a short and easy to remember version :-

find <directory path> -ctime +7 -delete

This will delete files older than 7 days

Added by: Montana Shanahan

Popular Search

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9