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

📄 ch07.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 4 页
字号:


</DL>







<H3 ALIGN="CENTER"><A NAME="Heading20<FONT COLOR="#000077">Online Help Available



in Linux</FONT></H3>



<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 <TT>bash</TT> shell's



<TT>help</TT> command, and the <TT>man</TT> command, which is available on almost



all UNIX systems, including Linux.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading21<FONT COLOR="#000077"><B>NOTE:</B> </FONT>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.



<HR>







</DL>







<H3 ALIGN="CENTER"><A NAME="Heading22<FONT COLOR="#000077">The Linux Man Pages</FONT></H3>



<P>The &quot;man&quot; in &quot;man pages&quot; stands for &quot;manual.&quot; (As



usual, the creators of UNIX shortened a long but descriptive word to a shorter, cryptic



one!) Typing <TT>man &lt;</TT>command<TT>&gt;</TT> lets you view the manual pages



dealing with a particular command.</P>



<P>Try typing <TT>man passwd</TT> to see what the Linux manual has to say about the



<TT>passwd</TT> command.</P>



<P>The general layout of a man page is as follows:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">COMMAND(1)           Linux Programmer's Manual           COMMAND(1)







NAME



       command - summary of what command does







SYNOPSIS



       &lt;complete syntax of command in the standard Linux form&gt;







DESCRIPTION



       More verbose explanation of what &quot;command&quot; does.







OPTIONS



       Lists each available option with description of what it does







FILES



       lists files used by, or related to, command







SEE ALSO



       command_cousin(1), command_spouse(1), etc.







BUGS



       There are bugs in Linux commands??







AUTHOR



       J. S. Goobly (goobly@hurdly-gurdly.boondocks)











Linux 1.2                  22 June 1994                         1



</FONT></PRE>



<P>The man page for <TT>passwd</TT> is actually quite understandable. Be warned,



however, that man pages are often written in a very formal and stylized way that



sometimes bears little resemblance to English. This is done not to baffle people,



but to cram a great deal of information into as short a description as possible.</P>



<P>For example, try <TT>man ls</TT>. Notice how many options are available for <TT>ls</TT>



and how long it takes to explain them!</P>



<P>Although it can take practice (and careful reading!) to understand man pages,



once you get used to them, the first thing you'll do when you encounter a strange



command is call up the man page for that command.



<H4 ALIGN="CENTER"><A NAME="Heading23<FONT COLOR="#000077">Finding Keywords



in Man Pages</FONT></H4>



<P>Sometimes you know what you want to do, but you don't know which command you should



use to do it. You can use the keyword option by typing <TT>man -k &lt;</TT>keyword<TT>&gt;</TT>.



The <TT>man</TT> program will return the name of every command whose <TT>name</TT>



entry (which includes a very brief description) contains that keyword.</P>



<P>For instance, you can search on <TT>manual</TT>:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">darkstar:~$ man -k manual



man (1)              - format and display the on-line manual pages .br manpath--



		       determine user's search path for man pages



whereis (1)          - locate binary, spource, and manual page files for a command



</FONT></PRE>







<PRE><FONT COLOR="#0066FF">



xman (1)             - Manual page display program for the X Window System



</FONT></PRE>



<P>You have to be careful to specify your keyword well, though! Using <TT>directory</TT>



as your keyword isn't too bad, but using <TT>file</TT> will give you many more entries



than you will want to wade through.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading24<FONT COLOR="#000077"><B>NOTE: </B></FONT>You might have



	noticed that commands seem to be followed by numbers in brackets, usually <TT>(1)</TT>.



	This refers to the manual section. Back in the days when UNIX manuals came in printed,



	bound volumes, normal commands were in Section 1, files used by administrators were



	in Section 5, programming routines were described in Section 3, and so on. Therefore,



	some man pages are not about commands at all, but rather about files or system calls



	used in Linux! If a particular entry shows up in more than one section, <TT>man</TT>



	will show you the lowest-numbered entry by default. You can see higher-numbered entries



	by specifying the section number. For instance, Section 5 has a manual entry on the



	<TT>passwd</TT> file. To see this rather than the manual entry for the <TT>passwd</TT>



	command, type <TT>man</TT> <TT>5</TT> <TT>passwd</TT>. In general, <TT>man</TT> <TT>&lt;</TT>n<TT>&gt;</TT>



	<TT>&lt;</TT>entry<TT>&gt;</TT> will find the man page for <TT>&lt;</TT>entry<TT>&gt;</TT>



	in Section <TT>&lt;</TT>n<TT>&gt;</TT>.



<HR>







</DL>







<H4 ALIGN="CENTER"><A NAME="Heading25<FONT COLOR="#000077">The bash Shell help



