📄 rhl07.htm
字号:
-rw-r—r— 1 fido users 34 Jun 6 1993 .less
-rw-r—r— 1 fido users 114 Nov 23 1993 .lessrc
drwxr-xr-x 2 fido users 1024 Dec 7 13:36 .term/
-rw-r—r— 1 fido users 163 Dec 7 14:31 .kermrc
drwxr-xr-x 6 root root 1024 Dec 14 01:39 ../
-rw-r—r— 1 fido users 333 Dec 21 22:11 .bash_history
drwxr-xr-x 3 fido users 1024 Jan 2 13:48 ./</FONT></PRE>
<P>Many other options can be used with ls, although we have now tried the most commonly used ones. The important thing to remember is that you can usually customize a Linux command by using one or more command options.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>As with basic Linux commands, case is important! For instance, ls has an R option (recursive: show files in subdirectories, too) that gives much different results from the r option.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>You can think of a as the "all files" option, l as the "long list" option, t as the "sort by time" option, r as the "reverse sort" option, and so on. In fact, most options in Linux are mnemonic—the option
letter stands for a word or phrase. Some option letters mean the same thing in many different Linux commands. For instance, v often means verbose—in other words, "Give me lots of detail."
<BR>However, do not assume that, on any unfamiliar command, certain options will work in the "usual" way! For instance, r is the recursive option for many Linux commands; however, in the case of ls, reverse sort is more commonly used, and
therefore it gets the easier-to-type lowercase r, while recursive is left with the capital R. It might seem like not much extra effort to press the Shift key to get the capital letter, but try typing a string of four or five options, one of which is
capitalized!</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>You can easily find out which options are available for any Linux command by using the man command. See the section "The Linux Man Pages" later in this chapter.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E69E41"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Other Parameters</B></FONT></CENTER></H4>
<BR>
<P>Linux commands often use parameters that are not actual command options. These parameters, such as filenames or directories, are not preceded by a dash.
<BR>
<P>For instance, by default ls lists the files in your current directory. You can, however, tell ls to list the files in any other directory simply by adding the directory to the command line. For instance, ls /bin will list everything in the /bin
directory. This can be combined with command options, so that ls -l /bin gives you detailed listings of the files in /bin. Try this. You will be impressed by the number of files in the /bin directory!
<BR>
<P>You can also specify ls to list information about any particular file by entering its filename. For instance, ls -la .lessrc gives detailed information only about the .lessrc file.
<BR>
<BR>
<A NAME="E69E42"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Input and Output Redirection</B></FONT></CENTER></H4>
<BR>
<P>Many Linux commands let you specify which file or directory they are to act upon, as we saw with the example ls -l /bin earlier.
<BR>
<P>You can also "pipe" the output from a command so that it becomes another command's input. This is done by typing two or more commands separated by the | character. (This character normally is found on the same key as the \ character. You must
hold down the Shift key or you will get \ instead of |). The | character means "Use the output from the previous command as the input for the next command." Therefore, typing command_1|command_2 does both commands, one after the other, before
giving you the results.
<BR>
<P>Using our assembly-line metaphor, we are processing items through two black boxes instead of just one. When we use piping, it's like hooking up the first command's output conveyor belt to become the input conveyor belt for the second command.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Although Linux doesn't care whether | is set off by spaces, if command_1 | command_2 is easier for you to read and understand than command_1|command_2, by all means use spaces around |.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>You will have noticed that the output of ls -l /bin is many lines long, so that much of the information scrolls off the screen before you can read it. You can pipe this output to a formatting program called more, which displays information in
screen-sized chunks. When you enter ls -l /bin | more, you will see the following:
<BR>
<PRE>
<FONT COLOR="#000080">darkstar:~$ ls -l /bin | more
total 1611
-rwxr-xr-x 1 root bin 1248 Sep 17 04:25 arch*
-rwxr-xr-x 1 root bin 295940 Sep 5 01:45 bash*
-rwxr-xr-x 1 root bin 4840 Nov 24 1993 cat*
-rwxr-xr-x 1 root bin 9220 Jul 20 12:06 chgrp*
-rwxr-xr-x 1 root bin 13316 Jul 20 12:06 chmod*
-rwxr-xr-x 1 root bin 13316 Jul 20 12:06 chown*
lrwxrwxrwx 1 root root 17 Dec 7 13:37 compress -> /usr/bin/comp_ress*
-rwxr-xr-x 1 root bin 21508 Jul 20 12:06 cp*
-rwxr-xr-x 1 root bin 41988 May 1 1994 cpio*
lrwxrwxrwx 1 root root 4 Dec 7 13:40 csh -> tcsh*
-rwxr-xr-x 1 root bin 5192 Nov 24 1993 cut*
-rwxr-xr-x 1 root bin 19872 Mar 23 1994 date*
-rwxr-xr-x 1 root bin 17412 Jul 20 12:06 dd*
-rwxr-xr-x 1 root bin 13316 Jul 20 12:06 df*
-rwxr-xr-x 1 root bin 66564 Jun 9 1994 dialog*
-rwxr-xr-x 1 root bin 1752 Sep 17 04:25 dmesg*
lrwxrwxrwx 1 root root 8 Dec 7 13:37 dnsdomainname -> hostname*
-rwxr-xr-x 1 root bin 13316 Jul 20 12:06 du*
-rwxr-xr-x 1 root bin 3312 Mar 23 1994 echo*
-rwxr-xr-x 1 root bin 36684 May 4 1994 ed*
-rwxr-xr-x 1 root bin 326 Mar 23 1994 false*
—More—</FONT></PRE>
<P>The —More— at the bottom of the screen tells you that there's more text to come. To go to the next screen of text, press the spacebar. Every time you press the spacebar, more displays another screenful of text. When the last screenful of text
has been displayed, more returns you to the Linux prompt.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>The more command can do many other things. For instance, to move back one screen at a time, type b for "back." Another useful command is q for "quit." This lets you leave immediately, without having to go through all the remaining
screens of text.
<BR>While in more, type h for "help." This will list the commands available within more.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>The Linux system sometimes uses the command less instead of more. One difference you will notice is that, unlike more, less requires you to type q to return to the command line, even if you're at the end of the text to be displayed. This might seem
cumbersome, but it prevents you from accidentally exiting the program by pressing the spacebar once too often.
<BR>The name less is a play on more. Originally, less was designed to have many features that more lacked. The version of more included in your Linux system has most of these features, however.
<BR>The Linux man program, discussed later, uses less to display text. Most other UNIX systems use more by default. Don't get confused. Remember to type q to exit from less!</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>Another thing you can do in Linux is to send output to a file instead of the screen. There are many different reasons why you might want to do this. You might want to save a "snapshot" of a command's output as it was at a certain time, or you
might want to save a command's output for further examination. You might also want to save the output from a command that takes a very long time to run, and so on.
<BR>
<P>To send output to a file, use the > symbol (found above the period on your keyboard). For instance, you can place the output of the ls -l /bin command into a file called test by typing ls -l /bin > test. Again, spaces around > are optional and
not strictly necessary, but they do make the command much more readable.
<BR>
<P>If you now do an ls or ls -l, you will see that you've created a new file called test in your own directory.
<BR>
<P>To see the contents of a file, you can again use the more command. Just specify the name of the file you want to look at. In this case, you would type more test.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Be careful! When you use >, you completely overwrite the previous contents of the file you specify to take the output (if that file existed). For example, if we already had a file called test in our directory, its old contents would be completely
replaced by the output from ls -l /bin. Linux will not warn you that you are about to do this!
<BR>Be particularly careful if you're not in your usual directory, or if you're logged in as root. You could, for instance, accidentally clobber the Linux program test, which exists as a file named test—fortunately, not in the directory where we
created our test file! It's a good idea to check if the output file already exists before using >. In our example, we could have typed ls -l test beforehand. If no information is displayed, the file does not exist.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>You can specify that you want to add your output to the end of the file, rather than replace the file's contents, by using >>. Type who >> test to add the output of the who command to the end of the text already in the file test.
<BR>
<P>You can examine the results by using either more or less and paging through to the end of the file, or by using the Linux command tail, which displays the last few lines of the specified file. In this case, you would type tail test to see the last few
lines of the file test. Try using tail!
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>For a more detailed discussion of redirection and piping, see <A HREF="rhl10.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl10.htm">Chapter 10</A>, "Using bash."</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E68E43"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Notational Conventions Used to Describe Linux Commands</B></FONT></CENTER></H3>
<BR>
<P>There is a set of accepted notational conventions used to describe, in a concise and consistent way, the correct syntax for any given Linux command. This specifies what options or parameters you must use, what options or parameters you can use or not
use, and so on. Sometimes this set of conventions is used to give a complete and exhaustive listing of a command's syntax, showing every possible command and parameter. Sometimes it is used to make a particular example more general and the command's basic
usage clearer.
<BR>
<P>If you remember the following six basic rules, you will be able, in principle, to understand the syntax of any Linux or UNIX command.
<BR>
<OL>
<LI>Any text standing by itself, and not within [], <>, or {}, must be typed exactly as shown.
<BR>
<BR>
<LI>Any text within square brackets ([]) is optional. You can type it or not type it. For instance, the syntax ls [-l] means you must type ls (per the first rule), while adding -l is optional, but not necessary. Do not type the square brackets themselves!
In our example, type ls or ls -l. Don't type ls [-l].
<BR>
<BR>
<LI>Angle brackets (<>) and the text within them must be replaced by appropriate text (usually a name or value). The text within the brackets usually indicates the nature of the replacement. For instance, the syntax more <filename> means that
you should replace <filename> with the name of the file you wish to examine using more. If you want to look at the file test, you would type more test. Remember, do not use the angle brackets when you actually type the command!
<BR>
<BR>
<LI>Curly braces ({}) indicate that you must choose one of the values given within the braces. The values are separated by | (which in this case means or, not pipe!). For example, the syntax command -{a|b} means you must enter either command -a or command
-b.
<BR>
<BR>
<LI>An ellipsis (...) means "and so on." It is normally used with parameters such as filenames, as described later.
<BR>
<BR>
<LI>The sixth basic rule states that the brackets can be combined as necessary. For instance, you don't have to type a filename with the more command. This would be indicated as more [<filename>]. The outer set of square brackets makes the entire
parameter optional. If you do decide to use the parameter, replace the inner set of angle brackets with the appropriate value. Because the more command enables one or more filenames to be specified, the syntax becomes more [<filename>...]. The
ellipsis means you can have as many <filenames> as you wish.
<BR>
<BR>
</OL>
<BR>
<A NAME="E68E44"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Online Help Available in Linux</B></FONT></CENTER></H3>
<BR>
<P>Linux has help facilities available online. If you forget the exact use of a command, or you're looking for the right command to use, the answer might be available straight from Linux. The two help facilities we will try out are the bash shell's help
command, and the man command, which is available on almost all UNIX systems, including Linux.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>If you have not installed the man pages package, you should do so now. Although it is possible to get by without man pages, they are a very valuable resource for both novice and expert Linux users.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E68E45"></A>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -