个人工具

“命令行指南”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
什么是linux的命令操作模式?
 
(未显示19个用户的28个中间版本)
第1行: 第1行:
<p class="line867"><strong>Note that this is still a work in progress. If you're just looking for a basic introduction to the Linux command line, please see <a href="http://127.0.0.1:8000/BasicCommands">BasicCommands</a>.</strong> </p>
+
== 命令行指南 ==
<p class="line867"><strong>注意:本文仍在修改之中,如果你只是想找一篇关于linux操作指令的文章,请参阅</strong><strong><a href="http://127.0.0.1:8000/BasicCommands">BasicCommands</a>.</strong> </p>
+
<hr />
+
<p class="line874">&nbsp;</p>
+
<p class="line867">&nbsp;</p>
+
<h2 id="head-40b91de4e73e6d5f081fbc7f68716c9fff3e197b">1. Introduction(引言)</h2>
+
<p>&nbsp;</p>
+
<p class="line862">Even though Ubuntu is the newbie friendly and polished graphical distribution, there are still situations when a serious amount of time and mouse-clickage can be spared by typing a bit. I don't think this is a bad thing at all, no matter what you do Linux has one of its real strengths in the Command Line! <img width="15" height="15" title=":)" src="http://127.0.0.1:8000/wiki/ubuntu-cn/img/smile.png" alt=":)" /> </p>
+
<ul>
+
    <li style="list-style-type: none;">可 以说Ubuntu是当前图形界面最为友好和易操作的linux发行版,但还是有很多时候,只需执行几条简单的指令就可以完成繁琐的鼠标点击所完成的操作, 从而节约大量的时间和精力,我向来提倡通过命令操作方式来使用linux,因为linux的命令操作模式功能实在太强大了!它可以实现你需要的所有操作! </li>
+
</ul>
+
<p class="line867">&nbsp;</p>
+
<h3 id="head-1f8bf73c82e9ac347ef9a917727be193aa02b03f">1.1. What is it?(什么是linux的命令操作模式?)</h3>
+
<p>&nbsp;</p>
+
<p class="line862">A Command Line is in all simplicity a user interface which is based on lines of commands. You can say that it is a <strong>textual direct serial processor</strong>. </p>
+
<p class="line862">简单的说,命令行就是基于成行的命令的用户界面。您也可称其为一个<strong>文本化指令序列处理器。</strong> </p>
+
<ul>
+
    <li style="list-style-type: none;">
+
    <p class="line862">Most commonly, the user interacts directly with the computer by typing one line (although it can be more than one), to which triggers actions from the computer based on the syntax of the current processor.<br />
+
    Before everything gets too complicated, we can quite simply move on. <img width="15" height="15" title="/!\" src="http://127.0.0.1:8000/wiki/ubuntu-cn/img/alert.png" alt="/!\" /> The impatient can move right on to the <strong>Basic Usage</strong> section. </p>
+
    </li>
+
    <li style="list-style-type: none;">
+
    <p class="line862">绝大多数情况下, 用户通过输入一行命令(尽管可以不止一行)直接与计算机互动, 所触发的行为基于当前处理器的语法。<br />
+
    在一切变得复杂之前,我们悄悄地简单扼要的继续。 <img width="15" height="15" title="/!\" src="http://127.0.0.1:8000/wiki/ubuntu-cn/img/alert.png" alt="/!\" /> 不耐烦地人可以直接看 <strong>基本用法</strong> 章节。 </p>
+
    </li>
+
    <li style="list-style-type: none;">命令操作模式是一个很简洁的操作界面,它通过输入一条一条的指命(有些情况下可能是成组的命令)来实现对计算机的操作,通常它也被称为&ldquo;文本操作模式&rdquo; </li>
+
</ul>
+
<p class="line867">&nbsp;</p>
+
<p class="line867">&nbsp;</p>
+
<ul>
+
    <li style="list-style-type: none;">&nbsp;</li>
+
</ul>
+
<p class="line867">&nbsp;</p>
+
<p class="line867">&nbsp;</p>
+
<h3 id="head-b7700cc003ce8dd71cae99b1e956abc1f549e226">1.2. History(发展史)</h3>
+
<p>&nbsp;</p>
+
<p class="line862">In the early days of computers there was only the Command Line. The concept of a Graphical User Interface (GUI) to which most GUI are modelled after today were invented by engineers at <strong>Xerox's Palo Alto Research Center (PARC)</strong>. A bit later, Apple paid a whole bunch of money to be allowed to &quot;study&quot; their GUI idea. And, after a while Apple had their own GUI. </p>
+
<p class="line862">早期的计算机操作系统都只有命令行操作模式,现在非常流行的&ldquo;图形用户界面(GUI)&rdquo;的概念最早是由施乐公司&ldquo;<strong>帕尔托研究中心 (PARC)&rdquo;</strong>的一名工程师所提出来的,在它提出来不久之后,苹果电脑公司出了一大笔钱才被许可&ldquo;研究&rdquo;他们的GUI概念,不久以后,苹果就有了他们自己的GUI。 </p>
+
<ul>
+
    <li style="list-style-type: none;">
+
    <p class="line862">Not until 1986 did UNIX get its first GUI, developed by the <strong>MIT Project</strong>. They named it X. Linux however, had to wait ten more years before XFree86 were released. XFree86 was, and is even today, a free adoptation of the original X server. </p>
+
    </li>
+
    <li style="list-style-type: none;">
+
    <p class="line862">在UNIX系统上直到1986年才出现第一个图形操作界面,是由<strong>MIT Project</strong>开发的,当时给这个图形界面命名为X,不过,在XFree86发布前,linux还要再多等上十年。XFree86今天依然是原始X 服务器的一个自由改编版。 </p>
+
    </li>
+
    <li style="list-style-type: none;">
+
    <p class="line862">As mentioned earlier, the CLI (Command Line Interface) were the only way to communicate with computers before the GUI was invented. In 1969, <strong>Bell Telephone Laboratories</strong> released V1 of the UNIX Timeshare System. UNIX had a shell called sh, which was the only means of communicating with the computer, and it would stay that way for quite some time. </p>
+
    </li>
+
    <li style="list-style-type: none;">如上所述,在GUI发明以前,CLI(命令行用户界面)是用户操控计算机的唯一途径,1969年,&ldquo;贝尔电话实验室&rdquo;发布了UNIX分时系统的V1版。UNIX中有个外壳程序叫做sh ,是与计算机交流的唯一方法,这种情况持续了很久。 </li>
+
</ul>
+
<p class="line874">Later on there came dervatives of UNIX. HP-UX, 1BSD, Solaris, OpenVMS, IRIX, SCO XENIX, etc etc... As more time progressed, GNU/Linux emerged. However, the history of Linux itself is way off the scope for this HOWTO. As time progressed alternative CLI to sh emerged. zsh, ksh, bourne shell, etc etc... </p>
+
<ul>
+
    <li style="list-style-type: none;">稍后涌现了很多的UNIX衍生系统(purewind:个人以为原文中的dervative应为derivative,可能原作者打错字了,或者其他原因。汗)。比如HP-UX,1BSD,Solaris,OpenVMS,IRIX,SCO,ENIX等等,随着时间的推移,GNU/Linux出现了。不过Linux的发展历史并不是本文所要阐述的。时间继续推移,用以替代sh的CLI也出现了,比如 zsh ,ksh ,bourne shell等等。 </li>
+
</ul>
+
<p class="line867">&nbsp;</p>
+
<h4 id="head-cc6bf0f542cce05a29c7769ed8fe8fc1bde2b5bf">1.2.1. POSIX(UNIX可移植操作系统接口)</h4>
+
<p>&nbsp;</p>
+
<p class="line874">The wikipedia defines POSIX as the following; </p>
+
<p class="line874">维基百科是这样定义&ldquo;UNIX可移植操作系统接口&quot;的: </p>
+
<ul>
+
    <li style="list-style-type: none;">&quot;POSIX is the collective name of a family of related standards specified by the IEEE to define the application program interface (API) for software designed to run on variants of the Unix OS. They are formally designated as IEEE 1003 and the international standard name is ISO/IEC 9945. The standards emerged from a project, begun circa 1985. The term POSIX was suggested by Richard Stallman in response to an IEEE request for a memorable name; before that the standards effort was called IEEE-IX. POSIX is a near acronym for Portable Operating System Interface, with the X signifying the Unix heritage of the API.&quot; </li>
+
</ul>
+
<p class="line874">&quot;UNIX 可移植操作系统接口&quot;是对所有参照IEEE组织制定的&ldquo;Unix软件接口标准&rdquo;而开发的软件的统称,依这个标准而开发的软件可以运行在所有基于Unix的 操作系统上,IEEE组织给这一标准的命名为IEEE 1003,它的国际标准名称为ISO/IEC 9945。这个标准(UNIX可移植操作系统接口)来自于大约1985年的一个开发项目。后来应IEEE组织的要求,该项目成员Richard Stallman提议了一个好记的名字叫&ldquo;POSIX&quot;,在那以前,它被称为IEEE-IX 。POSIX实际上就是可移植(Portable)操作(Operating)系统(System)接口(Interface)的首字母简写,最后加上X 表明它的Unix血统。 </p>
+
<ul>
+
    <li style="list-style-type: none;">This sounds fancy and all, but to stay rather concise, it will suffice to say that POSIX is the underlying standards and functionality of how your CLI responds and interacts. 这听起来确实古怪,为了保持简洁,可以说POSIX是您的CLI响应和交互的根本标准和功能。 </li>
