mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-25 00:50:15 +08:00
Merge pull request #1396 from cvsher/master
Command Line Tuesdays – Part Five 翻译完毕
This commit is contained in:
commit
88386ab53f
@ -1,89 +0,0 @@
|
||||
translating by cvsher
|
||||
Command Line Tuesdays – Part Five
|
||||
================================================================================
|
||||
Yes, you’ve guessed what time it is! It’s time to rrrrrrrrummmbleeeee! And this time, we’ll learn how to work with commands. So without further ado, let’s 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. We’ll learn the following commands and what they do: type, which, help and man. But first, let’s learn…
|
||||
|
||||
### …what are commands? ###
|
||||
|
||||
All great things come in fours, and it’s the same with commands. We can split them up into four categories:
|
||||
|
||||
**1) An executable program:** a command can be an executable program. If you’ve ‘traveled’ across your file system in the previous lessons like you were supposed to, you probably visited the /usr/bin folder. You’ve seen quite a number of familiar names like transmission-gtk, deluge-gtk etc. What’s 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, we’ll 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, it’s useful to know what type of command we’re dealing with. And we can find out using…
|
||||
|
||||
### …type ###
|
||||
|
||||
You can use **type + command** to inspect what kind of command is the command you’d like to use. You do it by simply typing: type command and you’ll get an output. For example:
|
||||
|
||||

|
||||
|
||||
or
|
||||
|
||||

|
||||
|
||||
…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.
|
||||
|
||||

|
||||
|
||||
Now, mostly every command has documentation that comes with it. So you’re somewhere doing your CLI thing, no access to the internet so you can’t 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. You’ll 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 (it’s in square brackets, which means they are optional! Also, if there’s a vertical separator inside the square brackets, it means the options mentioned are mutually exclusive. Don’t use them together!)
|
||||
|
||||
### –help ###
|
||||
|
||||
help works only for the shell builtins. But most executables work with –help. As far as usage goes, it’s 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, let’s 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 doesn’t offer examples, as it’s not a tutorial.
|
||||
|
||||
And we’re stoping to a halt there.
|
||||
|
||||
I’d 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 I’d also like to add a formal heads up: part six will not come next Tuesday, as I’ll sadly be away, so we’ll 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]:
|
63
translated/tech/Command Line Tuesdays – Part Five
Normal file
63
translated/tech/Command Line Tuesdays – Part Five
Normal file
@ -0,0 +1,63 @@
|
||||
命令行星期二-第五部分
|
||||
=========================================================
|
||||
对,你也许已经猜到了又是我们相见的时候了。这一次我们将会学习如何使用命令工作。因此,事不宜迟,我们直入正题吧。
|
||||
|
||||
肖茨先生指出,到现在为止,我们学习了一些神奇的命令及其参数和选项,而今天正是我们揭开他们那神秘面纱一角的一天。我们将会学习如下的一些命令及其作用:type, which, help和man。但是在此之前,我么先学习一下...
|
||||
|
||||
###什么是命令?###
|
||||
我们可以将**命令**分为四个种类。
|
||||
|
||||
**1)可执行的程序:**命令可以是一个可执行程序。如果你在前面的课程中有遍历过你的系统,这也是你应该做的。你也许已经发现了/user/bin这个目录,你看到很多的像transmission-gtk, deluge-gtk等的名字。对我们新手来说,现在这些可以编译成二进制文件或者用脚本语言编写的可执行程序具体是什么并不太重要。重点是,他们是可执行文件,你可以运行它们。找到/user/bin这个目录,列出里面的文件,随便挑一个去运行它。
|
||||
|
||||
**2)shell内置命令:** bash提供了一系列的shell内置命令,例如,cd命令就是一个shell内置命令。
|
||||
|
||||
**3)shell函数:**内置于系统环境中的小型的shell脚本。现在我们简单的提及一下它,因为在后面的几个星期中我们将要学习它。
|
||||
|
||||
**4)别名:**你可以基于其他命令定义你自己的命令。我们也会在后面的课程中学习到。
|
||||
|
||||
现在,知道我们要处理的命令的哪一类是有意义的。我们可以使用**type**命令查看。
|
||||
|
||||
###type###
|
||||
|
||||
你可以使用**type + command**来查看你要使用的命令属于什么类型。你只要输入type command就可以得到命令类型的输出,如下:
|
||||
|
||||

|
||||
|
||||
或者
|
||||
|
||||

|
||||
|
||||
从上面例子可以看出‘ls’命令实际上是‘_ls’的别名。
|
||||
|
||||
###whitch###
|
||||
有时(虽然在桌面系统中很少会出现这种情况),在一台机器中存在一个可执行程序的多个版本。为了找到某个可执行程序的准确位置,我们可以使用which命令。whic命令只对可执行程序有用。
|
||||
|
||||

|
||||
|
||||
如今,多数的命令都会附带说明文档,因此,当你在没有网络的的情况下使用命令行时,你不能在论坛或者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/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user