I am looking to understand how a directory with the immutable bit set behaves on Linux. It is straightforward with files, but the nature of directories having two sides to themselves—the directories themselves and their contents—makes it more confusing. Let's say I had a directory that looked like this:
${ROOT}/
build/
config/
src/
Makefile
README
Can the immutable bits be used in such a way so as to make ${ROOT}
, ${ROOT}/build
, ${ROOT}/config
, ${ROOT}/src
, ${ROOT}/Makefile
, and ${ROOT}/README
read-only (i.e., permissions, owners, extended attributes, and names cannot be changed nor may files/directories be deleted or added) EXCEPT that files and directories may be freely added, removed, and modified under ${ROOT}/build
and ${ROOT}/config
? I imagine that this could be achieved by running either chattr -R +i ${ROOT}; chattr -R -i ${ROOT}/build ${ROOT}/config
or chattr -R +i ${ROOT}; chattr -R -i ${ROOT}/build/* ${ROOT}/config/*
, but the behavior of directories on this front is ambiguous to me. A potential use case for this would be if an administrator wants to leave the source code, the makefile, the README, and the top-level directory structure of this project unmodifiable by other users while still allowing them to build in it.
${ROOT}/build
read-only" and "freely add and remove files under${ROOT}/build
" are mutually exclusive...