A
A
alexxor2015-11-27 10:08:33
bash
alexxor, 2015-11-27 10:08:33

Find folders with a given name, delete old files and empty folders in the found folders?

is it possible to write such a script?
1. find folders named "share folder" in /volume1/public
2. in found folders and their subfolders find files older than 5 days and delete them
3. find empty subfolders in found folders and delete them

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Taran, 2015-11-27
@shambler81

find - build a directory tree
-regex (set a regular folder)
-mtime +5 (older than 5 days)
-exec pm (run the command to remove matches)
-empty (empty folders)
Actually, everything can be done with one find

K
Konkase, 2015-11-27
@Konkase

find /tmp/test/ -name 'папка обмена' -type d -exec sh -c "find '{}' -mtime 4 -type f | xargs -I -=- rm "-=-" && find '{}' -type d | xargs -I =_= rmdir "=_="" \;

so if on the knee

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question