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

📄 external.html

📁 一本完整的描述Unix Shell 编程的工具书的所有范例
💻 HTML
📖 第 1 页 / 共 2 页
字号:
BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>rm -badname</B></TT> <TTCLASS="COMPUTEROUTPUT">rm: invalid option -- b Try `rm --help' for more information.</TT></PRE></TD></TR></TABLE>	      </P><P>One way to accomplish this is to preface the filename to be	      removed with a <ICLASS="EMPHASIS">dot-slash</I> .	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>rm ./-badname</B></TT></PRE></TD></TR></TABLE>	        		Another method is to precede the filename with a <SPANCLASS="QUOTE">" -- "</SPAN>.	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>rm -- -badname</B></TT></PRE></TD></TR></TABLE>	      </P></TD></TR></TABLE></DIV><DIVCLASS="WARNING"><TABLECLASS="WARNING"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/warning.png"HSPACE="5"ALT="Warning"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>When used with the recursive flag	      <TTCLASS="OPTION">-r</TT>, this command removes files all the	      way down the directory tree from the current directory.	      A careless <BCLASS="COMMAND">rm -rf *</B> can wipe out a big	      chunk of a directory structure.</P></TD></TR></TABLE></DIV></DD><DT><BCLASS="COMMAND">rmdir</B></DT><DD><P>Remove directory. The directory must be empty of	      all files -- including <SPANCLASS="QUOTE">"invisible"</SPAN>	      <ICLASS="EMPHASIS">dotfiles</I>		<ANAME="AEN7140"HREF="#FTN.AEN7140">[1]</A>	      -- for this command to succeed.</P></DD><DT><BCLASS="COMMAND">mkdir</B></DT><DD><P>Make directory, creates a new directory. For example,	      <TTCLASS="USERINPUT"><B>mkdir -p project/programs/December</B></TT>	      creates the named directory. The	      <TTCLASS="REPLACEABLE"><I>-p</I></TT> option automatically creates	      any necessary parent directories.</P></DD><DT><ANAME="CHMODREF"></A><BCLASS="COMMAND">chmod</B></DT><DD><P>Changes the attributes of an existing file (see <AHREF="internal.html#EX44">Example 11-12</A>).</P><P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;chmod +x filename   2&nbsp;# Makes "filename" executable for all users.   3&nbsp;   4&nbsp;chmod u+s filename   5&nbsp;# Sets "suid" bit on "filename" permissions.   6&nbsp;# An ordinary user may execute "filename" with same privileges as the file's owner.   7&nbsp;# (This does not apply to shell scripts.)</PRE></TD></TR></TABLE></P><P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;chmod 644 filename   2&nbsp;# Makes "filename" readable/writable to owner, readable to   3&nbsp;# others   4&nbsp;# (octal mode).</PRE></TD></TR></TABLE></P><P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;chmod 1777 directory-name   2&nbsp;# Gives everyone read, write, and execute permission in directory,   3&nbsp;# however also sets the "sticky bit".   4&nbsp;# This means that only the owner of the directory,   5&nbsp;# owner of the file, and, of course, root   6&nbsp;# can delete any particular file in that directory.</PRE></TD></TR></TABLE></P></DD><DT><BCLASS="COMMAND">chattr</B></DT><DD><P>Change file attributes. This is analogous to	      <BCLASS="COMMAND">chmod</B> above, but with different options	      and a different invocation syntax, and it works only on	      an <ICLASS="EMPHASIS">ext2</I> filesystem.</P><P>One particularly interesting <BCLASS="COMMAND">chattr</B>	      option is <TTCLASS="OPTION">i</TT>. A <BCLASS="COMMAND">chattr +i	      <TTCLASS="FILENAME">filename</TT></B> marks the file	      as immutable. The file cannot be modified, linked to,	      or deleted , <ICLASS="EMPHASIS">not even by root</I>. This	      file attribute can be set or removed only by root. In a	      similar fashion, the <TTCLASS="OPTION">a</TT> option marks the	      file as append only.</P><P>	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">root# </TT><TTCLASS="USERINPUT"><B>chattr +i file1.txt</B></TT>   <TTCLASS="PROMPT">root# </TT><TTCLASS="USERINPUT"><B>rm file1.txt</B></TT>  <TTCLASS="COMPUTEROUTPUT">rm: remove write-protected regular file `file1.txt'? y rm: cannot remove `file1.txt': Operation not permitted</TT> 	      </PRE></TD></TR></TABLE>	    </P><P>If a file has the <TTCLASS="OPTION">s</TT> (secure)              attribute set, then when it is deleted its block is zeroed out	      on the disk.</P><P>If a file has the <TTCLASS="OPTION">u</TT> (undelete)              attribute set, then when it is deleted, its contents can still	      be retrieved (undeleted).</P><P>If a file has the <TTCLASS="OPTION">c</TT> (compress)              attribute set, then it will automatically be compressed	      on writes to disk, and uncompressed on reads.</P><DIVCLASS="NOTE"><TABLECLASS="NOTE"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/note.png"HSPACE="5"ALT="Note"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>The file attributes set with	      <BCLASS="COMMAND">chattr</B> do not show in a file listing	      (<BCLASS="COMMAND">ls -l</B>).</P></TD></TR></TABLE></DIV></DD><DT><ANAME="LINKREF"></A><BCLASS="COMMAND">ln</B></DT><DD><P>Creates links to pre-existings files. A <SPANCLASS="QUOTE">"link"</SPAN>	      is a reference to a file, an alternate name for it.	      The <BCLASS="COMMAND">ln</B> command permits referencing	      the linked file by more than one name and is a superior	      alternative to aliasing (see <AHREF="othertypesv.html#EX18">Example 4-6</A>).</P><P>The <BCLASS="COMMAND">ln</B> creates only a reference, a	       pointer to the file only a few bytes in size.</P><P><ANAME="SYMLINKREF"></A></P><P>The <BCLASS="COMMAND">ln</B> command is most often used	      with the <TTCLASS="OPTION">-s</TT>, symbolic or	      <SPANCLASS="QUOTE">"soft"</SPAN> link flag. Advantages of using the	      <TTCLASS="OPTION">-s</TT> flag are that it permits linking across	      file systems or to directories.</P><P>The syntax of the command is a bit tricky. For example:	      <TTCLASS="USERINPUT"><B>ln -s oldfile newfile</B></TT> links the	      previously existing <TTCLASS="FILENAME">oldfile</TT> to the	      newly created link, <TTCLASS="FILENAME">newfile</TT>.</P><DIVCLASS="CAUTION"><TABLECLASS="CAUTION"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/caution.png"HSPACE="5"ALT="Caution"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>If a file named <TTCLASS="FILENAME">newfile</TT> has	      previously existed, an error message will	      result.</P></TD></TR></TABLE></DIV><TABLECLASS="SIDEBAR"BORDER="1"CELLPADDING="5"><TR><TD><DIVCLASS="SIDEBAR"><ANAME="AEN7241"></A><P><B>Which type of link to use?</B></P><P>As John Macdonald explains it:</P><P>Both of these [types of links] provide a certain measure of dual reference		-- if you edit the contents of the file using any name,		your changes will affect both the original name and either		a hard or soft new name.  The differences between them		occurs when you work at a higher level.  The advantage of		a hard link is that the new name is totally independent		of the old name -- if you remove or rename the old name,		that does not affect the hard link, which continues		to point to the data while it would leave a soft link		hanging pointing to the old name which is no longer		there. The advantage of a soft link is that it can refer		to a different file system (since it is just a reference		to a file name, not to actual data). And, unlike a hard		link, a symbolic link can refer to a directory.</P></DIV></TD></TR></TABLE><P>Links give the ability to invoke a script (or any other type	      of executable) with multiple names, and having that script	      behave according to how it was invoked.</P><DIVCLASS="EXAMPLE"><HR><ANAME="HELLOL"></A><P><B>Example 12-2. Hello or Good-bye</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#!/bin/bash   2&nbsp;# hello.sh: Saying "hello" or "goodbye"   3&nbsp;#+          depending on how script is invoked.   4&nbsp;   5&nbsp;# Make a link in current working directory ($PWD) to this script:   6&nbsp;#    ln -s hello.sh goodbye   7&nbsp;# Now, try invoking this script both ways:   8&nbsp;# ./hello.sh   9&nbsp;# ./goodbye  10&nbsp;  11&nbsp;  12&nbsp;HELLO_CALL=65  13&nbsp;GOODBYE_CALL=66  14&nbsp;  15&nbsp;if [ $0 = "./goodbye" ]  16&nbsp;then  17&nbsp;  echo "Good-bye!"  18&nbsp;  # Some other goodbye-type commands, as appropriate.  19&nbsp;  exit $GOODBYE_CALL  20&nbsp;fi  21&nbsp;  22&nbsp;echo "Hello!"  23&nbsp;# Some other hello-type commands, as appropriate.  24&nbsp;exit $HELLO_CALL</PRE></TD></TR></TABLE><HR></DIV></DD><DT><BCLASS="COMMAND">man</B>, <BCLASS="COMMAND">info</B></DT><DD><P>These commands access the manual and information pages on	      system commands and installed utilities. When available, the	      <ICLASS="EMPHASIS">info</I> pages usually contain a more detailed	      description than do the <ICLASS="EMPHASIS">man</I> pages.</P></DD></DL></DIV></DIV></DIV><H3CLASS="FOOTNOTES">Notes</H3><TABLEBORDER="0"CLASS="FOOTNOTES"WIDTH="100%"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="5%"><ANAME="FTN.AEN7140"HREF="external.html#AEN7140">[1]</A></TD><TDALIGN="LEFT"VALIGN="TOP"WIDTH="95%"><P><ANAME="DOTFILESREF"></A></P><P><ICLASS="EMPHASIS">Dotfiles</I> are files whose		    names begin with a <ICLASS="EMPHASIS">dot</I>, such as		    <TTCLASS="FILENAME">~/.Xdefaults</TT>. Such filenames do		    not appear in a normal <BCLASS="COMMAND">ls</B> listing		    (although an <BCLASS="COMMAND">ls -a</B> will show		    them), and they cannot be deleted by an accidental		    <BCLASS="COMMAND">rm -rf *</B>. Dotfiles are generally		    used as setup and configuration files in a user's		    home directory.</P></TD></TR></TABLE><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="internal.html">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="index.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="moreadv.html">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Internal Commands and Builtins</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="part3.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Complex Commands</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

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