📄 operating_systems.html
字号:
</li><li class="level1"><div class="li">writing a file</div></li><li class="level1"><div class="li">executing a file</div></li></ul><p>Further, a file has three user categories </p><ul><li class="level1"><div class="li">the file’s owner</div></li><li class="level1"><div class="li">the file’s group</div></li><li class="level1"><div class="li">all other users</div></li></ul><p>File permissions are written as three concatenated triads. The first triad refers to the file owner, and the second to the file group, and the third to all other user’s. Here are some example permissions and what they mean:</p><p><code>rwxrwxrwx</code><code> </code>- file owner, file group, and all others have read/write/execute permission.</p><p><code>rw</code><code>-rw—- </code> - file owner and file group have read/write access, but all others have no access.</p><p><code>rwxr</code><code>-</code><code>xr</code><code>-x </code> - file owner has read/write/execute access, while group and all others have read/execute access.</p></div><h4><a name="setuid_and_getgid_programs" id="setuid_and_getgid_programs">Setuid and Getgid Programs</a></h4><div class="level4"><p>The three concatenated permission triads (for owner, group, and others) are preceded by another field whose purpose it is to give the user of the program special permissions. In particular, the user’s effective uid (user ID) or effective gid (group ID) can be set to the file owner’s uid or gid. As a somewhat dated example consider a user changing his/her password in the days before shadow passwords became prevalent. The passwords were kept in <code>/etc/</code><code>passwd</code> with permissions <code>rw-r–r-</code>and root as owner. So the average user does not have write access to change a personal password. However, the <code>/usr/bin/passwd</code> command has permissions <code>r-s–x–x</code> where the s means that the user’s effective uid is set to that of root and will be allowed to update <code>/etc/passwd</code>. The following commands can be used to set the user’s effective id and effective gid to that of the file’s owner</p><p><code>chmod</code><code> u+s program</code> ... we now say the program is a setuid program</p><p><code>chmod g+s program</code> ... we now say the program is a setgid program</p><p>We’ll see the chmod command in the next section.</p></div><!-- SECTION [11271-13315] --><h3><a name="commands" id="commands">Commands</a></h3><div class="level3"><p>Here we’ll look at some useful commands which perform such tasks as file system manipulation and navigation, getting information, and modifying file permissions. Many of the commands care about permissions and the command will fail if you don’t have the proper permissions. Linux, although relatively new, profits from the historical evolution of UNIX in that it comes close to achieving the following goals: </p><ul><li class="level1"><div class="li">there is a command or combination of commands to perform any task you can dream up</div></li><li class="level1"><div class="li">the securely configured system prevents you from harming the system or other users</div></li></ul><p>Part of the philosophy of Linux (again, inherited from UNIX) is that commands tend to be very simple, but can be combined very compactly to do complex tasks. Note: Linux is case sensitive so <code>Cat</code>, <code>CAT</code>, and <code>cat</code> would be distinct - our typical commands will be lower case. In this chapter, we’ll consider some useful commands and then look at what might be called plumbing - standard input, standard output, standard error, redirection, and pipes. These plumbing operators are not commands, but rather operators provided by the shell. They are used in concert with the commands, allowing the commands to be used in combination.</p></div><h4><a name="some_useful_commands" id="some_useful_commands">Some useful commands</a></h4><div class="level4"><p>From the many commands provided by Linux, we’ll consider those tabulated next. We’ll discuss these only briefly, and in most cases they have many further options which can be explored via the man pages.</p><table class="inline"> <tr> <td class="centeralign"> <em><strong>Command</strong></em> </td><td class="centeralign"> <em><strong>Purpose</strong></em> </td> </tr> <tr> <td><code>ls</code></td><td>lists directory contents</td> </tr> <tr> <td><code>cd</code></td><td>changes from the current working directory to another</td> </tr> <tr> <td><code>pwd</code></td><td>show pathname of present working directory</td> </tr> <tr> <td><code>mkdir</code></td><td>make a directory</td> </tr> <tr> <td><code>rmdir</code></td><td>remove a directory (directory must be empty)</td> </tr> <tr> <td><code>rm</code></td><td>removes a file, but has a recursive option that can be used to remove non empty directories as well</td> </tr> <tr> <td><code>cp</code></td><td>copies a file</td> </tr> <tr> <td><code>mv</code></td><td>moves its argument (a file name) to a new name</td> </tr> <tr> <td><code>more</code></td><td>lists its argument a page at a time</td> </tr> <tr> <td><code>cat</code></td><td>concatenates its arguments and sends the result to standard out</td> </tr> <tr> <td><code>grep</code></td><td>print lines matching a pattern (regular expression)</td> </tr> <tr> <td><code>tar</code></td><td>archives its argument (with compression if specified)</td> </tr> <tr> <td><code>man</code></td><td>displays the manual pages of its argument</td> </tr> <tr> <td><code>su</code></td><td>switch to another user</td> </tr> <tr> <td><code>chmod</code></td><td>changes file/directory permissions</td> </tr> <tr> <td><code>chown</code></td><td>changes file/directory owner</td> </tr> <tr> <td><code>chgrp</code></td><td>changes file/directory group.</td> </tr></table><br /></div><h4><a name="the_ls_command" id="the_ls_command">The ls command</a></h4><div class="level4"><p>If you want to list the contents of your current working directory, you can simply type <code>ls</code> and if you want lots of information (e.g., permissions, sizes), use the long form <code>ls -l</code> As you would expect, you can list contents of other directories (as allowed by the permissions) e.g. ls<code> -l /usr/</code><code>src</code> Other options allow sorting on such information as date etc.</p></div><h4><a name="the_cd_command" id="the_cd_command">The cd command</a></h4><div class="level4"><p>This allows you to change your working directory to another, if permissions allow. Here are some examples:</p><p><code>cd / </code> change to the root directory of the file system </p><p><code>cd /usr/src </code> change to /usr/src</p><p><code>cd .. </code> change to the parent of your current directory, i.e. one level up</p><p><code>cd ../.. </code> change two levels up</p><p><code>cd - </code> change back to the directory you were in before this one</p></div><h4><a name="the_pwd_command" id="the_pwd_command">The pwd command</a></h4><div class="level4"><p>This is the ‘present working directory’ command. It displays the absolute pathname of where in the directory hierarchy you currently are.</p></div><h4><a name="the_mkdir_and_rmdir_command" id="the_mkdir_and_rmdir_command">The mkdir and rmdir command</a></h4><div class="level4"><p>These can make and remove (empty) directories. Assuming our current working directory is <code>/home/jsmythe</code>, consider these sequential examples:</p><p><code>mkdir emails</code> - creates the directory <code>/home/jsmythe/emails</code></p><p><code>mkdir emails/outgoing</code> - creates directory <code>/home/jsmythe/emails/outgoing</code></p><p><code>rmdir emails/outgoing</code> - removes directory <code>/home/jsmythe/emails/outgoing</code>.</p></div><h4><a name="the_rm_command" id="the_rm_command">The rm command</a></h4><div class="level4"><p>This command allows you to delete files. For example, if you are in directory <code>/home/jsmythe</code> and want to delete a file at that level named <code>vita.txt</code>, you could enter <code>rm vita.txt</code> This is a very powerful command in that you can delete a whole chunk of a hierarchy. For example, if <code>/home/jsmythe/project1/</code> was the top of a significant hierarchy of subdirectories and files, you can delete it via <code>rm -</code><code>rf</code><code> /home/jsmythe/project1</code></p></div><h4><a name="the_cp_and_mv_command" id="the_cp_and_mv_command">The cp and mv command</a></h4><div class="level4"><p>If you want a copy of a program, the format is <code>cp existing new </code>for example, <code>cp vita.txt vita1.txt </code>Now there are two files, the original (<code>vita.txt</code>) and a new copy (<code>vita1.txt</code>). On the other hand, if you want to rename a file, the syntax is <code>mv existing new</code> for example <code>mv vita.txt </code><code>resume.txt</code> In this case, the file <code>vita.txt</code> has been replaced by the identical file, except that it has a new name, r<code>esume.txt</code>. The <code>mv</code> command can also be used to rename any node in the file hierarchy e.g. <code>mv project/ project1</code></p></div><h4><a name="the_more_command" id="the_more_command">The more command</a></h4><div class="level4"><p>This command can display a file at the console, one screen full at a time. For example, <code>more vita.txt</code> Once invoked, more provides some helpful key strokes: </p><ul><li class="level1"><div class="li">space key - display next screen</div></li><li class="level1"><div class="li">q key - quit</div></li></ul><p> <code>less</code> </p></div><h4><a name="the_cat_command" id="the_cat_command">The cat command</a></h4><div class="level4"><p>The <code>cat</code> command concatenates its arguments and displays the entire result at the console, so a multi-screen result will quickly scroll off the end. For example, <code>cat file1 file2</code> </p></div>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -