I need to delete all folders inside a folder using a daily script. The folder for that day needs to be left.
Folder ‘myfolder’ has 3 sub folder: ‘test1’, ‘test2’ and ‘test3’
I need to delete all except ‘test2’.
I am trying to match exact name here:
find /home/myfolder -type d ! -name 'test2' | xargs rm -rf
OR
find /home/myfolder -type d ! -name 'test2' -delete
This command always tries to delete the main folder ‘myfolder’ also !
Is there a way to avoid this ?