-1

After

chattr +i /etc/hosts

I can't edit this file (obviously). But how can I revert it back. I need to edit this file and then lock again.

UPD

ls -l /etc/hosts
-rw-r--r-- 1 root root 274 2011-06-09 14:14 /etc/hosts

UPD 2

lsattr /etc/hosts
-----a-----------e- /etc/hosts

UPD 3

Thanx, @womble, I've removed a attribute

chattr -a /etc/hosts
fl00r
  • 575
  • 2
  • 7
  • 20
  • `lsattr /etc/hosts` would be useful to see. Also, "Operation is denied" is not the usual error message you'd expect to see for a permissions problem; I suspect something else is wrong. – womble Aug 11 '11 at 08:21
  • @womble `Operation is denied` is my translation of error from my localization. – fl00r Aug 11 '11 at 08:24
  • Please don't do your own translations; get error messages in the `C` locale and post them directly -- exact wording can be critical in diagnosing what's gone wrong. – womble Aug 11 '11 at 08:28
  • @womble, Thank you! I don't know how can I switch locale for only one command (it is system-wide). I can switch to `English` in whole system only. – fl00r Aug 11 '11 at 08:30
  • 3
    `LANG=C ` will do it. – womble Aug 11 '11 at 08:30
  • `Operation not permitted` – fl00r Aug 11 '11 at 08:31

3 Answers3

2

chattr -i will remove immutability, then you can chattr +i it again afterwards.

EDIT

Based on your lsattr output, you've also set "append-only". Clear that as well (chattr -a).

womble
  • 96,255
  • 29
  • 175
  • 230
1

I guess you have (accidentally|purposely) made your /etc immutable as well. Try chattr -i /etc as well. If that was not the case, please fill your question more. Give us stat /etc and stat /etc/hosts as well as lsattr /etc/hosts.

Can you modify any other file under /etc?

EDIT after your own edit: You have a attribute set for /etc/hosts. That means you can only append to that file, every other write operation is denied. Try chattr -a /etc/hosts.

Janne Pikkarainen
  • 31,852
  • 4
  • 58
  • 81
1

The a attribute makes your file append-only, use chattr -a to remove it. See man 1 chattr to see what all other attribute flags are are.

Sgaduuw
  • 1,833
  • 12
  • 16