+
</ul>
+
<p class="line867">&nbsp;</p>
+
  
<h3 id="head-f96f243842a8c16759c0b0f8cceb66530cf12acf">1.3. Why you should care (为什么使用命令操作模式?)</h3>
+
原文作者:Dag Rune Sneeggen
<p>&nbsp;</p>
+
<p class="line862">So, this all sounds very dull and boring. Not to mention hard work and thinking?<br />
+
Well, it isn't really. <img width="15" height="15" title=";-)" src="http://127.0.0.1:8000/wiki/ubuntu-cn/img/smile4.png" alt=";-)" /> It's quite easy once you understand the basics. </p>
+
<p class="line874">这些听上去都非常枯燥乏味。更别提繁重的工作和思考了!事实上并非如此,只要你掌握了它的基本技巧,它就会变得相当简单。 </p>
+
<p class="line874">You should care because the CLI can; </p>
+
<p class="line874">使用CLI可以给你带来下面这些好处(非全部的好处) </p>
+
<ul>
+
    <li>save you time. </li>
+
    <li>为您节省时间 </li>
+
    <li>help you out of a rough-spot. </li>
+
    <li>救您脱离苦海 </li>
+
    <li>enable you to use Linux in ways that using a GUI exclusively can not. </li>
+
    <li>您可以通过GUI所没有的方式来使用Linux </li>
+
    <li>help you figure out why something doesn't work as expected, and you will most likely be able to fix the issue. </li>
+
    <li>帮助您找出为何目标没有实现,增加您解决问题的几率 </li>
+
</ul>
+
<p class="line862">For example you have been called by the systems administrator that you have used too much space. You want to quickly work out where the most space is used, using a graphical interface start you timer - go. Now go to a command line and type <tt>du&nbsp;|&nbsp;sort&nbsp;-n</tt> we will describe more later. It is faster to do some things on the command line and sometimes easier for graphical. Sometimes you need a hammer, sometimes a screwdriver. </p>
+
<p class="line874">举 个例子:某天,公司的计算机管理员提醒您,你已经使用太多的磁盘空间了。您可能很急切地想知道到底是什么东西占了那么多的硬盘空间,对比一下通过图形界面 查询和执行一条du | sort -n(我们以后再来解释),你会发现有些事情用命令行来做比较快,而用图形界面可能比较简单。有时候你需要锤子,有时候你需要起子。 </p>
+
<p class="line867">&nbsp;</p>
+
<h3 id="head-6d067c393f8e1c939a3d5e0c04a1c90cf5a3c873">1.4. Prerequisites(本文的假设前提)</h3>
+
<p>&nbsp;</p>
+
<p class="line874">This assumes that you are running any version of Ubuntu Linux, with default GNOME. You can however run Fluxbox, KDE, XFCE or basically anything else that you like, but this assumes GNOME for simplicity's sake. </p>
+
<p class="line874">本文假设您正在使用默认的图形界面为GNOME的任意版本Ubuntu Linux,当然您也可能正在使用Fluxbox,KDE,XFCE或是其他的图形操作界面,我们简单点就假设是GNOME 了。 </p>
+
<p class="line867">&nbsp;</p>
+
<h3 id="head-c6accd8b618d7901ef017a68d50eb04cd50ba34a">1.5. How to invoke it(如何进入命令模式)</h3>
+
<p>&nbsp;</p>
+
<p class="line862">Click on your GNOME Menu. Then proceed to Accessories -&gt; Terminal.<br />
+
This will launch what is called gnome-terminal. Which is the terminal emulator that ships with GNOME. </p>
+
<p class="line862">点击GNOME菜单-&gt;附件-&gt;终端,就可以启动名为gnome-termina的程序,它就是GNOME随机的终端模拟器。 </p>
+
<p class="line867">&nbsp;</p>
+
<h3 id="head-bd45d68ea2215d4a9db78382097266cd9c1f0426">1.6. Basic structure and concepts(命令模式的基本结构和概念)</h3>
+
<p>&nbsp;</p>
+
<p class="line874">The first thing that you should notice is something like: </p>
+
<p class="line874">打开命令终端后你首先可能会注意到类似下面的界面: </p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $<br />or<br />[dud@shadowplay ~]$<br /></pre>
+
<p>&nbsp;</p>
+
<p class="line862">What you see here is called the prompt. It signifies that the computer is ready and awaiting user input. In my case, <strong>dud</strong> is the user that I'm logged in as. <strong>shadowplay</strong> is the computers hostname, and <strong>~</strong> is the current directory. Each line of command is parsed by the computer after you press the <strong>Enter</strong> key. You can try now writing: </p>
+
<p class="line862">你所看到的这些被称为命令终端提示符,它表示计算机已就绪,正在等待着用户输入操作指令。以我的屏幕画面为例,<strong>dud</strong>是我所登录的用户,<strong>shadowplay</strong>是这台计算机的主机名,<strong>~</strong>表示当前目录。此时输入任何指令按回车之后该指令将会提交到计算机运行,比如你可以输入命令:ls 再按下回车 </p>
+
<p class="line867">&nbsp;</p>
+
<pre>ls [ENTER]<br /></pre>
+
<p>&nbsp;</p>
+
<p class="line867"><img width="16" height="16" title="{i}" src="http://127.0.0.1:8000/wiki/ubuntu-cn/img/icon-info.png" alt="{i}" /> Do not type [ENTER], just hit the keyboard key <br />
+
This will give you a list of the files and directories within your current location. </p>
+
<p class="line867"><img width="16" height="16" title="{i}" src="http://127.0.0.1:8000/wiki/ubuntu-cn/img/icon-info.png" alt="{i}" /> [ENTER]是指输入完ls后按下回车键,而不是叫你输入这个单词,ls这个命令将会列出你当前所在目录里的所有文件和子目录列表。 </p>
+
<p class="line874">Concepts: </p>
+
<p class="line874">相关的概念 </p>
+
<ul>
+
    <li>A terminal is a &quot;physical&quot;(direct) interface to your Linux Operating System. </li>
+
    <li>终端是与操作系统连接的物理(直接)接口 </li>
+
    <li>A terminal emulator is what we'll be using here. This is a CLI wrapped within your running GUI. Any applications running in a terminal emulator will be killed if you close the terminal emulator. </li>
+
    <li>终端模拟器是我们这里要用的,是你运行的GUI中封装的CLI序。当您关闭一个终端模拟器时,通过这个终端打开的所有程序将会关闭。 </li>
+
    <li>A shell is an interpeter for your terminal. You can drive a BMW or a Honda, but you'll still be driving in the same direction on the same road. It's slightly different ways to interact, simply speaking. </li>
+
    <li>外壳程序(shell)是您的终端的解释程序(purewind:原文的interpeter应为interpreter)。您可以开宝马也可以开本田,但是走得还是是一个方向一条路。简单的说就是交互的方式有点小差异。 </li>
+
    <li>A command is usually a small application which the shell will execute for you. Usually a command creates output, and often it takes arguments (input). </li>
+
    <li>命令一般是外壳程序为您执行的小程序。它通常会有一些结果提示信息输出。命令经常会接受一些参数(输入)来执行。 </li>
+
    <li>Output is what a command returns, most often this is returned on the terminal. </li>
+
    <li>&ldquo;运行提示&rdquo;指的是当执行某一命令时,系统给出的一些提示信息,大多回显到终端上。 </li>
+
    <li>Input is the arguments or data that any given command will take. Input will change the way a given command acts. </li>
+
    <li>输入是命令执行时接受的参数或者数据。输入会改变给出命令的行为。 </li>
+
    <li>Arguments are usually given either plainly, or by --switch=&quot;argument&quot;. Commonly they also have a short form eg, -s. </li>
+
    <li>参数通常会直接给出,或者通过 --switch=&quot;参数&quot; 来给出。一般还会有简写形式,比如 -s 。 </li>
+
    <li>A process is a command/application that is currently running on your computer. It doesn't actually have to be active, it can sleep or be in a number of states. </li>
+
    <li>进程是当前在您的计算机中运行的命令或者程序。它并不总是活动的,它可以睡眠或者是处于其他几种状态。 </li>
+
</ul>
+
<p class="line867">&nbsp;</p>
+
<h2 id="head-410fe53f2aae851a75612c12a703f4c85834a8cd">2. Basic Usage(基本用法)</h2>
+
<p>&nbsp;</p>
+
<p class="line874">This section will try to give you a good rundown of the basic usage for the bash shell, which is the default shell in ubuntu.</p>
+
<p class="line874">本节将向您介绍bash shell程序的精要,它是ubuntu默认的外壳程序。</p>
+
<p class="line867">&nbsp;</p>
+
<h3 id="head-71385fdb8b23c76cd71d76643e26cc7f7064eb67">2.1. Commands(常用指令)</h3>
+
<p>&nbsp;</p>
+
<p class="line862">I will now list a few of the basic and most useful commands that comes with Ubuntu Linux. <img title="/!\" height="15" alt="/!\" width="15" src="http://127.0.0.1:8000/wiki/ubuntu-cn/img/alert.png" /> Remember to type the commands exactly as they are written, and end with pressing the Enter key!</p>
+
<p class="line862">接下来我将举例阐述一下常用的基本指令: <img title="/!\" height="15" alt="/!\" width="15" src="http://127.0.0.1:8000/wiki/ubuntu-cn/img/alert.png" /> 记住要正确的按照下面写的输入,后面还得带上回车键!</p>
+
<p class="line874">Listing files:</p>
+
<p class="line874">查询文件列表</p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ ls<br />file1.txt<br />file2.pdf<br />file3.mp3<br />file1.pdf<br />another_file.txt<br />Yet-Another_file.txt<br />file-with_other-NAME.TXT</pre>
+
<p>&nbsp;</p>
+
<p class="line874">ls will default to listing your current directory, and sorting by alphabetical order. It will also be quite sparse about the information it returns. Common arguments for ls:</p>
+
<p class="line874">ls命令默认状态下将按首字母升序列出你当前文件夹下面的所有内容,但这样直接运行所得到的信息也是比较少的,通常它可以结合以下这些参数运行以查询更多的信息:</p>
+
<ul>
+
    <li>
+
    <p class="line891"><strong><tt>ls&nbsp;/</tt></strong> will return the file listing for directory /. If ls is given one argument, it will take that as the directory it should work on. It will not use your current working directory in other words.</p>
+
    </li>
+
    <li>
+
    <p class="line891"><strong><tt>ls&nbsp;-l</tt></strong> will give you a more detailed listing.</p>
+
    </li>
+
    <li>
+
    <p class="line891"><strong><tt>ls&nbsp;-a</tt></strong> will list all files, even hidden(files starting with .) files.</p>
+
    </li>
+
    <li>
+
    <p class="line891"><strong><tt>ls&nbsp;-h</tt></strong> will give file sizes in KB/MB/GB, instead of mere Bytes.</p>
+
    </li>
+
</ul>
+
<p class="line874">Listi ng current directory:</p>
+
<p class="line874">查询当前所在目录:</p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ pwd<br />/home/dud</pre>
+
<p>&nbsp;</p>
+
<p class="line874">Changing directory:</p>
+
<p class="line874">进入其他目录(用命令cd)</p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ pwd<br />/home/dud<br />dud@shadowplay:~ $ cd /root/<br />dud@shadowplay:~ $ pwd<br />/root</pre>
+
<p>&nbsp;</p>
+
<p class="line874">You can see how pwd first lists /home/dud as current directory, then cd changes it to /root/. Which pwd confirms.</p>
+
<p class="line874">上面例子中,当前目录原来是/home/dud,执行cd /root/之后再运行pwd可以发现,当前目录已经改为/root了</p>
+
<p class="line874">Echoing:</p>
+
<p class="line874">在屏幕上输出字符:</p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ echo &quot;Hello World&quot;<br />Hello World</pre>
+
<p>&nbsp;</p>
+
<p class="line862">A very useful command, which will quite simply echo back what you give it as arguments. <img title="/!\" height="15" alt="/!\" width="15" src="http://127.0.0.1:8000/wiki/ubuntu-cn/img/alert.png" /> It's important to note that although this works without the quotes, it's a very good practise to start using quotes as you'll be needing that often later on!</p>
+
<p class="line874">这是一个很有用的命令,它可以在屏幕上输入你指定的参数(&quot;&quot;号中的内容),当然这里举的这个例子中它没有多大的实际意义,但随着你对LINUX指令的不断深入,就会发现它的价值所在。</p>
+
<p class="line874">List content of a file:</p>
+
<p class="line874">显示文件内容:</p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ cat file1.txt<br />Roses are red.<br />Violets are blue,<br />and you have the bird-flue!</pre>
+
<p>&nbsp;</p>
+
<p class="line862">The command cat will print out content of <strong>text</strong> files to your terminal. The file file1.txt had a poem as we saw. <img title=";-)" height="15" alt=";-)" width="15" src="http://127.0.0.1:8000/wiki/ubuntu-cn/img/smile4.png" /></p>
+
<p class="line874">cat这个命令可以用来在终端上显示txt文本文件的内容。如上例输出的这首&ldquo;诗&rdquo;;</p>
+
<p class="line874">Copying a file:</p>
+
<p class="line874">复制文件:</p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ cp file1.txt file1_copy.txt<br />dud@shadowplay:~ $ cat file1_copy.txt<br />Roses are red.<br />Violets are blue,<br />and you have the bird-flue!</pre>
+
<p>&nbsp;</p>
+
<p class="line874">Moving a file:</p>
+
<p class="line874">移动文件:</p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ ls<br />file1.txt<br />file2.txt<br />dud@shadowplay:~ $ mv file1.txt new_file.txt<br />dud@shadowplay:~ $ ls<br />file2.txt<br />new_file.txt</pre>
+
<p>&nbsp;</p>
+
<p class="line862">You might have noticed by now that the CLI is rather mute in terms of giving feedback. <strong>Most common commands can be given a -v argument to be a bit more verbose.</strong></p>
+
<p class="line867"><strong>需要注意的是,在命令操作时系统基本上不会给你什么提示,当然,绝大多数的命令可以通过加上一个参数 -v来要求系统给出执行命令的反馈信息; </strong></p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ mv -v file1.txt new_file.txt<br />`file1.txt' -&gt; `new_file.txt'</pre>
+
<p>&nbsp;</p>
+
<p class="line874">This will tell you that it moved file1.txt to new_file.txt.</p>
+
<p class="line874">加上-v参数后,系统就会输出操作提示</p>
+
<p class="line867">&nbsp;</p>
+
<pre>`file1.txt' -&gt; `new_file.txt'</pre>
+
<p>&nbsp;</p>
+
<p class="line874">Creating an empty file:</p>
+
<p class="line874">建立一个空文本文件:</p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ ls<br />file1.txt<br />dud@shadowplay:~ $ touch tempfile.txt<br />dud@shadowplay:~ $ ls<br />file1.txt<br />tempfile.txt</pre>
+
<p>&nbsp;</p>
+
<p class="line874">Creating a directory:</p>
+
<p class="line874">建立一个目录</p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ ls<br />file1.txt<br />tempfile.txt<br />dud@shadowplay:~ $ mkdir test_dir<br />dud@shadowplay:~ $ ls<br />file1.txt<br />tempfile.txt<br />test_dir</pre>
+
<p>&nbsp;</p>
+
<p class="line874">Removing a file/directory</p>
+
<p class="line874">删除文件/目录</p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ ls -p<br />file1.txt<br />tempfile.txt<br />test_dir/<br />dud@shadowplay:~ $ rm -i tempfile.txt<br />rm: remove regular empty file `test.txt'? y<br />dud@shadowplay:~ $ ls -p<br />file1.txt<br />test_dir/<br />dud@shadowplay:~ $ rm test_dir<br />rm: cannot remove `test_dir': Is a directory<br />dud@shadowplay:~ $ rm -R test_dir<br />dud@shadowplay:~ $ ls -p<br />file1.txt</pre>
+
<p>&nbsp;</p>
+
<p class="line874">So what happened here? First we listed the files, which has 2 files and a directory.</p>
+
<p class="line874">我们来分析一下上面的操作:首先我们通过ls命令查询可知当前目下有两个文件和一个文件夹;</p>
+
<ul>
+
    <li>
+
    <p class="line862">You can use <strong>ls -p</strong>, which will indicate if an item is a file/directory/symlink/etc.</p>
+
    </li>
+
    <li>你可以用参数-p来让系统显示某一项的类型,比如是文件/文件夹/快捷链接等等;</li>
+
    <li>
+
    <p class="line862">Next we used <strong>rm -i</strong> to delete the file. the -i switch will ask for confirmation before doing things; interactivity.</p>
+
    </li>
+
    <li>接下来我们用rm -i尝试删除文件,-i参数是让系统在执行删除操作前输出一条确认提示;i也就是交互性的意思;</li>
+
    <li>
+
    <p class="line862">We then tried to delete the directory with <strong>rm test_dir</strong>, which failed because you have to use <strong>rm -R</strong> to delete directories.</p>
+
    </li>
+
    <li>当我们尝试用上面的命令去删除一个文件夹时会得到错误的提示,因为删除文件夹必须使用-R参数</li>
+
</ul>
+
<p class="line867"><img title="/!\" height="15" alt="/!\" width="15" src="http://127.0.0.1:8000/wiki/ubuntu-cn/img/alert.png" /> <strong>EXTREMELY IMPORTANT: The CLI will automatically assume that you have full and utter control of what you are doing!</strong> If you tell it to <strong>rm -Rf /</strong> it will delete your entire harddrive without even telling you that it is doing so! By always using <strong>rm -i</strong>, you assure that you at least will have to confirm before doing stupid things. If you want it to always ask before running any deletion, you can run a simple command:</p>
+
<p class="line874">特 别提示:在使用命令操作时,系统假设你很明确自己在做什么,它不会给你太多的提示,比如你执行rm -Rf /,它将会删除你硬盘上所有的东西,并且不会给你任何提示,所以,尽量在使用命令时加上-i的参数,以让系统在执行前进行一次确认,防止你干一些蠢事。如 果你觉得每次都要输入-i太麻烦,你可以执行以下的命令,让-i成为默认参数:</p>
+
<p class="line867">&nbsp;</p>
+
<pre>alias rm='rm -i'</pre>
+
<p>&nbsp;</p>
+
<p class="line874">Listing processes:</p>
+
<p class="line874">查询当前进程:</p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ ps<br />  PID TTY          TIME CMD<br />11278 pts/1    00:00:00 bash<br />24448 pts/1    00:00:00 ps</pre>
+
<p>&nbsp;</p>
+
<p class="line874">This shows the processes running, that is &quot;owned&quot; by you.</p>
+
<p class="line874">这条命令会例出你所启动的所有进程;</p>
+
<ul>
+
    <li>
+
    <p class="line891"><strong>ps -a</strong> will show all processes that is running, for all owners.</p>
+
    </li>
+
    <li>ps -a可以例出系统当前运行的所有进程,包括由其他用户启动的进程;</li>
+
    <li>
+
    <p class="line891"><strong>ps auxww</strong> is incredibly handy! It will show all processes except for some specific system processes, but it will also list it in a more readable format; with extra details.</p>
+
    </li>
+
    <li>ps auxww是一条相当人性化的命令,它会例出除一些很特殊进程以外的所有进程,并会以一个高可读的形式显示结果,每一个进程都会有较为详细的解释;</li>
+
</ul>
+
<p class="line862">Ok, that should do as an introduction! <img title=":D" height="15" alt=":D" width="15" src="http://127.0.0.1:8000/wiki/ubuntu-cn/img/biggrin.png" /> You can have a look at for instance:</p>
+
<p class="line874">基本命令的介绍就到此为止,你可以参阅以下地址得到更加详细的命令指南:</p>
+
<ul>
+
    <li>
+
    <p class="line891"><a class="http" href="http://www.ss64.com/bash/">HTML - Bash command reference</a></p>
+
    </li>
+
    <li>
+
    <p class="line891"><a class="http" href="http://www.indiana.edu/%7Euitspubs/b017/b017.pdf">PDF - Unix commands: A Quick Reference Card</a></p>
+
    </li>
+
    <li>
+
    <p class="line891"><a class="http" href="http://tinyurl.co.uk/k6xz">Book - UNIX for Dummies Quick Reference @ amazon.com</a></p>
+
    </li>
+
</ul>
+
<p class="line867">&nbsp;</p>
+
<p class="line867">&nbsp;</p>
+
<h3 id="head-5af3e87f2b8e14f33cda7ee19e95187658cb1330">2.2. Control flow(控制流程)</h3>
+
<p>&nbsp;</p>
+
<p class="line867">&nbsp;</p>
+
<h4 id="head-8dd27a217284f5c772835b6f8b320211a9066901">2.2.1. Input/Output(输入/输出)</h4>
+
<p>&nbsp;</p>
+
<p class="line874">Commands read input from the keyboard (standard input or stdin) and write to output (standard out or stdout). There is also a special category for error messages called standard error (or stderr). These are automatically created by your shell when it runs you command.</p>
+
<p class="line874">input用来读取你通过键盘(或其他标准输入设备)输入的信息,output用于在屏幕(或其他标准输出设备)上输出你指定的输出内容.另外还有一些标准的出错提示也是通过这个命令来实现的。通常在遇到操作错误时,系统会自动调用这个命令来输出标准错误提示;</p>
+
<p class="line874">We can redirect input and output to and from a command</p>
+
<p class="line874">我们能重定向命令中产生的输入和输出流的位置</p>
+
<p class="line867">&nbsp;</p>
+
<h3 id="head-1bc8c4e75f9aaab8f2bb424ec59824572292ebd4">2.3. Redirection</h3>
+
<p>&nbsp;</p>
+
<p class="line874">重定向If you wanted the output of a command to go to a file instead of the terminal, then you would use the following syntax:</p>
+
<p class="line874">如果你想把命令产生的输出流指向一个文件而不是(默认的)终端,你可以使用如下的语句:</p>
+
<p class="line874">Example:</p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ ls &gt; file4.txt<br />dud@shadowplay:~ $ cat file4.txt<br />file1.txt<br />file2.pdf<br />file3.mp3<br />file1.pdf<br />another_file.txt<br />Yet-Another_file.txt<br />file-with_other-NAME.TXT<br />file4.txt</pre>
+
<p>&nbsp;</p>
+
<p class="line862">The above example will create file4.txt if it is not found. <strong>NOTE:</strong> If file4.txt exists already, the above command will overwrite its contents. If you want to add to the end of a existing file, then you would use the following syntax:</p>
+
<p class="line862">以上例子将创建文件file4.txt如果file4.txt不存在的话。<strong>注意:</strong>如果file4.txt已经存在,那么上面的命令将覆盖文件的内容。如果你想将内容添加到已存在的文件内容的最后,那你可以用下面这个语句:</p>
+
<ul>
+
    <li style="list-style-type: none">
+
    <p class="line891"><strong>command &gt;&gt; filename</strong></p>
+
    </li>
+
</ul>
+
<p class="line874">Example:</p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ ls &gt;&gt; file4.txt<br />dud@shadowplay:~ $ cat file4.txt<br />file1.txt<br />file2.pdf<br />file3.mp3<br />file1.pdf<br />another_file.txt<br />Yet-Another_file.txt<br />file-with_other-NAME.TXT<br />file4.txt<br />file1.txt<br />file2.pdf<br />file3.mp3<br />file1.pdf<br />another_file.txt<br />Yet-Another_file.txt<br />file-with_other-NAME.TXT<br />file4.txt</pre>
+
<p>&nbsp;</p>
+
<p class="line874">In the example, you will notice the file was appended with the new information. Now we are going to do a different redirection: We are going to take the input from a file for the command to be executed. Here is the syntax for this redirection:</p>
+
<p class="line874">在这个例子中,你会发现原有的文件中添加了新的内容。接下来我们会见到另一种重定向方式:我们将把一个文件的内容作为将要执行的命令的输入。以下是这个语句:</p>
+
<ul>
+
    <li style="list-style-type: none">
+
    <p class="line891"><strong>command &lt; filename</strong></p>
+
    </li>
+
</ul>
+
<p class="line874">Example:</p>
+
<p class="line867">&nbsp;</p>
+
<pre>dud@shadowplay:~ $ sort &lt; file4.txt<br />another_file.txt<br />another_file.txt<br />file1.txt<br />file1.txt<br />file2.pdf<br />file2.pdf<br />file3.mp3<br />file3.mp3<br />file4.txt<br />file4.txt<br />file-with_other-NAME.TXT<br />file-with_other-NAME.TXT<br />Yet-Another_file.txt<br />Yet-Another_file.txt</pre>
+
<p>&nbsp;</p>
+
<p class="line874">As you can see from this example, we used the file4.txt as input into the sort command.</p>
+
<p class="line874">如你所见,我们将file4.txt(的内容)作为命令的参数输入。</p>
+
<p class="line867">&nbsp;</p>
+
<h4 id="head-4d256de562beba2c1a17d9eee6866542ec12f804">2.3.1. 管道(Pipes)</h4>
+
<p>&nbsp;</p>
+
<p class="line874">The true power of Linux comes from the ability to combine simple programs into more complex functions by simply joining them together. This is done by the pipe character '|' represented by a broken bar on the keyboard. For example let's sort our grep command above:</p>
+
<p class="line862">grep -i command &lt; myfile | sort &gt; result.text</p>
+
<p class="line874">Search for command in myfile, push this output into sort and then write the sorted file to result.text.</p>
+
<p class="line874">搜索 myfile 中的命令,将输出分类并写入分类文件到 result.text 。</p>
+
<p class="line867">&nbsp;</p>
+
<h4 id="head-b06983fe5bfce0861f78acaeae5bfc9d36825e4e">2.3.2. 后台进程(Background Processes)</h4>
+
<p>&nbsp;</p>
+
<p class="line862">The CLI is not a serial interface to the system. You can give the system commands while it is executing others. To start a process in the background, append a '&amp;' to the command:</p>
+
<p class="line862">CLI 不是系统的串行接口。您可以在执行其他命令时给出系统命令。要启动一个进程到后台,追加一个&ldquo;&amp;&rdquo;到命令后面。</p>
+
<p class="line867">&nbsp;</p>
+
<pre>sleep 60 &amp;<br />ls</pre>
+
<p>&nbsp;</p>
+
<p class="line862">The sleep command runs in the background, and you can still interact with the computer. The best way to think of '&amp;' is like ';' except that it starts commands asynchronously.</p>
+
<p class="line862">睡眠命令在后台运行,您依然可以与计算机交互。除了不同步启动命令以外,最好把 '&amp;' 理解成 ';'。</p>
+
<p class="line862">If you have a command that is taking a long time, and you want to put it into the background, it is easy. Simply type <em>ctrl-z</em> while the command is running, and it will stop. Then type <tt>bg</tt> to put it into the background. The command <tt>fg</tt> will put it back into the foreground.</p>
+
<p class="line862">如果您有一个命令将占用很多时间,您想把它放入后台运行,也很简单。只要在命令运行时按下<em>ctrl-z,</em>它就会停止。然后键入<tt>&nbsp;bg</tt> 使其转入后台。<tt>fg</tt> 命令可使其转回前台。</p>
+
<p class="line867">&nbsp;</p>
+
<pre>sleep 60<br />&lt;ctrl-z&gt;<br />bg<br />fg</pre>
+
<p>&nbsp;</p>
+
<p class="line862">Finally, you can kill a foreground process with <em>ctrl-c</em></p>
+
<p class="line862">最后,您可以使用 <em>ctrl-c 来杀死一个前台进程。</em></p>
+
<p class="line867">&nbsp;</p>
+
  
