B
B
BlagoYar Silence2021-04-23 07:35:54
linux
BlagoYar Silence, 2021-04-23 07:35:54

Will such a command delete a folder older than a certain time?

There is such a script for DB backup.
That is, I store hourly backups in a directory named date.
The last command will delete files.
But as far as I understand correctly, it will not delete directories.
How to delete directories older than a certain time, taking into account that there are no files older than this very specific time?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Dmitriev, 2021-04-23
@SignFinder

You need to go to Google, search for "find search directories older than",
find the line with directories and add it to the script with the -delete key

S
Saboteur, 2021-04-23
@saboteur_kiev

find $dest -type d \( -name "*-1[^5]" -o -name "*-[023]?" \) -ctime +30 -exec rm -R {} \; 2>&1
find $dest -type d -name "*-*" -ctime +180 -exec rm -R {} \; 2>&1

Why -exec rm -R {} if find has a -delete option?
How can I make sure that directories older than a certain time are deleted, taking into account that there are no files older than this very specific time?

Search for directories - to do this, you can add the option to find to find only directories.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question