22.9 Protect Important Files: Make Them UnwritableA good way to prevent yourself from making mistakes is to make certain files read-only. If you try to delete a read-only file, you will get a warning. You will also get a warning if you try to move a file onto another file that is write - protected. If you know you want to remove or move a file, even though the file is read-only, you can use the -f option with rm or mv to force the change without warnings. Manually changing the permissions of files all the time is counterproductive. You could create two aliases to make it easier to type:
# change mode to read only alias -w chmod -w # change mode to add write permission alias +w chmod u+w [These are really handy! I use a script named c-w and cw , respectively, instead. For shell programming, I also added cx that does chmod +x . Article 22.10 explains the script. -JP ] It is a good idea to remove write permission from some files. Occasionally some files contain information difficult to replace. These files might be included with other, easily replaceable files. Or you might want to protect some files that rarely change. Combined with directory permissions, and the current value of umask ( 22.4 ) , you can find some file that might be protected in this manner. You can always create a script that adds write permission, edits the file, and removes write permission:
- |
|