📄 125-128.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Unleashed, Third Edition:Basic Linux Commands</TITLE>
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0672313723//-->
<!--TITLE=Linux Unleashed, Third Edition//-->
<!--AUTHOR=Tim Parker//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Sams//-->
<!--CHAPTER=7//-->
<!--PAGES=125-128//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch06/122-124.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="128-130.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 7<BR>Basic Linux Commands
</FONT></H2>
<P><I>by Ed Treijs and Tim Parker</I></P>
<DL>
<DT><B>In This Chapter</B>
<DT>• How Linux commands work
<DT>• Notational conventions used to describe Linux commands
<DT>• Online help available in Linux
<DT>• The Linux man pages
<DT>• Wildcards: * and ?
<DT>• Environment variables
<DT>• Processes and how to terminate them
<DT>• Becoming someone else: the su command
<DT>• The grep command
</DL>
<H3><A NAME="Heading2"></A><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:
</P>
<DL>
<DD><B>•</B> Specifying or redirecting a command’s input and output
<DD><B>•</B> Using command options
</DL>
<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. This analogy seems simple, but is a surprisingly effective way of understanding some complex concepts of UNIX and Linux.
</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 is based on a few simple design principles. The most important of these principles for our purposes is that commands are simple and single-purpose, as well as flexible about where they get information from and where to put it when they’ve finished. All Linux commands, therefore, should work in consistent ways. Of course, UNIX has evolved over the 35 years or so it has been around, and 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 surprisingly coherent and consistent in how they work.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Tip: </B><BR>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 “back up” 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. Alternatively, you can use the Ctrl+C sequence to cancel whatever you are typing and display a new shell prompt.<P>Perhaps the most powerful keys to use at the command prompt are the arrow keys in those versions of the shell that support them. 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><B>DOSKEY</B></TT> utility).<HR></FONT>
</BLOCKQUOTE>
</P>
<H4 ALIGN="LEFT"><A NAME="Heading3"></A><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 does 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. A simple example is when you want to sort a list of names into order. Linux has a sort command that can do that for you, but maybe you want to reverse the order of sorting so Z comes before A. Instead of having a backward sort command, a single letter option reverses the sort order. Some commands have many options, some have a few.
</P>
<P>The <TT><B>ls</B></TT> command is an excellent, and useful, example of a command that has a great many options. The <TT><B>ls</B></TT> command lists the files found on the Linux system’s hard drive. This sounds simple enough, doesn’t it? Try entering the following command:</P>
<!-- CODE SNIP //-->
<PRE>
darkstar:~$ ls
darkstar:~$
</PRE>
<!-- END CODE SNIP //-->
<P>Well, nothing much seems to happen in this case, and most systems respond like this if you’re using a brand-new user login.
</P>
<P>Now try typing <TT><B>ls -a</B></TT>. Type it exactly as shown. The space between <TT><B>ls</B></TT> and <TT><B>-a</B></TT> is necessary, and there must be no space between the <TT><B>-</B></TT> and the <TT><B>a</B></TT>.</P>
<!-- CODE SNIP //-->
<PRE>
darkstar:~$ <TT><B>ls -a</B></TT>
./ .bash_history .kermrc .lessrc
</PRE>
<!-- END CODE SNIP //-->
<P>Here you have modified what <TT><B>ls</B></TT> does by adding a command option—in this case, <TT><B>-a</B></TT>. By default, <TT><B>ls</B></TT> lists only files whose names don’t begin with a period. However, <TT><B>-a</B></TT> tells <TT><B>ls</B></TT> to list all files, even ones that begin with a period. (These are usually special files created for you by Linux. Because Linux can’t hide files the way some operating systems can, it treats any file starting with a period as a special configuration file that doesn’t appear with the usual list commands.) At present, all the files in your directory start with a period, so <TT><B>ls</B></TT> by itself does not list any files; you must add <TT><B>-a</B></TT> to see all of the files you have at present.</P>
<P>The <TT><B>ls</B></TT> command has many more options. You can use more than one option at a time. For example, try typing <TT><B>ls -al</B></TT>:</P>
<!-- CODE //-->
<PRE>
darkstar:~$ <TT><B>ls -al</B></TT>
total 10
drwxr-xr-x 3 fido users 1024 Dec 21 22:11 ./
drwxr-xr-x 6 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 163 Dec 7 14:31 .kermrc
-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/
</PRE>
<!-- END CODE //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch06/122-124.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="128-130.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -