Sometimes permissions get messed up, it’s normally easy to fix, but if the problem also breaks your access control lists (ACLs) then the fix can be much more time consuming (especially when external drives are involved).
Most of the time, for a quick fix, I use the commands below to clone the permissions and ACLs from a known good folder to my broken folder. Usually, this is all I need.
chown $(stat -f%u:%g "$SRCDIR") "$DSTDIR" chmod $(stat -f%Mp%Lp "$SRCDIR") "$DSTDIR" (ls -lde "$SRCDIR" | tail +2 | sed 's/^ [0-9]*: //'; echo) | chmod -E "$DSTDIR"
Either set the environmental variables as you need to or replace them directly (liberal use of
sudo may also be required depending on the folder being updated).
I can’t take credit for the above commands, I discovered them on StackOverflow a good while ago and added them to my useful snippets – if I come across the original I will add the necessary credit.