I have a directory in my home folder containing some build output, which the build process has chown to another user (for reasons unknown to me.) I want to delete the directory, but can't because it's not empty, and I can't delete the files it contains because they are not owned by me. Of course, I could recursively chown all the files, but getting all the hidden files is a pain. Is there a straight forward way?
If you have write access to the directory, you can remove the files in it, regardless of the files' owners. The sticky bit on the directory would prevent you from removing other users' files, but if you own the directory you can just unset the bit... Same for giving yourself write access.
However, a non-empty directory owned by some other user would be more of a problem.
In any case, if you can
chown the files in the directory, you're probably superuser already, and should be able to just
rm -r the whole tree. Though this is somewhat system specific, e.g. on Linux you could have the
CAP_CHOWN capability allowing
chown but not
CAP_DAC_OVERRIDE which would allow bypassing the lack of write access.
It's a workaround that doesn't immediately delete the files (so it won't help if you need the disk space right now), but: move the whole folder to
/tmp and if
/tmp is a
tmpfs it will be gone after the next reboot.