How to make a Linux File unchangeable ( unalterable ) so that no one can modify it
Q. How do I write protect file under Linux so that no one can modify it?
A. You need to use chattr command, which changes the file attributes on a Linux second extended file system. The chattr command supports various attributes.
A file with the i attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute in other words you make a file unchangeable or unalterable.
For example if you want file /data/financial.txt unchangeable by anyone on your system, type the following command (login as the root user):
# chattr +i /data/financial.txt
Now no one can delete or modify file /data/financial.txt. To reset back permission, type the following command:
# chattr -i /data/financial.txt
Use lsattr command to lists the file attributes on a second extended file system. It is use to see attributes set by chattr command.
# lsattr financial.txt
Output:
----i------------ financial.txt
See also:
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Other Helpful FAQs:
- Is There a UNIX / Linux unerase / undelete Command?
- DHCP Client Error: mv cannot move /etc/resolv.conf.dhclient-new to /etc/resolv.conf: Operation not permitted
- Steps for compiling Linux kernel on SMP Itanium IA64 system
- Reconfiguring FreeBSD Ports - Remove OPTIONS config For Any Port
- Environment variable changing on Linux/FreeBSD
Discussion on This FAQ
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: capability, change file attributes, chatter command, chattr command, Linux, list file attributes, lsatter command, root user, second extended file system, superuser, write protect file




June 13th, 2008 at 8:08 pm
How do you do this in a jffs2 file system?