4

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?

3
  • If you can chmod, then chmod -R youruser DIR ought to do everything, including hidden files.
    – derobert
    Commented Jun 22, 2017 at 20:39
  • Do you mean chown?
    – Brent
    Commented Jun 22, 2017 at 20:43
  • Yes, sorry, I meant chown -R. Though actually you don't need to own files to delete them—you just need write permission on the parent directory.
    – derobert
    Commented Jun 22, 2017 at 20:45

1 Answer 1

3

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .