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

📄 unx03.htm

📁 Linux Unix揭密.高质量电子书籍.对学习Linux有大帮助,欢迎下载学习.
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<TR>

<TD>

<P>Write</P>

<TD>

<P>2</P>

<TD>

<P>2</P>

<TD>

<P>-</P>

<TR>

<TD>

<P>Execute</P>

<TD>

<P>-</P>

<TD>

<P>-</P>

<TD>

<P>-</P>

<TR>

<TD>

<P>Total</P>

<TD>

<P>6</P>

<TD>

<P>6</P>

<TD>

<P>4</P></TABLE>

<P>In Table 3.3, the resulting numeric mode is 664, the total of the columns for owner, group, and other. The following command sets those permissions regardless of the current ones:

<BR></P>

<PRE>$ ls -l plan-doc2

-r&#151;&#151;&#151;&#151;   1 karen   planners  1721 Aug 14 11:28 plan_doc2

$ chmod 664 plan_doc2

$ ls -l plan-doc2

-rw-rw-r&#151; 1 karen   planners    1721 Aug 14 11:28 plan_doc2</PRE>

<P>Now suppose that Karen has a game program named trek. She wants everyone on the system to be able run the program, but she doesn't want anyone to alter or read it. As the owner, she wants to have read, write, and execute permission. Table 3.4 shows how 

to calculate the correct numeric mode.

<BR></P>

<UL>

<LH><B>Table 3.4. Calculating another set of numeric </B><B>chmod</B><B> options.</B>

<BR></LH></UL>

<TABLE BORDER>

<TR>

<TD>

<PRE><I>Permission</I>

<BR></PRE>

<TD>

<PRE><I>Owner</I>

<BR></PRE>

<TD>

<PRE><I>Group</I>

<BR></PRE>

<TD>

<PRE><I>Other</I>

<BR></PRE>

<TR>

<TD>

<P>Read</P>

<TD>

<P>4</P>

<TD>

<P>-</P>

<TD>

<P>-</P>

<TR>

<TD>

<P>Write</P>

<TD>

<P>2</P>

<TD>

<P>-</P>

<TD>

<P>-</P>

<TR>

<TD>

<P>Execute</P>

<TD>

<P>1</P>

<TD>

<P>1</P>

<TD>

<P>1</P>

<TR>

<TD>

<P>Total</P>

<TD>

<P>7</P>

<TD>

<P>1</P>

<TD>

<P>1</P></TABLE>

<P>Because the three columns add up to 711, the correct chmod command is as follows:

<BR></P>

<PRE>$ chmod 711 trek

$ ls -l trek

-rwx&#151;x&#151;1 1 karen   user1    56743 Apr 9 17:10 trek</PRE>

<P>Numeric arguments work equally well for files and directories.

<BR></P>

<H3 ALIGN="CENTER">

<CENTER><A ID="I18" NAME="I18">

<FONT SIZE=4><B>Default File and Directory Permissions&#151;Your </B><B><I>umask</I></B>

<BR></FONT></A></CENTER></H3>

<P>How are default file and directory modes chosen? Consider the following commands, for example:

<BR></P>

<PRE>$ touch myfile

$ mkdir mydir</PRE>

<P>What permissions will be assigned to myfile and mydir by default, and how can you control those defaults? After all, you don't want to type a chmod command every time that you create a file or directory&#151;it would be much more convenient if they were 

created with the modes that you most often want.

<BR></P>

<P>Your umask (user-mask) controls default file and directory permissions. The command umask sets a new umask for you if you're dissatisfied with the one that the system gives you when you log in. Many users include a umask command in their login start-up 

files (.profile or .login). To find out your current umask, just type <B>umask</B>:

<BR></P>

<PRE>$ umask

022</PRE>

<P>To change your umask, enter <B>umask</B> and a three digit number that specifies your new umask. For instance, to change your umask to 027, enter the following command:

<BR></P>

<PRE>$ umask 027</PRE>

<P>UNIX determines the default directory modes by subtracting your umask from the octal number 777. Therefore, if your umask is 027, your default directory mode is 750.

<BR></P>

<P>The result of this arithmetic is a mode specification like that which you give chmod, so the effect of using the umask command is similar to using a chmod command. However, umask never sets file execute bits, so you must turn them on with chmod, 
regardless of your umask. To find the corresponding file permissions, you subtract your umask from 666. For example, if your umask is 022, your default file modes will be 644.

<BR></P>

<P>Table 3.5 shows some typical umasks and the default file and directory modes that result from them. Choose one that is appropriate for you and insert it into your login start-up file. Table 3.5 shows file and directory modes both numerically and 
symbolically, and umask values range from the most to the least secure.

<BR></P>

<UL>

<LH><B>Table 3.5. Typical </B><B>umask</B><B> values.</B>

<BR></LH></UL>

<TABLE BORDER>

<TR>

<TD>

<PRE><I>umask Value</I>

<BR></PRE>

<TD>

<PRE><I>Default File Mode</I>

<BR></PRE>

<TD>

<PRE><I>Default Directory </I><I>Mode</I>

<BR></PRE>

<TR>

<TD>

<P>077</P>

<TD>

<P>600 (rw&#151;&#151;&#151;-)</P>

<TD>

<P>700 (rwx&#151;&#151;&#151;)</P>

<TR>

<TD>

<P>067</P>

<TD>

<P>600 (rw&#151;&#151;&#151;-)</P>

<TD>

<P>710 (rwx&#151;x&#151;-)</P>

<TR>

<TD>

<P>066</P>

<TD>

<P>600 (rw&#151;&#151;&#151;-)</P>

<TD>

<P>711 (rwx&#151;x&#151;x)</P>

<TR>

<TD>

<P>027</P>

<TD>

<P>640 (rw-r&#151;&#151;-)</P>

<TD>

<P>750 (rwxr-xr-x)</P>

<TR>

<TD>

<P>022</P>

<TD>

<P>644 (rw-r&#151;r&#151;)</P>

<TD>

<P>755 (rwxr-xr-x)</P>

<TR>

<TD>

<P>000</P>

<TD>

<P>666 (rw-rw-rw-)</P>

<TD>

<P>777 (rwxrwxrwx)</P></TABLE>

<P>Perhaps the best way to understand umask values is to experiment with the commands umask, touch, mkdir, and ls to see how they interact, as in the following examples:

<BR></P>

<PRE>$ umask 066

$ touch myfile

$ mkdir mydir

$ ls -l

-rw&#151;&#151;&#151;1 karen     user1     0  Feb 12 14:22 myfile

drwx&#151;x&#151;1 2 karen     user1    512 Feb 12 14:22 mydir

$ rm myfile

$ rmdir mydir

$ umask 027

$ touch myfile

$ mkdir mydir

$ ls -l

-rw-r&#151;&#151; 1 karen    user1     0  Feb 12 14:23 myfile

drwxr-x&#151;  2 karen    user1   512  Feb 12 14:23 mydir</PRE>

<P>The umask command may seem confusing, but it's important. You must choose a umask that provides the default file and directory permissions that are right for you. Otherwise, you'll spend all your time changing file and directory permissions, or leave 
your files and directories with insecure permissions.

<BR></P>

<H3 ALIGN="CENTER">

<CENTER><A ID="I19" NAME="I19">

<FONT SIZE=4><B>Hard and Symbolic Links</B>

<BR></FONT></A></CENTER></H3>

<P>The ln (link) command creates both hard and symbolic links. When you refer to the file &quot;prufrock&quot; in the command cat prufrock, UNIX translates the filename into an internal name. Because UNIX uses a different representation for its internal 
bookkeeping, you can refer to files by more than one name. A hard link is an alternative name for a file. Suppose you have a file data and you use ln to make a hard link to it called data2:

<BR></P>

<PRE>$ ln data data2

$ ls

data  data2</PRE>

<P>The name data2 now refers to exactly the same internal file as data. If you edit data, the changes will be reflected in data2 and vice versa. Data2 is not a copy of data1 but a different name for the same file. Suppose that Karen enters:

<BR></P>

<PRE>$ ln memo1 memo2</PRE>

<P>Karen now has two filenames&#151;memo1 and memo2&#151;that refer to the same file. Since they refer to the same internal file, they are identical except for their names. If she removes memo1, memo2 remains because the underlying file that memo2 refers 
to is still there. UNIX removes the internal file only after you remove all of the filenames that refer to it, in this case both memo1 and memo2. You can now see that rather than saying that rm removes a file, it's more accurate to say that it removes the 

file's name from the file system. When the last name for a file is gone, UNIX removes the internal file.

<BR></P>

<P>What good are hard links? Sometimes people working together on projects share files. Suppose that you and Joe work on a report together and must edit the same file. You want changes that you make to be reflected in Joe's copy automatically, without 
having Joe copy the file anew each time you change it. You also want Joe's changes to be reflected in the copy. Instead of trying to synchronize two separate files, you can make a hard link to Joe's file. Changes he makes will be reflected in your version 

and vice versa because you both are working with the same file even though you use different names for it.

<BR></P>

<P>A symbolic link (also known as a symlink) allows you to create an alias for a file, a sort of signpost in the file system that points to the real file someplace else. Suppose that you frequently look through your friend Joe's Italian recipes, but you 
are

⌨️ 快捷键说明

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