Here is a cool way to delete files according to some complex rules without knowing complicated bash commands.

First, create a file as follows that contains your deletion rules.

+ public_html/
+ public_html/*
- access-logs
- etc/
- logs/
- mail/
- .cpanel/
- .cpaddons/
- .spamassassin/
- .ssh/
- public_ftp/
- cpmove.psql/
- tmp/
- cpeasyapache/
- MySQL-install/

Then, run rsync with the source and destination folder being the same
rsync -avz --include-from:rulesFile.txt . . --delete-excluded

You can add –dry-run if you want to see what will be deleted:

rsync -avz --include-from:rulesFile.txt . . --delete-excluded --dry-run

Tags: