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

📄 ch07.htm

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


<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->






 











 

















<H1></H1>







<UL>



	<LI><A HREF="#Heading1">- 7 -</A>



	<UL>



		<LI><A HREF="#Heading2">Basic Commands</A>



		<UL>



			<LI><A HREF="#Heading3">How Linux Commands Work</A>



			<LI><A HREF="#Heading4">TIP</A>



			<UL>



				<LI><A HREF="#Heading5">Command Options</A>



			</UL>



			<LI><A HREF="#Heading6">NOTE</A>



			<LI><A HREF="#Heading7">NOTE</A>



			<LI><A HREF="#Heading8">TIP</A>



			<LI><A HREF="#Heading9">NOTE</A>



			<UL>



				<LI><A HREF="#Heading10">Other Parameters</A>



				<LI><A HREF="#Heading11">Input and Output Redirection</A>



			</UL>



			<LI><A HREF="#Heading12">TIP</A>



			<LI><A HREF="#Heading13">TIP</A>



			<LI><A HREF="#Heading14">NOTE</A>



			<LI><A HREF="#Heading15">WARNING</A>



			<LI><A HREF="#Heading16">NOTE</A>



			<LI><A HREF="#Heading17">Notational Conventions Used to Describe Linux Commands</A>



			<LI><A HREF="#Heading18



			<UL>



				<LI><A HREF="#Heading19">Six Basic Rules of Linux Notation</A>



			</UL>



			<LI><A HREF="#Heading20">Online Help Available in Linux</A>



			<LI><A HREF="#Heading21">NOTE</A>



			<LI><A HREF="#Heading22">The Linux Man Pages</A>



			<UL>



				<LI><A HREF="#Heading23">Finding Keywords in Man Pages</A>



			</UL>



			<LI><A HREF="#Heading24">NOTE</A>



			<UL>



				<LI><A HREF="#Heading25">The bash Shell help Facility</A>



			</UL>



			<LI><A HREF="#Heading26">Wildcards: * and ?</A>



			<LI><A HREF="#Heading27">NOTE</A>



			<LI><A HREF="#Heading28">WARNING</A>



			<LI><A HREF="#Heading29">Environment Variables</A>



			<LI><A HREF="#Heading30">Processes and How to Terminate Them</A>



			<UL>



				<LI><A HREF="#Heading31">The Process Status Command: ps</A>



			</UL>



			<LI><A HREF="#Heading32">NOTE</A>



			<LI><A HREF="#Heading33">NOTE</A>



			<UL>



				<LI><A HREF="#Heading34">The Process Termination Command: kill</A>



			</UL>



			<LI><A HREF="#Heading35">NOTE</A>



			<LI><A HREF="#Heading36">NOTE</A>



			<LI><A HREF="#Heading37">Becoming Someone Else: The su Command</A>



			<LI><A HREF="#Heading38">NOTE</A>



			<LI><A HREF="#Heading39">The grep Command</A>



			<LI><A HREF="#Heading40">Summary</A>



			<LI><A HREF="#Heading41">NOTE</A>



		</UL>



	</UL>



</UL>







<P>



<HR SIZE="4">







<H2 ALIGN="CENTER"><A NAME="Heading1<FONT COLOR="#000077">- 7 -</FONT></H2>



<H2 ALIGN="CENTER"><A NAME="Heading2<FONT COLOR="#000077">Basic Commands</FONT></H2>



<P><I>by Ed Treijs</I></P>







<P>IN THIS CHAPTER</P>







<UL>



	<LI>How Linux Commands Work



	<P>



	<LI>Notational Conventions Used to Describe Linux Commands



	<P>



	<LI>Online Help Available in Linux 



	<P>



	<LI>The Linux Man Pages 



	<P>



	<LI>Wildcards: * and ? 



	<P>



	<LI>Environment Variables



	<P>



	<LI>Processes and How to Terminate Them 



	<P>



	<LI>Becoming Someone Else: The su Command 



	<P>



	<LI>The grep Command 



