Quote:
Originally Posted by ruisselet
I would like to make sure a file's content (the inode content) cannot be modified in any way, but still allow deleting (unlinking) the file (rationale below). That is, I could like to do something to file dest so that 'cp source dest' fails, even as root, but 'cp --remove-destination source dest' succeeds. The only thing I could find is to use chattr +i on the file. However, that also prevents unlinking. Is there a better solution?
|
To be honest, this problem surpasses my capacities.
In such cases I write a small script, or better a shell function, e.g.
function Jar_Remove {
DEST=my_destination
SOUR=my_source
chattr -i $DEST
echo "Chattr -i $DEST..."
cp --remove-destination $SOUR $DEST
echo "Remove $DEST and copying $SOUR to $DEST..."
chattr +i $DEST
echo "chattr restored."
}
export -f Jar_Remove
This function with the export in a file sourced by .bashrc. It is perhaps not elegant, but your destination is safe, and only the call of Jar_Remove by root does the right thing. If you want to use it as a user, use "sudo".
HTH er1ch