permission 400

#ls -l
-r-------- 1 root root 0 Oct 21 01:50 hello.txt
#cat > hello.txt
Hello World!
ctrl+d

#cat hello.txt
Hello World!

How come root can still write to this file even though the file is read only..?

To protect against it, you could set this in your profile:

set -o noclobber

But this prevent overwriting any file with ">" unlsess you use >|

echo Hello World >| file
How come root can still write to this file even though the file is read only..?

Sorry. That bit got lost :wink:

I meant to say:

Root can do anything!

...

if you really want root to do nothing to it, chattr -i

Then nobody will be able to do anything to the file to modify it until the immutable flag is removed.

A little note. chattr which stands for (change attribute) should be defined as follows:

chattr +i filename

In this case you won't be able to remove the file(unless you change it to -i) even if your root.