Here's what I want to achieve:

I want to protect folder /mnt/sdmmc0p2/test from being removed or moved, but files inside can be removed.

I try to use chattr +a /mnt/sdmmc0p2/test, but fail.

~# chattr +a /mnt/sdmmc0p2/test
chattr: No such file or directory while trying to stat /mnt/sdmmc0p2/test
~# mkdir /mnt/sdmmc0p2/test
~# chattr +a /mnt/sdmmc0p2/test
~# date >> /mnt/sdmmc0p2/test/test
~# rm /mnt/sdmmc0p2/test/test
rm: can't remove '/mnt/sdmmc0p2/test/test': Operation not permitted

Then I try 'u' (undeletable) flag

~# chattr =u /mnt/sdmmc0p2/test
~# rm /mnt/sdmmc0p2/test/test
~# rm -r /mnt/sdmmc0p2/test

Here's two questions:

  1. Can my goal being achieved by chattr?
  2. Why 'u' flag is not working? Do I misunderstand meaning of "undeletable"?

You can do this simply with chmod and chown

sudo chown root:root /mnt/sdmmc0p2/test
sudo chmod 777  /mnt/sdmmc0p2/test

then to test

cd  /mnt/sdmmc0p2/test
touch mytest1
rm mytest1
cd ..
rm -rf  /mnt/sdmmc0p2/test
rm: cannot remove '/mnt/sdmmc0p2/test': Permission denied
| improve this answer | |
  • Thanks for your answer. However, real user in my system would be root, and I want to ban root user from deleting this folder. – Yu-Ting Chen Nov 7 '19 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.