</UL>







<P><BR>



In this chapter, we will discover the following:







<UL>



	<LI>How to modify the basic function of Linux commands by using command options



	<P>



	<LI>How to run two or more Linux commands in tandem by using input and output redirection



	<P>



	<LI>How to use parameters, such as filenames, with Linux commands



	<P>



	<LI>How to read and understand the notational shorthand used in Linux and UNIX documentation



	<P>



	<LI>How to use Linux online man pages and help facilities



	<P>



	<LI>How to use wildcards that fill in for one or more filenames



	<P>



	<LI>How to check your environment variables



	<P>



	<LI>How to list processes running on the Linux system



	<P>



	<LI>How to kill processes



	<P>



	<LI>How to temporarily become another user



	<P>



	<LI>How to use <TT>grep</TT> (and understand what <TT>grep</TT> means!)



</UL>







<H3 ALIGN="CENTER"><A NAME="Heading3<FONT COLOR="#000077">How Linux Commands



Work</FONT></H3>



<P>Most Linux commands are very flexible. When you enter a Linux command, there are



several ways to tailor the basic command to your specific needs. We will look at



the two main ways used to modify the effect of a command:







<UL>



	<LI>Specifying or redirecting a command's input and output



	<P>



	<LI>Using command options



</UL>







<P>A simple way to picture what a Linux command does is to imagine that it's a black



box that is part of an assembly line. Items come down a conveyor belt, enter the



black box, get processed in some way, come out of the black box, and are taken away



on another conveyor belt. Command options let you fine-tune the basic process happening



inside the black box. Command redirection lets you specify which conveyor belt will



supply the black box with items and which conveyor belt will take away the resulting



products.</P>



<P>Once you understand how redirection and command options work, you will be able



to (at least in principle) use any Linux or UNIX command. This is because UNIX was



based on a few simple design principles. Commands, therefore, should work in consistent



ways. Of course, UNIX has grown and changed over the years, and the design principles



can sometimes get buried under all the changes. But they still make up the foundation,



so that UNIX-based systems such as Linux are quite coherent and consistent in how



they work.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading4<FONT COLOR="#000077"><B>TIP: </B></FONT>Pressing Ctrl-U at



	any point, right up to before you press Enter, lets you clear everything you've typed



	on the command line. You can use this whenever you spot an error at the very beginning



	of your typing, or when you decide you don't want to run a particular command after



	all. You can also use the Backspace key to &quot;back up&quot; by erasing characters



	(in fact, it can be almost a reflex action), but it's usually faster to just erase



	the whole command line and start again. Perhaps the most powerful keys to use at



	the command prompt are the arrow keys. The left and right arrows move the cursor



	non-destructively. If you make a typo early in the line, you can left-arrow your



	way to the character and type in a correction. Additionally, the up and down arrows



	enable you to jump through a list of the last several commands used (similar to DOS's



	<TT>DOSKEY</TT> utility).



<HR>







</DL>







<H4 ALIGN="CENTER"><A NAME="Heading5<FONT COLOR="#000077">Command Options</FONT></H4>



<P>You can use command options to fine-tune the actions of a Linux command. Quite



often, a Linux command will do almost--but not quite--what you want it to do. Instead



of making you learn a second command, Linux lets you modify the basic, or default,



actions of the command by using options.</P>



<P>The <TT>ls</TT> command is an excellent, and useful, example of a command that



has a great many options. The <TT>ls</TT> command lists the files found on the Linux



system's hard drive. This sounds simple enough, doesn't it? Try entering the command<FONT



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



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







darkstar:~$



</FONT></PRE>



<P>Well, nothing much seemed to happen.</P>



<P>Now try typing <TT>ls -a</TT>. Type it exactly as listed. The space between <TT>ls</TT>



and <TT>-a</TT> is necessary, and there must be no space between the <TT>-</TT> and



