⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch22_09.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 22] 22.9 Protect Important Files: Make Them Unwritable </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:40:30Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch22_01.htm"TITLE="22. File Security, Ownership, and Sharing"><LINKREL="prev"HREF="ch22_08.htm"TITLE="22.8 The Handy chmod = Operator "><LINKREL="next"HREF="ch22_10.htm"TITLE="22.10 cx, cw, c-w: Quick File Permission Changes "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch22_08.htm"TITLE="22.8 The Handy chmod = Operator "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 22.8 The Handy chmod = Operator "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 22<BR>File Security, Ownership, and Sharing</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch22_10.htm"TITLE="22.10 cx, cw, c-w: Quick File Permission Changes "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 22.10 cx, cw, c-w: Quick File Permission Changes "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0407">22.9 Protect Important Files: Make Them Unwritable </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-24281"></A><ACLASS="indexterm"NAME="AUTOID-24285"></A><ACLASS="indexterm"NAME="AUTOID-24289"></A><ACLASS="indexterm"NAME="AUTOID-24291"></A>A good way to prevent yourself from making mistakes is to makecertain 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 movea file onto another file that is write&nbsp;- protected. If you know you want to remove or move a file, even though the file isread-only, you can use the <EMCLASS="emphasis">-f</EM>option with<EMCLASS="emphasis">rm</EM>or<EMCLASS="emphasis">mv</EM>to <EMCLASS="emphasis">force</EM>the change without warnings.</P><PCLASS="para">Manually changing the permissions of files all the time is counterproductive. You could create two aliases to make it easier to type:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">&#13;# change mode to read only alias -w chmod -w# change mode to add write permissionalias +w chmod u+w</PRE></BLOCKQUOTE></P><PCLASS="para">[These are really handy!I use a script named <EMCLASS="emphasis">c-w</EM> and <EMCLASS="emphasis">cw</EM>, respectively, instead.For shell programming, I also added <EMCLASS="emphasis">cx</EM> that does <EMCLASS="emphasis">chmod +x</EM>.Article<ACLASS="xref"HREF="ch22_10.htm"TITLE="cx, cw, c-w: Quick File Permission Changes ">22.10</A>explains the script. <EMCLASS="emphasis">-JP</EM>&nbsp;]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<SPANCLASS="link"><EMCLASS="emphasis">umask</EM> (<ACLASS="linkend"HREF="ch22_04.htm"TITLE="Setting an Exact umask ">22.4</A>)</SPAN>,you can find some file that might be protected in this manner.You can always create a script that adds write permission, edits thefile, and removes write permission:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist">&#13;<ACLASS="co"HREF="ch44_15.htm"TITLE="44.15 Handling Command-Line Arguments in Shell Scripts ">&quot;$@&quot;</A> <ACLASS="co"HREF="ch45_12.htm"TITLE="45.12 Parameter Substitution ">${..=..}</A> &#13;</PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">&#13;#!/bin/sh# add write permission to the fileschmod u+w &quot;$@&quot;# edit the files; use vi if VISUAL not defined${VISUAL=vi} &quot;$@&quot;# remove write permissionchmod -w &quot;$@&quot;</PRE></TD></TR></TABLE></P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">BB</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch22_08.htm"TITLE="22.8 The Handy chmod = Operator "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 22.8 The Handy chmod = Operator "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch22_10.htm"TITLE="22.10 cx, cw, c-w: Quick File Permission Changes "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 22.10 cx, cw, c-w: Quick File Permission Changes "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">22.8 The Handy chmod = Operator </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">22.10 cx, cw, c-w: Quick File Permission Changes </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -