Merge pull request #1396 from cvsher/master

Command Line Tuesdays – Part Five 翻译完毕
This commit is contained in:
Xingyu.Wang 2014-07-28 22:47:30 +08:00
commit 88386ab53f
2 changed files with 63 additions and 89 deletions

View File

@ -1,89 +0,0 @@
translating by cvsher
Command Line Tuesdays Part Five
================================================================================
Yes, youve guessed what time it is! Its time to rrrrrrrrummmbleeeee! And this time, well learn how to work with commands. So without further ado, lets get to business.
Mr Shotts states that until now, we worked with a few mysterious commands, arguments and options, and today is the day we shed a little light upon that mystery. Well learn the following commands and what they do: type, which, help and man. But first, lets learn…
### …what are commands? ###
All great things come in fours, and its the same with commands. We can split them up into four categories:
**1) An executable program:** a command can be an executable program. If youve traveled across your file system in the previous lessons like you were supposed to, you probably visited the /usr/bin folder. Youve seen quite a number of familiar names like transmission-gtk, deluge-gtk etc. Whats less important for us novices currently is that programs there can be compiled binaries or programs written in scripting languages. Point is, since they are executable programs, you can run them. Try it. Navigate to it, list the files inside, pick one and run it simply by typing its name.
**2) A command built into the shell:** bash provides a number of commands internally called shell builtins. The cd command, for example, is a shell builtin, mr Shotts says.
**3) A shell function:** miniature shell script, built into the environment. For the time being, well just mention it, as it will be covered in the following weeks.
**4) An alias:** commands you can define yourself, using other commands. Also coming in the following lessons.
Now, its useful to know what type of command were dealing with. And we can find out using…
### …type ###
You can use **type + command** to inspect what kind of command is the command youd like to use. You do it by simply typing: type command and youll get an output. For example:
![type mkdir](https://news.opensuse.org/wp-content/uploads/2014/07/Zaslonska-slika-2014-07-15-091448.png)
or
![type ls](https://news.opensuse.org/wp-content/uploads/2014/07/Zaslonska-slika-2014-07-15-091640.png)
…where we can see that the ls command is actually an alias of _ls!
### which ###
Sometimes (but rarely on a desktop system, though) there are more versions of one executable installed on a machine. To find out the exact location of a given executable, we can use command which. Additionally, it only works with executable programs.
![which transmission-gtk](https://news.opensuse.org/wp-content/uploads/2014/07/Zaslonska-slika-2014-07-15-092052.png)
Now, mostly every command has documentation that comes with it. So youre somewhere doing your CLI thing, no access to the internet so you cant bug geekos on the forums or IRC, and you need to find out how to exactly use a command. You can do it two ways. First being…
### …help ###
help command works with shell builtins (the second category we have mentioned above). So you can pick a shell builtin, like cd, for example, and simply type help cd. Youll get a helpful page printed out in your terminal, so go ahead and read what cd has to offer. It shows in what ways you can use the command, what options you can use (its in square brackets, which means they are optional! Also, if theres a vertical separator inside the square brackets, it means the options mentioned are mutually exclusive. Dont use them together!)
### help ###
help works only for the shell builtins. But most executables work with help. As far as usage goes, its similar to help, but you have to type help after the command you want to inspect. For example, transmission-gtk help. Try it out, and see what options you can use with that executable etc.
### man ###
Most executables come with a formal documentation page. You can inspect it using the man command. You just enter man program, and see what it prints out. Pick any program on your computer, and try it out. For example, lets try man transmission-gtk. You get a file opened, split into categories. It gives you information what the program is, what it does, how you can use it etc., but it doesnt offer examples, as its not a tutorial.
And were stoping to a halt there.
Id like to take a minute and thank everyone commenting and contributing to this section. You make this series vastly better, and I hope that with your help, us noobs will be able to use the CLI basics by the end of summer (just in time for 13.2 :) ). You guys are the best. Newbie users like me, who are feeling lost, stick with it. It will pay off in the end!
And Id also like to add a formal heads up: part six will not come next Tuesday, as Ill sadly be away, so well see/hear each other in 14 days, on July 29th. And until then…
### …have a lot of fun! ###
--------------------------------------------------------------------------------
via: https://news.opensuse.org/2014/07/15/command-line-tuesdays-part-five/
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:
[2]:
[3]:
[4]:
[5]:
[6]:
[7]:
[8]:
[9]:
[10]:
[11]:
[12]:
[13]:
[14]:
[15]:
[16]:
[17]:
[18]:
[19]:
[20]:

View File

@ -0,0 +1,63 @@
命令行星期二-第五部分
=========================================================
对,你也许已经猜到了又是我们相见的时候了。这一次我们将会学习如何使用命令工作。因此,事不宜迟,我们直入正题吧。
肖茨先生指出到现在为止我们学习了一些神奇的命令及其参数和选项而今天正是我们揭开他们那神秘面纱一角的一天。我们将会学习如下的一些命令及其作用type, which, help和man。但是在此之前我么先学习一下...
###什么是命令?###
我们可以将**命令**分为四个种类。
**1可执行的程序**命令可以是一个可执行程序。如果你在前面的课程中有遍历过你的系统,这也是你应该做的。你也许已经发现了/user/bin这个目录你看到很多的像transmission-gtk, deluge-gtk等的名字。对我们新手来说现在这些可以编译成二进制文件或者用脚本语言编写的可执行程序具体是什么并不太重要。重点是他们是可执行文件你可以运行它们。找到/user/bin这个目录列出里面的文件随便挑一个去运行它。
**2shell内置命令** bash提供了一系列的shell内置命令例如cd命令就是一个shell内置命令。
**3shell函数**内置于系统环境中的小型的shell脚本。现在我们简单的提及一下它因为在后面的几个星期中我们将要学习它。
**4别名**你可以基于其他命令定义你自己的命令。我们也会在后面的课程中学习到。
现在,知道我们要处理的命令的哪一类是有意义的。我们可以使用**type**命令查看。
###type###
你可以使用**type + command**来查看你要使用的命令属于什么类型。你只要输入type command就可以得到命令类型的输出如下
![type mkdir](https://news.opensuse.org/wp-content/uploads/2014/07/Zaslonska-slika-2014-07-15-091448.png)
或者
![type ls](https://news.opensuse.org/wp-content/uploads/2014/07/Zaslonska-slika-2014-07-15-091640.png)
从上面例子可以看出ls命令实际上是_ls的别名。
###whitch###
有时虽然在桌面系统中很少会出现这种情况在一台机器中存在一个可执行程序的多个版本。为了找到某个可执行程序的准确位置我们可以使用which命令。whic命令只对可执行程序有用。
![which transmission-gtk](https://news.opensuse.org/wp-content/uploads/2014/07/Zaslonska-slika-2014-07-15-092052.png)
如今多数的命令都会附带说明文档因此当你在没有网络的的情况下使用命令行时你不能在论坛或者IRC上提问但是你又必须要知道某个命令的准确用法。此时你有两种解决方法第一个是。。。
###help###
help命令对shell内置命令有用在上面的第二类中我们有提到过。所以你可以选择一个shell内置命令为例如cd简单的输入help cd即可。你会得到一个有用的页面去试一下看cd为我们提供了什么功能。该页面列出了该命令的用法和可选项选项列在方括号中表明它们是可选的如果方括号中有垂直分隔符分隔某些选项则这些选项是互斥的不要同时使用他们
###-help###
help只对shell内置命令有用。但是很多的可执行程序有-help选项。其作用类似于help命令但是你必须在你要查看帮助的命令后输入 -help。例如transmission-gtk -help。试一下看在改该可执行程序中有什么可选项可以使用。
###man###
多数的可执行程序都提供一个正式发说明文档。你可以使用man命令查看这份说明文档。试一下只输入man program看有什么输出。在你的系统中随便找一个程序去尝试一下。例如我们试一下man transmission-gtk。你会打开了一个由目录分割的文件。这个文件包含该程序是什么、做什么和你可以怎样去使用它等的信息。但是这个文件并没有提供使用范例因为它不是一个指导手册。
这周我们就到先讲这里了。
我想再花一分钟来感谢大家对本节的建议和贡献。是你们让这个系列的文章变得越来越好,我希望在你们的帮助下,我们这些新用户在夏季结束前可以使用基本的命令行工具。你们是最棒的。像我一样的新用户们,我们都会感到失落,坚持到底,我们的付出总会有回报的!
最后我想再补充一个正式的提醒因为我会离开一段时间因此下周二的第六部分将会推迟。我们将会在14天后再会在7月29日。那时我们将会有更多的乐趣
--------------------------------------------------------
via: https://news.opensuse.org/2014/07/15/command-line-tuesdays-part-five/
译者:[cvsher](https://github.com/cvsher) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出