ÅÝܽ¶ÌÊÓƵ

print friendly version

Questions and answers

219
On the Unix system, how do I protect individual files against deletion?


The commands described below need to be entered while logged in to the Unix server.   Normally you'll see a prompt ending with $ when the command interpreter (or shell) is ready for another command.

You can protect individual files by changing their permissions, by means of the chmod command (which stands for "change mode") to remove write permission. Use the command like this:

chmod   u-w   myfile

where u-w means "remove write permission for user" and myfile is the name of the file to be protected.  Note however that this will also prevent the file content from being changed (edited).

Alternatively, you could move the file(s) into a subdirectory of their own and remove write permission from that subdirectory with the same command.

To reinstate write permission on the file, use the command

chmod   u+w   myfile

Help us to improve this answer

Please suggest an improvement
(login needed, link opens in new window)

Your views are welcome and will help other readers of this page.

Categories

This is question number 219, which appears in the following categories:

Created by Andy Clews on 27 July 2001 and last updated by Andy Clews on 4 August 2015