<h2 id="head-efbd18f84006aa2ce2950172850075c140a5ee95">3. Environment(环境)</h2>
+
授权许可:
<p>&nbsp;</p>
+
 
<p class="line874">Special variables.   PATH, PS1,  ... </p>
+
* [http://creativecommons.org/licenses/by-sa/2.0/ 创作共用协议Attribution-ShareAlike 2.0]
<p class="line874">特殊变量。PATH, PS1,  ... </p>
+
* [http://www.gnu.org/copyleft/fdl.html GNU自由文档许可证]
<p class="line867">&nbsp;</p>
+
翻译人员:雕啸长空 purewind
<h4 id="head-548f2979d6cb230c8bc49a768ff6ef9c75ef6d5e">3.0.1. Manipulating Variables(操作变量)</h4>
+
 
<p>&nbsp;</p>
+
校正人员:purewind
<p class="line867">&nbsp;</p>
+
 
<h3 id="head-428cc13b451aedfcb0dfbdaea366efeb959d8242">3.1. Simple scripting(简单脚本)</h3>
+
----
<p>&nbsp;</p>
+
 
<p class="line867">&nbsp;</p>
+
'''注意:本文仍在修改之中,如果你只是想找一篇关于linux操作指令的文章,请参阅''''''BasicCommands.'''
<p class="line867">&nbsp;</p>
+
 
<h2 id="head-8030ad4734eb7e3f14f9e5db12d641f4e5068edf">4. Further reading(深入读本)</h2>
+
----
<p>&nbsp;</p>
+
 
<p class="line867"><a href="http://rute.2038bug.com/index.html.gz" class="http">http://rute.2038bug.com/index.html.gz</a> </p>
+
=== 引言 ===
<ul>
+
 
    <li style="list-style-type: none;">
+
* 可以说Ubuntu是当前图形界面最为友好和易操作的linux发行版,但还是有很多时候,只需执行几条简单的指令就可以完成繁琐的鼠标点击所完成的操作,从而节约大量的时间和精力,我向来提倡通过命令操作方式来使用linux,因为linux的命令操作模式功能实在太强大了!它可以实现你需要的所有操作!
    <p class="line891"><a href="http://127.0.0.1:8000/CategoryDocumentation">CategoryDocumentation</a> <a href="http://127.0.0.1:8000/CategoryCleanup">CategoryCleanup</a> </p>
+
==== 什么是linux的命令操作模式? ====
    </li>
+
 
</ul>
+
简单的说,命令行就是基于成行的命令的用户界面。您也可称其为一个'''文本化指令序列处理器。'''
<p>&nbsp;</p>
+
 
<p lang="zh" dir="ltr" class="info" id="pageinfo">CommandlineHowto  (2007-03-19 12:18:30由<span title="??? @ localhost[127.0.0.1]">localhost</span>编辑)</p>
+
* 绝大多数情况下, 用户通过输入一行命令(尽管可以不止一行)直接与计算机互动, 所触发的行为基于当前处理器的语法。<br> 在一切变得复杂之前,我们悄悄地简单扼要的继续。 /!\ 不耐烦的人可以直接看 '''基本用法''' 章节。
 +
* 命令操作模式是一个很简洁的操作界面,它通过输入一条一条的指令(有些情况下可能是成组的命令)来实现对计算机的操作,通常它也被称为“文本操作模式”
 +
 
 +
==== 发展史 ====
 +
 
 +
早期的计算机操作系统都只有命令行操作模式,现在非常流行的“图形用户界面(GUI)”的概念最早是由施乐公司“'''帕尔托研究中心 (PARC)”'''的一名工程师所提出来的,在它提出来不久之后,苹果电脑公司出了一大笔钱才被许可“研究”他们的GUI概念,不久以后,苹果就有了他们自己的GUI。
 +
 
 +
* 在UNIX系统上直到1986年才出现第一个图形操作界面,是由'''MIT Project'''开发的,当时给这个图形界面命名为X,不过,在XFree86发布前,linux还要再多等上十年。XFree86今天依然是原始X 服务器的一个自由改编版。
 +
* 如上所述,在GUI发明以前,CLI(命令行用户界面)是用户操控计算机的唯一途径,1969年,“贝尔电话实验室”发布了UNIX分时系统的V1版。UNIX中有个外壳程序叫做sh ,是与计算机交流的唯一方法,这种情况持续了很久。
 +
* 稍候涌现了很多的UNIX衍生系统(purewind:个人以为原文中的dervative应为derivative,可能原作者打错字了,或者其他原因,汗)。比如HP-UX,1BSD,Solaris,OpenVMS,IRIX,SCO,ENIX,等等...,随着时间的推移,GNU/Linux出现了。不过Linux的发展历史并不是本文所要阐述的。时间继续推移,用以替代sh的CLI也出现了,比如 zsh ,ksh ,bourne shell等等。
 +
===== POSIX - UNIX可移植操作系统接口=====
 +
 
 +
维基百科是这样定义“UNIX可移植操作系统接口"的:
 +
 
 +
* "UNIX可移植操作系统接口"是对所有参照IEEE组织制定的“Unix软件接口标准”而开发的软件的统称,依这个标准而开发的软件可以运行在所有基于Unix的操作系统上,IEEE组织给这一标准的命名为IEEE 1003,它的国际标准名称为ISO/IEC 9945。这个标准(UNIX可移植操作系统接口)来自于大约1985年的一个开发项目。后来应IEEE组织的要求,该项目成员Richard Stallman提议了一个好记的名字叫“POSIX",在那以前,它被称为IEEE-IX 。POSIX实际上就是可移植(Portable)操作(Operating)系统(System)接口(Interface)的首字母简写,最后加上X表明它的Unix血统。
 +
 
 +
* 这听起来确实古怪,为了保持简洁,可以说POSIX是您的CLI响应和交互的根本标准和功能。
 +
 
 +
==== 为什么使用命令操作模式? ====
 +
 
 +
这些听上去都非常枯燥乏味。更别提繁重的工作和思考了!事实上并非如此,只要你掌握了它的基本技巧,它就会变得相当简单。
 +
 
 +
使用CLI可以给你带来下面这些好处(非全部的好处)
 +
 
 +
* 为您节省时间
 +
* 救您脱离苦海
 +
* 您可以通过GUI所没有的方式来使用Linux
 +
* 帮助您找出为何目标没有实现,增加您解决问题的几率
 +
 
 +
举个例子:某天,公司的计算机管理员提醒您,你已经使用太多的磁盘空间了。您可能很急切地想知道到底是什么东西占了那么多的硬盘空间,对比一下通过图形界面查询和执行一条du | sort -n(我们以後再来解释),你会发现有些事情用命令行来做比较快,而用图形界面可能比较简单。有时候你需要锤子,有时候你需要锯子<br>。
 +
 
 +
==== 本文的假设前提====
 +
 
 +
本文假设您正在使用默认的图形界面为GNOME的任意版本Ubuntu Linux,当然您也可能正在使用Fluxbox,KDE,XFCE或是其他的图形操作界面,我们简单点就假设是GNOME 了。
 +
 
 +
==== [[UbuntuHelp:UsingTheTerminal/zh|如何进入命令模式]] ====
 +
 
 +
点击GNOME菜单->附件->终端,就可以启动名为gnome-terminal的程序,它就是GNOME随机的终端模拟器。
 +
 
 +
==== 命令模式的基本结构和概念 ====
 +
 
 +
打开命令终端后你首先可能会注意到类似下面的界面:
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $
 +
or
 +
[dud@shadowplay:~]$
 +
</nowiki></pre>
 +
 
 +
你所看到的这些被称为命令终端提示符,它表示计算机已就绪,正在等待着用户输入操作指令。以我的屏幕画面为例,'''dud'''是我所登录的用户,'''shadowplay'''是这台计算机的主机名,'''~'''表示当前目录。此时输入任何指令按回车之后该指令将会提交到计算机运行,比如你可以输入命令:ls 再按下回车
 +
 
 +
<pre><nowiki>
 +
ls [ENTER]
 +
</nowiki></pre>
 +
 
 +
{i} [ENTER]是指输入完ls后按下回车键,而不是叫你输入这个单词,ls这个命令将会列出你当前所在目录里的所有文件和子目录列表。
 +
 
 +
 
 +
相关的概念
 +
 
 +
* 终端是与操作系统连接的物理(直接)接口
 +
* 终端模拟器是我们这里要用的,是你运行的GUI中封装的CLI序。当您关闭一个终端模拟器时,通过这个终端打开的所有程序将会关闭。
 +
* 外壳程序(shell)是您的终端的解释程序(purewind:原文的interpeter应为interpreter)。您可以开宝马也可以开本田,但是走得还是是一个方向一条路。简单的说就是交互的方式有点小差异。
 +
* 命令一般是外壳程序为您执行的小程序。它通常会有一些结果提示信息输出。命令经常会接受一些参数(输入)来执行。
 +
* “运行提示”指的是当执行某一命令时,系统给出的一些提示信息,大多回显到终端上。
 +
* 输入是命令执行时接受的参数或者数据。输入会改变给出命令的行为。
 +
* 参数通常会直接给出,或者通过 --switch="参数" 来给出。一般还会有简写形式,比如 -s 。
 +
* 进程是当前在您的计算机中运行的命令或者程序。它并不总是活动的,它可以睡眠或者是处于其他几种状态。
 +
 
 +
=== 基本用法 ===
 +
 
 +
本节将向您介绍bash shell程序的精要,它是ubuntu缺省的外壳程序。
 +
 
 +
==== 常用指令 ====
 +
 
 +
接下来我将举例阐述以下常用的基本指令: /!\ 记住要正确的按照下面写的输入,后面还得带上回车键!
 +
 
 +
查询文件列表
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ ls
 +
file1.txt
 +
file2.pdf
 +
file3.mp3
 +
file1.pdf
 +
another_file.txt
 +
Yet-Another_file.txt
 +
file-with_other-NAME.TXT
 +
</nowiki></pre>
 +
 
 +
ls命令默认状态下将按首字母升序列出你当前文件夹下面的所有内容,但这样直接运行所得到的信息也是比较少的,通常它可以结合以下这些参数运行以查询更多的信息:
 +
 
 +
* '''<code><nowiki>ls /</nowiki></code>''' 将列出根目录'/'下的文件清单.如果给定一个参数,则命令行会把该参数当作命令行的工作目录。换句话说,命令行不再以当前目录为工作目录。
 +
* '''<code><nowiki>ls -l</nowiki></code>''' 将给你列出一个更详细的文件清单.
 +
* '''<code><nowiki>ls -a</nowiki></code>''' 将列出包括隐藏文件(以.开头的文件)在内的所有文件.
 +
* '''<code><nowiki>ls -h</nowiki></code>''' 将以KB/MB/GB的形式给出文件大小,而不是以纯粹的Bytes.
 +
 
 +
查询当前所在目录:
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ pwd
 +
/home/dud
 +
</nowiki></pre>
 +
 
 +
进入其他目录(用命令cd)
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ pwd
 +
/home/dud
 +
dud@shadowplay:~ $ cd /root/
 +
dud@shadowplay:/root $ pwd
 +
/root
 +
</nowiki></pre>
 +
 
 +
上面例子中,当前目录原来是/home/dud,执行cd /root/之后再运行pwd可以发现,当前目录已经改为/root了
 +
 
 +
 
 +
在屏幕上输出字符:
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ echo "Hello World"
 +
Hello World
 +
</nowiki></pre>
 +
 
 +
这是一个很有用的命令,它可以在屏幕上输入你指定的参数(""号中的内容),当然这里举的这个例子中它没有多大的实际意义,但随着你对LINUX指令的不断深入,就会发现它的价值所在。
 +
 
 +
显示文件内容:
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ cat file1.txt
 +
Roses are red.
 +
Violets are blue,
 +
and you have the bird-flue!
 +
</nowiki></pre>
 +
 
 +
cat这个命令可以用来在终端上显示txt文本文件的内容。如上例输出的这首“诗”;
 +
 
 +
复制文件:
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ cp file1.txt file1_copy.txt
 +
dud@shadowplay:~ $ cat file1_copy.txt
 +
Roses are red.
 +
Violets are blue,
 +
and you have the bird-flue!
 +
</nowiki></pre>
 +
 
 +
移动文件:
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ ls
 +
file1.txt
 +
file2.txt
 +
dud@shadowplay:~ $ mv file1.txt new_file.txt
 +
dud@shadowplay:~ $ ls
 +
file2.txt
 +
new_file.txt
 +
</nowiki></pre>
 +
 
 +
'''需要注意的是,在命令操作时系统基本上不会给你什么提示,当然,绝大多数的命令可以通过加上一个参数 -v来要求系统给出执行命令的反馈信息; '''
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ mv -v file1.txt new_file.txt
 +
`file1.txt' -> `new_file.txt'
 +
</nowiki></pre>
 +
 
 +
加上-v参数后,系统就会输出操作提示
 +
 
 +
<pre><nowiki>
 +
`file1.txt' -> `new_file.txt'</nowiki></pre>
 +
 
 +
建立一个空文本文件:
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ ls
 +
file1.txt
 +
dud@shadowplay:~ $ touch tempfile.txt
 +
dud@shadowplay:~ $ ls
 +
file1.txt
 +
tempfile.txt
 +
</nowiki></pre>
 +
 
 +
建立一个目录
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ ls
 +
file1.txt
 +
tempfile.txt
 +
dud@shadowplay:~ $ mkdir test_dir
 +
dud@shadowplay:~ $ ls
 +
file1.txt
 +
tempfile.txt
 +
test_dir
 +
</nowiki></pre>
 +
 
 +
删除文件/目录
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ ls -p
 +
file1.txt
 +
tempfile.txt
 +
test_dir/
 +
dud@shadowplay:~ $ rm -i tempfile.txt
 +
rm: remove regular empty file `test.txt'? y
 +
dud@shadowplay:~ $ ls -p
 +
file1.txt
 +
test_dir/
 +
dud@shadowplay:~ $ rm test_dir
 +
rm: cannot remove `test_dir': Is a directory
 +
dud@shadowplay:~ $ rm -R test_dir
 +
dud@shadowplay:~ $ ls -p
 +
file1.txt
 +
</nowiki></pre>
 +
 
 +
我们来分析一下上面的操作:首先我们通过ls命令查询可知当前目下有两个文件和一个文件夹;
 +
 
 +
* 你可以用参数-p来让系统显示某一项的类型,比如是文件/文件夹/快捷链接等等;
 +
* 接下来我们用rm -i尝试删除文件,-i参数是让系统在执行删除操作前输出一条确认提示;i(interactive)也就是交互性的意思;
 +
* 当我们尝试用上面的命令去删除一个文件夹时会得到错误的提示,因为删除文件夹必须使用-R(recursive,循环)参数
 +
 
 +
特别提示:在使用命令操作时,系统假设你很明确自己在做什么,它不会给你太多的提示,比如你执行rm -Rf /,它将会删除你硬盘上所有的东西,并且不会给你任何提示,所以,尽量在使用命令时加上-i的参数,以让系统在执行前进行一次确认,防止你干一些蠢事。如果你觉得每次都要输入-i太麻烦,你可以执行以下的命令,让-i成为默认参数:
 +
 
 +
<pre><nowiki>
 +
alias rm='rm -i'
 +
</nowiki></pre>
 +
 
 +
查询当前进程:
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ ps
 +
PID TTY          TIME CMD
 +
11278 pts/1    00:00:00 bash
 +
24448 pts/1   00:00:00 ps
 +
</nowiki></pre>
 +
 
 +
这条命令会例出你所启动的所有进程;
 +
 
 +
* ps -a可以例出系统当前运行的所有进程,包括由其他用户启动的进程;
 +
* ps auxww是一条相当人性化的命令,它会例出除一些很特殊进程以外的所有进程,并会以一个高可读的形式显示结果,每一个进程都会有较为详细的解释;
 +
 
 +
基本命令的介绍就到此为止,你可以参阅以下地址得到更加详细的命令指南:
 +
 
 +
* [http://www.ss64.com/bash/ HTML - Bash command reference]
 +
* [http://www.indiana.edu/~uitspubs/b017/b017.pdf PDF - Unix commands: A Quick Reference Card]
 +
 
 +
==== 控制流程 ====
 +
===== 输入/输出 =====
 +
 
 +
input用来读取你通过键盘(或其他标准输入设备)输入的信息,output用于在屏幕(或其他标准输出设备)上输出你指定的输出内容.另外还有一些标准的出错提示也是通过这个命令来实现的。通常在遇到操作错误时,系统会自动调用这个命令来输出标准错误提示;
 +
 
 +
我们能重定向命令中产生的输入和输出流的位置
 +
 
 +
==== 重定向 ====
 +
 
 +
 
 +
如果你想把命令产生的输出流指向一个文件而不是(默认的)终端,你可以使用如下的语句:
 +
 
 +
Example:
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ ls > file4.txt
 +
dud@shadowplay:~ $ cat file4.txt
 +
file1.txt
 +
file2.pdf
 +
file3.mp3
 +
file1.pdf
 +
another_file.txt
 +
Yet-Another_file.txt
 +
file-with_other-NAME.TXT
 +
file4.txt
 +
</nowiki></pre>
 +
 
 +
以上例子将创建文件file4.txt如果file4.txt不存在的话。'''注意:'''如果file4.txt已经存在,那么上面的命令将覆盖文件的内容。如果你想将内容添加到已存在的文件内容的最后,那你可以用下面这个语句:
 +
 
 +
* '''command >> filename'''
 +
示例:
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ ls >> file4.txt
 +
dud@shadowplay:~ $ cat file4.txt
 +
file1.txt
 +
file2.pdf
 +
file3.mp3
 +
file1.pdf
 +
another_file.txt
 +
Yet-Another_file.txt
 +
file-with_other-NAME.TXT
 +
file4.txt
 +
file1.txt
 +
file2.pdf
 +
file3.mp3
 +
file1.pdf
 +
another_file.txt
 +
Yet-Another_file.txt
 +
file-with_other-NAME.TXT
 +
file4.txt
 +
</nowiki></pre>
 +
 
 +
在这个例子中,你会发现原有的文件中添加了新的内容。接下来我们会见到另一种重定向方式:我们将把一个文件的内容作为将要执行的命令的输入。以下是这个语句:
 +
 
 +
* '''command < filename'''
 +
Example:
 +
 
 +
<pre><nowiki>
 +
dud@shadowplay:~ $ sort < file4.txt
 +
another_file.txt
 +
another_file.txt
 +
file1.txt
 +
file1.txt
 +
file2.pdf
 +
file2.pdf
 +
file3.mp3
 +
file3.mp3
 +
file4.txt
 +
file4.txt
 +
file-with_other-NAME.TXT
 +
file-with_other-NAME.TXT
 +
Yet-Another_file.txt
 +
Yet-Another_file.txt
 +
</nowiki></pre>
 +
 
 +
如你所见,我们将file4.txt(的内容)作为命令的参数输入。
 +
 
 +
===== 管道 =====
 +
 
 +
Linux的强大之处在于它能把几个简单的命令联合成为复杂的功能,通过键盘上的管道符号'|' 完成。现在,我们来排序上面的"grep"命令:
 +
 
 +
grep -i command < myfile | sort > result.text
 +
 
 +
 
 +
搜索 myfile 中的命令,将输出分类并写入分类文件到 result.text 。
 +
有时候用ls列出很多命令的时候很不方便
 +
这时“|”就充分利用到了
 +
ls -l |  less
 +
慢慢看吧.
 +
 
 +
===== 后台进程 =====
 +
 
 +
CLI 不是系统的串行接口。您可以在执行其他命令时给出系统命令。要启动一个进程到后台,追加一个“&”到命令后面。
 +
 
 +
<pre><nowiki>
 +
sleep 60 &
 +
ls
 +
</nowiki></pre>
 +
 
 +
睡眠命令在后台运行,您依然可以与计算机交互。除了不同步启动命令以外,最好把 '&' 理解成 ';'。
 +
 
 +
如果您有一个命令将占用很多时间,您想把它放入后台运行,也很简单。只要在命令运行时按下''ctrl-z,''它就会停止。然后键入<code><nowiki> bg</nowiki></code> 使其转入后台。<code><nowiki>fg</nowiki></code> 命令可使其转回前台。
 +
 
 +
<pre><nowiki>
 +
sleep 60
 +
<ctrl-z>
 +
bg
 +
fg
 +
</nowiki></pre>
 +
 
 +
最后,您可以使用 ''ctrl-c 来杀死一个前台进程。''
 +
2010年7月2日 (五) 18:04 (CST)
 +
 
 +
=== 环境 ===
 +
 
 +
特殊变量。PATH, PS1,  ...
 +
 
 +
===== 操作变量 =====
 +
==== 简单脚本 ====
 +
=== 深入读本 ===
 +
http://rute.2038bug.com/index.html.gz

2013年11月25日 (一) 22:36的最新版本

命令行指南

原文作者:Dag Rune Sneeggen

授权许可:

翻译人员:雕啸长空 purewind

校正人员:purewind


'注意:本文仍在修改之中,如果你只是想找一篇关于linux操作指令的文章,请参阅'BasicCommands.


引言

  • 可以说Ubuntu是当前图形界面最为友好和易操作的linux发行版,但还是有很多时候,只需执行几条简单的指令就可以完成繁琐的鼠标点击所完成的操作,从而节约大量的时间和精力,我向来提倡通过命令操作方式来使用linux,因为linux的命令操作模式功能实在太强大了!它可以实现你需要的所有操作!

什么是linux的命令操作模式?

简单的说,命令行就是基于成行的命令的用户界面。您也可称其为一个文本化指令序列处理器。

  • 绝大多数情况下, 用户通过输入一行命令(尽管可以不止一行)直接与计算机互动, 所触发的行为基于当前处理器的语法。
    在一切变得复杂之前,我们悄悄地简单扼要的继续。 /!\ 不耐烦的人可以直接看 基本用法 章节。
  • 命令操作模式是一个很简洁的操作界面,它通过输入一条一条的指令(有些情况下可能是成组的命令)来实现对计算机的操作,通常它也被称为“文本操作模式”

发展史

早期的计算机操作系统都只有命令行操作模式,现在非常流行的“图形用户界面(GUI)”的概念最早是由施乐公司“帕尔托研究中心 (PARC)”的一名工程师所提出来的,在它提出来不久之后,苹果电脑公司出了一大笔钱才被许可“研究”他们的GUI概念,不久以后,苹果就有了他们自己的GUI。

  • 在UNIX系统上直到1986年才出现第一个图形操作界面,是由MIT Project开发的,当时给这个图形界面命名为X,不过,在XFree86发布前,linux还要再多等上十年。XFree86今天依然是原始X 服务器的一个自由改编版。
  • 如上所述,在GUI发明以前,CLI(命令行用户界面)是用户操控计算机的唯一途径,1969年,“贝尔电话实验室”发布了UNIX分时系统的V1版。UNIX中有个外壳程序叫做sh ,是与计算机交流的唯一方法,这种情况持续了很久。
  • 稍候涌现了很多的UNIX衍生系统(purewind:个人以为原文中的dervative应为derivative,可能原作者打错字了,或者其他原因,汗)。比如HP-UX,1BSD,Solaris,OpenVMS,IRIX,SCO,ENIX,等等...,随着时间的推移,GNU/Linux出现了。不过Linux的发展历史并不是本文所要阐述的。时间继续推移,用以替代sh的CLI也出现了,比如 zsh ,ksh ,bourne shell等等。
POSIX - UNIX可移植操作系统接口

维基百科是这样定义“UNIX可移植操作系统接口"的:

  • "UNIX可移植操作系统接口"是对所有参照IEEE组织制定的“Unix软件接口标准”而开发的软件的统称,依这个标准而开发的软件可以运行在所有基于Unix的操作系统上,IEEE组织给这一标准的命名为IEEE 1003,它的国际标准名称为ISO/IEC 9945。这个标准(UNIX可移植操作系统接口)来自于大约1985年的一个开发项目。后来应IEEE组织的要求,该项目成员Richard Stallman提议了一个好记的名字叫“POSIX",在那以前,它被称为IEEE-IX 。POSIX实际上就是可移植(Portable)操作(Operating)系统(System)接口(Interface)的首字母简写,最后加上X表明它的Unix血统。
  • 这听起来确实古怪,为了保持简洁,可以说POSIX是您的CLI响应和交互的根本标准和功能。

为什么使用命令操作模式?

这些听上去都非常枯燥乏味。更别提繁重的工作和思考了!事实上并非如此,只要你掌握了它的基本技巧,它就会变得相当简单。

使用CLI可以给你带来下面这些好处(非全部的好处)

  • 为您节省时间
  • 救您脱离苦海
  • 您可以通过GUI所没有的方式来使用Linux
  • 帮助您找出为何目标没有实现,增加您解决问题的几率

举个例子:某天,公司的计算机管理员提醒您,你已经使用太多的磁盘空间了。您可能很急切地想知道到底是什么东西占了那么多的硬盘空间,对比一下通过图形界面查询和执行一条du | sort -n(我们以後再来解释),你会发现有些事情用命令行来做比较快,而用图形界面可能比较简单。有时候你需要锤子,有时候你需要锯子

本文的假设前提

本文假设您正在使用默认的图形界面为GNOME的任意版本Ubuntu Linux,当然您也可能正在使用Fluxbox,KDE,XFCE或是其他的图形操作界面,我们简单点就假设是GNOME 了。

如何进入命令模式

点击GNOME菜单->附件->终端,就可以启动名为gnome-terminal的程序,它就是GNOME随机的终端模拟器。

命令模式的基本结构和概念

打开命令终端后你首先可能会注意到类似下面的界面:

dud@shadowplay:~ $
or
[dud@shadowplay:~]$

你所看到的这些被称为命令终端提示符,它表示计算机已就绪,正在等待着用户输入操作指令。以我的屏幕画面为例,dud是我所登录的用户,shadowplay是这台计算机的主机名,~表示当前目录。此时输入任何指令按回车之后该指令将会提交到计算机运行,比如你可以输入命令:ls 再按下回车

ls [ENTER]

{i} [ENTER]是指输入完ls后按下回车键,而不是叫你输入这个单词,ls这个命令将会列出你当前所在目录里的所有文件和子目录列表。


相关的概念

  • 终端是与操作系统连接的物理(直接)接口
  • 终端模拟器是我们这里要用的,是你运行的GUI中封装的CLI序。当您关闭一个终端模拟器时,通过这个终端打开的所有程序将会关闭。
  • 外壳程序(shell)是您的终端的解释程序(purewind:原文的interpeter应为interpreter)。您可以开宝马也可以开本田,但是走得还是是一个方向一条路。简单的说就是交互的方式有点小差异。
  • 命令一般是外壳程序为您执行的小程序。它通常会有一些结果提示信息输出。命令经常会接受一些参数(输入)来执行。
  • “运行提示”指的是当执行某一命令时,系统给出的一些提示信息,大多回显到终端上。
  • 输入是命令执行时接受的参数或者数据。输入会改变给出命令的行为。
  • 参数通常会直接给出,或者通过 --switch="参数" 来给出。一般还会有简写形式,比如 -s 。
  • 进程是当前在您的计算机中运行的命令或者程序。它并不总是活动的,它可以睡眠或者是处于其他几种状态。

基本用法

本节将向您介绍bash shell程序的精要,它是ubuntu缺省的外壳程序。

常用指令

接下来我将举例阐述以下常用的基本指令: /!\ 记住要正确的按照下面写的输入,后面还得带上回车键!

查询文件列表

dud@shadowplay:~ $ ls
file1.txt
file2.pdf
file3.mp3
file1.pdf
another_file.txt
Yet-Another_file.txt
file-with_other-NAME.TXT

ls命令默认状态下将按首字母升序列出你当前文件夹下面的所有内容,但这样直接运行所得到的信息也是比较少的,通常它可以结合以下这些参数运行以查询更多的信息:

  • ls / 将列出根目录'/'下的文件清单.如果给定一个参数,则命令行会把该参数当作命令行的工作目录。换句话说,命令行不再以当前目录为工作目录。
  • ls -l 将给你列出一个更详细的文件清单.
  • ls -a 将列出包括隐藏文件(以.开头的文件)在内的所有文件.
  • ls -h 将以KB/MB/GB的形式给出文件大小,而不是以纯粹的Bytes.

查询当前所在目录:

dud@shadowplay:~ $ pwd
/home/dud

进入其他目录(用命令cd)

dud@shadowplay:~ $ pwd
/home/dud
dud@shadowplay:~ $ cd /root/
dud@shadowplay:/root $ pwd
/root

上面例子中,当前目录原来是/home/dud,执行cd /root/之后再运行pwd可以发现,当前目录已经改为/root了


在屏幕上输出字符:

dud@shadowplay:~ $ echo "Hello World"
Hello World

这是一个很有用的命令,它可以在屏幕上输入你指定的参数(""号中的内容),当然这里举的这个例子中它没有多大的实际意义,但随着你对LINUX指令的不断深入,就会发现它的价值所在。

显示文件内容:

dud@shadowplay:~ $ cat file1.txt
Roses are red.
Violets are blue,
and you have the bird-flue!

cat这个命令可以用来在终端上显示txt文本文件的内容。如上例输出的这首“诗”;

复制文件:

dud@shadowplay:~ $ cp file1.txt file1_copy.txt
dud@shadowplay:~ $ cat file1_copy.txt
Roses are red.
Violets are blue,
and you have the bird-flue!

移动文件:

dud@shadowplay:~ $ ls
file1.txt
file2.txt
dud@shadowplay:~ $ mv file1.txt new_file.txt
dud@shadowplay:~ $ ls
file2.txt
new_file.txt

需要注意的是,在命令操作时系统基本上不会给你什么提示,当然,绝大多数的命令可以通过加上一个参数 -v来要求系统给出执行命令的反馈信息;

dud@shadowplay:~ $ mv -v file1.txt new_file.txt
`file1.txt' -> `new_file.txt'

加上-v参数后,系统就会输出操作提示

`file1.txt' -> `new_file.txt'

建立一个空文本文件:

dud@shadowplay:~ $ ls
file1.txt
dud@shadowplay:~ $ touch tempfile.txt
dud@shadowplay:~ $ ls
file1.txt
tempfile.txt

建立一个目录

dud@shadowplay:~ $ ls
file1.txt
tempfile.txt
dud@shadowplay:~ $ mkdir test_dir
dud@shadowplay:~ $ ls
file1.txt
tempfile.txt
test_dir

删除文件/目录

dud@shadowplay:~ $ ls -p
file1.txt
tempfile.txt
test_dir/
dud@shadowplay:~ $ rm -i tempfile.txt
rm: remove regular empty file `test.txt'? y
dud@shadowplay:~ $ ls -p
file1.txt
test_dir/
dud@shadowplay:~ $ rm test_dir
rm: cannot remove `test_dir': Is a directory
dud@shadowplay:~ $ rm -R test_dir
dud@shadowplay:~ $ ls -p
file1.txt

我们来分析一下上面的操作:首先我们通过ls命令查询可知当前目下有两个文件和一个文件夹;

  • 你可以用参数-p来让系统显示某一项的类型,比如是文件/文件夹/快捷链接等等;
  • 接下来我们用rm -i尝试删除文件,-i参数是让系统在执行删除操作前输出一条确认提示;i(interactive)也就是交互性的意思;
  • 当我们尝试用上面的命令去删除一个文件夹时会得到错误的提示,因为删除文件夹必须使用-R(recursive,循环)参数

特别提示:在使用命令操作时,系统假设你很明确自己在做什么,它不会给你太多的提示,比如你执行rm -Rf /,它将会删除你硬盘上所有的东西,并且不会给你任何提示,所以,尽量在使用命令时加上-i的参数,以让系统在执行前进行一次确认,防止你干一些蠢事。如果你觉得每次都要输入-i太麻烦,你可以执行以下的命令,让-i成为默认参数:

alias rm='rm -i'

查询当前进程:

dud@shadowplay:~ $ ps
PID TTY          TIME CMD
11278 pts/1    00:00:00 bash
24448 pts/1    00:00:00 ps

这条命令会例出你所启动的所有进程;

  • ps -a可以例出系统当前运行的所有进程,包括由其他用户启动的进程;
  • ps auxww是一条相当人性化的命令,它会例出除一些很特殊进程以外的所有进程,并会以一个高可读的形式显示结果,每一个进程都会有较为详细的解释;

基本命令的介绍就到此为止,你可以参阅以下地址得到更加详细的命令指南:

控制流程

输入/输出

input用来读取你通过键盘(或其他标准输入设备)输入的信息,output用于在屏幕(或其他标准输出设备)上输出你指定的输出内容.另外还有一些标准的出错提示也是通过这个命令来实现的。通常在遇到操作错误时,系统会自动调用这个命令来输出标准错误提示;

我们能重定向命令中产生的输入和输出流的位置

重定向

如果你想把命令产生的输出流指向一个文件而不是(默认的)终端,你可以使用如下的语句:

Example:

dud@shadowplay:~ $ ls > file4.txt
dud@shadowplay:~ $ cat file4.txt
file1.txt
file2.pdf
file3.mp3
file1.pdf
another_file.txt
Yet-Another_file.txt
file-with_other-NAME.TXT
file4.txt

以上例子将创建文件file4.txt如果file4.txt不存在的话。注意:如果file4.txt已经存在,那么上面的命令将覆盖文件的内容。如果你想将内容添加到已存在的文件内容的最后,那你可以用下面这个语句:

  • command >> filename

示例:

dud@shadowplay:~ $ ls >> file4.txt
dud@shadowplay:~ $ cat file4.txt
file1.txt
file2.pdf
file3.mp3
file1.pdf
another_file.txt
Yet-Another_file.txt
file-with_other-NAME.TXT
file4.txt
file1.txt
file2.pdf
file3.mp3
file1.pdf
another_file.txt
Yet-Another_file.txt
file-with_other-NAME.TXT
file4.txt

在这个例子中,你会发现原有的文件中添加了新的内容。接下来我们会见到另一种重定向方式:我们将把一个文件的内容作为将要执行的命令的输入。以下是这个语句:

  • command < filename

Example:

dud@shadowplay:~ $ sort < file4.txt
another_file.txt
another_file.txt
file1.txt
file1.txt
file2.pdf
file2.pdf
file3.mp3
file3.mp3
file4.txt
file4.txt
file-with_other-NAME.TXT
file-with_other-NAME.TXT
Yet-Another_file.txt
Yet-Another_file.txt

如你所见,我们将file4.txt(的内容)作为命令的参数输入。

管道

Linux的强大之处在于它能把几个简单的命令联合成为复杂的功能,通过键盘上的管道符号'|' 完成。现在,我们来排序上面的"grep"命令:

grep -i command < myfile | sort > result.text


搜索 myfile 中的命令,将输出分类并写入分类文件到 result.text 。 有时候用ls列出很多命令的时候很不方便 这时“|”就充分利用到了 ls -l | less 慢慢看吧.

后台进程

CLI 不是系统的串行接口。您可以在执行其他命令时给出系统命令。要启动一个进程到后台,追加一个“&”到命令后面。

sleep 60 &
ls

睡眠命令在后台运行,您依然可以与计算机交互。除了不同步启动命令以外,最好把 '&' 理解成 ';'。

如果您有一个命令将占用很多时间,您想把它放入后台运行,也很简单。只要在命令运行时按下ctrl-z,它就会停止。然后键入 bg 使其转入后台。fg 命令可使其转回前台。

sleep 60
<ctrl-z>
bg
fg

最后,您可以使用 ctrl-c 来杀死一个前台进程。 2010年7月2日 (五) 18:04 (CST)

环境

特殊变量。PATH, PS1, ...

操作变量

简单脚本

深入读本

http://rute.2038bug.com/index.html.gz