Hi,
do you also want to remove files that do not exist in the source directory or just the directories?
If you want to remove both files and directories, I would recommend using
rsync with the
--del switch.
If you want to only remove directories, you'll have to filter the files out first. Something like this might work:
Code:
#!/bin/bash
src_dir="/ThisFolder"
dst_dir="./media/disk/DriveQ/backup"
IFS='
'
# get the list of files/directories to be deleted
del_list=($(rsync -avirun --del "$src_dir/" "$dst_dir"|grep "^\*deleting"|cut -c13- ))
# remove the directories
for i in "${del_list[@]}"; do
if [[ -d "${dst_dir}/$i" ]]; then echo rm -r "$i"; fi
done
Anyway, be very careful with this,
allways run with the echo first to see what is going to be deleted before you actually do it.
also, with
rsync, pay attention to the trailing slash in the source directory. It
does matter.
Hope this helps