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

📄 operating_systems.html

📁 ADI 公司blackfin系列的用户使用文挡。
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<h4><a name="the_grep_command" id="the_grep_command">The grep  command</a></h4><div class="level4"><p>The <code>grep</code> command can search a file or set of files for a pattern. For example, let&rsquo;s say we&rsquo;re searching for mention of sys_write in any of the C files in a directory. This could be done via <code>grep &lsquo;sys_write&rsquo; *.c</code> Then <code>grep</code> would print all lines in all files mentioning the sought for pattern, sys_write. There is also a recursive grep (<code>rgrep</code>) available which can search recursively through a directory hierarchy. While we&rsquo;re on the subject of searching, there is a wonderful tool for searching through the source hierarchy which can be used over the web or downloaded. See <a href="http://lxr.linux.no/" class="urlextern" title="http://lxr.linux.no/"  rel="nofollow">http://lxr.linux.no</a>  </p></div><h4><a name="the_tar_command" id="the_tar_command">The tar command</a></h4><div class="level4"><p>We&rsquo;ll just give two examples of this convenient and powerful command. Let&rsquo;s say you have a project at work which you also pursue at home and are faced with moving the project back and forth as you work on it in both places. Let&rsquo;s say the project hierarchy starts at the node <code>/home/jsmythe/project/</code> and consists of many subdirectories and files. To compress and archive the hierarchy into a single file called <code>proj.tgz</code>, use the command <code>tar </code><code>cvfz</code><code> proj.tgz project/</code> where we have assumed that the command is issued from directory <code>/home/jsmythe</code>. To subsequently expand and unarchive the file on your other machine from directory <code>/home/jsmythe</code>, use <code>tar </code><code>xvfz</code><code> proj.tgz</code> and it will produce the <code>/home/jsmythe/project</code> hierarchy if it does not currently exist and append to it if it does. </p><p>  </p></div><h4><a name="the_man_command" id="the_man_command">The man command</a></h4><div class="level4"><p>If a manual page on some entity, name, exists, then <code>man name</code> will give the information. For example, if you want to learn what options are supported for the <code>ls</code> command, enter <code>man ls</code> or to learn about the vi editor, enter <code>man vi</code>. You can even learn more about <code>man</code> by entering <code>man man.</code></p></div><h4><a name="the_su_command" id="the_su_command">The su command</a></h4><div class="level4"><p>The switch user command (sometimes misnamed the super user command) allows you to switch to a different user. If no argument is supplied, you will switch to super user if you successfully respond to the subsequent prompt for the super user password. If an argument (a valid username) is provided then you will switch to that user if you successfully respond to the subsequent prompt for that user&rsquo;s password. You return to your previous identity with the <code>exit</code> command. As you can see, it is essentially a nested log on scenario.</p><p> In this document there are several command line instructions given that must be run as root.  To switch to the root user, without having to logout from a user session, the switch user command may be used as follows:</p><pre class="code">bash$ su -</pre><p>You will then be prompted to enter the password for root access, if this is successful a root session will be started.  You can exit back to the user session by typing the command <code>exit</code>.  If you wish to run graphical programs which use the XWindows interface then use the <code>sux</code><strong> -</strong> command instead.  This transfers your XWindows credentials.</p><p>Alternately, to execute a single command as root use the <code>sudo</code><strong> </strong>command as follows:</p><pre class="code">bash$ sudo &lt;command to execute as root&gt;</pre><p>If this is your first time running <code>sudo</code> in this session you will be prompted for a password.  After successfully entering the password your command will be run as root.</p><p>+</p></div><h5><a name="the_chmod_chown_and_chgrp_command" id="the_chmod_chown_and_chgrp_command">The chmod, chown, and chgrp command</a></h5><div class="level5"><p>These allow you to change permissions (<code>chmod</code>), ownership (<code>chown</code>), and group (<code>chgrp</code>) of files to which you have appropriate access. There are typically used for system administration. For example, as root I could change a file&rsquo;s owner and group to <code>fred</code><code>_smith</code> (assuming there is such a user and group) via <code>chown fred_</code><code>smith.fred</code><code>_smith filename</code> Similarly, if an owner wants to change a file&rsquo;s permissions to <code>rw-rw-r&ndash;</code>, the appropriate command would be <code>chmod 664 filename</code> For those uncomfortable with octal permissions (like 664 representing <code>rw-rw-r&ndash;</code>), there is the option of using letter based syntax. Investigate these commands further via their man pages.</p></div><!-- SECTION [13316-22860] --><h3><a name="standard_input_output_error" id="standard_input_output_error">Standard Input, Output, Error</a></h3><div class="level3"><p>Commands and other programs often expect input to come from the keyboard, which we call standard input. Similarly they often send output to the console, which we call standard output. Error information is also typically sent to the console, but the destination is then called standard error. We&rsquo;ll see in the next section that the distinction between standard output and standard error is not as trivial as it first seems. A command such as <code>more vita.txt</code> sends its output to standard output, the console.</p></div><!-- SECTION [22861-23408] --><h3><a name="redirection_and_pipes" id="redirection_and_pipes">Redirection and Pipes</a></h3><div class="level3"><p>The simple concepts of standard input, output, and error become significantly more powerful when used with redirection and pipes. Some examples are in order. </p></div><h4><a name="redirection" id="redirection">Redirection</a></h4><div class="level4"><p>Recall that the command <code>cat file1 file2</code> will concatenate <code>file1</code> and <code>file2</code>, sending the output to standard out, the console.  However, standard output can be redirected to a file other than the console e.g. <code>cat file1 file2 &gt; file3</code> where the right arrow (<code>&gt;</code>) is the redirection operator for standard output. In this case <code>file3</code> will hold the concatenated result of <code>file1</code> and <code>file2</code>. In the case just shown <code>file3</code> is created and any existing file by that name would have been destroyed. If file3already existed and you wanted to append the new information, you would enter cat file1 file2 &raquo; file3where the double right arrow is called the nondestructive redirection operator.  Similarly, the left arrow (&lt;)is the redirection operator for standard input. There is also a syntax (somewhat shell dependent) for redirecting standard error. For example, in the bash shell we might perform a compilation with this syntax: </p><pre class="code">gcc file5.c -o file5.c 2&gt; file5.err</pre><p> where the last piece 2&gt; file5.err redirects standard error (but not standard output) to the file called file5.err. This is quite useful when your compilation triggers many errors which scrolldown the screen. Typically, the early errors are significant, but may scroll off the screen. However, they will be available in a redirected error file such as the example&rsquo;s file5.err. </p><p>To capture all the output of a command into a log file use the following syntax:</p><pre class="code">gcc file5.c -o file5.c &gt; file5.log 2&gt;&amp;1</pre><p>This directs the output of the compile to file5.log and also sends the error output to the same output file.</p><p>These redirection operators appear very handy, but when combined with the pipe concept the power is much enhanced. </p></div><h4><a name="the_pipe" id="the_pipe">The Pipe</a></h4><div class="level4"><p>The pipe connects commands so the output of one becomes input for the second. Let&rsquo;s look at its use without redirection, first. Consider using <code>ls -l</code> on a very large directory. It would scroll off the screen. However you can pipe it to more, which you&rsquo;ll recall, displays one screen at a time. The syntax is <code>ls -l | more</code> where the vertical bar (<code>|</code>) is the pipe operator. You can pipe several commands together and combine them with redirection. Here is a slightly more involved example,</p><pre class="code">cat file1 file2 | sort &gt; file3</pre><p> which does these tasks in order </p><ul><li class="level1"><div class="li">concatenates <code>file1</code> and <code>file2</code></div></li><li class="level1"><div class="li">sends the result to the <code>sort</code> command, which sorts the lines in alphabetical order</div></li><li class="level1"><div class="li">stores the alphabetized, concatenated result as a new file called <code>file3</code></div></li></ul><p>The above set of tasks might be given to beginning programming students who would then write some high level language program to get the result. Here we see how the UNIX philosophy of simple commands used in combination can do complex tasks.</p><p>If you require more information on the Linux operating system a good introductory guide is available  <a href="http://linux-newbie.sunsite.dk/" class="urlextern" title="http://linux-newbie.sunsite.dk/"  rel="nofollow">here</a>.</p></div><!-- SECTION [23409-26564] --><h3><a name="activities_excercises" id="activities_excercises">Activities/Excercises</a></h3><div class="level3"><p>The exercises assume you have read through the entire chapter. These excercises should be completed on the host or development PC.</p></div><h4><a name="logging_on" id="logging_on">Logging on</a></h4><div class="level4"><p>Log on your workstation. Try the command </p><pre class="code">ls -l</pre><p>and then</p><pre class="code">ls -al</pre><p> What does the additional a switch do? [see man ls]</p><p>Try the command</p><pre class="code">sh -version</pre><p> What does this tell you?</p></div><h4><a name="standard_directories" id="standard_directories">Standard Directories</a></h4><div class="level4"><p>Using the command <code>ls -F</code>, check out the contents of each of the standard directories from Table 1 of this chapter. For example, try <code>ls -F /dev</code> and so on. What does the <code>F</code> switch do?</p></div><h4><a name="standard_directories1" id="standard_directories1">Standard Directories</a></h4><div class="level4"><p>Look at the contents of the <code>/proc</code> directory. Examine these files in <code>/proc</code> with <code>cat</code>: </p><ul><li class="level1"><div class="li">cpuinfo</div></li><li class="level1"><div class="li">meminfo</div></li><li class="level1"><div class="li">interrupts</div></li><li class="level1"><div class="li">ioports</div></li><li class="level1"><div class="li">pci</div></li></ul><p>If any of the <code>cat</code> displays are more than a screen full, pipe the display through more e.g. <code>cat /proc/pci | more</code></p></div><h4><a name="more_about_ls" id="more_about_ls">More about ls</a></h4><div class="level4"><p>Try ls with the f and t options:</p><pre class="code">ls -f or ls -lfls -t or ls -lt</pre><p> What do these options do?</p></div><h4><a name="mkdir_and_tree" id="mkdir_and_tree">mkdir and tree</a></h4><div class="level4"><p>

⌨️ 快捷键说明

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