Facility</FONT></H4>



<P>When you type a command at the prompt, the shell program takes what you've written,



interprets it as necessary, and passes the result to the Linux operating system.



Linux then performs the actions requested of it. Many Linux commands require Linux



to find and start up a new program. However, the shell itself can perform a number



of functions. These functions can be simple, often-used commands, so that the overhead



of starting up separate programs is eliminated, or they can be facilities that make



the shell environment friendlier and more useful. One of these facilities is the



<TT>help</TT> command, which provides information on the <TT>bash</TT> shell's built-in



functions.</P>



<P>Type <TT>help</TT> at the prompt. You will see at least some of the following:</P>



<PRE><FONT COLOR="#0066FF">



GNU bash, version 1.14.7(1)



Shell commands that are defined internally. Type `help' to see this list.



Type `help name' to find out more about the function `name'.



Use `info bash' to find out more about the shell in general.







A star (*) next to a name means that the command is disabled.







%[DIGITS | WORD] [&amp;]               . [filename]



:                                  [ arg... ]



alias [ name[=value] ... ]         bg [job_spec]



bind [-lvd] [-m keymap] [-f filena break [n]



builtin [shell-builtin [arg ...]]  case WORD in [PATTERN [| PATTERN].



cd [dir]                           command [-pVv] [command [arg ...]]



continue [n]                       declare [-[frxi]] name[=value] ...



dirs [-l]                          echo [-neE] [arg ...]



enable [-n] [name ...]             eval [arg ...]



exec [ [-] file [redirection ...]] exit [n]



export [-n] [-f] [name ...] or exp fc [-e name] [-nlr] [first] [last



fg [job_spec]                      for NAME [in WORDS ... ;] do COMMA



function NAME { COMMANDS ; } or NA getopts optstring name [arg]



hash [-r] [name ...]               help [pattern ...]



history [n] [ [-awrn] [filename]]  if COMMANDS; then COMMANDS; [elif



jobs [-lnp] [jobspec ...] | jobs - kill [-s sigspec | -sigspec] [pid



let arg [arg ...]                  local name[=value] ...



logout                             popd [+n | -n]



pushd [dir | +n | -n]              pwd



read [-r] [name ...]               readonly [-n] [-f] [name ...] or r



return [n]                         select NAME [in WORDS ... ;] do CO



set [--abefhknotuvxldHCP] [-o opti shift [n]



source filename                    suspend [-f]



test [expr]                        times



trap [arg] [signal_spec]           type [-all] [-type | -path] [name



typeset [-[frxi]] name[=value] ... ulimit [-SHacdmstfpnuv [limit]]



umask [-S] [mode]                  unalias [-a] [name ...]



unset [-f] [-v] [name ...]         until COMMANDS; do COMMANDS; done



variables - Some variable names an wait [n]



while COMMANDS; do COMMANDS; done  { COMMANDS }



</FONT></PRE>



<P>You will have to pipe the output of <TT>help</TT> to <TT>more</TT> (<TT>help |



more</TT>) to keep the first part from scrolling off your screen.



<H3 ALIGN="CENTER"><A NAME="Heading26<FONT COLOR="#000077">Wildcards: * and



?</FONT></H3>



<P>In many a late-night card game, jokers are shuffled into the deck. The jokers



are wildcards that can become any card of your choice. This is obviously very useful!



Linux has wildcards also. They are, if anything, more useful than jokers in a card



game.</P>



<P>Linux has several wildcards. Wildcards are used as a convenient and powerful shortcut



when specifying files (or directories) that a command is to operate on. We will briefly



look at the two most popular wildcards: <TT>*</TT> and <TT>?</TT>.</P>



<P>The most commonly used wildcard is <TT>*</TT>, which stands in for any combination



of one or more characters. For example, <TT>c*</TT> will match all filenames that



begin with c. You can see this for yourself by typing <TT>ls /bin/c*</TT>.</P>



<P>What happens if you type <TT>ls /bin/c*t</TT>? How about <TT>ls /bin/*t</TT>?</P>



<P>The <TT>?</TT> wildcard is more restrictive than <TT>*</TT>. It only stands in



for any one character. You can see this by comparing <TT>ls/bin/d*</TT> with <TT>ls/bin/d?</TT>.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading27<FONT COLOR="#000077"><B>NOTE:</B> </FONT>Wildcards can only



	be used to match filenames and directory names. You can't, for example, type <TT>pass*</TT>



	at the Linux prompt and expect Linux to run the <TT>passwd</TT> program for you.



<HR>







</DL>











<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading28<FONT COLOR="#000077"><B>WARNING:</B></FONT> Be very careful



	when using wildcards with dangerous commands, such as the ones used to permanently



	delete files! A good check is to run <TT>ls</TT> with the wildcards you plan to use



	and examine the resulting list of files to see if the wildcard combination did what



	you expected it to do. Also double-check that you typed everything correctly before



	pressing the Enter key!



<HR>







</DL>







<H3 ALIGN="CENTER"><A NAME="Heading29<FONT COLOR="#000077">Environment Variables</FONT></H3>



<P>When you log in, Linux keeps a number of useful data items in the background ready



for the system to use. The actual data is held in something called an environment



variable, whose name is often descriptive or mnemonic. In fact, this is no different



from the way you and I remember things. We know that there always is a piece of information



called &quot;day of the week&quot; (the environment variable); however, we change



the data in this variable, from Monday to Tuesday to Wednesday, and so on, as days



go by.</P>



<P>To see the list of exported environment variables, type <TT>env</TT>. The environment



variable's name is on the left, and the value held by the variable is on the right.</P>



<P>The most important variable to note is the <TT>PATH</TT>, whose value is your



search path. As we will see in the next chapter, when you type a command, Linux will



search every place listed in your search path for that command.</P>



<P>A longer list of environment variables, consisting of several new variables in



addition to the ones you saw earlier, is displayed by the command <TT>set</TT>. The



new variables are local: they have not been marked for export. For more information



on exporting variables, see Chapter 10. You can think of local variables as items



of information you need for only a certain time or location. For instance, remembering



the variable &quot;what-floor-am-I-on&quot; becomes an unnecessary piece of information



once you leave the building!



<H3 ALIGN="CENTER"><A NAME="Heading30<FONT COLOR="#000077">Processes and How



to Terminate Them</FONT></H3>



<P>In the previous chapter, we learned about the <TT>who</TT> command, which shows



you the usernames of everyone who is logged into the system. The <TT>who</TT> program



actually gets its information from the Linux system, which maintains and updates



the list of the system's current users.</P>



<P>In fact, Linux keeps much more detailed records about what is happening on the



system than just who is logged in. Because Linux is a multitasking system, in which



many programs or program threads may be running simultaneously, Linux keeps track



of individual tasks or processes.</P>



<P>Although these processes are usually well behaved and well managed by Linux, sometimes



they might go out of control. This can happen if a program hits a bug or a flaw in



its internal code or supplied data, or if you accidentally enter the wrong command



or command option.</P>



<P>Being able to identify these misbehaving processes, and then being able to terminate



or kill them, is an essential piece of knowledge for all Linux/UNIX users. (Obviously



the world was a less kind and gentle place when the <TT>kill</TT> command was developed



and named.) When you are your own system administrator, as in our case, it's doubly



important!



<H4 ALIGN="CENTER"><A NAME="Heading31<FONT COLOR="#000077">The Process Status



Command: ps</FONT></H4>



<P>To find out what processes are running, we use the <TT>ps</TT> command. <TT>ps</TT>



stands for &quot;process status,&quot; not the &quot;post script&quot; you would



write at the end of a letter.</P>



<P>Typing <TT>ps</TT> by itself gives you a concise listing of your own processes:<FONT



COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">darkstar:~$ ps



  PID TTY STAT  TIME COMMAND



   41 v01 S     0:00 -bash



  134 v01 R     0:00 ps



</FONT></PRE>



<P>The information in the first column, headed <TT>PID</TT>, is important. This is



the Process ID number, which is unique, and which Linux uses to identify that particular



process. You must know a process's PID to be able to kill it.</P>



<P>The <TT>TTY</TT> column shows you which terminal the process was started from.</P>



<P>The <TT>STAT</TT> column gives the status of the process. The two most common



entries in the status column are <TT>S</TT> for sleeping and <TT>R</TT> for running.



A sleeping process is one that isn't currently active. However, don't be misled.



A sleeping process might just be taking a very brief catnap! In fact, a process might



switch between sleeping and running many times every second.</P>



<P>The <TT>TIME</TT> column shows the amount of system time used by the process.



Clearly, neither of our processes are taking up any appreciable system time!</P>



<P>Finally, the <TT>NAME</TT> column contains the name of the program you're running.



This will usually be the command you typed at the command line. However, sometimes



the command you type starts one or more child processes, and in this case, you would



see these additional processes show up as well, without ever having typed them yourself.



Your <TT>login</TT> shell will have a <TT>-</TT> before it, as in <TT>-bash</TT>



in the previous example. This helps to distinguish this primary shell from any shells



you might enter from it. These will not have the <TT>-</TT> in front.





⌨️ 快捷键说明

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