the <TT>a</TT>.</P>



<PRE><FONT COLOR="#0066FF">darkstar:~$ ls -a



./ ../            .bash_history  .less   .lessrc     



</FONT></PRE>



<P>What you have done is modified what <TT>ls</TT> does by adding a command option--in



this case, <TT>-a</TT>. By default, <TT>ls</TT> lists only files whose names don't



begin with a period. However, <TT>-a</TT> tells <TT>ls</TT> to list all files, even



ones that begin with a period. (These are usually special files created for you by



Linux.) At present, all the files in your directory start with a period, so <TT>ls</TT>



by itself does not list any files; you must add <TT>-a</TT> to see the files you



have at present.</P>



<P>The <TT>ls</TT> command has many more options. You can use more than one option



at a time. For example, try typing <TT>ls -al</TT>:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">darkstar:~$ ls -al



total 10



drwxr-xr-x   2 fido     users        1024 Dec 21 22:11 ./



drwxr-xr-x   4 root     root         1024 Dec 14 01:39 ../



-rw-r--r--   1 fido     users         333 Dec 21 22:11 .bash_history



-rw-r--r--   1 fido     users          34 Nov  23  1993 .less



-rw-r--r--   1 fido     users         114 Nov 23  1993 .lessrc



</FONT></PRE>



<P>You now get a listing with many more details about the files. (These will be explained



in Chapter 8, &quot;File System.&quot;) The <TT>l</TT> option can be used by itself;



<TT>ls -l</TT> will give detailed descriptions of files that don't begin with a period.



Sometimes filenames are so long they don't fit on a single line. Linux simply wraps



the remainder to the next line.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading6<FONT COLOR="#000077"><B>NOTE:</B> </FONT>Strictly speaking,



	the dash (<TT>-</TT>) is not part of the command option. The dash simply tells Linux



	to understand each letter immediately following it as a command option. There must



	be a space before the dash, and there must not be a space between the dash and the



	letter or letters making up the command option. There must be a space after the command



	option if anything else is to be entered on the command line after it. You can type



	more than one command option after the dash, as we did with <TT>ls -al</TT>. In this



	case, we are specifying both the <TT>a</TT> and the <TT>l</TT> options. The order



	you specify options in usually doesn't matter; <TT>ls -al</TT> will give the same



	results as <TT>ls -la</TT>. Combining options doesn't work with all Linux commands,



	and then only with those that use a single letter to specify each option. Multiple



	options can also be specified individually, with each option preceded by a dash and



	separated from other options by spaces--for example, <TT>ls -a -l</TT>. This is usually



	done only when a particular option requires a further parameter.



<HR>







</DL>







<P>By default, <TT>ls</TT> lists files in alphabetical order. Sometimes you might



be more interested in when a file was created or last modified. The <TT>t</TT> option



tells <TT>ls</TT> to sort files by date instead of alphabetically by filename, showing



the newest files first. Therefore, typing <TT>ls -alt</TT> gives<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">darkstar:~$ ls -alt



total 10



drwxr-xr-x   3 fido     users        1024 Jan  2 13:48 ./



-rw-r--r--   1 fido     users         333 Dec 21 22:11 .bash_history



drwxr-xr-x   6 root     root         1024 Dec 14 01:39 ../



-rw-r--r--   1 fido     users         114 Nov 23  1993 .lessrc



-rw-r--r--   1 fido     users          34 Nov 23  1993 .less



</FONT></PRE>



<P>The <TT>r</TT> option tells <TT>ls</TT> to produce a reverse output. This is often



used with the <TT>t</TT> option. The following is an example of what you might get



if you entered <TT>ls -altr</TT>:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">darkstar:~$ ls -altr



total 10



-rw-r--r--   1 fido     users          34 Nov 23  1993 .less



-rw-r--r--   1 fido     users         114 Nov 23  1993 .lessrc



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 <TT>ls</TT>, 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.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>

⌨️ 快捷键说明

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