id
int64 2.05k
16.6k
| title
stringlengths 5
75
| fromurl
stringlengths 19
185
| date
timestamp[s] | tags
sequencelengths 0
11
| permalink
stringlengths 20
37
| content
stringlengths 342
82.2k
| fromurl_status
int64 200
526
⌀ | status_msg
stringclasses 339
values | from_content
stringlengths 0
229k
⌀ |
---|---|---|---|---|---|---|---|---|---|
7,900 | 通过 AWS 的 Lambda 和 API Gateway 走向 Serverless | http://blog.ryankelly.us/2016/08/07/going-serverless-with-aws-lambda-and-api-gateway.html | 2016-10-26T11:01:00 | [
"serverless"
] | https://linux.cn/article-7900-1.html | 近来,在计算领域出现了很多关于 serverless 的讨论。serverless 是一个概念,它允许你提供代码或可执行程序给某个服务,由服务来为你执行它们,而你无需自己管理服务器。这就是所谓的<ruby> 执行即服务 <rp> ( </rp> <rt> execution-as-a-service </rt> <rp> ) </rp></ruby>,它带来了很多机会,同时也遇到了它独有的挑战。
### 简短回忆下计算领域的发展
早期,出现了……好吧,这有点复杂。很早的时候,出现了机械计算机,后来又有了埃尼阿克 ENIAC(Electronic Numerical Integrator And Computer,很早的电子计算机),但是都没有规模生产。直到大型机出现后,计算领域才快速发展。

* 上世纪 50 年代 - 大型机
* 上世纪 60 年代 - 微型机
* 1994 - 机架服务器
* 2001 - 刀片服务器
* 本世纪初 - 虚拟服务器
* 2006 - 服务器云化
* 2013 - 容器化
* 2014 - serverless(计算资源服务化)
>
> 这些日期是大概的发布或者流行日期,无需和我争论时间的准确性。
>
>
>
计算领域的演进趋势是执行的功能单元越来越小。每一次演进通常都意味着运维负担的减小和运维灵活性的增加。
### 发展前景
喔,Serverless!但是,serverless 能给我们带来什么好处? 我们将面临什么挑战呢?
**未执行代码时无需付费。**我认为,这是个巨大的卖点。当无人访问你的站点或用你的 API 时,你无需付钱。没有持续支出的基础设施成本,仅仅支付你需要的部分。换句话说,这履行了云计算的承诺:“仅仅支付你真正用的资源”。
**无需维护服务器,也无需考虑服务器安全。**服务器的维护和安全将由你的服务提供商来处理(当然,你也可以架设自己的 serverless 主机,只是这似乎是在向错误的方向前进)。由于你的执行时间也是受限的,安全补丁也被简化了,因为完全不需要重启。这些都应该由你的服务提供商无缝地处理。
**无限的可扩展性。**这是又一个大的好处。假设你又开发了一个 Pokemon Go, 与其频繁地把站点下线维护升级,不如用 serverless 来不断地扩展。当然,这也是个双刃剑,大量的账单也会随之而来。如果你的业务的利润强依赖于站点上线率的话,serverless 确实能帮上忙。
**强制的微服务架构。**这也有两面性,一方面,微服务似乎是一种好的构建灵活可扩展的、容错的架构的方式。另一方面,如果你的业务没有按照这种方式设计,你将很难在已有的架构中引入 serverless。
### 但是现在你被限制在**他们的**平台上
**受限的环境。**你只能用服务提供商提供的环境,你想在 Rust 中用 serverless?你可能不会太幸运。
**受限的预装包。**你只有提供商预装的包。但是你或许能够提供你自己的包。
**受限的执行时间。**你的 Function 只可以运行这么长时间。如果你必须处理 1TB 的文件,你可能需要有一个解决办法或者用其他方案。
**强制的微服务架构。**参考上面的描述。
**受限的监视和诊断能力。**例如,你的代码**在**干什么? 在 serverless 中,基本不可能在调试器中设置断点和跟踪流程。你仍然可以像往常一样记录日志并发出统计度量,但是这带来的帮助很有限,无法定位在 serverless 环境中发生的难点问题。
### 竞争领域
自从 2014 年出现 AWS Lambda 以后,serverless 的提供商已经增加了一些。下面是一些主流的服务提供商:
* AWS Lambda - 起步最早的
* OpenWhisk - 在 IBM 的 Bluemix 云上可用
* Google Cloud Functions
* Azure Functions
这些平台都有它们的相对优势和劣势(例如,Azure 支持 C#,或者紧密集成在其他提供商的平台上)。这里面最大的玩家是 AWS。
### 通过 AWS 的 Lambda 和 API Gateway 构建你的第一个 API
我们来试一试 serverless。我们将用 AWS Lambda 和 API Gateway 来构建一个能返回 [Jimmy](http://blog.ryankelly.us/2016/07/11/jimmy.html) 所说的“Guru Meditations”的 API。
所有代码在 [GitHub](https://github.com/f0rk/meditations) 上可以找到。
API文档:
```
POST /
{
"status": "success",
"meditation": "did u mention banana cognac shower"
}
```
### 怎样组织工程文件
文件结构树:
```
.
├── LICENSE
├── README.md
├── server
│ ├── __init__.py
│ ├── meditate.py
│ └── swagger.json
├── setup.py
├── tests
│ └── test_server
│ └── test_meditate.py
└── tools
├── deploy.py
├── serve.py
├── serve.sh
├── setup.sh
└── zip.sh
```
AWS 中的信息(想了解这里究竟在做什么的详细信息,可查看源码 `tools/deploy.py`)。
* **API。**实际构建的对象。它在 AWS 中表示为一个单独的对象。
* **执行角色。**在 AWS 中,每个 Function 作为一个单独的角色执行。在这里就是 meditations。
* **角色策略。**每个 Function 作为一个角色执行,每个角色需要权限来干活。我们的 Lambda Function 不干太多活,故我们只添加一些日志记录权限。
* **Lambda Function。**运行我们的代码的地方。
* **Swagger。** Swagger 是 API 的规范。API Gateway 支持解析 swagger 的定义来为 API 配置大部分资源。
* **部署。**API Gateway 提供部署的概念。我们只需要为我们的 API 用一个就行(例如,所有的都用生产或者 yolo等),但是得知道它们是存在的,并且对于真正的产品级服务,你可能想用开发和暂存环境。
* **监控。**在我们的业务崩溃的情况下(或者因为使用产生大量账单时),我们想以云告警查看方式为这些错误和费用添加一些监控。注意你应该修改 `tools/deploy.py` 来正确地设置你的 email。
### 代码
Lambda Function 将从一个硬编码列表中随机选择一个并返回 guru meditations,非常简单:
```
import logging
import random
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def handler(event, context):
logger.info(u"received request with id '{}'".format(context.aws_request_id))
meditations = [
"off to a regex/",
"the count of machines abides",
"you wouldn't fax a bat",
"HAZARDOUS CHEMICALS + RKELLY",
"your solution requires a blood eagle",
"testing is broken because I'm lazy",
"did u mention banana cognac shower",
]
meditation = random.choice(meditations)
return {
"status": "success",
"meditation": meditation,
}
```
### deploy.py 脚本
这个脚本相当长,我没法贴在这里。它基本只是遍历上述“AWS 中的信息”下的项目,确保每项都存在。
### 我们来部署这个脚本
只需运行 `./tools/deploy.py`。
基本完成了。不过似乎在权限申请上有些问题,由于 API Gateway 没有权限去执行你的 Function,所以你的 Lambda Function 将不能执行,报错应该是“Execution failed due to configuration error: Invalid permissions on Lambda function”。我不知道怎么用 botocore 添加权限。你可以通过 AWS console 来解决这个问题,找到你的 API, 进到 `/POST` 端点,进到“integration request”,点击“Lambda Function”旁边的编辑图标,修改它,然后保存。此时将弹出一个窗口提示“You are about to give API Gateway permission to invoke your Lambda function”, 点击“OK”。
当你完成后,记录下 `./tools/deploy.py` 打印出的 URL,像下面这样调用它,然后查看你的新 API 的行为:
```
$ curl -X POST https://a1b2c3d4.execute-api.us-east-1.amazonaws.com/prod/
{"status": "success", "meditation": "the count of machines abides"}
```
### 本地运行
不幸的是,AWS Lambda 没有好的方法能在本地运行你的代码。在这个例子里,我们将用一个简单的 flask 服务器来在本地托管合适的端点,并调用 handler 函数。
```
from __future__ import absolute_import
from flask import Flask, jsonify
from server.meditate import handler
app = Flask(__name__)
@app.route("/", methods=["POST"])
def index():
class FakeContext(object):
aws_request_id = "XXX"
return jsonify(**handler(None, FakeContext()))
app.run(host="0.0.0.0")
```
你可以在仓库中用 `./tools/serve.sh` 运行它,像这样调用:
```
$ curl -X POST http://localhost:5000/
{
"meditation": "your solution requires a blood eagle",
"status": "success"
}
```
### 测试
你总是应该测试你的代码。我们的测试方法是导入并运行我们的 handler 函数。这是最基本的 python 测试方法:
```
from __future__ import absolute_import
import unittest
from server.meditate import handler
class SubmitTestCase(unittest.TestCase):
def test_submit(self):
class FakeContext(object):
aws_request_id = "XXX"
response = handler(None, FakeContext())
self.assertEquals(response["status"], "success")
self.assertTrue("meditation" in response)
```
你可以在仓库里通过 nose2 运行这个测试代码。
### 更多前景
* **和 AWS 服务的无缝集成。**通过 boto,你可以完美地轻易连接到任何其他的 AWS 服务。你可以轻易地让你的执行角色用 IAM 访问这些服务。你可以从 S3 取文件或放文件到 S3,连接到 Dynamo DB,调用其他 Lambda Function,等等。
* **访问数据库。**你也可以轻易地访问远程数据库。在你的 Lambda handler 模块的最上面连接数据库,并在handler 函数中执行查询。你很可能必须从它的安装位置上传相关的包内容才能使它正常工作。可能你也需要静态编译某些库。
* **调用其他 webservices。**API Gateway 也是一种把 webservices 的输出从一个格式转换成另一个格式的方法。你可以充分利用这个特点通过不同的 webservices 来代理调用,或者当业务变更时提供后向兼容能力。
---
via: <http://blog.ryankelly.us/2016/08/07/going-serverless-with-aws-lambda-and-api-gateway.html>
作者:[Ryan Kelly](https://github.com/f0rk/blog.ryankelly.us/) 译者:[messon007](https://github.com/messon007) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # Going Serverless with AWS Lambda and API Gateway
### 07 August 2016
Lately, there's been a lot of buzz in the computing world about "serverless". Serverless is a concept wherein you don't manage any servers yourself but instead provide your code or executables to a service that executes them for you. This is execution-as-a-service. It introduces many opportunities and also presents its own unique set of challenges.
## A brief digression on computing
In the beginning, there was... well. It's a little complicated. At the very beginning, we had mechanical computers. Then along came ENIAC. Things really don't start to get "mass production", however, until the advent of mainframes.
- 1950s - Mainframes
- 1960s - Minicomputers
- 1994 - Rack servers
- 2001 - Blade servers
- 2000s - Virtual servers
- 2006 - Cloud servers
- 2013 - Containers
- 2014 - Serverless
These are rough release/popularity dates. Argue amongst yourselves about the timeline.
The progression here seems to be a trend toward executing smaller and smaller units of functionality. Each step down generally represents a decrease in the operational overhead and an increase in the operational flexibility.
## The possibilities
Yay! Serverless! But. What advantages do we gain by going serverless? And what challenges do we face?
**No billing when there is no execution.** In my mind,
this is a huge selling point. When no one is using your
site or your API, you aren't paying for. No ongoing
infrastructure costs. Pay only for what you need. In some
ways, this is the fulfillment of the cloud computing
promise "pay only for what you use".
**No servers to maintain or secure.** Server maintenance
and security is handled by your vendor (you could, of
course, host serverless yourself, but in some ways this
seems like a step in the wrong direction). Since your
execution times are also limited, the patching of security
issues is also simplified since there is nothing to
restart. This should all be handled seamlessly by your
vendor.
**Unlimited scalability.** This is another big one.
Let's say you write the next Pokémon Go. Instead of your
site being down every couple of days, serverless lets you
just keep growing and growing. A double-edged sword, for
sure (with great scalability comes great... bills), but if
your service's profitability depends on being up, then
serverless can help enable that.
**Forced microservices architecture.** This one really
goes both ways. Microservices seem to be a good way to
build flexible, scalable, and fault-tolerant architectures.
On the other hand, if your business' services aren't
designed this way, you're going to have difficulty adding
serverless into your existing architecture.
## But now your stuck on *their* platform
**Limited range of environments.** You get what the
vendor gives. You want to go serverless in Rust? You're
probably out of luck.
**Limited preinstalled packages.** You get what the
vendor pre-installs. But you may be able to supply your
own.
**Limited execution time.** Your function can only run
for so long. If you have to process a 1TB file you will
likely need to 1) use a work around or 2) use something
else.
**Forced microservices architecture.** See above.
**Limited insight and ability to instrument.** Just what
**is** your code doing? With serverless, it is basically
impossible to drop in a debugger and ride along. You still
have the ability to log and emit metrics the usual way but
these generally can only take you so far. Some of the most
difficult problems may be out of reach when the occur in a
serverless environment.
## The playing field
Since the introduction of AWS Lambda in 2014, the number of offerings has expanded quite a bit. Here are a few popular ones:
- AWS Lambda - The Original
- OpenWhisk - Available on IBM's Bluemix cloud
- Google Cloud Functions
- Azure Functions
While all of these have their relative strengths and weaknesses (like, C# support on Azure or tight integration on any vendor's platform) the biggest player here is AWS.
## Building your first API with AWS Lambda and API Gateway
Let's give serverless a whirl, shall we? We'll be using AWS
Lambda and API Gateway offerings to build an API that
returns "Guru Meditations" as spoken by [Jimmy](/2016/07/11/jimmy.html).
All of the code is available on
[GitHub](https://github.com/f0rk/meditations).
API Documentation:
POST / { "status": "success", "meditation": "did u mention banana cognac shower" }
## How we'll structure things
The layout:
. ├── LICENSE ├── README.md ├── server │ ├── __init__.py │ ├── meditate.py │ └── swagger.json ├── setup.py ├── tests │ └── test_server │ └── test_meditate.py └── tools ├── deploy.py ├── serve.py ├── serve.sh ├── setup.sh └── zip.sh
Things in AWS (for a more detailed view as to what is
happening here, consult the source of
`tools/deploy.py`
):
-
**API.**The thing that were actually building. It is represented as a separate object in AWS. -
**Execution Role.**Every function executes as a particular role in AWS. Ours will be meditations. -
**Role Policy.**Every function executes as a role, and every role needs permission to do things. Our lambda function doesn't do much, so we'll just add some logging permissions. -
**Lambda Function.**The thing that runs our code. -
**Swagger.**Swagger is a specification of an API. API Gateway supports consuming a swagger definition to configure most resources for that API. -
**Deployments.**API Gateway provides for the notion of deployments. We won't be using more than one of these for our API here (i.e., everything is production, yolo, etc.), but know that they exist and for a real production-ready service you will probably want to use development and staging environments. -
**Monitoring.**In case our service crashes (or begins to accumulate a hefty bill from usage) we'll want to add some monitoring in the form of cloudwatch alarms for errors and billing. Note that you should modify`tools/deploy.py`
to set your email correctly.
## the codes
The lambda function itself will be returning guru meditations at random from a hardcoded list and is very simple:
import logging import random logger = logging.getLogger() logger.setLevel(logging.INFO) def handler(event, context): logger.info(u"received request with id '{}'".format(context.aws_request_id)) meditations = [ "off to a regex/", "the count of machines abides", "you wouldn't fax a bat", "HAZARDOUS CHEMICALS + RKELLY", "your solution requires a blood eagle", "testing is broken because I'm lazy", "did u mention banana cognac shower", ] meditation = random.choice(meditations) return { "status": "success", "meditation": meditation, }
## The `deploy.py`
script
This one is rather long (sadly) and I won't be including it here. It basically goes through each of the items under "Things in AWS" and ensures each item exists.
There is a caveat here: If you have just created your AWS
account, sending email with SES (Simple Email Service) will
not yet be available. Presumably, this is to limit the use
of SES as a platform for spammers. As a result, the
monitoring portions of the deploy script will fail with an
error like "An error occurred (OptInRequired) when calling
the PutMetricAlarm operation: The AWS Access Key Id needs a
subscription for the service". This will work itself out if
you wait for a day or so. For the time being, you can
comment out the related code in
`tools/deploy.py`
(around lines 211-273).
## Let's deploy this shit
Just run `./tools/deploy.py`
.
Well. Almost. There seems to be some issue applying
privileges that I can't seem to figure out. Your lambda
function will fail to execute because API Gateway does not
have permissions to execute your function. The specific
error should be "Execution failed due to configuration
error: Invalid permissions on Lambda function". I am not
sure how to add these using botocore. You can work around
this issue by going to the AWS console (sadness), locating
your API, going to the `/ POST`
endpoint, going
to integration request, clicking the pencil icon next to
"Lambda Function" to edit it, and then saving it. You'll
get a popup stating "You are about to give API Gateway
permission to invoke your Lambda function". Click "OK".
When you're finished with that, take the URL that
`./tools/deploy.py`
printed and call it like so
to see your new API in action:
$ curl -X POST https://a1b2c3d4.execute-api.us-east-1.amazonaws.com/prod/ {"status": "success", "meditation": "the count of machines abides"}
## Running Locally
One unfortunate thing about AWS Lambda is that there isn't really a good way to run your code locally. In our case, we will use a simple flask server to host the appropriate endpoint locally and handle calling our handler function:
from __future__ import absolute_import from flask import Flask, jsonify from server.meditate import handler app = Flask(__name__) @app.route("/", methods=["POST"]) def index(): class FakeContext(object): aws_request_id = "XXX" return jsonify(**handler(None, FakeContext())) app.run(host="0.0.0.0")
You can run this in the repo with
`./tools/serve.sh`
. Invoke like:
$ curl -X POST http://localhost:5000/ { "meditation": "your solution requires a blood eagle", "status": "success" }
## Testing
You should always test your code. The way we'll be doing this is importing and running our handler function. This is really just plain vanilla python testing:
from __future__ import absolute_import import unittest from server.meditate import handler class SubmitTestCase(unittest.TestCase): def test_submit(self): class FakeContext(object): aws_request_id = "XXX" response = handler(None, FakeContext()) self.assertEquals(response["status"], "success") self.assertTrue("meditation" in response)
You can run the tests in the repo with `nose2`
.
## Other possibilities
**Seamless integration with AWS services.** Using boto,
you can pretty simply connect to any of AWS other services.
You simply allow your execution role access to these
services using IAM and you're on your way. You can get/put
files from S3, connect to Dynamo DB, invoke other lambda
functions, etc. etc. The list goes on.
**Accessing a database.** You can easily access remote
databases as well. Connect to the database at the top of
your lambda handler's module. Execute queries on the
connection from within the handler function itself. You
will (very likely) have to upload the associated package
contents from where it is installed locally for this to
work. You may also need to statically compile certain
libraries.
**Calling other webservices.** API Gateway is also a way
to translate the output from one web service into a
different form. You can take advantage of this to proxy
calls through to a different webservice or provide
backwards compatibility when a service changes. |
7,901 | 开发者的实用 Vim 插件(一) | https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers/ | 2016-10-26T11:53:00 | [
"插件",
"Vim"
] | https://linux.cn/article-7901-1.html | 作为 Vi 的升级版,[Vim](http://www.vim.org/) 毫无争议是 Linux 中最受欢迎的命令行编辑器之一。除了是一个多功能编辑器外,世界各地的软件开发者将 Vim 当做 IDE(<ruby> 集成开发环境 <rp> ( </rp> <rt> Integrated Development Environment </rt> <rp> ) </rp></ruby>)来使用。

事实上,因为 Vim 可以通过插件来扩展其自身功能才使得它如此功能强大。不用说,肯定有那么几个 Vim 插件是旨在提高用户的编程体验的。
特别是对于刚刚使用 Vim 或者使用 Vim 做开发的的软件开发者来说,我们将在本教程中讨论一些非常有用的 Vim 插件,具体请看例示。
请注意:本教程中列举的所有例示、命令和说明都是在 Ubuntu 16.04 环境下进行测试的,并且,我们使用的 Vim 版本是 7.4。
### 插件安装设置
这是为新用户准备的,假设他们不知道如何安装 Vim 插件。所以,首先,就是给出一些完成安装设置的步骤。
* 在你的家目录下创建 `.vim` 目录,并在其中创建子目录 `autoload` 和 `bundle`。
* 然后,在 `autoload` 放置 [pathogen.vim](http://www.vim.org/scripts/script.php?script_id=2332) 文件,这个文件可以从[此处](https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim) 下载。
* 最后,在你的家目录创建 `.vimrc` 文件,并添加以下内容。
```
call pathogen#infect()
```

至此,你已完成了 Vim 插件安装的准备工作。
注意:我们已经讨论了使用 Pathogen 管理 Vim 插件。当然还有其他的插件管理工具——欲了解,请访问[此处](http://vi.stackexchange.com/questions/388/what-is-the-difference-between-the-vim-plugin-managers)。
现在已经全部设置完毕,就让我们来讨论两个好用的 Vim 插件吧。
### Vim 标签侧边栏(Tagbar)插件
首先就是标签侧边栏(Tagbar)插件。该插件能够让你浏览源文件包含的标签,从而提供该源文件的结构简览。[其官网的插件说明](http://majutsushi.github.io/tagbar/)是这样说的:“它通过创建侧边栏,然后以一定顺序展示从当前文件以 ctags 提取的标签来完成这一功能。这意味着,比如,C++ 中的方法将展示在其自身所定义在的类里边。”
听起来很酷,不是吗?让我们来看看该怎么安装它。
标签侧边栏(Tagbar)的安装过程是相当容易的——你只需要运行下列命令:
```
cd ~/.vim/bundle/
git clone git://github.com/majutsushi/tagbar
```
安装完之后就可以使用了,你可以在 Vim 中打开一个 .cpp 文件来测试它:进入[命令模式](http://www.tldp.org/LDP/intro-linux/html/sect_06_02.html),然后运行 `:TagbarOpen` 命令。以下是运行 `:TagbarOpen` 命令之后出现侧边栏(右侧) 的效果图。
[](https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/big/vimplugins-tagbar-example.png)
使用 `:TagbarClose` 可以关闭侧边栏。值得一提的是,可以使用 `:TagbarOpen fj` 命令打开侧边栏来打开它的跳转(shift control)功能。也就是说,你可以很方便的浏览当前文件包含的标签——在对应的标签上按下 Enter 键,然后在左侧的源代码窗口跳转到对应的位置。

假如你想要反复地开关侧边栏,你可以使用 `:TagbarToggle` 命令,而不用交替的使用 `:TagbarOpen` 和 `:TagbarClose` 命令。
如果你觉得输入这些命令很费时间,你可以为 `:TagbarToggle` 命令创建快捷键。比如,添加以下内容到 `.vimrc` 文件中:
```
nmap <F8> :TagbarToggle<CR>
```
这样,你就可以用 F8 来切换标签侧边栏(Tagbar)了。
更进一步,有时候你可能会注意到某个标签前边有一个 `+`、`-` 或者 `#` 符号。比如,以下截图(取自该插件的官网)展示了一些前边有 `+` 号的标签。

这些符号基本是用来表明一个特定标签的可见性信息。特别是 `+` 表示该类是 public 的,而 `-` 表示一个 private 类。`#` 则是表示一个 protected 类。
以下是使用标签侧边栏(Tagbar)的一些注意事项:
* 该插件的官网早就有说明:“标签侧边栏(Tagbar)并非是管理标签(tags)文件而设计,它只是在内存中动态创建所需的标签,而非创建任何文件。标签(tags)文件的管理有其他插件提供支持。”
* 低于 7.0.167 版本的 Vim 和标签侧边栏(Tagbar)插件存在着一个兼容性问题。根据官网:“如果你受到此问题的影响,请使用代替版:[下载 zip 压缩包](https://github.com/majutsushi/tagbar/zipball/70fix)。这对应到 2.2 版本,但由于大量的依赖变更,它可能不会再升级。”
* 如果你在加载该插件时遇到这样的错误:未找到 ctags!(Tagbar: Exuberant ctags not found!)。你可以从 [此处](http://ctags.sourceforge.net/)下载并安装 ctags 来修复错误。
* 获取更多信息请访问 [这里](https://github.com/majutsushi/tagbar)。
### Vim 界定符自动补齐(delimitMate)插件
下一个要介绍的插件就是界定符自动补齐(delimitMate)。该插件在 Vim 插入模式下提供引号、圆括号和方括号等界定符自动补齐功能。
[该插件官网](https://github.com/Raimondi/delimitMate)说:“它同时也提供一些相关的特性让你在输入模式下变得更加便捷,比如语法纠错(在注释区或者其他的可配置区不会自动插入结束界定符)、回车和空格填充(默认关闭)等。”
安装步骤与之前介绍的相似:
```
cd ~/.vim/bundle/
git clone git://github.com/Raimondi/delimitMate.git
```
一旦你成功安装这个插件(即上述命令执行成功),你就不需要进行任何配置了——当 Vim 启动时会自动加载这个插件。
至此,在你使用 Vim 的任何时候,只要你输入一个双引号、单引号、单号、圆括号、方括号,它们都会自动补齐。
你可以自己配置界定符自动补齐(delimitMate)。比如,你可以添加需要自动补齐的符号列表,阻止自动加载该插件,对指定类型文件关闭该插件等。想了解如何配置这些(或者其他更多的配置),请阅读该插件的详细文档——运行 `:help delimitMate` 即可。
上述命令会将你的 Vim 窗口水平分割成两个,上边一个包含我们所说的文档。

### 结论
本文之中提到的两个插件,Tagbar 需要花费较多时间来适应——你应该会同样这个说法。但只要正确设置好它(这意味着你像是有了快捷键一样方便),就容易使用了。至于 delimitMate,不需要任何要求就可以上手。
本教程就是向你展示 Vim 如何高效能的想法。除了本文中提及的,仍然还有许多开发者可用的插件,我们将在下一个部分进行讨论。假如你正在使用一个关于开发的 Vim 插件,并希望广为人知,请在下方留下评论。
我们将在本教程的第二部分讲到 [语法高亮插件:Syntastic](https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-2-syntastic/)。
---
via: <https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers/>
作者:[Ansh](https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers/) 译者:[GHLandy](https://github.com/GHLandy) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # Useful Vim editor plugins for software developers - part 1
An improved version of Vi, [Vim](http://www.vim.org/) is unarguably one of the most popular command line-based text editors in Linux. Besides being a feature-rich text editor, Vim is also used as an IDE (Integrated Development Environment) by software developers around the world.
What makes Vim really powerful is the fact that it's functionality can be extended through plugins. And needless to say, there exist several Vim plugins that are aimed at enhancing users' programming experience.
Especially for software developers who are new to Vim, and are using the editor for development purposes, we'll be discussing some useful Vim plugins - along with examples - in this tutorial.
Please note that all the examples, commands, and instructions mentioned in this tutorial have been tested on Ubuntu 16.04, and the Vim version we've used is 7.4.
## Plugin installation setup
Given that the tutorial is aimed at new users, it would be reasonable to assume that they don't know how Vim plugins are installed. So, first up, here are the steps required to complete the installation setup:
- Create a directory dubbed
*.vim*in your home directory, and then create two sub-directories named*autoload*and*bundle*. - Then, inside the
*autoload*directory, you need to place a file named, which you can download from*pathogen.vim*[here](https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim). - Finally, create a file named
*.vimrc*in your home directory and add the following two lines to it:
call pathogen#infect()
call pathogen#helptags()
That's it. You are now ready to install Vim plugins.
**Note**: Here we've discussed Vim plugin management using Pathogen. There are other plugin managers available as well - to get started, visit [this thread](http://vi.stackexchange.com/questions/388/what-is-the-difference-between-the-vim-plugin-managers).
Now that we are all set, let's discuss a couple of useful Vim plugins.
## Vim Tagbar plugin
First up is the Tagbar plugin. This plugin gives you an overview of the structure of a source file by letting you browse the tags it contains. "It does this by creating a sidebar that displays the ctags-generated tags of the current file, ordered by their scope," the [plug-in's official website](http://majutsushi.github.io/tagbar/) says. "This means that for example methods in C++ are displayed under the class they are defined in."
Sounds cool, right? Now, lets see how you can install it.
Tagbar's installation is pretty easy - all you have to do is to run the following two commands:
cd ~/.vim/bundle/
git clone git://github.com/majutsushi/tagbar
After the plugin is installed, it's ready for use. You can test it out by opening a .cpp file in Vim, entering [the command mode](http://www.tldp.org/LDP/intro-linux/html/sect_06_02.html), and running the **:TagbarOpen** command. Following is an example screenshot showing the sidebar (towards right) that comes up when the **:TagbarOpen** Vim command was executed:
To close the sidebar, use the **:TagbarClose** command. What's worth mentioning here is that you can use the **:TagbarOpen fj** command to open the sidebar as well as shift control to it. This way, you can easily browse the tags it contains - pressing the Enter key on a tag brings up (and shifts control to) the corresponding function in the source code window on the left.
In case you want to repeatedly open and close the sidebar, you can use the **:TagbarToggle** command instead of using **:TagbarOpen** and **:TagbarClose**, respectively.
If typing these commands seems time consuming to you, then you can create a shortcut for the **:TagbarToggle** command. For example, if you put the following line in your *.vimrc* file:
nmap <F8> :TagbarToggle<CR>
then you can use the F8 key to toggle the Tagbar plugin window.
Moving on, sometimes you'll observe that certain tags are pre-fixed with a +, -, or `#`
symbol. For example, the following screenshot (taken from the plugin's official website) shows some tags prefixed with a + symbol.
These symbols basically depict the visibility information for a particular tag. Specifically, `+`
indicates that the member is public, while - indicates a private member. The `#`
symbol, on the other hand, indicates that the member is protected`.`
`Following are some of the important points related to Tagbar:`
- The plugin website makes it clear that "Tagbar is not a general-purpose tool for managing
`tags`
files. It only creates the tags it needs on-the-fly in-memory without creating any files.`tags`
file management is provided by other plugins." - Vim versions < 7.0.167 have a compatibility issue with Tagbar. "If you are affected by this use this alternate Tagbar download instead:
[zip](https://github.com/majutsushi/tagbar/zipball/70fix)," the website says. "It is on par with version 2.2 but probably won't be updated after that due to the amount of changes required." - If you encounter the error
*Tagbar: Exuberant ctags not found!*while launching the plugin, then you can fix it by downloading and installing ctags from[here](http://ctags.sourceforge.net/). - For more information on Tagbar, head
[here](https://github.com/majutsushi/tagbar).
## Vim delimitMate Plugin
The next plugin we'll be discussing here is delimitMate. The plugin basically provides insert mode auto-completion for quotes, parens, brackets, and more.
It also offers "some other related features that should make your time in insert mode a little bit easier, like syntax awareness (will not insert the closing delimiter in comments and other configurable regions), and expansions (off by default), and some more," the [plugin's official github page](https://github.com/Raimondi/delimitMate) says.
Installation of this plugin is similar to the way we installed the previous one:
cd ~/.vim/bundle/
git clone git://github.com/Raimondi/delimitMate.git
Once the plugin is installed successfully (meaning the above commands are successful), you don't have to do anything else - it loads automatically when the Vim editor is launched.
Now, whenever - while in Vim - you type a double quote, single quote, brace, parentheses, or bracket, they'll be automatically completed.
The delimitMate plugin is configurable. For example, you can extend the list of supported symbols, prevent the plugin from loading automatically, turns off the plugin for certain file types, and more. To learn how to configure delimitMate to do all this (and much more), go through the plugin's detailed documentation, which you can access by running the **:help delimitMate** command.
The aforementioned command will split your Vim window horizontally into two, with the upper part containing the said documentation.
## Conclusion
Of the two plugins mentioned in this article, Tagbar - you'll likely agree - requires comparatively more time to get used to. But once it's setup properly (meaning you have things like shortcut launch keys in place), it's a breeze to use. delimitMate, on the other hand, doesn't require you to remember anything.
The tutorial would have given you an idea how useful Vim plugins can be. Apart from the ones discussed here, there are many more plugins available for software developers. We'll discuss a selected bunch in the next part. Meanwhile, drop in a comment if you use a cool development-related Vim plugin and want others to know about it.
In part 2 of this tutorial series I will cover the [Syntax highlighting plugin Syntastic](https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-2-syntastic/). |
7,904 | NitroShare:内网多操作系统间快捷文件共享工具 | http://www.tecmint.com/nitroshare-share-files-between-linux-ubuntu-windows/ | 2016-10-27T10:15:44 | [
"NitroShare",
"共享",
"局域网"
] | https://linux.cn/article-7904-1.html | 网络的最重要用途之一就是实现文件共享的目的。现在,虽然有多种方式可以让在同一网络中的 Linux 和 Windows 以及 MacOS X 用户之间共享文件,但这篇文章,我们只打算介绍 NitroShare。这是一款跨平台、[开源](https://github.com/nitroshare/nitroshare-desktop)以及易于使用的应用软件,可以在本地网络(内网)中共享文件。

NitroShare 大大简化了本地网络的文件共享操作,一旦安装上,它就会与操作系统无缝集成。Ubuntu 系统中,从应用程序显示面板中可以简单的打开,在 Windows 系统中,在系统托盘中可以找到它。
此外,在装有 NitroShare 的机器上,它会自动检测在同一网段的其它安装了它的设备,用户只需选择好需要传输到的设备,就可以直接向其传输文件。
NitroShare 的特性如下:
* 跨平台,即可以运行于 Linux, Windows 和 MacOS X 系统
* 设置容易,无需配置
* 易于使用
* 支持在本地网络上自动发现运行着 Nitroshare 设备的能力
* 安全性上支持可选的 TLS (<ruby> 传输层安全协议 <rp> ( </rp> <rt> Transport Layer Security </rt> <rp> ) </rp></ruby>) 编码传输方式
* 支持网络高速传输功能
* 支持文件和目录(Windows 上的文件夹)传输
* 支持对发送文件、连接设备等这些的桌面通知功能
最新版本的 NitroShare 是使用 Qt5 开发的,它做了一些重大的改进,例如:
* 用户界面焕然一新
* 简化设备发现过程
* 移除不同版本传输文件大小的限制
* 为了使用方便,已经去除配置向导
### Linux 系统中安装 Nitroshare
NitroShare 可运行于各种各样的现代 Linux 发行版和桌面环境。
#### Debian Sid 和 Ubuntu 16.04+
NitroShare 已经包含在 Debian 和 Ubuntu 的软件源仓库中,所以可以很容易的就安装上,使用如下命令:
```
$ sudo apt-get install nitroshare
```
但安装的版本可能已经过期了。要安装最新的版本的话,可按照如下的命令添加最新的 PPA。
```
$ sudo apt-add-repository ppa:george-edison55/nitroshare
$ sudo apt-get update
$ sudo apt-get install nitroshare
```
#### Fedora 24-23
最近,NitroShare 已经包含在 Fedora 源仓库中了,可以按如下命令安装:
```
$ sudo dnf install nitroshare
```
#### Arch Linux
在 Arch Linux 系统中,NitroShare 包在 AUR 上已经可用了,可以用如下命令来构建/安装:
```
# wget https://aur.archlinux.org/cgit/aur.git/snapshot/nitroshare.tar.gz
# tar xf nitroshare.tar.gz
# cd nitroshare
# makepkg -sri
```
### Linux 中使用 NitroShare
注意:如我前面所述,在本地网络中,您想要共享文件的其它机器设备都需要安装上 NitroShare 并运行起来。
在成功安装后,在系统 dash 面板里或系统菜单里搜索 NitroShare,然后启动。NitroShare 非常容易使用,你可从该应用或托盘图标上找到“发送文件”、“发送目录”、“查看传输”等选项。

选择文件后,点击“打开”继续选择目标设备,如下图所示。如果在本地网络有设备正的运行 NitroShare 的话,选择相应的设备然后点击“确定”。


如果需要,在 NitroShare 的配置 -- 通用标签页里,您可以增加设备的名字,设置默认文件下载位置,在高级设置里您能设置端口、缓存、超时时间等等。
主页:<https://nitroshare.net/index.html>
这就是所要介绍的,如果您有关于 Nitroshare 的任何问题,可以在下面的评论区给我们分享。您也可以给我们提供一些建议,告诉一些可能我们不知道的很不错的跨平台文件共享应用程序。
---
via: <http://www.tecmint.com/nitroshare-share-files-between-linux-ubuntu-windows/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[runningwater](https://github.com/runningwater) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,905 | 解决 Linux 内核代码审查人员短缺问题 | https://opensource.com/business/16/10/linux-kernel-review | 2016-10-27T11:17:16 | [
"内核",
"代码审核"
] | https://linux.cn/article-7905-1.html | 操作系统安全是[现在最重要的事情](http://www.infoworld.com/article/3124432/linux/is-the-linux-kernel-a-security-problem.html),而 Linux 则是一个主要被讨论的部分。首先要解决的问题之一就是:我们如何确定提交到上游的补丁已经进行了代码审核?
Wolfram Sang 从 2008 年开始成为一名 Linux 内核开发者,他经常在各地召开的 Linux 峰会上发表讲话,比如在 [2016 年柏林 Linux 峰会](https://linuxconcontainerconeurope2016.sched.org/event/7oA4/kernel-development-i-still-think-we-have-a-scaling-problem-wolfram-sang-consultant),他提出了如何提高内核开发实践的想法。
让我们来看看他的观点。

**在 2013 年的时候,你曾在爱丁堡(Edinburgh)提醒 ELCE 委员会,如果不作出改变,那么子系统的潜在问题和其他争议问题将会逐渐扩大。他们做出改变了吗?你所提及的那些事件发生了吗?**
是的,在某些程度上来说。当然了,Linux 内核是一个很多部分组成的项目,所以给以 Linux 各个子系统更多关注应该放在一个更重要的位置。然而,有太多的子系统“只是拼图中的一块”,所以通常来说,这些子系统的潜在问题还未被解决。
**你曾指出代码审核人数是一个大问题。为何你觉得 Linux 内核开发社区没有足够的代码审核人员呢?**
理由之一就是,大多数开发者实际上只是编写代码,而读代码并不多。这本是没有什么错,但却说明了并非每个人都是代码审核人员,所以我们真的应该鼓励每个人都进行代码审核。
我所看到另一件事就是,但我们要请人员加入我们的社区时,最重要的考核就是补丁贡献数量。我个人认为这是很正常的,并且在初期总贡献量少的时候是非常好的做法。但是随着越来越多的人员,特别是公司的加入,我们就碰到源码审核的问题。但是别误解了,有着数量可观的贡献是很棒的。但目前需要指出的是,参与社区有着更多内涵,比方说如何为下一步发展负责。有些部分在改善,但是还不够。
**你认为更多的代码审核人员培训或者审核激励措施是否会有帮助?**
我最主要的观点就是要指出,现今仍存在问题。是的,目前为止我们做到很好,但不意味着全都做的很好。我们也有类似扩张方面的问题。让人们了解事实,是希望能够让一些团体对此感兴趣并参与其中。尽管,我并不认为我们需要特殊的训练。我所熟悉的一些代码审核人员都非常棒或者很有天赋,只是这类人太少或者他们的空闲时间太少。
首先就是需要有这种内在动力,至于其它的,边做边学就非常好了。这又是我想要指出的优势之一:审核补丁能够使你成为更出色的代码开发者。
**依你之见,是否有那么一个受欢迎的大项目在扩张这方面做的很好,可以供我们借鉴?**
我还真不知道有这么一个项目,如果有的话随时借鉴。
我很专注于 Linux 内核,所以可能会存在一些偏见。然而在我看来,Linux 内核项目在规模大小、贡献数量和多样性方面真的很特别。所以当我想要找另一个项目来寻找灵感以便改善工作流是很正常的想法,目前我们的扩张问题真的比较特别。而且我发现,看看其他子系统在内核中做了什么是一个很有的方法。
**你曾说安全问题是我们每个人都该想到的事情,那用户应该做些什么来避免或者改善安全问题的危险?**
在今年(2016年)柏林 Linux 峰会我的谈话是针对开发层面的。安全隐患可能来自于没有正确审核的补丁中。我并不想要用户亲自解决这种问题,我更希望这些安全问题永远不会出现。当然这是不可能的,但这仍然是我处理问题所首选的方法。
**我很好奇这个庞大社区如何改善这些问题。是否有你希望用户定期以文件形式提交的某些类型的错误报告?需要定期检查的区域却因为某些原因没有注意到的?**
我们并不缺少错误报告。我所担心的是:由于代码审核人员的短缺造成补丁不完整,从而导致更多的错误报告。所以,到时候不仅需要处理大量的贡献,还需要处理更多错误或者进行版本回退。
**你是否还有什么事情希望我们读者知道,以了解你所在的努力?**
Linux 内核的特殊性,常常让我牢记着,在底层它就是代码而已。
---
via: <https://opensource.com/business/16/10/linux-kernel-review>
作者:[Deb Nicholson](https://opensource.com/users/eximious) 译者:[GHLandy](https://github.com/GHLandy) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Operating system security is [top of mind right now](http://www.infoworld.com/article/3124432/linux/is-the-linux-kernel-a-security-problem.html), and Linux is a big part of that discussion. One of the questions to be solved is: How do we ensure that patches going upstream are properly reviewed?
Wolfram Sang has been a Linux kernel developer since 2008, and frequently talks at Linux conferences around the world, like [LinuxCon Berlin 2016](https://linuxconcontainerconeurope2016.sched.org/event/7oA4/kernel-development-i-still-think-we-have-a-scaling-problem-wolfram-sang-consultant), about ways to improve kernel development practices.
Let's get his point of view.
### In 2013, you warned the ELCE audience in Edinburgh about subsystem latencies and other issues that may arise if things don't change. Did things change? Did some of the things you warned about end up happening?
Yes, to some extent. Of course, the Linux kernel is a very heterogeneous project, so subsystems with more focus are in a slightly better position. However, there are enough subsystems which are "just a piece of the puzzle" and for them latency has not improved, generally speaking.
### You've pointed out that the number of reviewers is a problem. Why do you think the kernel development community doesn't have enough reviewers?
One thing is that some people prefer to actually write code and not so much read code. This is OK. It just shows that not everyone is a reviewer, so we should really encourage everyone who likes to do that.
Another thing I see is when we ask people to join our community, it is first mostly about contributing patches. This is natural, I think, and worked well in the beginning when contributions were fewer. But as more and more have joined, especially companies, we've hit this review resource problem. Don't get me wrong, having so many contributions is awesome! I think that we now need to point out that taking part in the community also means more, like to take over some responsibility as a next step. It happens in some parts, but it is not enough to scale yet.
### Do you think more reviewer training or incentivization of reviewing would help?
One key point for me is to speak out about there being a problem. Yes, we are doing great so far, but that doesn't mean all is well. We also have problems like this scalability issue. Let people know so maybe some parties get interested and join. I don't think we need special training, though. Most reviewers I know are pretty good or talented, they are just too few or have too little time.
What you should have is this intrinsic motivation. For the rest, learning-by-doing works great in this field. This is one of the advantages I like to point out: Reviewing patches makes you a better coder.
### In your opinion, are there large, popular projects that you think are doing a really great job at scaling that we might borrow some ideas from?
I don't know one, but am open to hearing about them if there are.
I am very focused on the Linux kernel, so it might be plain bias. However, in my opinion the kernel is indeed special in terms of size, number of contributions, and diversity. So while I think looking at other projects to get inspiration for workflow improvements is always healthy, our scalability problems are pretty unique currently. I find it most useful to look what other subsystems in the kernel are doing.
### You've mentioned security issues as something that could come up. What should users be doing to avoid or ameliorate the severity of security issues?
My talk at LinuxCon Berlin this year is targeted at the development level. The security implications could come from patches going in without proper review. I don't want to have users deal with that, I rather want such issues to never happen. This will never work perfectly, but it is still my preferred way to tackle things.
### I'm wondering how the wider community could help. Are there certain kinds of bug reports that you wish people would file more often? Particular areas that need regular attention but don't get it for some reason?
We are not short on bug reports. What I am more afraid of is that the shortage of reviewers will lead to more bug reports due to incomplete patches going in. So, we then we'll not only have to deal with the huge amount of contributions, but also with more bugs and regressions.
### Is there anything else you wish our readers knew about your work?
With all the specialities around the Linux kernel, it often helps me to remember that at the bottom, it is just code.
## 2 Comments |
7,906 | ORWL:能够删除被篡改数据的微型开源计算机 | https://itsfoss.com/orwl-physically-secure-computer/ | 2016-10-27T12:14:00 | [
"安全",
"ORWL"
] | https://linux.cn/article-7906-1.html | 
在当今这个信息时代,安全是最重要的。恐怕没有人会希望自己的重要数据落入到坏人的手里。但是即便是无安全防护的硬件同样面临不少威胁,而大多数时候人们还只是对软件采取安全防护措施。ORWL 就是来改变这件事的。

### [ORWL 是什么?](http://www.design-shift.com/orwl/)
ORWL 宣称是社区里“造得最安全的家用电脑”。 它是一台小型的飞碟形计算机,在设计上全面考虑了物理安全性。物理安全很重要,因为一旦有人获得了从物理上访问你的计算机的途径,那么就 Game Over 了,这是信息安全专业人员中的一个老生常谈。

ORWL 的基本规格包括英特尔 Skylake M3 处理器、USB-C 和微型 HDMI 接口、8GB 内存、120G 固态硬盘、蓝牙、Wifi 和 NFC 技术。目前它支持的操作系统有 Ubuntu 16.04、Qubes OS,以及 Windows 10 等,开箱即用。你只需要有一个显示器,键盘和鼠标就可以开始使用它了。
### ORWL 是开源的
ORWL 是**完全**开源的。这意味着,如果有人想设计一台自己的计算机或者对 ORWL 作出改进的话,原理图和设计文件、软件、固件、所有东西都是可以获取的。

### ORWL 是如何工作的?
ORWL 使用自加密固态硬盘(SSD)。一个安全微控制器集成到其主板上来产生和存储加密密匙。一旦核实了系统的完整性和已验证用户,它就使用密匙来解密固态硬盘(SSD)。无论对 ORWL 进行任何类型的篡改,密匙都会立即删除固态硬盘(SSD)上的无用数据
为了完成身份验证,ORWL 有一个使用和智能卡类似技术的密匙卡。它使用 NFC 技术来验证用户,同时使用蓝牙来检测用户是否在当前使用范围内。如果用户不在附近(不在使用范围内),ORWL 将会自动锁定。

整个 ORWL 系统被包裹在一个到处伴有压力开关的活动翻盖网格里。安全微控制器持续监控专用惯性测量部件,活动翻盖网格,内部温度和电源输入电压,以用于检测篡改。这将防止访问内部组件,比如试图破坏翻盖将会触发安全微控制器从而删除加密密匙。此外,出于安全考虑,动态随机存储器(DRAM)也焊有外壳。
这并不是全部安全防护措施,ORWL 还有更多详细的措施来确保设备绝对的物理安全性,包括冷启动防护,直接存储器访问(DMA)攻击防御等。
更多信息可以在 [ORWL 引导页](https://www.orwl.org/)找到。这儿是一个关于它如何工作的快速视频。
### ORWL 是信息安全的最终答案吗?
令人沮丧的是,ORWL 并不是信息安全的最终答案。ORWL 只能为计算机提供物理安全,尽管这很强大并且看起来<ruby> 极酷 <rp> ( </rp> <rt> totally ninja </rt> <rp> ) </rp></ruby>,但是还有许多来自其他方面的攻击会损坏你的系统。然而,ORWL 确实从整体上提高了计算机的安全性。
你认为 ORWL 怎么样?通过评论让我们知道你的想法。
---
via: <https://itsfoss.com/orwl-physically-secure-computer/>
作者:[Munif Tanjim](https://itsfoss.com/author/munif/) 译者:[ucasFL](https://github.com/ucasFL) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,907 | 构建你的数据科学作品集:机器学习项目 | https://www.dataquest.io/blog/data-science-portfolio-machine-learning/ | 2016-10-28T10:21:55 | [
"大数据",
"数据科学",
"预测"
] | https://linux.cn/article-7907-1.html |
>
> 这是[这个系列](https://www.dataquest.io/blog/data-science-portfolio-project/)发布的第三篇关于如何构建数据<ruby> 科学作品集 <rp> ( </rp> <rt> Data Science Portfolio </rt> <rp> ) </rp></ruby>的文章。如果你喜欢这个系列并且想继续关注,你可以在订阅页面的底部找到[链接](https://www.dataquest.io/blog/data-science-portfolio-machine-learning/#email-signup)。
>
>
>
数据科学公司在决定雇佣时越来越关注你在数据科学方面的<ruby> 作品集 <rp> ( </rp> <rt> Portfolio </rt> <rp> ) </rp></ruby>。这其中的一个原因是,这样的作品集是判断某人的实际技能的最好的方法。好消息是构建这样的作品集完全要看你自己。只要你在这方面付出了努力,你一定可以取得让这些公司钦佩的作品集。

构建高质量的作品集的第一步就是知道需要什么技能。公司想要在数据科学方面拥有的、他们希望你能够运用的主要技能有:
* 沟通能力
* 协作能力
* 技术能力
* 数据推理能力
* 动机和主动性
任何好的作品集都由多个项目表现出来,其中每个都能够表现出以上一到两点。这是本系列的第三篇,本系列我们主要讲包括如何打造面面俱到的数据科学作品集。在这一篇中,我们主要涵盖了如何构建组成你的作品集的第二个项目,以及如何创建一个端对端的机器学习项目。在最后,我们将拥有一个展示你的数据推理能力和技术能力的项目。如果你想看一下的话,[这里](https://github.com/dataquestio/loan-prediction)有一个完整的例子。
### 一个端到端的项目
作为一个数据科学家,有时候你会拿到一个数据集并被问如何[用它来讲故事](https://www.dataquest.io/blog/data-science-portfolio-project/)。在这个时候,沟通就是非常重要的,你需要用它来完成这个事情。像我们在前一篇文章中用过的,类似 Jupyter notebook 这样的工具,将对你非常有帮助。在这里你能找到一些可以用的报告或者总结文档。
不管怎样,有时候你会被要求创建一个具有操作价值的项目。具有操作价值的项目将直接影响到公司的日常业务,它会使用不止一次,经常是许多人使用。这个任务可能像这样 “创建一个算法来预测周转率”或者“创建一个模型来自动对我们的文章打标签”。在这种情况下,技术能力比讲故事更重要。你必须能够得到一个数据集,并且理解它,然后创建脚本处理该数据。这个脚本要运行的很快,占用系统资源很小。通常它可能要运行很多次,脚本的可使用性也很重要,并不仅仅是一个演示版。可使用性是指整合进操作流程,并且甚至是是面向用户的。
端对端项目的主要组成部分:
* 理解背景
* 浏览数据并找出细微差别
* 创建结构化项目,那样比较容易整合进操作流程
* 运行速度快、占用系统资源小的高性能代码
* 写好安装和使用文档以便其他人用
为了有效的创建这种类型的项目,我们可能需要处理多个文件。强烈推荐使用 [Atom](https://atom.io/) 这样的文本编辑器或者 [PyCharm](https://www.jetbrains.com/pycharm/) 这样的 IDE。这些工具允许你在文件间跳转,编辑不同类型的文件,例如 markdown 文件,Python 文件,和 csv 文件等等。结构化你的项目还利于版本控制,并上传一个类似 [Github](https://github.com/) 这样的协作开发工具上也很有用。

*Github 上的这个项目*
在这一节中我们将使用 [Pandas](http://pandas.pydata.org/) 和 [scikit-learn](http://scikit-learn.org/) 这样的库,我们还将大量用到 Pandas [DataFrames](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html),它使得 python 读取和处理表格数据更加方便。
### 找到好的数据集
为一个端到端的作品集项目的找到好的数据集很难。在内存和性能的限制下,数据集需要尽量的大。它还需要是实际有用的。例如,[这个数据集](https://collegescorecard.ed.gov/data/),它包含有美国院校的录取标准、毕业率以及毕业以后的收入,是个很好的可以讲故事的数据集。但是,不管你如何看待这个数据,很显然它不适合创建端到端的项目。比如,你能告诉人们他们去了这些大学以后的未来收入,但是这个快速检索却并不足够呈现出你的技术能力。你还能找出院校的招生标准和更高的收入相关,但是这更像是常理而不是你的技术结论。
这里还有内存和性能约束的问题,比如你有几千兆的数据,而且当你需要找到一些差异时,就需要对数据集一遍遍运行算法。
一个好的可操作的数据集可以让你构建一系列脚本来转换数据、动态地回答问题。一个很好的例子是股票价格数据集,当股市关闭时,就会给算法提供新的数据。这可以让你预测明天的股价,甚至预测收益。这不是讲故事,它带来的是真金白银。
一些找到数据集的好地方:
* [/r/datasets](https://reddit.com/r/datasets) – 有上百的有趣数据的 subreddit(Reddit 是国外一个社交新闻站点,subreddit 指该论坛下的各不同版块)。
* [Google Public Datasets](https://cloud.google.com/bigquery/public-data/#usa-names) – 通过 Google BigQuery 使用的公开数据集。
* [Awesome datasets](https://github.com/caesar0301/awesome-public-datasets) – 一个数据集列表,放在 Github 上。
当你查看这些数据集时,想一下人们想要在这些数据集中得到什么答案,哪怕这些问题只想过一次(“房价是如何与标准普尔 500 指数关联的?”),或者更进一步(“你能预测股市吗?”)。这里的关键是更进一步地找出问题,并且用相同的代码在不同输入(不同的数据)上运行多次。
对于本文的目标,我们来看一下 <ruby> 房利美 <rp> ( </rp> <rt> Fannie Mae </rt> <rp> ) </rp></ruby>[贷款数据](http://www.fanniemae.com/portal/funding-the-market/data/loan-performance-data.html)。房利美是一家在美国的政府赞助的企业抵押贷款公司,它从其他银行购买按揭贷款,然后捆绑这些贷款为贷款证券来转卖它们。这使得贷款机构可以提供更多的抵押贷款,在市场上创造更多的流动性。这在理论上会带来更多的住房和更好的贷款期限。从借款人的角度来说,它们大体上差不多,话虽这样说。
房利美发布了两种类型的数据 – 它获得的贷款的数据,和贷款偿还情况的数据。在理想的情况下,有人向贷款人借钱,然后还款直到还清。不管怎样,有些人多次不还,从而丧失了抵押品赎回权。抵押品赎回权是指没钱还了被银行把房子给收走了。房利美会追踪谁没还钱,并且哪个贷款需要收回抵押的房屋(取消赎回权)。每个季度会发布此数据,发布的是滞后一年的数据。当前可用是 2015 年第一季度数据。
“贷款数据”是由房利美发布的贷款发放的数据,它包含借款人的信息、信用评分,和他们的家庭贷款信息。“执行数据”,贷款发放后的每一个季度公布,包含借贷人的还款信息和是否丧失抵押品赎回权的状态,一个“贷款数据”的“执行数据”可能有十几行。可以这样理解,“贷款数据”告诉你房利美所控制的贷款,“执行数据”包含该贷款一系列的状态更新。其中一个状态更新可以告诉我们一笔贷款在某个季度被取消赎回权了。

*一个没有及时还贷的房子就这样的被卖了*
### 选择一个角度
这里有几个我们可以去分析房利美数据集的方向。我们可以:
* 预测房屋的销售价格。
* 预测借款人还款历史。
* 在获得贷款时为每一笔贷款打分。
最重要的事情是坚持单一的角度。同时关注太多的事情很难做出效果。选择一个有着足够细节的角度也很重要。下面的角度就没有太多细节:
* 找出哪些银行将贷款出售给房利美的多数被取消赎回权。
* 计算贷款人的信用评分趋势。
* 找到哪些类型的家庭没有偿还贷款的能力。
* 找到贷款金额和抵押品价格之间的关系。
上面的想法非常有趣,如果我们关注于讲故事,那是一个不错的角度,但是不是很适合一个操作性项目。
在房利美数据集中,我们将仅使用申请贷款时有的那些信息来预测贷款是否将来会被取消赎回权。实际上, 我们将为每一笔贷款建立“分数”来告诉房利美买还是不买。这将给我们打下良好的基础,并将组成这个漂亮的作品集的一部分。
### 理解数据
我们来简单看一下原始数据文件。下面是 2012 年 1 季度前几行的贷款数据:
```
100000853384|R|OTHER|4.625|280000|360|02/2012|04/2012|31|31|1|23|801|N|C|SF|1|I|CA|945||FRM|
100003735682|R|SUNTRUST MORTGAGE INC.|3.99|466000|360|01/2012|03/2012|80|80|2|30|794|N|P|SF|1|P|MD|208||FRM|788
100006367485|C|PHH MORTGAGE CORPORATION|4|229000|360|02/2012|04/2012|67|67|2|36|802|N|R|SF|1|P|CA|959||FRM|794
```
下面是 2012 年 1 季度的前几行执行数据:
```
100000853384|03/01/2012|OTHER|4.625||0|360|359|03/2042|41860|0|N||||||||||||||||
100000853384|04/01/2012||4.625||1|359|358|03/2042|41860|0|N||||||||||||||||
100000853384|05/01/2012||4.625||2|358|357|03/2042|41860|0|N||||||||||||||||
```
在开始编码之前,花些时间真正理解数据是值得的。这对于操作性项目优为重要,因为我们没有交互式探索数据,将很难察觉到细微的差别,除非我们在前期发现他们。在这种情况下,第一个步骤是阅读房利美站点的资料:
* [概述](http://www.fanniemae.com/portal/funding-the-market/data/loan-performance-data.html)
* [有用的术语表](https://loanperformancedata.fanniemae.com/lppub-docs/lppub_glossary.pdf)
* [常见问答](https://loanperformancedata.fanniemae.com/lppub-docs/lppub_faq.pdf)
* [贷款和执行文件中的列](https://loanperformancedata.fanniemae.com/lppub-docs/lppub_file_layout.pdf)
* [贷款数据文件样本](https://loanperformancedata.fanniemae.com/lppub-docs/acquisition-sample-file.txt)
* [执行数据文件样本](https://loanperformancedata.fanniemae.com/lppub-docs/performance-sample-file.txt)
在看完这些文件后后,我们了解到一些能帮助我们的关键点:
* 从 2000 年到现在,每季度都有一个贷款和执行文件,因数据是滞后一年的,所以到目前为止最新数据是 2015 年的。
* 这些文件是文本格式的,采用管道符号`|`进行分割。
* 这些文件是没有表头的,但我们有个文件列明了各列的名称。
* 所有一起,文件包含 2200 万个贷款的数据。
* 由于执行数据的文件包含过去几年获得的贷款的信息,在早些年获得的贷款将有更多的执行数据(即在 2014 获得的贷款没有多少历史执行数据)。
这些小小的信息将会为我们节省很多时间,因为这样我们就知道如何构造我们的项目和利用这些数据了。
### 构造项目
在我们开始下载和探索数据之前,先想一想将如何构造项目是很重要的。当建立端到端项目时,我们的主要目标是:
* 创建一个可行解决方案
* 有一个快速运行且占用最小资源的解决方案
* 容易可扩展
* 写容易理解的代码
* 写尽量少的代码
为了实现这些目标,需要对我们的项目进行良好的构造。一个结构良好的项目遵循几个原则:
* 分离数据文件和代码文件
* 从原始数据中分离生成的数据。
* 有一个 `README.md` 文件帮助人们安装和使用该项目。
* 有一个 `requirements.txt` 文件列明项目运行所需的所有包。
* 有一个单独的 `settings.py` 文件列明其它文件中使用的所有的设置
+ 例如,如果从多个 `Python` 脚本读取同一个文件,让它们全部 `import` 设置并从一个集中的地方获得文件名是有用的。
* 有一个 `.gitignore` 文件,防止大的或密码文件被提交。
* 分解任务中每一步可以单独执行的步骤到单独的文件中。
+ 例如,我们将有一个文件用于读取数据,一个用于创建特征,一个用于做出预测。
* 保存中间结果,例如,一个脚本可以输出下一个脚本可读取的文件。
+ 这使我们无需重新计算就可以在数据处理流程中进行更改。
我们的文件结构大体如下:
```
loan-prediction
├── data
├── processed
├── .gitignore
├── README.md
├── requirements.txt
├── settings.py
```
### 创建初始文件
首先,我们需要创建一个 `loan-prediction` 文件夹,在此文件夹下面,再创建一个 `data` 文件夹和一个 `processed` 文件夹。`data` 文件夹存放原始数据,`processed` 文件夹存放所有的中间计算结果。
其次,创建 `.gitignore` 文件,`.gitignore` 文件将保证某些文件被 git 忽略而不会被推送至 GitHub。关于这个文件的一个好的例子是由 OSX 在每一个文件夹都会创建的 `.DS_Store` 文件,`.gitignore` 文件一个很好的范本在[这里](https://github.com/github/gitignore/blob/master/Python.gitignore)。我们还想忽略数据文件,因为它们实在是太大了,同时房利美的条文禁止我们重新分发该数据文件,所以我们应该在我们的文件后面添加以下 2 行:
```
data
processed
```
[这里](https://github.com/dataquestio/loan-prediction/blob/master/.gitignore)是该项目的一个关于 .gitignore 文件的例子。
再次,我们需要创建 `README.md` 文件,它将帮助人们理解该项目。后缀 .md 表示这个文件采用 markdown 格式。Markdown 使你能够写纯文本文件,同时还可以添加你想要的神奇的格式。[这里](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)是关于 markdown 的导引。如果你上传一个叫 `README.md` 的文件至 Github,Github 会自动处理该 markdown,同时展示给浏览该项目的人。例子在[这里](https://github.com/dataquestio/loan-prediction)。
至此,我们仅需在 `README.md` 文件中添加简单的描述:
```
Loan Prediction
-----------------------
Predict whether or not loans acquired by Fannie Mae will go into foreclosure. Fannie Mae acquires loans from other lenders as a way of inducing them to lend more. Fannie Mae releases data on the loans it has acquired and their performance afterwards [here](http://www.fanniemae.com/portal/funding-the-market/data/loan-performance-data.html).
```
现在,我们可以创建 `requirements.txt` 文件了。这会帮助其它人可以很方便地安装我们的项目。我们还不知道我们将会具体用到哪些库,但是以下几个库是需要的:
```
pandas
matplotlib
scikit-learn
numpy
ipython
scipy
```
以上几个是在 python 数据分析任务中最常用到的库。可以认为我们将会用到大部分这些库。[这里](https://github.com/dataquestio/loan-prediction/blob/master/requirements.txt)是该项目 `requirements.txt` 文件的一个例子。
创建 `requirements.txt` 文件之后,你应该安装这些包了。我们将会使用 python3。如果你没有安装 python,你应该考虑使用 [Anaconda](https://www.continuum.io/downloads),它是一个 python 安装程序,同时安装了上面列出的所有包。
最后,我们可以建立一个空白的 `settings.py` 文件,因为我们的项目还没有任何设置。
### 获取数据
一旦我们有了项目的基本架构,我们就可以去获得原始数据。
房利美对获取数据有一些限制,所以你需要去注册一个账户。在创建完账户之后,你可以找到[在这里](https://loanperformancedata.fanniemae.com/lppub/index.html)的下载页面,你可以按照你所需要的下载或多或少的贷款数据文件。文件格式是 zip,在解压后当然是非常大的。
为了达到我们这个文章的目的,我们将要下载从 2012 年 1 季度到 2015 年 1 季度的所有数据。接着我们需要解压所有的文件。解压过后,删掉原来的 .zip 格式的文件。最后,loan-prediction 文件夹看起来应该像下面的一样:
```
loan-prediction
├── data
│ ├── Acquisition_2012Q1.txt
│ ├── Acquisition_2012Q2.txt
│ ├── Performance_2012Q1.txt
│ ├── Performance_2012Q2.txt
│ └── ...
├── processed
├── .gitignore
├── README.md
├── requirements.txt
├── settings.py
```
在下载完数据后,你可以在 shell 命令行中使用 `head` 和 `tail` 命令去查看文件中的行数据,你看到任何的不需要的数据列了吗?在做这件事的同时查阅[列名称的 pdf 文件](https://loanperformancedata.fanniemae.com/lppub-docs/lppub_file_layout.pdf)可能有帮助。
### 读入数据
有两个问题让我们的数据难以现在就使用:
* 贷款数据和执行数据被分割在多个文件中
* 每个文件都缺少列名标题
在我们开始使用数据之前,我们需要首先明白我们要在哪里去存一个贷款数据的文件,同时到哪里去存储一个执行数据的文件。每个文件仅仅需要包括我们关注的那些数据列,同时拥有正确的列名标题。这里有一个小问题是执行数据非常大,因此我们需要尝试去修剪一些数据列。
第一步是向 `settings.py` 文件中增加一些变量,这个文件中同时也包括了我们原始数据的存放路径和处理出的数据存放路径。我们同时也将添加其他一些可能在接下来会用到的设置数据:
```
DATA_DIR = "data"
PROCESSED_DIR = "processed"
MINIMUM_TRACKING_QUARTERS = 4
TARGET = "foreclosure_status"
NON_PREDICTORS = [TARGET, "id"]
CV_FOLDS = 3
```
把路径设置在 `settings.py` 中使它们放在一个集中的地方,同时使其修改更加的容易。当在多个文件中用到相同的变量时,你想改变它的话,把他们放在一个地方比分散放在每一个文件时更加容易。[这里的](https://github.com/dataquestio/loan-prediction/blob/master/settings.py)是一个这个工程的示例 `settings.py` 文件
第二步是创建一个文件名为 `assemble.py`,它将所有的数据分为 2 个文件。当我们运行 `Python assemble.py`,我们在处理数据文件的目录会获得 2 个数据文件。
接下来我们开始写 `assemble.py` 文件中的代码。首先我们需要为每个文件定义相应的列名标题,因此我们需要查看[列名称的 pdf 文件](https://loanperformancedata.fanniemae.com/lppub-docs/lppub_file_layout.pdf),同时创建在每一个贷款数据和执行数据的文件的数据列的列表:
```
HEADERS = {
"Acquisition": [
"id",
"channel",
"seller",
"interest_rate",
"balance",
"loan_term",
"origination_date",
"first_payment_date",
"ltv",
"cltv",
"borrower_count",
"dti",
"borrower_credit_score",
"first_time_homebuyer",
"loan_purpose",
"property_type",
"unit_count",
"occupancy_status",
"property_state",
"zip",
"insurance_percentage",
"product_type",
"co_borrower_credit_score"
],
"Performance": [
"id",
"reporting_period",
"servicer_name",
"interest_rate",
"balance",
"loan_age",
"months_to_maturity",
"maturity_date",
"msa",
"delinquency_status",
"modification_flag",
"zero_balance_code",
"zero_balance_date",
"last_paid_installment_date",
"foreclosure_date",
"disposition_date",
"foreclosure_costs",
"property_repair_costs",
"recovery_costs",
"misc_costs",
"tax_costs",
"sale_proceeds",
"credit_enhancement_proceeds",
"repurchase_proceeds",
"other_foreclosure_proceeds",
"non_interest_bearing_balance",
"principal_forgiveness_balance"
]
}
```
接下来一步是定义我们想要保留的数据列。因为我们要预测一个贷款是否会被撤回,我们可以丢弃执行数据中的许多列。我们将需要保留贷款数据中的所有数据列,因为我们需要尽量多的了解贷款发放时的信息(毕竟我们是在预测贷款发放时这笔贷款将来是否会被撤回)。丢弃数据列将会使我们节省下内存和硬盘空间,同时也会加速我们的代码。
```
SELECT = {
"Acquisition": HEADERS["Acquisition"],
"Performance": [
"id",
"foreclosure_date"
]
}
```
下一步,我们将编写一个函数来连接数据集。下面的代码将:
* 引用一些需要的库,包括 `settings`。
* 定义一个函数 `concatenate`,目的是:
+ 获取到所有 `data` 目录中的文件名。
+ 遍历每个文件。
- 如果文件不是正确的格式 (不是以我们需要的格式作为开头),我们将忽略它。
- 通过使用 Pandas 的 [read\_csv](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html) 函数及正确的设置把文件读入一个 [DataFrame](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html)。
* 设置分隔符为`|`,以便所有的字段能被正确读出。
* 数据没有标题行,因此设置 `header` 为 `None` 来进行标示。
* 从 `HEADERS` 字典中设置正确的标题名称 – 这将会是我们的 DataFrame 中的数据列名称。
* 仅选择我们加在 `SELECT` 中的 DataFrame 的列。
* 把所有的 DataFrame 共同连接在一起。
* 把已经连接好的 DataFrame 写回一个文件。
```
import os
import settings
import pandas as pd
def concatenate(prefix="Acquisition"):
files = os.listdir(settings.DATA_DIR)
full = []
for f in files:
if not f.startswith(prefix):
continue
data = pd.read_csv(os.path.join(settings.DATA_DIR, f), sep="|", header=None, names=HEADERS[prefix], index_col=False)
data = data[SELECT[prefix]]
full.append(data)
full = pd.concat(full, axis=0)
full.to_csv(os.path.join(settings.PROCESSED_DIR, "{}.txt".format(prefix)), sep="|", header=SELECT[prefix], index=False)
```
我们可以通过调用上面的函数,通过传递的参数 `Acquisition` 和 `Performance` 两次以将所有的贷款和执行文件连接在一起。下面的代码将:
* 仅在命令行中运行 `python assemble.py` 时执行。
* 将所有的数据连接在一起,并且产生 2 个文件:
+ `processed/Acquisition.txt`
+ `processed/Performance.txt`
```
if __name__ == "__main__":
concatenate("Acquisition")
concatenate("Performance")
```
我们现在拥有了一个漂亮的,划分过的 `assemble.py` 文件,它很容易执行,也容易建立。通过像这样把问题分解为一块一块的,我们构建工程就会变的容易许多。不用一个可以做所有工作的凌乱脚本,我们定义的数据将会在多个脚本间传递,同时使脚本间完全的彼此隔离。当你正在一个大的项目中工作时,这样做是一个好的想法,因为这样可以更加容易修改其中的某一部分而不会引起其他项目中不关联部分产生预料之外的结果。
一旦我们完成 `assemble.py` 脚本文件,我们可以运行 `python assemble.py` 命令。你可以[在这里](https://github.com/dataquestio/loan-prediction/blob/master/assemble.py)查看完整的 `assemble.py` 文件。
这将会在 `processed` 目录下产生 2 个文件:
```
loan-prediction
├── data
│ ├── Acquisition_2012Q1.txt
│ ├── Acquisition_2012Q2.txt
│ ├── Performance_2012Q1.txt
│ ├── Performance_2012Q2.txt
│ └── ...
├── processed
│ ├── Acquisition.txt
│ ├── Performance.txt
├── .gitignore
├── assemble.py
├── README.md
├── requirements.txt
├── settings.py
```
### 计算来自执行数据的值
接下来我们会计算来自 `processed/Performance.txt` 中的值。我们要做的就是推测这些资产是否被取消赎回权。如果能够计算出来,我们只要看一下关联到贷款的执行数据的参数 `foreclosure_date` 就可以了。如果这个参数的值是 `None`,那么这些资产肯定没有收回。为了避免我们的样例中只有少量的执行数据,我们会为每个贷款计算出执行数据文件中的行数。这样我们就能够从我们的训练数据中筛选出贷款数据,排除了一些执行数据。
下面是我认为贷款数据和执行数据的关系:

在上面的表格中,贷款数据中的每一行数据都关联到执行数据中的多行数据。在执行数据中,在取消赎回权的时候 `foreclosure_date` 就会出现在该季度,而之前它是空的。一些贷款还没有被取消赎回权,所以与执行数据中的贷款数据有关的行在 `foreclosure_date` 列都是空格。
我们需要计算 `foreclosure_status` 的值,它的值是布尔类型,可以表示一个特殊的贷款数据 `id` 是否被取消赎回权过,还有一个参数 `performance_count` ,它记录了执行数据中每个贷款 `id` 出现的行数。
计算这些行数有多种不同的方法:
* 我们能够读取所有的执行数据,然后我们用 Pandas 的 [groupby](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html) 方法在 DataFrame 中计算出与每个贷款 `id` 有关的行的行数,然后就可以查看贷款 `id` 的 `foreclosure_date` 值是否为 `None` 。
+ 这种方法的优点是从语法上来说容易执行。
+ 它的缺点需要读取所有的 129236094 行数据,这样就会占用大量内存,并且运行起来极慢。
* 我们可以读取所有的执行数据,然后在贷款 DataFrame 上使用 [apply](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html) 去计算每个贷款 `id` 出现的次数。
+ 这种方法的优点是容易理解。
+ 缺点是需要读取所有的 129236094 行数据。这样会占用大量内存,并且运行起来极慢。
* 我们可以在迭代访问执行数据中的每一行数据,而且会建立一个单独的计数字典。
+ 这种方法的优点是数据不需要被加载到内存中,所以运行起来会很快且不需要占用内存。
+ 缺点是这样的话理解和执行上可能有点耗费时间,我们需要对每一行数据进行语法分析。
加载所有的数据会非常耗费内存,所以我们采用第三种方法。我们要做的就是迭代执行数据中的每一行数据,然后为每一个贷款 `id` 在字典中保留一个计数。在这个字典中,我们会计算出贷款 `id` 在执行数据中出现的次数,而且看看 `foreclosure_date` 是否是 `None` 。我们可以查看 `foreclosure_status` 和 `performance_count` 的值 。
我们会新建一个 `annotate.py` 文件,文件中的代码可以计算这些值。我们会使用下面的代码:
* 导入需要的库
* 定义一个函数 `count_performance_rows` 。
+ 打开 `processed/Performance.txt` 文件。这不是在内存中读取文件而是打开了一个文件标识符,这个标识符可以用来以行为单位读取文件。
+ 迭代文件的每一行数据。
+ 使用分隔符`|`分开每行的不同数据。
+ 检查 `loan_id` 是否在计数字典中。
- 如果不存在,把它加进去。
+ `loan_id` 的 `performance_count` 参数自增 1 次,因为我们这次迭代也包含其中。
+ 如果 `date` 不是 `None ,我们就会知道贷款被取消赎回权了,然后为`foreclosure\_status` 设置合适的值。
```
import os
import settings
import pandas as pd
def count_performance_rows():
counts = {}
with open(os.path.join(settings.PROCESSED_DIR, "Performance.txt"), 'r') as f:
for i, line in enumerate(f):
if i == 0:
# Skip header row
continue
loan_id, date = line.split("|")
loan_id = int(loan_id)
if loan_id not in counts:
counts[loan_id] = {
"foreclosure_status": False,
"performance_count": 0
}
counts[loan_id]["performance_count"] += 1
if len(date.strip()) > 0:
counts[loan_id]["foreclosure_status"] = True
return counts
```
### 获取值
只要我们创建了计数字典,我们就可以使用一个函数通过一个 `loan_id` 和一个 `key` 从字典中提取到需要的参数的值:
```
def get_performance_summary_value(loan_id, key, counts):
value = counts.get(loan_id, {
"foreclosure_status": False,
"performance_count": 0
})
return value[key]
```
上面的函数会从 `counts` 字典中返回合适的值,我们也能够为贷款数据中的每一行赋一个 `foreclosure_status` 值和一个 `performance_count` 值。如果键不存在,字典的 [get](https://docs.python.org/3/library/stdtypes.html#dict.get) 方法会返回一个默认值,所以在字典中不存在键的时候我们就可以得到一个可知的默认值。
### 转换数据
我们已经在 `annotate.py` 中添加了一些功能,现在我们来看一看数据文件。我们需要将贷款到的数据转换到训练数据集来进行机器学习算法的训练。这涉及到以下几件事情:
* 转换所有列为数字。
* 填充缺失值。
* 为每一行分配 `performance_count` 和 `foreclosure_status`。
* 移除出现执行数据很少的行(`performance_count` 计数低)。
我们有几个列是文本类型的,看起来对于机器学习算法来说并不是很有用。然而,它们实际上是分类变量,其中有很多不同的类别代码,例如 `R`,`S` 等等. 我们可以把这些类别标签转换为数值:

通过这种方法转换的列我们可以应用到机器学习算法中。
还有一些包含日期的列 (`first_payment_date` 和 `origination_date`)。我们可以将这些日期放到两个列中:

在下面的代码中,我们将转换贷款数据。我们将定义一个函数如下:
* 在 `acquisition` 中创建 `foreclosure_status` 列,并从 `counts` 字典中得到值。
* 在 `acquisition` 中创建 `performance_count` 列,并从 `counts` 字典中得到值。
* 将下面的列从字符串转换为整数:
+ `channel`
+ `seller`
+ `first_time_homebuyer`
+ `loan_purpose`
+ `property_type`
+ `occupancy_status`
+ `property_state`
+ `product_type`
* 将 `first_payment_date` 和 `origination_date` 分别转换为两列:
+ 通过斜杠分离列。
+ 将第一部分分离成 `month` 列。
+ 将第二部分分离成 `year` 列。
+ 删除该列。
+ 最后,我们得到 `first_payment_month`、`first_payment_year`、`rigination_month` 和 `origination_year`。
* 所有缺失值填充为 `-1`。
```
def annotate(acquisition, counts):
acquisition["foreclosure_status"] = acquisition["id"].apply(lambda x: get_performance_summary_value(x, "foreclosure_status", counts))
acquisition["performance_count"] = acquisition["id"].apply(lambda x: get_performance_summary_value(x, "performance_count", counts))
for column in [
"channel",
"seller",
"first_time_homebuyer",
"loan_purpose",
"property_type",
"occupancy_status",
"property_state",
"product_type"
]:
acquisition[column] = acquisition[column].astype('category').cat.codes
for start in ["first_payment", "origination"]:
column = "{}_date".format(start)
acquisition["{}_year".format(start)] = pd.to_numeric(acquisition[column].str.split('/').str.get(1))
acquisition["{}_month".format(start)] = pd.to_numeric(acquisition[column].str.split('/').str.get(0))
del acquisition[column]
acquisition = acquisition.fillna(-1)
acquisition = acquisition[acquisition["performance_count"] > settings.MINIMUM_TRACKING_QUARTERS]
return acquisition
```
### 聚合到一起
我们差不多准备就绪了,我们只需要再在 `annotate.py` 添加一点点代码。在下面代码中,我们将:
* 定义一个函数来读取贷款的数据。
* 定义一个函数来写入处理过的数据到 `processed/train.csv`。
* 如果该文件在命令行以 `python annotate.py` 的方式运行:
+ 读取贷款数据。
+ 计算执行数据的计数,并将其赋予 `counts`。
+ 转换 `acquisition` DataFrame。
+ 将`acquisition` DataFrame 写入到 `train.csv`。
```
def read():
acquisition = pd.read_csv(os.path.join(settings.PROCESSED_DIR, "Acquisition.txt"), sep="|")
return acquisition
def write(acquisition):
acquisition.to_csv(os.path.join(settings.PROCESSED_DIR, "train.csv"), index=False)
if __name__ == "__main__":
acquisition = read()
counts = count_performance_rows()
acquisition = annotate(acquisition, counts)
write(acquisition)
```
修改完成以后,确保运行 `python annotate.py` 来生成 `train.csv` 文件。 你可以在[这里](https://github.com/dataquestio/loan-prediction/blob/master/annotate.py)找到完整的 `annotate.py` 文件。
现在文件夹看起来应该像这样:
```
loan-prediction
├── data
│ ├── Acquisition_2012Q1.txt
│ ├── Acquisition_2012Q2.txt
│ ├── Performance_2012Q1.txt
│ ├── Performance_2012Q2.txt
│ └── ...
├── processed
│ ├── Acquisition.txt
│ ├── Performance.txt
│ ├── train.csv
├── .gitignore
├── annotate.py
├── assemble.py
├── README.md
├── requirements.txt
├── settings.py
```
### 找到误差标准
我们已经完成了训练数据表的生成,现在我们需要最后一步,生成预测。我们需要找到误差的标准,以及该如何评估我们的数据。在这种情况下,因为有很多的贷款没有被取消赎回权,所以根本不可能做到精确的计算。
我们需要读取训练数据,并且计算 `foreclosure_status` 列的计数,我们将得到如下信息:
```
import pandas as pd
import settings
train = pd.read_csv(os.path.join(settings.PROCESSED_DIR, "train.csv"))
train["foreclosure_status"].value_counts()
```
```
False 4635982
True 1585
Name: foreclosure_status, dtype: int64
```
因为只有很少的贷款被取消赎回权,只需要检查正确预测的标签的百分比就意味着我们可以创建一个机器学习模型,来为每一行预测 `False`,并能取得很高的精确度。相反,我们想要使用一个度量来考虑分类的不平衡,确保我们可以准确预测。我们要避免太多的误报率(预测贷款被取消赎回权,但是实际没有),也要避免太多的漏报率(预测贷款没有别取消赎回权,但是实际被取消了)。对于这两个来说,漏报率对于房利美来说成本更高,因为他们买的贷款可能是他们无法收回投资的贷款。
所以我们将定义一个漏报率,就是模型预测没有取消赎回权但是实际上取消了,这个数除以总的取消赎回权数。这是“缺失的”实际取消赎回权百分比的模型。下面看这个图表:

通过上面的图表,有 1 个贷款预测不会取消赎回权,但是实际上取消了。如果我们将这个数除以实际取消赎回权的总数 2,我们将得到漏报率 50%。 我们将使用这个误差标准,因此我们可以评估一下模型的行为。
### 设置机器学习分类器
我们使用交叉验证预测。通过交叉验证法,我们将数据分为3组。按照下面的方法来做:
* 用组 1 和组 2 训练模型,然后用该模型来预测组 3
* 用组 1 和组 3 训练模型,然后用该模型来预测组 2
* 用组 2 和组 3 训练模型,然后用该模型来预测组 1
将它们分割到不同的组,这意味着我们永远不会用相同的数据来为其预测训练模型。这样就避免了过拟合。如果过拟合,我们将错误地拉低了漏报率,这使得我们难以改进算法或者应用到现实生活中。
[Scikit-learn](http://scikit-learn.org/) 有一个叫做 [cross*val*predict](http://scikit-learn.org/stable/modules/generated/sklearn.cross_validation.cross_val_predict.html) ,它可以帮助我们理解交叉算法.
我们还需要一种算法来帮我们预测。我们还需要一个分类器来做[二元分类](https://en.wikipedia.org/wiki/Binary_classification)。目标变量 `foreclosure_status` 只有两个值, `True` 和 `False`。
这里我们用 [逻辑回归算法](https://en.wikipedia.org/wiki/Logistic_regression),因为它能很好的进行二元分类,并且运行很快,占用内存很小。我们来说一下它是如何工作的:不使用像随机森林一样多树结构,也不像支持向量机一样做复杂的转换,逻辑回归算法涉及更少的步骤和更少的矩阵。
我们可以使用 scikit-learn 实现的[逻辑回归分类器](http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html)算法。我们唯一需要注意的是每个类的权重。如果我们使用等权重的类,算法将会预测每行都为 `false`,因为它总是试图最小化误差。不管怎样,我们重视有多少贷款要被取消赎回权而不是有多少不能被取消。因此,我们给[逻辑回归](http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html)类的 `class_weight` 关键字传递 `balanced` 参数,让算法可以为不同 counts 的每个类考虑不同的取消赎回权的权重。这将使我们的算法不会为每一行都预测 `false`,而是两个类的误差水平一致。
### 做出预测
既然完成了前期准备,我们可以开始准备做出预测了。我将创建一个名为 `predict.py` 的新文件,它会使用我们在最后一步创建的 `train.csv` 文件。下面的代码:
* 导入所需的库
* 创建一个名为 `cross_validate` 的函数:
+ 使用正确的关键词参数创建逻辑回归分类器
+ 创建用于训练模型的数据列的列表,移除 `id` 和 `foreclosure_status` 列
+ 交叉验证 `train` DataFrame
+ 返回预测结果
```
import os
import settings
import pandas as pd
from sklearn import cross_validation
from sklearn.linear_model import LogisticRegression
from sklearn import metrics
def cross_validate(train):
clf = LogisticRegression(random_state=1, class_weight="balanced")
predictors = train.columns.tolist()
predictors = [p for p in predictors if p not in settings.NON_PREDICTORS]
predictions = cross_validation.cross_val_predict(clf, train[predictors], train[settings.TARGET], cv=settings.CV_FOLDS)
return predictions
```
### 预测误差
现在,我们仅仅需要写一些函数来计算误差。下面的代码:
* 创建函数 `compute_error`:
+ 使用 scikit-learn 计算一个简单的精确分数(与实际 `foreclosure_status` 值匹配的预测百分比)
* 创建函数 `compute_false_negatives`:
+ 为了方便,将目标和预测结果合并到一个 DataFrame
+ 查找漏报率
- 找到原本应被预测模型取消赎回权,但实际没有取消的贷款数目
- 除以没被取消赎回权的贷款总数目
```
def compute_error(target, predictions):
return metrics.accuracy_score(target, predictions)
def compute_false_negatives(target, predictions):
df = pd.DataFrame({"target": target, "predictions": predictions})
return df[(df["target"] == 1) & (df["predictions"] == 0)].shape[0] / (df[(df["target"] == 1)].shape[0] + 1)
def compute_false_positives(target, predictions):
df = pd.DataFrame({"target": target, "predictions": predictions})
return df[(df["target"] == 0) & (df["predictions"] == 1)].shape[0] / (df[(df["target"] == 0)].shape[0] + 1)
```
### 聚合到一起
现在,我们可以把函数都放在 `predict.py`。下面的代码:
* 读取数据集
* 计算交叉验证预测
* 计算上面的 3 个误差
* 打印误差
```
def read():
train = pd.read_csv(os.path.join(settings.PROCESSED_DIR, "train.csv"))
return train
if __name__ == "__main__":
train = read()
predictions = cross_validate(train)
error = compute_error(train[settings.TARGET], predictions)
fn = compute_false_negatives(train[settings.TARGET], predictions)
fp = compute_false_positives(train[settings.TARGET], predictions)
print("Accuracy Score: {}".format(error))
print("False Negatives: {}".format(fn))
print("False Positives: {}".format(fp))
```
一旦你添加完代码,你可以运行 `python predict.py` 来产生预测结果。运行结果向我们展示漏报率为 `.26`,这意味着我们没能预测 `26%` 的取消贷款。这是一个好的开始,但仍有很多改善的地方!
你可以在[这里](https://github.com/dataquestio/loan-prediction/blob/master/predict.py)找到完整的 `predict.py` 文件。
你的文件树现在看起来像下面这样:
```
loan-prediction
├── data
│ ├── Acquisition_2012Q1.txt
│ ├── Acquisition_2012Q2.txt
│ ├── Performance_2012Q1.txt
│ ├── Performance_2012Q2.txt
│ └── ...
├── processed
│ ├── Acquisition.txt
│ ├── Performance.txt
│ ├── train.csv
├── .gitignore
├── annotate.py
├── assemble.py
├── predict.py
├── README.md
├── requirements.txt
├── settings.py
```
### 撰写 README
既然我们完成了端到端的项目,那么我们可以撰写 `README.md` 文件了,这样其他人便可以知道我们做的事,以及如何复制它。一个项目典型的 `README.md` 应该包括这些部分:
* 一个高水准的项目概览,并介绍项目目的
* 任何必需的数据和材料的下载地址
* 安装命令
+ 如何安装要求依赖
* 使用命令
+ 如何运行项目
+ 每一步之后会看到的结果
* 如何为这个项目作贡献
+ 扩展项目的下一步计划
[这里](https://github.com/dataquestio/loan-prediction/blob/master/README.md) 是这个项目的一个 `README.md` 样例。
### 下一步
恭喜你完成了端到端的机器学习项目!你可以在[这里](https://github.com/dataquestio/loan-prediction)找到一个完整的示例项目。一旦你完成了项目,把它上传到 [Github](https://www.github.com/) 是一个不错的主意,这样其他人也可以看到你的文件夹的部分项目。
这里仍有一些留待探索数据的角度。总的来说,我们可以把它们分割为 3 类: 扩展这个项目并使它更加精确,发现其他可以预测的列,并探索数据。这是其中一些想法:
* 在 `annotate.py` 中生成更多的特性
* 切换 `predict.py` 中的算法
* 尝试使用比我们发表在这里的更多的房利美数据
* 添加对未来数据进行预测的方法。如果我们添加更多数据,我们所写的代码仍然可以起作用,这样我们可以添加更多过去和未来的数据。
* 尝试看看是否你能预测一个银行原本是否应该发放贷款(相对地,房利美是否应该获得贷款)
+ 移除 `train` 中银行在发放贷款时间的不知道的任何列
- 当房利美购买贷款时,一些列是已知的,但之前是不知道的
+ 做出预测
* 探索是否你可以预测除了 `foreclosure_status` 的其他列
+ 你可以预测在销售时资产值是多少?
* 探索探索执行数据更新之间的细微差别
+ 你能否预测借款人会逾期还款多少次?
+ 你能否标出的典型贷款周期?
* 将数据按州或邮政编码标出
+ 你看到一些有趣的模式了吗?
如果你建立了任何有趣的东西,请在评论中让我们知道!
如果你喜欢这篇文章,或许你也会喜欢阅读“构建你的数据科学作品集”系列的其他文章:
* [用数据讲故事](https://www.dataquest.io/blog/data-science-portfolio-project/)
* [如何搭建一个数据科学博客](https://www.dataquest.io/blog/how-to-setup-a-data-science-blog/)
* [构建一个可以帮你找到工作的数据科学作品集的关键](https://www.dataquest.io/blog/build-a-data-science-portfolio/)
* [找到数据科学用的数据集的 17 个地方](https://www.dataquest.io/blog/free-datasets-for-projects)
---
via: <https://www.dataquest.io/blog/data-science-portfolio-machine-learning/>
作者:[Vik Paruchuri](https://www.dataquest.io/blog) 译者:[kokialoves](https://github.com/kokialoves), [zky001](https://github.com/zky001), [vim-kakali](https://github.com/vim-kakali), [cposture](https://github.com/cposture), [ideas4u](https://github.com/ideas4u) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # Building a Data Science Portfolio: Machine Learning Project
*(This is the third in a series of posts on how to build a Data Science Portfolio. You can find links to the other posts in this series at the bottom of the post.)*
The first step in making a high-quality portfolio is to know what skills to demonstrate. The primary skills that companies want in data scientists, and thus the primary skills they want a portfolio to demonstrate, are:
- Ability to communicate
- Ability to collaborate with others
- Technical competence
- Ability to reason about data
- Motivation and ability to take initiative
Any good portfolio will be composed of multiple projects, each of which may demonstrate 1-2 of the above points. This is the third post in a series that will cover how to make a well-rounded data science portfolio.
In this post, we'll cover how to make the second project in your portfolio, and how to build an end to end machine learning project. At the end, you'll have a project that shows your ability to reason about data, and your technical competence.
[Here's](https://github.com/dataquestio/loan-prediction) the completed project if you want to take a look.
## An End to End Machine Learning Project
As a data scientist, there are times when you'll be asked to take a data set and figure out how to [tell a story with it](https://www.dataquest.io/blog/data-science-portfolio-project/). In times like this, it's important to communicate very well, and walk through your process. Tools like Jupyter notebook, which we used in a previous post, are very good at helping you do this. The expectation here is that the deliverable is a presentation or document summarizing your findings.
However, there are other times when you'll be asked to create a project that has operational value. A project with operational value directly impacts the day-to-day operations of a company, and will be used more than once, and often by multiple people. A task like this might be "create an algorithm to forecast our churn rate", or "create a model that can automatically tag our articles".
In cases like this, storytelling is less important than technical competence. You need to be able to take a data set, understand it, then create a set of scripts that can process that data. It's often important that these scripts run quickly, and use minimal system resources like memory. It's very common that these scripts will be run several times, so the deliverable becomes the scripts themselves, not a presentation. The deliverable is often integrated into operational flows, and may even be user-facing. The main components of building an end to end project are:
- Understanding the context
- Exploring the data and figuring out the nuances
- Creating a well-structured project, so its easy to integrate into operational flows
- Writing high-performance code that runs quickly and uses minimal system resources
- Documenting the installation and usage of your code well, so others can use it
In order to effectively create a project of this kind, we'll need to work with multiple files. Using a text editor like [Atom](https://atom.io/), or an IDE like [PyCharm](https://www.jetbrains.com/pycharm/) is highly recommended. These tools will allow you to jump between files, and edit files of different types, like markdown files, Python files, and csv files.
Structuring your project so it's easy to version control and upload to collaborative coding tools like [Github](https://github.com/) is also useful.
*This project on Github.* We'll use our editing tools along with libraries like [Pandas](https://pandas.pydata.org/) and [scikit-learn](https://scikit-learn.org/) in this post. We'll make extensive use of Pandas [DataFrames](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html), which make it easy to read in and work with tabular data in Python.
## Finding Good Data Sets
A good data set for an end to end machine learning project can be hard to find. The data set needs to be sufficiently large that memory and performance constraints come into play. It also needs to potentially be operationally useful. For instance, [this data set](https://collegescorecard.ed.gov/data/), which contains data on the adlesson criteria, graduation rates, and graduate future earnings for US colleges would be a great data set to use to tell a story.
However, as you think about the data set, it becomes clear that there isn't enough nuance to build a good end to end project with it. For example, you could tell someone their potential future earnings if they went to a specific college, but that would be a quick lookup without enough nuance to demonstrate technical competence. You could also figure out if colleges with higher adlessons standards tend to have graduates who earn more, but that would be more storytelling than operational.
These memory and performance constraints tend to come into play when you have more than a gigabyte of data, and when you have some nuance to what you want to predict, which involves running algorithms over the data set. A good operational data set enables you to build a set of scripts that transform the data, and answer dynamic questions.
A good example would be a data set of stock prices. You would be able to predict the prices for the next day, and keep feeding new data to the algorithm as the markets closed. This would enable you to make trades, and potentially even profit. This wouldn't be telling a story -- it would be adding direct value. Some good places to find data sets like this are:
-
[/r/datasets](https://reddit.com/r/datasets)— a subreddit that has hundreds of interesting data sets. -
[Google Public Data sets](https://cloud.google.com/bigquery/public-data/#usa-names)— public data sets available through Google BigQuery. -
[Awesome data sets](https://github.com/caesar0301/awesome-public-datasets)— a list of data sets, hosted on Github.
As you look through these data sets, think about what questions someone might want answered with the data set, and think if those questions are one-time ("how did housing prices correlate with the S&P 500?"), or ongoing ("can you predict the stock market?"). The key here is to find questions that are ongoing, and require the same code to be run multiple times with different inputs (different data).
For the purposes of this post, we'll look at [Fannie Mae Loan Data](https://www.fanniemae.com/portal/funding-the-market/data/loan-performance-data.html). Fannie Mae is a government sponsored enterprise in the US that buys mortgage loans from other lenders. It then bundles these loans up into mortgage-backed securities and resells them. This enables lenders to make more mortgage loans, and creates more liquidity in the market. This theoretically leads to more home ownership, and better loan terms.
From a borrowers perspective, things stay largely the same, though.
Fannie Mae releases two types of data -- data on loans it acquires, and data on how those loans perform over time. In the ideal case, someone borrows money from a lender, then repays the loan until the balance is zero. However, some borrowers miss multiple payments, which can cause foreclosure. Foreclosure is when the house is seized by the bank because mortgage payments cannot be made.
Fannie Mae tracks which loans have missed payments on them, and which loans needed to be foreclosed on. This data is published quarterly, and lags the current date by `1`
year.
As of this writing, the most recent data set that's available is from the first quarter of `2015`
. Acquisition data, which is published when the loan is acquired by Fannie Mae, contains information on the borrower, including credit score, and information on their loan and home. Performance data, which is published every quarter after the loan is acquired, contains information on the payments being made by the borrower, and the foreclosure status, if any.
A loan that is acquired may have dozens of rows in the performance data. A good way to think of this is that the acquisition data tells you that Fannie Mae now controls the loan, and the performance data contains a series of status updates on the loan. One of the status updates may tell us that the loan was foreclosed on during a certain quarter.
*A foreclosed home being sold.*
## Picking an Angle
There are a few directions we could go in with the Fannie Mae data set. We could:
- Try to predict the sale price of a house after it's foreclosed on.
- Predict the payment history of a borrower.
- Figure out a score for each loan at acquisition time.
The important thing is to stick to a single angle. Trying to focus on too many things at once will make it hard to make an effective project. It's also important to pick an angle that has sufficient nuance. Here are examples of angles without much nuance:
- Figuring out which banks sold loans to Fannie Mae that were foreclosed on the most.
- Figuring out trends in borrower credit scores.
- Exploring which types of homes are foreclosed on most often.
- Exploring the relationship between loan amounts and foreclosure sale prices
All of the above angles are interesting, and would be great if we were focused on storytelling, but aren't great fits for an operational project. With the Fannie Mae data set, we'll try to predict whether a loan will be foreclosed on in the future by only using information that was available when the loan was acquired. In effect, we'll create a "score" for any mortgage that will tell us if Fannie Mae should buy it or not. This will give us a nice foundation to build on, and will be a great portfolio piece.
## Understanding the Data
Let's take a quick look at the raw data files. Here are the first few rows of the acquisition data from quarter `1`
of `2012`
:
```
100000853384|R|OTHER|4.625|280000|360|02/2012|04/2012|31|31|1|23|801|N|C|SF|1|I|CA|945||FRM|
100003735682|R|SUNTRUST MORTGAGE INC.|3.99|466000|360|01/2012|03/2012|80|80|2|30|794|N|P|SF|1|P|MD|208||FRM|788
100006367485|C|PHH MORTGAGE CORPORATION|4|229000|360|02/2012|04/2012|67|67|2|36|802|N|R|SF|1|P|CA|959||FRM|794
```
Here are the first few rows of the performance data from quarter
`1`
of `2012`
:
```
100000853384|03/01/2012|OTHER|4.625||0|360|359|03/2042|41860|0|N||||||||||||||||
100000853384|04/01/2012||4.625||1|359|358|03/2042|41860|0|N||||||||||||||||
100000853384|05/01/2012||4.625||2|358|357|03/2042|41860|0|N||||||||||||||||
```
Before proceeding too far into coding, it's useful to take some time and really understand the data. This is more critical in operational projects -- because we aren't interactively exploring the data, it can be harder to spot certain nuances unless we find them upfront.
In this case, the first step is to read the materials on the Fannie Mae site:
-
[Overview](https://www.fanniemae.com/portal/funding-the-market/data/loan-performance-data.html) -
[Glossary of useful terms](https://s3.amazonaws.com/dq-blog-files/lppub_glossary.pdf) -
[FAQs](https://s3.amazonaws.com/dq-blog-files/lppub_faq.pdf) -
[Columns in the Acquisition and Performance files](https://s3.amazonaws.com/dq-blog-files/lppub_file_layout.pdf) -
[Sample Acquisition data file](#)(no longer available) -
[Sample Performance data file](#)(no longer available)
After reading through these files, we know some key facts that will help us:
-
There's an Acquisition file and a Performance file for each quarter, starting from the year
`2000`
to present. There's a`1`
year lag in the data, so the most recent data is from`2015`
as of this writing. -
The files are in text format, with a pipe (
`|`
) as a delimiter. - The files don't have headers, but we have a list of what each column is.
-
All together, the files contain data on
`22`
million loans. -
Because the Performance files contain information on loans acquired in previous years, there will be more performance data for loans acquired in earlier years (ie loans acquired in
`2014`
won't have much performance history).
These small bits of information will save us a ton of time as we figure out how to structure our project and work with the data.
## Structuring the Project
Before we start downloading and exploring the data, it's important to think about how we'll structure the project. When building an end-to-end project, our primary goals are:
- Creating a solution that works
- Having a solution that runs quickly and uses minimal resources
- Enabling others to easily extend our work
- Making it easy for others to understand our code
- Writing as little code as possible
In order to achieve these goals, we'll need to structure our project well. A well structured project follows a few principles:
- Separates data files and code files.
- Separates raw data from generated data.
-
Has a
`README.md`
file that walks people through installing and using the project. -
Has a
`requirements.txt`
file that contains all the packages needed to run the project. -
Has a single
`settings.py`
file that contains any settings that are used in other files.-
For example, if you are reading the same file from multiple Python scripts, it's useful to have them all import
`settings`
and get the file name from a centralized place.
-
For example, if you are reading the same file from multiple Python scripts, it's useful to have them all import
-
Has a
`.gitignore`
file that prevents large or secret files from being committed. -
Breaks each step in our task into a separate file that can be executed separately.
- For example, we may have one file for reading in the data, one for creating features, and one for making predictions.
-
Stores intermediate values. For example, one script may output a file that the next script can read.
- This enables us to make changes in our data processing flow without recalculating everything.
Our file structure will look something like this shortly:
```
loan-prediction
├── data
├── processed
├── .gitignore
├── README.md
├── requirements.txt
├── settings.py
```
## Creating the Initial Files
To start with, we'll need to create a `loan-prediction`
folder. Inside that folder, we'll need to make a `data`
folder and a `processed`
folder. The first will store our raw data, and the second will store any intermediate calculated values.
Next, we'll make a `.gitignore`
file. A `.gitignore`
file will make sure certain files are ignored by git and not pushed to Github. One good example of such a file is the `.DS_Store`
file created by OSX in every folder. A good starting point for a `.gitignore`
file is [here](https://github.com/github/gitignore/blob/master/Python.gitignore).
We'll also want to ignore the data files because they are very large, and the Fannie Mae terms prevent us from redistributing them, so we should add two lines to the end of our file:
```
data
processed
```
[Here's](https://github.com/dataquestio/loan-prediction/blob/master/.gitignore) an example `.gitignore`
file for this project. Next, we'll need to create `README.md`
, which will help people understand the project. `.md`
indicates that the file is in markdown format. Markdown enables you write plain text, but also add some fancy formatting if you want. [Here's](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) a guide on markdown. If you upload a file called `README.md`
to Github, Github will automatically process the markdown, and show it to anyone who views the project. [Here's](https://github.com/dataquestio/loan-prediction) an example. For now, we just need to put a simple description in `README.md`
:
```
Loan Prediction
-----------------------
Predict whether or not loans acquired by Fannie Mae will go into foreclosure. Fannie Mae acquires loans from other lenders as a way of inducing them to lend more. Fannie Mae releases data on the loans it has acquired and their performance afterwards [here](https://www.fanniemae.com/portal/funding-the-market/data/loan-performance-data.html).
```
Now, we can create a `requirements.txt`
file. This will make it easy for other people to install our project. We don't know exactly what libraries we'll be using yet, but here's a good starting point:
```
pandas
matplotlib
scikit-learn
numpy
ipython
scipy
```
The above libraries are the most commonly used for data analysis tasks in Python, and its fair to assume that we'll be using most of them. [Here's](https://github.com/dataquestio/loan-prediction/blob/master/requirements.txt) an example requirements file for this project. After creating `requirements.txt`
, you should install the packages. For this post, we'll be using `Python 3`
.
If you don't have Python installed, you should look into using [Anaconda](https://www.anaconda.com/distribution/), a Python installer that also installs all the packages listed above. Finally, we can just make a blank `settings.py`
file, since we don't have any settings for our project yet.
## Acquiring the Data
Once we have the skeleton of our project, we can get the raw data. Fannie Mae has some restrictions around acquiring the data, so you'll need to sign up for an account. You can find the download page [here](https://apps.pingone.com/4c2b23f9-52b1-4f8f-aa1f-1d477590770c/signon/?flowId=03f6778d-1505-44e3-91dc-70698453816d). After creating an account, you'll be able to download as few or as many loan data files as you want.
The files are in zip format, and are reasonably large after decompression. For the purposes of this blog post, we'll download everything from `Q1 2012`
to `Q1 2015`
, inclusive. We'll then need to unzip all of the files. After unzipping the files, remove the original `.zip`
files. At the end, the `loan-prediction`
folder should look something like this:
```
loan-prediction
├── data
│ ├── Acquisition_2012Q1.txt
│ ├── Acquisition_2012Q2.txt
│ ├── Performance_2012Q1.txt
│ ├── Performance_2012Q2.txt
│ └── ...
├── processed
├── .gitignore
├── README.md
├── requirements.txt
├── settings.py
```
After downloading the data, you can use the `head`
and `tail`
shell commands to look at the lines in the files. Do you see any columns that aren't needed? It might be useful to consult the [pdf of column names](https://s3.amazonaws.com/dq-blog-files/lppub_file_layout.pdf) while doing this.
## Reading in the Data
There are two issues that make our data hard to work with right now:
- The acquisition and performance data sets are segmented across multiple files.
- Each file is missing headers.
Before we can get started on working with the data, we'll need to get to the point where we have one file for the acquisition data, and one file for the performance data. Each of the files will need to contain only the columns we care about, and have the proper headers.
One wrinkle here is that the performance data is quite large, so we should try to trim some of the columns if we can. The first step is to add some variables to `settings.py`
, which will contain the paths to our raw data and our processed data. We'll also add a few other settings that will be useful later on:
```
DATA_DIR = "data"
PROCESSED_DIR = "processed"
MINIMUM_TRACKING_QUARTERS = 4
TARGET = "foreclosure_status"
NON_PREDICTORS = [TARGET, "id"]
CV_FOLDS = 3
```
Putting the paths in `settings.py`
will put them in a centralized place and make them easy to change down the line. When referring to the same variables in multiple files, it's easier to put them in a central place than edit them in every file when you want to change them. [Here's](https://github.com/dataquestio/loan-prediction/blob/master/settings.py) an example `settings.py`
file for this project.
The second step is to create a file called `assemble.py`
that will assemble all the pieces into `2`
files. When we run `python assemble.py`
, we'll get `2`
data files in the `processed`
directory. We'll then start writing code in `assemble.py`
.
We'll first need to define the headers for each file, so we'll need to look at [pdf of column names](https://s3.amazonaws.com/dq-blog-files/lppub_file_layout.pdf) and create lists of the columns in each Acquisition and Performance file:
```
HEADERS = {
"Acquisition": [
"id",
"channel",
"seller",
"interest_rate",
"balance",
"loan_term",
"origination_date",
"first_payment_date",
"ltv",
"cltv",
"borrower_count",
"dti",
"borrower_credit_score",
"first_time_homebuyer",
"loan_purpose",
"property_type",
"unit_count",
"occupancy_status",
"property_state",
"zip",
"insurance_percentage",
"product_type",
"co_borrower_credit_score"
],
"Performance": [
"id",
"reporting_period",
"servicer_name",
"interest_rate",
"balance",
"loan_age",
"months_to_maturity",
"maturity_date",
"msa",
"delinquency_status",
"modification_flag",
"zero_balance_code",
"zero_balance_date",
"last_paid_installment_date",
"foreclosure_date",
"disposition_date",
"foreclosure_costs",
"property_repair_costs",
"recovery_costs",
"misc_costs",
"tax_costs",
"sale_proceeds",
"credit_enhancement_proceeds",
"repurchase_proceeds",
"other_foreclosure_proceeds",
"non_interest_bearing_balance",
"principal_forgiveness_balance"
]
}
```
The next step is to define the columns we want to keep. Since all we're measuring on an ongoing basis about the loan is whether or not it was ever foreclosed on, we can discard many of the columns in the performance data. We'll need to keep all the columns in the acquisition data, though, because we want to maximize the information we have about when the loan was acquired (after all, we're predicting if the loan will ever be foreclosed or not at the point it's acquired). Discarding columns will enable us to save disk space and memory, while also speeding up our code.
```
SELECT = {
"Acquisition": HEADERS["Acquisition"],
"Performance": [
"id",
"foreclosure_date"
]
}
```
Next, we'll write a function to concatenate the data sets. The below code will:
-
Import a few needed libraries, including
`settings`
. -
Define a function
`concatenate`
, that:-
Gets the names of all the files in the
`data`
directory. -
Loops through each file.
- If the file isn't the right type (doesn't start with the prefix we want), we ignore it.
-
Reads the file into a
[DataFrame](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html)with the right settings using the Pandas[read_csv](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html)function.-
Sets the separator to
`|`
so the fields are read in correctly. -
The data has no header row, so sets
`header`
to`None`
to indicate this. -
Sets names to the right value from the
`HEADERS`
dictionary -- these will be the column names of our DataFrame. -
Picks only the columns from the DataFrame that we added in
`SELECT`
.
-
Sets the separator to
- Concatenates all the DataFrames together.
- Writes the concatenated DataFrame back to a file.
-
Gets the names of all the files in the
```
import os
import settings
import pandas as pd
def concatenate(prefix="Acquisition"):
files = os.listdir(settings.DATA_DIR)
full = []
for f in files:
if not f.startswith(prefix):
continue
data = pd.read_csv(os.path.join(settings.DATA_DIR, f), sep="|", header=None, names=HEADERS[prefix], index_col=False)
data = data[SELECT[prefix]]
full.append(data)
full = pd.concat(full, axis=0)
full.to_csv(os.path.join(settings.PROCESSED_DIR, "{}.txt".format(prefix)), sep="|", header=SELECT[prefix], index=False)
```
We can call the above function twice with the arguments
`Acquisition`
and `Performance`
to concatenate all the acquisition and performance files together. The below code will:
-
Only execute if the script is called from the command line with
`python assemble.py`
. -
Concatenate all the files, and result in two files:
-
`processed/Acquisition.txt`
-
`processed/Performance.txt`
-
```
if __name__ == "__main__":
concatenate("Acquisition")
concatenate("Performance")
```
We now have a nice, compartmentalized `assemble.py`
that's easy to execute, and easy to build off of. By decomposing the problem into pieces like this, we make it easy to build our project. Instead of one messy script that does everything, we define the data that will pass between the scripts, and make them completely separate from each other.
When you're working on larger projects, it's a good idea to do this, because it makes it much easier to change individual pieces without having unexpected consequences on unrelated pieces of the project. Once we finish the `assemble.py`
script, we can run `python assemble.py`
. You can find the complete `assemble.py`
file [here](https://github.com/dataquestio/loan-prediction/blob/master/assemble.py). This will result in two files in the `processed`
directory:
```
loan-prediction
├── data
│ ├── Acquisition_2012Q1.txt
│ ├── Acquisition_2012Q2.txt
│ ├── Performance_2012Q1.txt
│ ├── Performance_2012Q2.txt
│ └── ...
├── processed
│ ├── Acquisition.txt
│ ├── Performance.txt
├── .gitignore
├── assemble.py
├── README.md
├── requirements.txt
├── settings.py
```
## Computing Values From the Performance Data
The next step we'll take is to calculate some values from `processed/Performance.txt`
. All we want to do is to predict whether or not a property is foreclosed on. To figure this out, we just need to check if the performance data associated with a loan ever has a `foreclosure_date`
. If `foreclosure_date`
is `None`
, then the property was never foreclosed on.
In order to avoid including loans with little performance history in our sample, we'll also want to count up how many rows exist in the performance file for each loan. This will let us filter loans without much performance history from our training data. One way to think of the loan data and the performance data is like this:
As you can see above, each row in the Acquisition data can be related to multiple rows in the Performance data. In the Performance data, `foreclosure_date`
will appear in the quarter when the foreclosure happened, so it should be blank prior to that. Some loans are never foreclosed on, so all the rows related to them in the Performance data have `foreclosure_date`
blank.
We need to compute `foreclosure_status`
, which is a Boolean that indicates whether a particular loan `id`
was ever foreclosed on, and `performance_count`
, which is the number of rows in the performance data for each loan `id`
. There are a few different ways to compute the counts we want:
-
We could read in all the performance data, then use the Pandas
[groupby](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html)method on the DataFrame to figure out the number of rows associated with each loan`id`
, and also if the`foreclosure_date`
is ever not`None`
for the`id`
.- The upside of this method is that it's easy to implement from a syntax perspective.
-
The downside is that reading in all
`129236094`
lines in the data will take a lot of memory, and be extremely slow.
-
We could read in all the performance data, then use
[apply](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html)on the acquisition DataFrame to find the counts for each`id`
.- The upside is that it's easy to conceptualize.
-
The downside is that reading in all
`129236094`
lines in the data will take a lot of memory, and be extremely slow.
-
We could iterate over each row in the performance data set, and keep a separate dictionary of counts.
- The upside is that the data set doesn't need to be loaded into memory, so it's extremely fast and memory-efficient.
- The downside is that it will take slightly longer to conceptualize and implement, and we need to parse the rows manually.
Loading in all the data will take quite a bit of memory, so let's go with the third option above. All we need to do is to iterate through all the rows in the Performance data, while keeping a dictionary of counts per loan `id`
.
In the dictionary, we'll keep track of how many times the `id`
appears in the performance data, as well as if `foreclosure_date`
is ever not `None`
. This will give us `foreclosure_status`
and `performance_count`
. We'll create a new file called `annotate.py`
, and add in code that will enable us to compute these values. In the below code, we'll:
- Import needed libraries.
-
Define a function called
`count_performance_rows`
.-
Open
`processed/Performance.txt`
. This doesn't read the file into memory, but instead opens a file handler that can be used to read in the file line by line. -
Loop through each line in the file.
-
Split the line on the delimiter (
`|`
) -
Check if the
`loan_id`
is not in the`counts`
dictionary.-
If not, add it to
`counts`
.
-
If not, add it to
-
Increment
`performance_count`
for the given`loan_id`
because we're on a row that contains it. -
If
`date`
is not`None`
, then we know that the loan was foreclosed on, so set`foreclosure_status`
appropriately.
-
Split the line on the delimiter (
-
Open
```
import os
import settings
import pandas as pd
def count_performance_rows():
counts = {}
with open(os.path.join(settings.PROCESSED_DIR, "Performance.txt"), 'r') as f:
for i, line in enumerate(f):
if i == 0:
# Skip header row
continue
loan_id, date = line.split("|")
loan_id = int(loan_id)
if loan_id not in counts:
counts[loan_id] = {
"foreclosure_status": False,
"performance_count": 0
}
counts[loan_id]["performance_count"] += 1
if len(date.strip()) > 0:
counts[loan_id]["foreclosure_status"] = True
return counts
```
## Getting the Values
Once we create our counts dictionary, we can make a function that will extract values from the dictionary if a `loan_id`
and a `key`
are passed in:
```
def get_performance_summary_value(loan_id, key, counts):
value = counts.get(loan_id, {
"foreclosure_status": False,
"performance_count": 0
})
return value[key]
```
The above function will return the appropriate value from the `counts`
dictionary, and will enable us to assign a `foreclosure_status`
value and a `performance_count`
value to each row in the Acquisition data. The [get](https://docs.python.org/3/library/stdtypes.html#dict.get) method on dictionaries returns a default value if a key isn't found, so this enables us to return sensible default values if a key isn't found in the counts dictionary.
## Annotating the Data
We've already added a few functions to `annotate.py`
, but now we can get into the meat of the file. We'll need to convert the acquisition data into a training data set that can be used in a machine learning algorithm. This involves a few things:
- Converting all columns to numeric.
- Filling in any missing values.
-
Assigning a
`performance_count`
and a`foreclosure_status`
to each row. -
Removing any rows that don't have a lot of performance history (where
`performance_count`
is low).
Several of our columns are strings, which aren't useful to a machine learning algorithm. However, they are actually categorical variables, where there are a few different category codes, like `R`
, `S`
, and so on.
We can convert these columns to numeric by assigning a number to each category label: Converting the columns this way will allow us to use them in our machine learning algorithm. Some of the columns also contain dates (
`first_payment_date`
and `origination_date`
). We can split these dates into `2`
columns each:
In the below code, we'll transform the Acquisition data. We'll define a function that:
-
Creates a
`foreclosure_status`
column in`acquisition`
by getting the values from the`counts`
dictionary. -
Creates a
`performance_count`
column in`acquisition`
by getting the values from the`counts`
dictionary. -
Converts each of the following columns from a string column to an integer column:
-
`channel`
-
`seller`
-
`first_time_homebuyer`
-
`loan_purpose`
-
`property_type`
-
`occupancy_status`
-
`property_state`
-
`product_type`
-
-
Converts
`first_payment_date`
and`origination_date`
to`2`
columns each:- Splits the column on the forward slash.
-
Assigns the first part of the split list to a
`month`
column. -
Assigns the second part of the split list to a
`year`
column. - Deletes the column.
-
At the end, we'll have
`first_payment_month`
,`first_payment_year`
,`origination_month`
, and`origination_year`
.
-
Fills any missing values in
`acquisition`
with`-1`
.
```
def annotate(acquisition, counts):
acquisition["foreclosure_status"] = acquisition["id"].apply(lambda x: get_performance_summary_value(x, "foreclosure_status", counts))
acquisition["performance_count"] = acquisition["id"].apply(lambda x: get_performance_summary_value(x, "performance_count", counts))
for column in [
"channel",
"seller",
"first_time_homebuyer",
"loan_purpose",
"property_type",
"occupancy_status",
"property_state",
"product_type"
]:
acquisition[column] = acquisition[column].astype('category').cat.codes
for start in ["first_payment", "origination"]:
column = "{}_date".format(start)
acquisition["{}_year".format(start)] = pd.to_numeric(acquisition[column].str.split('/').str.get(1))
acquisition["{}_month".format(start)] = pd.to_numeric(acquisition[column].str.split('/').str.get(0))
del acquisition[column]
acquisition = acquisition.fillna(-1)
acquisition = acquisition[acquisition["performance_count"] > settings.MINIMUM_TRACKING_QUARTERS]
return acquisition
```
## Pulling Everything Together
We're almost ready to pull everything together, we just need to add a bit more code to `annotate.py`
. In the below code, we:
- Define a function to read in the acquisition data.
-
Define a function to write the processed data to
`processed/train.csv`
-
If this file is called from the command line, like
`python annotate.py`
:- Read in the acquisition data.
-
Compute the counts for the performance data, and assign them to
`counts`
. -
Annotate the
`acquisition`
DataFrame. -
Write the
`acquisition`
DataFrame to`train.csv`
.
```
def read():
acquisition = pd.read_csv(os.path.join(settings.PROCESSED_DIR, "Acquisition.txt"), sep="|")
return acquisition
def write(acquisition):
acquisition.to_csv(os.path.join(settings.PROCESSED_DIR, "train.csv"), index=False)
if __name__ == "__main__":
acquisition = read()
counts = count_performance_rows()
acquisition = annotate(acquisition, counts)
write(acquisition)
```
Once you're done updating the file, make sure to run it with `python annotate.py`
, to generate the `train.csv`
file. You can find the complete `annotate.py`
file [here](https://github.com/dataquestio/loan-prediction/blob/master/annotate.py). The folder should now look like this:
```
loan-prediction
├── data
│ ├── Acquisition_2012Q1.txt
│ ├── Acquisition_2012Q2.txt
│ ├── Performance_2012Q1.txt
│ ├── Performance_2012Q2.txt
│ └── ...
├── processed
│ ├── Acquisition.txt
│ ├── Performance.txt
│ ├── train.csv
├── .gitignore
├── annotate.py
├── assemble.py
├── README.md
├── requirements.txt
├── settings.py
```
## Finding an Error Metric for Our Machine Learning Project
We're done with generating our training data set, and now we'll just need to do the final step, generating predictions. We'll need to figure out an error metric, as well as how we want to evaluate our data.
In this case, there are many more loans that aren't foreclosed on than are, so typical accuracy measures don't make much sense. If we read in the training data, and check the counts in the `foreclosure_status`
column, here's what we get:
```
import pandas as pd
import settings
train = pd.read_csv(os.path.join(settings.PROCESSED_DIR, "train.csv"))
train["foreclosure_status"].value_counts()
```
```
False 4635982
True 1585
Name: foreclosure_status, dtype: int64
```
Since so few of the loans were foreclosed on, just checking the percentage of labels that were correctly predicted will mean that we can make a machine learning model that predicts `False`
for every row, and still gets a very high accuracy. Instead, we'll want to use a metric that takes the class imbalance into account, and ensures that we predict foreclosures accurately.
We don't want too many false positives, where we make predictions that a loan will be foreclosed on even though it won't, or too many false negatives, where we predict that a loan won't be foreclosed on, but it is. Of these two, false negatives are more costly for Fannie Mae, because they're buying loans where they may not be able to recoup their investment.
We'll define false negative rate as the number of loans where the model predicts no foreclosure but the loan was actually foreclosed on, divided by the number of total loans that were actually foreclosed on. This is the percentage of actual foreclosures that the model "Missed".
Here's a diagram:
In the diagram above, `1`
loan was predicted as not being foreclosed on, but it actually was. If we divide this by the number of loans that were actually foreclosed on, `2`
, we get the false negative rate, `50%`
. We'll use this as our error metric, so we can evaluate our model's performance.
## Setting up the Classifier for Machine Learning
We'll use cross-validation to make predictions. With cross-validation, we'll divide our data into `3`
groups. Then we'll do the following:
-
Train a model on groups
`1`
and`2`
, and use the model to make predictions for group`3`
. -
Train a model on groups
`1`
and`3`
, and use the model to make predictions for group`2`
. -
Train a model on groups
`2`
and`3`
, and use the model to make predictions for group`1`
.
Splitting it up into groups this way means that we never train a model using the same data we're making predictions for. This avoids overfitting. If we overfit, we'll get a falsely low false negative rate, which makes it hard to improve our algorithm or use it in the real world. [Scikit-learn](https://scikit-learn.org/) has a function called [cross_val_predict](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.cross_val_predict.html) which will make it easy to perform cross validation.
We'll also need to pick an algorithm to use to make predictions. We need a classifier that can do [binary classification](https://en.wikipedia.org/wiki/Binary_classification). The target variable, `foreclosure_status`
only has two values, `True`
and `False`
. We'll use [logistic regression](https://en.wikipedia.org/wiki/Logistic_regression), because it works well for binary classification, runs extremely quickly, and uses little memory. This is due to how the algorithm works — instead of constructing dozens of trees, like a random forest, or doing expensive transformations, like a support vector machine, logistic regression has far fewer steps involving fewer matrix operations. We can use the [logistic regression classifier](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) algorithm that's implemented in scikit-learn.
The only thing we need to pay attention to is the weights of each class. If we weight the classes equally, the algorithm will predict `False`
for every row, because it is trying to minimize errors. However, we care much more about foreclosures than we do about loans that aren't foreclosed on. Thus, we'll pass `balanced`
to the `class_weight`
keyword argument of the [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) class, to get the algorithm to weight the foreclosures more to account for the difference in the counts of each class. This will ensure that the algorithm doesn't predict `False`
for every row, and instead is penalized equally for making errors in predicting either class.
## Making Predictions
Now that we have the preliminaries out of the way, we're ready to make predictions. We'll create a new file called `predict.py`
that will use the `train.csv`
file we created in the last step. The below code will:
- Import needed libraries.
-
Create a function called
`cross_validate`
that:- Creates a logistic regression classifier with the right keyword arguments.
-
Creates a list of columns that we want to use to train the model, removing
`id`
and`foreclosure_status`
. -
Run cross validation across the
`train`
DataFrame. - Return the predictions.
```
import os
import settings
import pandas as pd
from sklearn.model_selection import cross_validation
from sklearn.linear_model import LogisticRegression
from sklearn import metrics
def cross_validate(train):
clf = LogisticRegression(random_state=1, class_weight="balanced")
predictors = train.columns.tolist()
predictors = [p for p in predictors if p not in settings.NON_PREDICTORS]
predictions = cross_validation.cross_val_predict(clf, train[predictors], train[settings.TARGET], cv=settings.CV_FOLDS)
return predictions
```
## Predicting Error
Now, we just need to write a few functions to compute error. The below code will:
-
Create a function called
`compute_error`
that:-
Uses scikit-learn to compute a simple accuracy score (the percentage of predictions that matched the actual
`foreclosure_status`
values).
-
Uses scikit-learn to compute a simple accuracy score (the percentage of predictions that matched the actual
-
Create a function called
`compute_false_negatives`
that:- Combines the target and the predictions into a DataFrame for convenience.
- Finds the false negative rate.
-
Create a function called
`compute_false_positives`
that:- Combines the target and the predictions into a DataFrame for convenience.
-
Finds the false positive rate.
- Finds the number of loans that weren't foreclosed on that the model predicted would be foreclosed on.
- Divide by the total number of loans that weren't foreclosed on.
```
def compute_error(target, predictions):
return metrics.accuracy_score(target, predictions)
def compute_false_negatives(target, predictions):
df = pd.DataFrame({"target": target, "predictions": predictions})
return df[(df["target"] == 1) & (df["predictions"] == 0)].shape[0] / (df[(df["target"] == 1)].shape[0] + 1)
def compute_false_positives(target, predictions):
df = pd.DataFrame({"target": target, "predictions": predictions})
return df[(df["target"] == 0) & (df["predictions"] == 1)].shape[0] / (df[(df["target"] == 0)].shape[0] + 1)
```
## Putting It All Together
Now, we just have to put the functions together in `predict.py`
. The below code will:
- Read in the data set.
- Compute cross validated predictions.
-
Compute the
`3`
error metrics above. - Print the error metrics.
```
def read():
train = pd.read_csv(os.path.join(settings.PROCESSED_DIR, "train.csv"))
return train
if __name__ == "__main__":
train = read()
predictions = cross_validate(train)
error = compute_error(train[settings.TARGET], predictions)
fn = compute_false_negatives(train[settings.TARGET], predictions)
fp = compute_false_positives(train[settings.TARGET], predictions)
print("Accuracy Score: {}".format(error))
print("False Negatives: {}".format(fn))
print("False Positives: {}".format(fp))
```
Once you've added the code, you can run `python predict.py`
to generate predictions. Running everything shows that our false negative rate is `.26`
, which means that of the foreclosed loans, we missed predicting `26%`
of them.
This is a good start, but can use a lot of improvement! You can find the complete `predict.py`
file [here](https://github.com/dataquestio/loan-prediction/blob/master/predict.py). Your file tree should now look like this:
```
loan-prediction
├── data
│ ├── Acquisition_2012Q1.txt
│ ├── Acquisition_2012Q2.txt
│ ├── Performance_2012Q1.txt
│ ├── Performance_2012Q2.txt
│ └── ...
├── processed
│ ├── Acquisition.txt
│ ├── Performance.txt
│ ├── train.csv
├── .gitignore
├── annotate.py
├── assemble.py
├── predict.py
├── README.md
├── requirements.txt
├── settings.py
```
## Writing Up a README
Now that we've finished our end to end project, we just have to write up a `README.md`
file so that other people know what we did, and how to replicate it. A typical `README.md`
for a project should include these sections:
- A high level overview of the project, and what the goals are.
- Where to download any needed data or materials.
-
Installation instructions.
- How to install the requirements.
-
Usage instructions.
- How to run the project.
- What you should see after each step.
-
How to contribute to the project.
- Good next steps for extending the project.
[Here's](https://github.com/dataquestio/loan-prediction/blob/master/README.md) a sample `README.md`
for this project.
## Next Steps
Congratulations, you're done making an end to end machine learning project! You can find a complete example project [here](https://github.com/dataquestio/loan-prediction).
It's a good idea to upload your project to [Github](https://www.github.com) once you've finished it, so others can see it as part of your portfolio. There are still quite a few angles left to explore with this data. Broadly, we can split them up into `3`
categories -- extending this project and making it more accurate, finding other columns to predict, and exploring the data. Here are some ideas:
-
Generate more features in
`annotate.py`
. -
Switch algorithms in
`predict.py`
. - Try using more data from Fannie Mae than we used in this post.
- Add in a way to make predictions on future data. The code we wrote will still work if we add more data, so we can add more past or future data.
-
Try seeing if you can predict if a bank should have issued the loan originally (vs if Fannie Mae should have acquired the loan).
-
Remove any columns from
`train`
that the bank wouldn't have known at the time of issuing the loan.- Some columns are known when Fannie Mae bought the loan, but not before.
- Make predictions.
-
Remove any columns from
-
Explore seeing if you can predict columns other than
`foreclosure_status`
.- Can you predict how much the property will be worth at sale time?
-
Explore the nuances between performance updates.
- Can you predict how many times the borrower will be late on payments?
- Can you map out the typical loan lifecycle?
-
Map out data on a state by state or zip code by zip code level.
- Do you see any interesting patterns?
If you build anything interesting, please [let us know](https://twitter.com/dataquestio)! At [Dataquest](https://www.dataquest.io), our interactive guided projects are designed to help you start building a data science portfolio to demonstrate your skills to employers and get a job in data. If you're interested, you can [sign up and do our first module for free](https://www.dataquest.io).
*If you liked this, you might like to read the other posts in our 'Build a Data Science Portfolio' series:* |
7,909 | 开发者的实用 Vim 插件(二) | https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-2-syntastic/ | 2016-10-28T16:39:00 | [
"插件",
"Syntastic",
"Vim"
] | https://linux.cn/article-7909-1.html | 毫无疑问,Vim 是一个开箱即用并能够胜任编程任务的编辑器,但实际上是该编辑器中的插件帮你实现这些方便的功能。在 [开发者的实用 Vim 插件(一)](/article-7901-1.html),我们已经讨论两个编程相关的 Vim 插件——标签侧边栏(Tagbar)和定界符自动补齐(delimitMate)。作为相同系列,我们在本文讨论另一个非常有用、专门为软件开发正定制的插件——语法高亮插件。

请注意:本教程中列举的所有例示、命令和说明都是在 Ubuntu 16.04 环境下进行测试的,并且,我们使用的 Vim 版本是 7.4。
### 语法高亮(Syntastic)插件
假如你的软件开发工作涉及到 C/C++ 语言,毫无疑问的说,遇到编译错误也是你每天工作中的一部分。很多时候,编译错误是由源代码之中的语法不正确造成的,因为开发者在浏览源码的时候很少能够一眼就看出所有这些错误。
那么 Vim 中是否存在一种插件可以让你不经编译源码就可以显示出语法错误呢?当然是有这样一种插件的,其名字就是 Syntastic。
“Syntastic 是 Vim 用来检验语法的插件,通过外部语法校验器校验文件并将错误呈现给用户。该过程可以在需要时进行,或者在文件保存的时候自动进行。”该插件 [官方文档](https://github.com/scrooloose/syntastic) 如是说。“如果检测到语法错误就会提示用户,因为不用编译代码或者执行脚本就可以知道语法错误,用户也就乐享与此了。”
安装过程和第一部分提到的方法类似,你只需要运行下列命令即可:
```
cd ~/.vim/bundle/
git clone https://github.com/scrooloose/syntastic.git
```
一旦你成功安装这个插件(即上述命令执行成功),你就不需要进行任何配置了——当 Vim 启动时会自动加载这个插件。
现在,打开一个源码文件并用 `:w` Vim 命令保存即可使用这个插件了。等待片刻之后,如果在源码中有语法错误的好,就会高亮显示出来。比如,看看一下截图你就会明白该插件是如何高亮显示语法错误的:

在每行之前的 `>>` 表示该行中有语法错误。了解确切的错误或者想知道是什么东西错了,将光标移到该行——错误描述就会展示在 Vim 窗口的最底下。

这样,不用进行编译你就能够修复大多数语法相关的错误。
再往下,如果你运行 `:Errors` 命令,就会展现当前源文件中所有语法相关错误的描述。比如,我运行 `:Errors` 命令就是下图的效果:

请记住,`:Errors` 展现的语法错误是不会自动更新的,这意味着在你修复错误之后,你需要重新运行 `:Errors` 命令,编辑器底部的错误描述才会消除。
值得一提的是,还有 [许多配置选项](https://github.com/scrooloose/syntastic/blob/master/doc/syntastic.txt) 能够使得 Syntastic 插件使用起来更加友好。比如,你可以在你的 `.vimrc` 中添加下列内容,然后 `:Errors` 就可以在修复错误之后自动更新它的底部描述。
```
let g:syntastic_always_populate_loc_list = 1
```
添加以下内容,以确保在你打开文件时 Syntastic 插件自动高亮显示错误。
```
let g:syntastic_check_on_open = 1
```
类似的,你也可以在保存或打开文件时让光标跳转到检测到的第一个问题处,将下列行放到你的 `.vimrc` 文件之中:
```
let g:syntastic_auto_jump = 1
```
这个值也可以指定为其它两个值: 2 和 3,其官方文档的解释如下:
“如果设置为 2 的话,光标就会跳到检测到的第一个问题,当然,只有这个问题是一个错误的时候才跳转;设置为 3 的话,如果存在错误,则会跳到第一个错误。所有检测到的问题都会有警告,但光标不会跳转。”
以下信息可能对你有帮助:
“使用 `:SyntasticCheck` 来手动检测错误。使用 `:Errors` 打开错误位置列表并使用 `:lclose` 来关闭。使用 `:SyntasticReset` 可以清除掉错误列表,使用 `:SyntasticToggleMode` 来切换激活(在写到 buffer 时检测)和被动(即手动检测)检测错误。”
注意:Syntastic 并不局限于 C/C++ 所写的代码,它同时也支持很多的编程语言——点击 [此处](https://github.com/scrooloose/syntastic) 了解更多相关信息。
### 结论
毫无疑问的,Syntastic 是一个非常有用的 Vim 插件,因为在出现语法相关错误时候,它至少能够让免去频繁编译的麻烦,而且不用说,同时也节约了你不少的时间。
正如你所看到的一样,配置好几个主要选项之后,Syntastic 变得非常好用了。为了帮助你了解这些设置,官方文档中包含了一份“推荐设置”——跟着文档进行设置即可。加入你遇到一些错误、有些疑问或者问题,你也可以查询一下 FAQ。
---
via: <https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-2-syntastic/>
作者:[Ansh](https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-2-syntastic/) 译者:[GHLandy](https://github.com/GHLandy) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # Useful Vim editor plugins for software developers - part 2: Syntastic
There's no doubt that Vim is a capable programming editor out-of-the-box, but it's the editor's plugins that help you make the most out of it. In the [first part](https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers/) of this article series, we discussed a couple of programing-related Vim plugins (Tagbar and delimitMate). Continuing on the same path, in this article, we will discuss another useful Vim plugin aimed at software developers - **Syntastic**.
Please note that all the examples, commands, and instructions mentioned in this tutorial have been tested on Ubuntu 16.04, and the Vim version we've used is 7.4.
## Syntastic
If your software development work involves working with languages like C and C++, it's needless to say that resolving compile time errors would be part of your daily work. Many a times, compilation errors arise due to incorrect syntax used in source code, as developers fail to observe them while just looking at the code.
What if I tell you there exists a Vim plugin that provides information about syntax errors without you having to compile your code? Yes, such a plugin exists, and it's name is Syntastic.
"Syntastic is a syntax checking plugin for [Vim](http://www.vim.org/) that runs files through external syntax checkers and displays any resulting errors to the user. This can be done on demand, or automatically as files are saved," the [official documentation](https://github.com/scrooloose/syntastic) of the plugin says. "If syntax errors are detected, the user is notified and is happy because they didn't have to compile their code or execute their script to find them."
Installation of this plugin is similar to the way we installed the ones that were discussed in the first part - all you need to do is to run the following commands:
cd ~/.vim/bundle/
git clone https://github.com/scrooloose/syntastic.git
Once the plugin is installed successfully (meaning the above commands are successful), you don't have to do anything else - it loads automatically when the Vim editor is launched.
Now, to use the plugin, open a source code file and save it using the **:w** Vim command. After a very brief pause, you'll observe that syntax errors - if any - in your code will be highlighted. For example, the following screenshot should give you an idea about how the plugin highlights the errors:
The '>>' sign in the beginning of a line indicates that there's some problem with the code written in that line. To know what exactly the error is, or at-least get a rough idea about it, bring the cursor to that line - the error description will be displayed at the bottom of the Vim window.
So this way, you can resolve most of the syntax-related errors without even compiling the code.
Moving on, if you run the **:Errors** command, description of all the syntax-related errors in the current source file will be displayed. For example, running the **:Errors** command in my case brought up the following information:
Keep in mind that the information the **:Errors** command displays isn't auto-refreshed, meaning even after an error is resolved, it's description will be there at the bottom area until you run the **:Errors** command again.
It's worth mentioning that there are [many configuration options](https://github.com/scrooloose/syntastic/blob/master/doc/syntastic.txt) that make Syntastic even more user-friendly. For example, you can put the following line in your *.vimrc* file if you want the **:Errors** command to automatically update its output each time an error is resolved:
let g:syntastic_always_populate_loc_list = 1
Another major limitation that the default Syntastic behaviour has is that you have to run the **:w** command in order to get the plugin to indicate erroneous lines - this is ok while editing a file, but gets a bit weird when you've just opened a source file.
To make sure that Syntastic highlights the errors automatically when a file is opened, add the following line to your *.vimrc* file:
let g:syntastic_check_on_open = 1
Similarly, if you want the cursor to jump to the first detected issue when saving or opening a file, then put the following line in your .vimrc file:
`let g:syntastic_auto_jump = 1`
There are two other values that you can assign to the aforementioned variable: 2 and 3. Here is what the official documentation says about these two values:
"When set to 2 the cursor will jump to the first issue detected, but only if this issue is an error," and "when set to 3 the cursor will jump to the first error detected, if any. If all issues detected are warnings, the cursor won't jump."
The following information should also be useful to you:
"Use **:SyntasticCheck** to manually check" for errors. "Use **:Errors** to open the location-list window, and **:lclose** to close it. You can clear the error list with **:SyntasticReset**, and you can use **:SyntasticToggleMode** to switch between active (checking on writing the buffer) and passive (manual) checking."
**Note**: Syntastic isn't just limited to code written in C and C++. It supports a huge list of other programming languages as well - head [here](https://github.com/scrooloose/syntastic) to learn more about it.
## Conclusion
Undoubtedly, Syntastic is a very useful Vim plugin as it saves you from the hassle of frequent compilation at-least when it comes to syntax-related errors. And not to mention that a lot of your time gets saved as well.
As you would have observed, Syntastic becomes even more useful once you've configured some of its main options. To help you get started with this, the official documentation contains a 'Recommended settings' section - do go through that. There is a nice little FAQ section as well in case you face some errors or have some doubts or queries. |
7,910 | 7 个 Linux 新手容易犯的错误 | http://www.datamation.com/open-source/7-mistakes-new-linux-users-make.html | 2016-10-30T13:15:00 | [
"新手"
] | https://linux.cn/article-7910-1.html | 
换操作系统对每个人来说都是一件大事——尤其是许多用户根本不清楚操作系统是什么。
然而,从 Windows 切换到 Linux 特别地困难。这两个操作系统有着不同的前提和优先级,以及不同的处理方式。结果导致 Linux 新手容易混淆,因为他们在 Windows 上面得到经验不再适用。
例如,这里有 7 个 Windows “难民”开始使用 Linux 的时候会犯的错误(没有先后顺序):
### 7. 选择错误的 Linux 发行版
Linux 有几百个不同的版本,或者按他们的称呼叫做<ruby> 发行版 <rp> ( </rp> <rt> distribution </rt> <rp> ) </rp></ruby>。其中许多是专门针对不同的版本或用户的。选择了错误的版本,你与 Linux 的第一次亲密体验将很快变成一个噩梦。
如果你是在朋友的帮助下切换的话,确认他们的建议是适合你,而不是他们。有大量的文章可以帮助到你,你只需要关注前 20 名左右的或者列在 [Distrowatch](http://distrowatch.com/) 的即可,就不太可能会搞错。
更好的做法是,在你安装某个发行版之前先试试它的 [Live DVD](https://en.wikipedia.org/wiki/Live_CD)。Live DVD 是在外设上运行发行版的,这样可以允许你在不对硬盘做任何改动的情况下对其进行测试。事实上,除非你知道怎么让硬盘在 Linux 下可访问,否则你是不会看到你的硬盘的。
### 6. 期待什么都是一样的
由于经验有限,许多 Windows 用户不知道新的操作系统意味着新的程序和新的处理方式。事实上你的 Windows 程序是无法在 Linux 上运行的,除非你用 [WINE](https://en.wikipedia.org/wiki/Wine_%28software%29) 或者 Windows 虚拟机。而且你还不能用 MS Office 或者 PhotoShop —— 你必须要学会使用 LibreOffice 和 Krita。经过这些年,这些应用可能会有和 Windows 上的应用类似的功能,但它们的功能可能具有不同的名称,并且会从不同的菜单或工具栏获得。
就连很多想当然的都不一样了。Windows 用户会特别容易因为他们有多个桌面环境可以选择而大吃一惊——至少有一个主要的和很多次要的桌面环境。
### 5. 安装软件的时候不知所措
在 Windows 上,新软件是作为一个完全独立的程序来安装的。通常它囊括了其它所需的依赖库。
有两种叫做 [Flatpak](http://flatpak.org/) 和 [Snap](http://snapcraft.io/) 的软件包服务目前正在 Linux 上引进类似的安装系统,但是它们对于移动设备和嵌入式设备来说太大了。更多情况下,Linux 依赖于包管理系统,它会根据已安装的包来判断软件的依赖包是否是必需的,从而提供其它所需的依赖包。
笔记本和工作站上的包管理本质上相当于手机或平板电脑上的 Google Play:它速度很快,并且不需要用于安装的物理介质。不仅如此,它还可以节省 20%-35% 的硬盘空间,因为依赖包不会重复安装。
### 4. 假想软件会自动更新好
Linux 用户认为控制权很重要。Linux 提供更新服务,不过默认需要用户手动运行。例如,大多数发行版会让你知道有可用的软件更新,但是你需要选择安装这些更新。
如果你选择更新的话,你甚至可以单独决定每一个更新。例如,你可能不想更新到新的内核,因为你安装了一些东西需要使用当前的内核。又或者你想要安装所有的安全性更新,但不想把发行版更新到一个新的版本。一切都由你来选择。
### 3. 忘记密码
许多 Windows 用户因为登录不方便而忘记密码。又或者为了方便起见,经常运行一个管理账户。
在 Linux 上这两种做法都不容易。许多发行版使用 [sudo](https://en.wikipedia.org/wiki/Sudo) 来避免以 root 登录,特别是那些基于 Ubuntu 的发行版,而其它发行版大多数是安装为禁止 root 运行图形界面。但是,如果你在 Linux 上成功绕开了这些限制,请注意你的大部分 Linux 安全性优势都会无效(其实在 Windows 上也不推荐这样做)。
对了,你是不是在安装程序上看到一个自动登录的选项?那是在不常用的情景下使用的,例如不包含隐私信息的虚拟机。
### 2. 担心没有碎片整理和杀毒软件
Linux 偶尔需要进行碎片整理,不过只有在恢复分区或者分区差不多满了的时候。并且由于固态硬盘越来越火,碎片整理正在变成过去时,尽管固态硬盘确实需要在任何操作系统上定期运行 [trim](https://en.wikipedia.org/wiki/Trim_%28computing%29)。
同样地,只有当你安装的 Linux 经常传输文件给 Windows 机器的时候,杀毒软件才是一个主要问题。很少有 Linux 病毒或恶意软件存在,并且日常使用非 root 用户、使用强密码、经常备份当前文件就已经足够阻止病毒了。
### 1. 认为自己没有软件可用
Windows 上的软件是收费的,大多数类别由一家公司独占——例如,办公套装 MS Office 以及图形和设计的 Adobe。这些条件鼓励用户坚持使用相同的应用程序,尽管它们错漏百出。
在 Linux 上,故事情节不一样了。只有少数高端程序是收费的,而且几乎每一类软件都有两三个替代品,所有这些可用的软件都可以在 10 分钟或者更短的时间内下载好。如果一个替代品不合你口味,你可以删掉它然后毫不费力就可以再装一个其它的。在 Linux 上,你几乎总会有选择。
### 过渡期
可能没有那么多建议可以让 Windows 用户充分准备好切换到 Linux。即使说新用户应该保持开放的心态也是没什么用的,因为他们的期望总是太高,以至于许多用户都没有意识到自己有如此高的期望。
Linux 新手可以做的最好的事情就是调整心态,并且花一点时间来适应它们。过渡期会需要一些功夫,不过,从长远来看,你的多次尝试终会得到回报。
---
via: <http://www.datamation.com/open-source/7-mistakes-new-linux-users-make.html>
作者:[Bruce Byfield](http://www.datamation.com/author/Bruce-Byfield-6030.html) 译者:[OneNewLife](https://github.com/OneNewLife) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,911 | 科学音频处理(三):如何使用 Octave 的高级数学技术处理音频文件 | https://www.howtoforge.com/tutorial/ubuntu-octave-audio-processing-part-3/ | 2016-10-30T13:53:56 | [
"Octave",
"音频"
] | https://linux.cn/article-7911-1.html | 我们的数字音频处理技术第三部分涵盖了信号调制内容,将解释如何进行<ruby> 调幅 <rp> ( </rp> <rt> Amplitude Modulation </rt> <rp> ) </rp></ruby>、<ruby> 颤音效果 <rp> ( </rp> <rt> Tremolo Effect </rt> <rp> ) </rp></ruby>和<ruby> 频率变化 <rp> ( </rp> <rt> Frequency Variation </rt> <rp> ) </rp></ruby>。

### 调制
#### 调幅
正如它的名字暗示的那样, 影响正弦信号的振幅变化依据传递的信息而不断改变。正弦波因为承载着大量的信息被称作<ruby> 载波 <rp> ( </rp> <rt> carrier </rt> <rp> ) </rp></ruby>。这种调制技术被用于许多的商业广播和市民信息传输波段(AM)。
#### 为何要使用调幅技术?
**调制发射**
假设信道是免费资源,有天线就可以发射和接收信号。这要求有效的电磁信号发射天线,它的大小和要被发射的信号的波长应该是同一数量级。很多信号,包括音频成分,通常在 100 赫兹或更低。对于这些信号,如果直接发射,我们就需要建立长达 300 公里的天线。如果通过信号调制将信息加载到 100MHz 的高频载波中,那么天线仅仅需要 1 米(横向长度)。
**集中调制与多通道**
假设多个信号占用一个通道,调制可以将不同的信号不同频域位置,以便接收者选择该特定信号。使用集中调制(“复用”)的应用有遥感探测数据、立体声调频收音机和长途电话等。
**克服设备限制的调制**
信号处理设备,比如过滤器、放大器,以及可以用它们简单组成的设备,它们的性能依赖于信号在频域中的境况以及高频率和低频信号的关系。调制可以用于传递信号到频域中的更容易满足设计需求的位置。调制也可以将“宽带信号“(高频和低频的比例很大的信号)转换成”窄带“信号。
**音频特效**
许多音频特效由于引人注目和处理信号的便捷性使用了调幅技术。我们可以说出很多,比如颤音、合唱、镶边等等。这种实用性就是我们关注它的原因。
### 颤音效果
颤音效果是调幅最简单的应用,为实现这样的效果,我们会用周期信号改变(乘)音频信号,使用正弦或其他。
```
>> tremolo='tremolo.ogg';
>> fs=44100;
>> t=0:1/fs:10;
>> wo=2*pi*440*t;
>> wa=2*pi*1.2*t;
>> audiowrite(tremolo, cos(wa).*cos(wo),fs);
```

这将创造一个正弦形状的信号,它的效果就像‘颤音’。

### 在真实音频文件中的颤音
现在我们将展示真实世界中的颤音效果。首先,我们使用之前记录过男性发声 ‘A’ 的音频文件。这个信号图就像下面这样:
```
>> [y,fs]=audioread('A.ogg');
>> plot(y);
```

现在我们将创建一个完整的正弦信号,使用如下的参数:
* 增幅 = 1
* 频率= 1.5Hz
* 相位 = 0
```
>> t=0:1/fs:4.99999999;
>> t=t(:);
>> w=2*pi*1.5*t;
>> q=cos(w);
>> plot(q);
```
注意: 当我们创建一组时间值时,默认情况下,它是以列的格式呈现,如, 1x220500 的值。为了乘以这样的值,必须将其变成行的形式(220500x1)。这就是 `t=t(:)` 命令的作用。

我们将创建第二份 ogg 音频格式的文件,它包含了如下的调制信号:
```
>> tremolo='tremolo.ogg';
>> audiowrite(tremolo, q.*y,fs);
```


### 频率变化
我们可以改变频率实现一些有趣的音效,比如原音变形,电影音效,多人比赛。
#### 正弦频率调制的影响
这是正弦调制频率变化的演示代码,根据方程:
```
Y=Ac*Cos(wo*Cos(wo/k))
```
这里:
* Ac = 增幅
* wo = 基频
* k = 标量除数
```
>> fm='fm.ogg';
>> fs=44100;
>> t=0:1/fs:10;
>> w=2*pi*442*t;
>> audiowrite(fm, cos(cos(w/1500).*w), fs);
>> [y,fs]=audioread('fm.ogg');
>> figure (); plot (y);
```
信号图:

你可以使用几乎任何类型的周期函数频率调制。本例中,我们仅仅用了一个正弦函数。请大胆的改变函数频率,用复合函数,甚至改变函数的类型。
---
via: <https://www.howtoforge.com/tutorial/ubuntu-octave-audio-processing-part-3/>
作者:[David Duarte](https://www.howtoforge.com/tutorial/ubuntu-octave-audio-processing-part-3/) 译者:[theArcticOcean](https://github.com/theArcticOcean) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | The third part of our Digital Audio processing tutorial series covers the signal Modulation, we explain how to apply Amplitude Modulation, Tremolo Effect, and Frequency Variation.
## Modulation
### Amplitude Modulation
As its name implies, this effect varies the amplitude of a sinusoid according to the message to be transmitted. A sine wave is called a carrier because it carries the information. This type of modulation is used in some commercial broadcasting and transmission citizen bands (AM).
### Why use the Amplitude Modulation?
**Modulation Radiation.**
If the communication channel is a free space, then antennas are required to radiate and receive the signal. It requires an efficient electromagnetic radiation antenna whose dimensions are of the same order of magnitude as the wavelength of the signal being radiated. Many signals, including audio components, have often 100 Hz or less. For these signals, it would be necessary to build antennas about 300 km in length if the signal were to be radiated directly. If signal modulation is used to print the message on a high-frequency carrier, let's say 100 MHz, then the antenna needs to have a length of over a meter (transverse length) only.
**Concentration modulation or multi-channeling.**
If more than one signal uses a single channel, modulation can be used for transferring different signals to different spectral positions allowing the receiver to select the desired signal. Applications that use concentration ("multiplexing") include telemetry data, stereo FM radio and long-distance telephony.
**Modulation to Overcome Limitations on equipment.**
The performance of signal processing devices such as filters and amplifiers, and the ease with which these devices can be constructed, depends on the situation of the signal in the frequency domain and the relationship between the higher frequency and low signal. Modulation can be used to transfer the signal to a position in the frequency domain where design requirements are met easier. The modulation can also be used to convert a "broadband signal" (a signal for which the ratio between the highest and lowest frequency is large) into a sign of "narrow band".
**Audio Effects**
Many audio effects use amplitude modulation due to the striking and ease with which it can handle such signals. We can name a few such as tremolo, chorus, flanger, etc. This utility is where we focus in this tutorial series.
### Tremolo effect
The tremolo effect is one of the simplest applications of amplitude modulation, to achieve this effect, we have to vary (multiply) the audio signal by a periodic signal, either sinusoidal or otherwise.
>> tremolo='tremolo.ogg';
>> fs=44100;
>> t=0:1/fs:10;
>> wo=2*pi*440*t;
>> wa=2*pi*1.2*t;
>> audiowrite(tremolo, cos(wa).*cos(wo),fs);
This will generate a sinusoid-shaped signal which effect is like a 'tremolo'.
### Tremolo on real Audio Files
Now we will show the tremolo effect in the real world, First, we use a file previously recorded by a male voice saying 'A'. The plot for this signal is the following:
>> [y,fs]=audioread('A.ogg');
>> plot(y);
Now we have to create an enveloping sinusoidal signal with the following parameters:
Amplitude = 1
Frequency= 1.5Hz
Phase = 0
>> t=0:1/fs:4.99999999;
>> t=t(:);
>> w=2*pi*1.5*t;
>> q=cos(w);
>> plot(q);
Note: when we create an array of values of the time, by default, this is created in the form of columns, ie, 1x220500 values. To multiply this set of values must transpose it in rows (220500x1). This is the t=t(:) command
We will create a second ogg file which contains the resulting modulated signal:
>> tremolo='tremolo.ogg';
>> audiowrite(tremolo, q.*y,fs);
## Frequency Variation
We can vary the frequency to obtain quite interesting musical effects such as distortion, sound effects for movies and games among others.
### Effect of sinusoidal frequency modulation
This is the code where the sinusoidal modulation frequency is shown, according to equation:
Y=Ac*Cos(wo*Cos(wo/k))
Where:
Ac = Amplitude
wo = fundamental frequency
k = scalar divisor
>> fm='fm.ogg';
>> fs=44100;
>> t=0:1/fs:10;
>> w=2*pi*442*t;
>> audiowrite(fm, cos(cos(w/1500).*w), fs);
>> [y,fs]=audioread('fm.ogg');
>> figure (); plot (y);
The plot of the signal is:
You can use almost any type of periodic function as the frequency modulator. For this example, we only used a sine function here. Please feel free to experiment with changing the frequencies of the functions, mixing with other functions or change, even, the type of function. |
7,913 | Linux 桌面份额连续四个月超过 2% | http://www.omgubuntu.co.uk/2016/10/linux-marketshare-2-percent-3rd-month-row | 2016-10-30T19:40:49 | [
"Linux"
] | https://linux.cn/article-7913-1.html | [据 Net Market Share 的数据](https://www.netmarketshare.com/report.aspx?qprid=11&qpaf=&qpcustom=Linux&qpcustomb=0),全球的 Linux 桌面用户的份额已经连续四个月超过了 2% 。

我们之前报道过,今年六月份时 Linux 桌面的市场份额[首次突破了 2%](/article-7538-1.html),并于次月达到了历史最高点 2.33%。
那些将 Linux 作为主要桌面的用户们为这个份额做出了贡献。显然,从 这个图表的趋势来看,使用 Linux 作为桌面的用户越来越多了。
不过,不同的分析公司由于采样范围和分析方法的不同,其报告的数据、图表会有些不同,但是从总体的趋势来看,都是呈现向上增长的。
Net Market Share 的报告是基于全球 4 万个网站的访客得出的,4 万个网站也是一个比较大的数量了,当然,与整个互联网相比还是较小。
事实上,我们并不能真正摸清 Linux 具体的市场份额,因为有太多的发行版、内核版本和浏览器了,而且有些专门在隐私保护方面做了不少的工作,因此这部分我们的采集不到的。
| 301 | Moved Permanently | null |
7,914 | Python 单元测试:assertTrue 是真值,assertFalse 是假值 | http://jamescooke.info/python-unittest-asserttrue-is-truthy-assertfalse-is-falsy.html | 2016-10-31T08:48:00 | [
"单元测试"
] | https://linux.cn/article-7914-1.html | 在这篇文章中,我们将介绍单元测试的布尔断言方法 `assertTrue` 和 `assertFalse` 与身份断言 `assertIs` 之间的区别。

### 定义
下面是目前[单元测试模块文档](https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertTrue)中关于 `assertTrue` 和 `assertFalse` 的说明,代码进行了高亮:
>
> `assertTrue(expr, msg=None)`
>
>
> `assertFalse(expr, msg=None)`
>
>
>
> >
> > 测试该*表达式*是真值(或假值)。
> >
> >
> > 注:这等价于
> >
> >
> > `bool(expr) is True`
> >
> >
> > 而不等价于
> >
> >
> > `expr is True`
> >
> >
> > (后一种情况请使用 `assertIs(expr, True)`)。
> >
> >
> >
>
>
>
[Mozilla 开发者网络中定义 `真值`](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) 如下:
>
> 在一个布尔值的上下文环境中能变成“真”的值
>
>
>
在 Python 中等价于:
```
bool(expr) is True
```
这个和 `assertTrue` 的测试目的完全匹配。
因此该文档中已经指出 `assertTrue` 返回真值,`assertFalse` 返回假值。这些断言方法从接受到的值构造出一个布尔值,然后判断它。同样文档中也建议我们根本不应该使用 `assertTrue` 和 `assertFalse`。
### 在实践中怎么理解?
我们使用一个非常简单的例子 - 一个名称为 `always_true` 的函数,它返回 `True`。我们为它写一些测试用例,然后改变代码,看看测试用例的表现。
作为开始,我们先写两个测试用例。一个是“宽松的”:使用 `assertTrue` 来测试真值。另外一个是“严格的”:使用文档中建议的 `assertIs` 函数。
```
import unittest
from func import always_true
class TestAlwaysTrue(unittest.TestCase):
def test_assertTrue(self):
"""
always_true returns a truthy value
"""
result = always_true()
self.assertTrue(result)
def test_assertIs(self):
"""
always_true returns True
"""
result = always_true()
self.assertIs(result, True)
```
下面是 `func.py` 中的非常简单的函数代码:
```
def always_true():
"""
I'm always True.
Returns:
bool: True
"""
return True
```
当你运行时,所有测试都通过了:
```
always_true returns True ... ok
always_true returns a truthy value ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.004s
OK
```
开心ing~
现在,某个人将 `always_true` 函数改变成下面这样:
```
def always_true():
"""
I'm always True.
Returns:
bool: True
"""
return 'True'
```
它现在是用返回字符串 `"True"` 来替代之前反馈的 `True` (布尔值)。(当然,那个“某人”并没有更新文档 - 后面我们会增加难度。)
这次结果并不如开心了:
```
always_true returns True ... FAIL
always_true returns a truthy value ... ok
======================================================================
FAIL: always_true returns True
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/assertttt/test.py", line 22, in test_is_true
self.assertIs(result, True)
AssertionError: 'True' is not True
----------------------------------------------------------------------
Ran 2 tests in 0.004s
FAILED (failures=1)
```
只有一个测试用例失败了!这意味着 `assertTrue` 给了我们一个<ruby> 误判 <rp> ( </rp> <rt> false-positive </rt> <rp> ) </rp></ruby>。在它不应该通过测试时,它通过了。很幸运的是我们第二个测试是使用 `assertIs` 来写的。
因此,跟手册上了解到的信息一样,为了保证 `always_true` 的功能和更严格测试的结果保持一致,应该使用 `assertIs` 而不是 `assertTrue`。
### 使用断言的辅助方法
使用 `assertIs` 来测试返回 `True` 和 `False` 来冗长了。因此,如果你有个项目需要经常检查是否是返回了 `True` 或者 `False`,那们你可以自己编写一些断言的辅助方法。
这好像并没有节省大量的代码,但是我个人觉得提高了代码的可读性。
```
def assertIsTrue(self, value):
self.assertIs(value, True)
def assertIsFalse(self, value):
self.assertIs(value, False)
```
### 总结
一般来说,我的建议是让测试越严格越好。如果你想测试 `True` 或者 `False`,听从[文档](https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertTrue)的建议,使用 `assertIs`。除非不得已,否则不要使用 `assertTrue` 和 `assertFalse`。
如果你面对的是一个可以返回多种类型的函数,例如,有时候返回布尔值,有时候返回整形,那么考虑重构它。这是代码的异味。在 Python 中,抛出一个异常比使用 `False` 表示错误更好。
此外,如果你确实想使用断言来判断函数的返回值是否是真,可能还存在第二个代码异味 - 代码是正确封装了吗?如果 `assertTrue` 和 `assertFalse` 是根据正确的 `if` 语句来执行,那么值得检查下你是否把所有你想要的东西都封装在合适的位置。也许这些 `if` 语句应该封装在测试的函数中。
测试开心!
---
via: <http://jamescooke.info/python-unittest-asserttrue-is-truthy-assertfalse-is-falsy.html>
作者:[James Cooke](http://jamescooke.info/pages/hello-my-name-is-james.html) 译者:[chunyang-wen](https://github.com/chunyang-wen) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,915 | 在维基激动人心的四年 | https://opensource.com/life/16/4/my-open-source-story-sailesh-patnaik | 2016-10-31T10:38:00 | [
"维基百科"
] | https://linux.cn/article-7915-1.html | 
我自认为自己是个奥迪亚的维基人。我通过写文章和纠正文章错误给很多维基项目贡献了<ruby> <a href="https://en.wikipedia.org/wiki/Odia_language"> 奥迪亚 </a> <rp> ( </rp> <rt> Odia </rt> <rp> ) </rp></ruby>知识(这是在印度的[奥里萨邦](https://en.wikipedia.org/wiki/Odisha)的主要语言),比如维基百科和维基文库,我也为用印地语和英语写的维基文章做贡献。

我对维基的爱从我第 10 次考试(像在美国的 10 年级学生的年级考试)之后看到的英文维基文章[孟加拉解放战争](https://en.wikipedia.org/wiki/Bangladesh_Liberation_War)开始。一不小心我打开了印度维基文章的链接,并且开始阅读它。在文章左边有用奥迪亚语写的东西,所以我点击了一下, 打开了一篇在奥迪亚维基上的 [ଭାରତ/Bhārat](https://or.wikipedia.org/s/d2) 文章。发现了用母语写的维基让我很激动!

一个邀请读者参加 2014 年 4 月 1 日召开的第二届布巴内斯瓦尔研讨会的旗帜广告引起了我的好奇。我过去从来没有为维基做过贡献,只用它做过研究,我并不熟悉开源和社区贡献流程。再加上,当时我只有 15 岁。我注册了,在研讨会上有很多语言爱好者,他们全比我大。尽管我害怕,我父亲还是鼓励我去参与。他起了非常重要的作用—他不是一个维基媒体人,和我不一样,但是他的鼓励给了我改变奥迪亚维基的动力和参加社区活动的勇气。
我觉得关于奥迪亚语言和文学的知识很多需要改进,有很多错误的观念和知识缺口,所以,我帮助组织关于奥迪亚维基的活动和和研讨会,我完成了如下列表:
* 在奥迪亚维基发起 3 次主要的 edit-a-thons :2015 年妇女节、2016年妇女节、abd [Nabakalebara edit-a-thon 2015](https://or.wikipedia.org/s/toq)
* 在全印度发起了征集[檀车节](https://commons.wikimedia.org/wiki/Commons:The_Rathyatra_Challenge)图片的比赛
* 在谷歌的两大事件([谷歌I/O大会扩展](http://cis-india.org/openness/blog-old/odia-wikipedia-meets-google-developer-group)和谷歌开发节)中代表奥迪亚维基
* 在2015 [Perception](http://perception.cetb.in/events/odia-wikipedia-event/) 和第一次 [Open Access India](https://opencon2015kolkata.sched.org/speaker/sailesh.patnaik007) 会议

我在维基项目当编辑直到去年( 2015 年 1 月)为止,当我出席[孟加拉语维基百科的十周年会议](https://meta.wikimedia.org/wiki/Bengali_Wikipedia_10th_Anniversary_Celebration_Kolkata)和[毗瑟挐](https://www.facebook.com/vishnu.vardhan.50746?fref=ts)活动时,[互联网和社会中心](http://cis-india.org/)主任,邀请我参加[培训师培训计划](https://meta.wikimedia.org/wiki/CIS-A2K/Events/Train_the_Trainer_Program/2015)。我的开始超越奥迪亚维基,为[GLAM](https://en.wikipedia.org/wiki/Wikipedia:GLAM)的活动举办聚会和培训新的维基人。这些经验告诉我作为一个贡献者该如何为社区工作。
[Ravi](https://www.facebook.com/ravidreams?fref=ts),在当时印度维基的总监,在我的旅程也发挥了重要作用。他非常相信我,让我参与到了 [Wiki Loves Food](https://commons.wikimedia.org/wiki/Commons:Wiki_Loves_Food),维基共享中的公共摄影比赛,组织方是 [2016 印度维基会议](https://meta.wikimedia.org/wiki/WikiConference_India_2016)。在 2015 的 Loves Food 活动期间,我的团队在维基共享中加入了 10000+ 采用 CC BY-SA 协议的图片。Ravi 进一步坚定了我的信心,和我分享了很多关于维基媒体运动的信息,以及他自己在 [奥迪亚维基百科 13 周年](https://or.wikipedia.org/s/sml)的经历。
不到一年后,在 2015 年十二月,我成为了网络与社会中心的[获取知识计划](https://meta.wikimedia.org/wiki/CIS-A2K)的项目助理( CIS-A2K 运动)。我自豪的时刻之一是在印度普里的研讨会,我们给奥迪亚维基媒体社区带来了 20 个新的维基人。现在,我在一个名为 [WikiTungi](https://or.wikipedia.org/s/xgx) 普里的非正式聚会上指导着维基人。我和这个小组一起工作,把奥迪亚 Wikiquotes 变成一个真实的计划项目。在奥迪亚维基我也致力于缩小性别差距。[八个女编辑](https://or.wikipedia.org/s/ysg)也正帮助组织聚会和研讨会,参加 [Women's History month edit-a-thon](https://or.wikipedia.org/s/ynj)。
在我四年短暂而令人激动的旅行之中,我也参与到 [维基百科的教育项目](https://outreach.wikimedia.org/wiki/Education),[通讯团队](https://outreach.wikimedia.org/wiki/Talk:Education/News#Call_for_volunteers),两个全球的 edit-a-thons: [Art and Feminsim](https://en.wikipedia.org/wiki/User_talk:Saileshpat#Barnstar_for_Art_.26_Feminism_Challenge) 和 [Menu Challenge](https://opensource.com/life/15/11/tasty-translations-the-open-source-way)。我期待着更多的到来!
我还要感谢 [Sameer](https://www.facebook.com/samirsharbaty?fref=ts) 和 [Anna](https://www.facebook.com/anna.koval.737?fref=ts)(都是之前维基百科教育计划的成员)。
---
via: <https://opensource.com/life/16/4/my-open-source-story-sailesh-patnaik>
作者:[Sailesh Patnaik](https://opensource.com/users/saileshpat) 译者:[hkurj](https://github.com/hkurj) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | I consider myself to be an *Odia Wikimedian*. I contribute [Odia](https://en.wikipedia.org/wiki/Odia_language) knowledge (the predominant language of the Indian state of [Odisha](https://en.wikipedia.org/wiki/Odisha)) to many Wikimedia projects, like Wikipedia and Wikisource, by writing articles and correcting mistakes in articles. I also contribute to Hindi and English Wikipedia articles.
My love for Wikimedia started while I was reading an article about the
[Bangladesh Liberation war](https://en.wikipedia.org/wiki/Bangladesh_Liberation_War) on the English Wikipedia after my 10th board exam (like, an annual exam for 10th grade students in America). By mistake I clicked on a link that took me to an India Wikipedia article, and I started reading. Something was written in Odia on the lefthand side of the article, so I clicked on that, and reached a [ଭାରତ/Bhārat](https://or.wikipedia.org/s/d2) article on the Odia Wikipedia. I was excited to find a Wikipedia article in my native language!
A banner inviting readers to be part of the 2nd Bhubaneswar workshop on April 1, 2012 sparked my curiousity. I had never contributed to Wikipedia before, only used it for research, and I wasn't familiar with open source and the community contribution process. Plus, I was only 15 years old. I registered. There were many language enthusiasts at the workshop, and all older than me. My father encouraged me to the participate despite my fear; he has played an important role—he's not a Wikimedian, like me, but his encouragement has helped me change Odia Wikipedia and participate in community activities.
I believe that knowledge about Odia language and literature needs to improve—there are many misconceptions and knowledge gaps—so, I help organize events and workshops for Odia Wikipedia. On my accomplished list at the point, I have:
- initiated three major edit-a-thons in Odia Wikipedia: Women's Day 2015, Women's Day 2016, abd
[Nabakalebara edit-a-thon 2015](https://or.wikipedia.org/s/toq) - initiated a photograph contest to get more
[Rathyatra](https://commons.wikimedia.org/wiki/Commons:The_Rathyatra_Challenge)images from all over the India - represented Odia Wikipedia during two events by Google (
[Google I/O extended](http://cis-india.org/openness/blog-old/odia-wikipedia-meets-google-developer-group)and Google Dev Fest) - spoke at
[Perception](http://perception.cetb.in/events/odia-wikipedia-event/)2015 and the first[Open Access India](https://opencon2015kolkata.sched.org/speaker/sailesh.patnaik007)meetup
I was just an editor to Wikipedia projects until last year, in January 2015, when I attended
[Bengali Wikipedia's 10th anniversary conference](https://meta.wikimedia.org/wiki/Bengali_Wikipedia_10th_Anniversary_Celebration_Kolkata) and [Vishnu](https://www.facebook.com/vishnu.vardhan.50746?fref=ts), the director of the [Center for Internet and Society](http://cis-india.org/) at the time, invited me to attend the [Train the Trainer Program](https://meta.wikimedia.org/wiki/CIS-A2K/Events/Train_the_Trainer_Program/2015). I was inspired to start doing outreach for Odia Wikipedia and hosting meetups for [GLAM](https://en.wikipedia.org/wiki/Wikipedia:GLAM) activities and training new Wikimedians. These experience taught me how to work with a community of contributors.
[Ravi](https://www.facebook.com/ravidreams?fref=ts), the director of Wikimedia India at the time, also played an important role in my journey. He trusted me and made me a part of [Wiki Loves Food](https://commons.wikimedia.org/wiki/Commons:Wiki_Loves_Food), a public photo competition on Wikimedia Commons, and the organizing committee of [Wikiconference India 2016](https://meta.wikimedia.org/wiki/WikiConference_India_2016). During Wiki Loves Food 2015, my team helped add 10,000+ CC BY-SA images on Wikimedia Commons. Ravi further solidified my commitment by sharing a lot of information with me about the Wikimedia movement, and his own journey, during [Odia Wikipedia's 13th anniversary](https://or.wikipedia.org/s/sml).
Less than a year later, in December 2015, I became a Program Associate at the Center for Internet and Society's [Access to Knowledge program](https://meta.wikimedia.org/wiki/CIS-A2K) (CIS-A2K). One of my proud moments was at a workshop in Puri, India where we helped bring 20 new Wikimedian editors to the Odia Wikimedia community. Now, I mentor Wikimedians during an informal meetup called [WikiTungi](https://or.wikipedia.org/s/xgx) Puri. I am working with this group to make Odia Wikiquotes a live project. I am also dedicated to bridging the gender gap in Odia Wikipedia. [Eight female editors](https://or.wikipedia.org/s/ysg) are now helping to organize meetups and workshops, and participate in the [Women's History month edit-a-thon](https://or.wikipedia.org/s/ynj).
During my brief but action-packed journey during the four years since, I have also been involved in the [Wikipedia Education Program](https://outreach.wikimedia.org/wiki/Education), the [newsletter team](https://outreach.wikimedia.org/wiki/Talk:Education/News#Call_for_volunteers), and two global edit-a-thons: [Art and Feminsim](https://en.wikipedia.org/wiki/User_talk:Saileshpat#Barnstar_for_Art_.26_Feminism_Challenge) and [Menu Challenge](https://opensource.com/life/15/11/tasty-translations-the-open-source-way). I look forward to the many more to come!
*I would also like to thank Sameer and Anna (both previous members of the Wikipedia Education Program).*
## 2 Comments |
7,918 | 如何在后台运行 Linux 命令并且将进程脱离终端 | http://www.tecmint.com/run-linux-command-process-in-background-detach-process/ | 2016-11-01T08:20:00 | [
"进程",
"后台"
] | https://linux.cn/article-7918-1.html | 在本指南中,我们将会阐明一个在 [Linux 系统中进程管理](http://www.tecmint.com/monitor-linux-processes-and-set-process-limits-per-user/)的简单但是重要的概念,那就是如何从它的控制终端完全脱离一个进程。
当一个进程与终端关联在一起时,可能会出现两种问题:
1. 你的控制终端充满了很多输出数据或者错误及诊断信息
2. 如果发生终端关闭的情况,进程连同它的子进程都将会终止
为了解决上面两个问题,你需要从一个控制终端完全脱离一个进程。在我们实际上解决这个问题之前,让我们先简要的介绍一下,如何在后台运行一个进程。

### 如何在后台开始一个 Linux 进程或者命令行
如果一个进程已经运行,例如下面的 [tar 命令行的例子](/article-7802-1.html),简单的按下 `Ctrl+Z` 就可以停止它(LCTT 译注:这里说的“停止”,不是终止,而是“暂停”的意思),然后输入命令 `bg` 就可以继续以一个任务在后台运行了。
你可以通过输入 `jobs` 查看所有的后台任务。但是,标准输入(STDIN)、标准输出(STDOUT)和标准错误(STDERR)依旧掺杂到控制台中。
```
$ tar -czf home.tar.gz .
$ bg
$ jobs
```

*在后台运行 Linux 命令*
你也可以直接使用符号 `&` 在后台运行一个进程:
```
$ tar -czf home.tar.gz . &
$ jobs
```

*在后台开始一个 Linux 进程*
看一下下面的这个例子,虽然 [tar 命令](/article-7802-1.html)是作为一个后台任务开始的,但是错误信息依旧发送到终端,这表示,进程依旧和控制终端关联在一起。
```
$ tar -czf home.tar.gz . &
$ jobs
```

*运行在后台的 Linux 进程信息*
### 退出控制台之后,保持 Linux 进程的运行
我们将使用 `disown` 命令,它在一个进程已经运行并且被放在后台之后使用,它的作用是从 shell 的活动任务列表中移走一个 shell 任务,因此,对于该任务,你将再也不能使用 `fg` 、 `bg` 命令了。
而且,当你关闭控制控制终端,这个任务将不会挂起(暂停)或者向任何一个子任务发送 SIGHUP 信号。
让我们看一下先下面的这个使用 bash 中内置命令 `disown` 的例子。
```
$ sudo rsync Templates/* /var/www/html/files/ &
$ jobs
$ disown -h %1
$ jobs
```

*关闭终端之后,保持 Linux 进程运行*
你也可以使用 `nohup` 命令,这个命令也可以在用户退出 shell 之后保证进程在后台继续运行。
```
$ nohup tar -czf iso.tar.gz Templates/* &
$ jobs
```

*关闭 shell 之后把 Linux 进程置于后台*
### 从控制终端脱离一个 Linux 进程
因此,为了彻底从控制终端脱离一个程序,对于图形用户界面 (GUI) 的程序例如 firefox 来说,使用下面的命令行格式会更有效:
```
$ firefox </dev/null &>/dev/null &
```
在 Linux 上,/dev/null 是一个特殊的文件设备,它会忽略所有的写在它上面的数据,上述命令,输入来源和输出发送目标都是 /dev/null。
作为结束陈述,运行一个连接到控制终端的进程,作为用户你将会在你的终端上看到这个进程数据的许多行的输出,也包含错误信息。同样,当你关闭一个控制终端,你的进程和子进程都将会终止。
重要的是,对于这个主题任何的问题或者观点,通过下面的评论联系我们。
---
via: <http://www.tecmint.com/run-linux-command-process-in-background-detach-process/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[yangmingming](https://github.com/yangmingming) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,920 | 一个老奶奶的唠叨:当年我玩 Linux 时…… | https://opensource.com/life/16/7/my-linux-story-carla-schroder | 2016-11-01T11:54:00 | [
"Linux"
] | https://linux.cn/article-7920-1.html | 
在很久以前,那时还没有 Linux 系统。真的没有!之前也从未存在过。不像现在,Linux 系统随处可见。那时有各种流派的 Unix 系统、有苹果的操作系统、有微软的 Windows 操作系统。
比如说 Windows,它的很多东西都改变了,但是依然保持不变的东西的更多。尽管它已经增加了 20GB 以上的鬼知道是什么的东西,但是 Windows 还是大体保持不变(除了不能在 DOS 的提示下实际做些什么了)。嘿,谁还记得 Gorilla.bas 那个出现在 DOS 系统里的炸香蕉的游戏吗?多么美好的时光啊!不过互联网却不会忘记,你可以在 Kongregate.com 这个网站玩这个游戏的 Flash版本。
苹果系统也改变了,从一个鼓励你 hack 的友善系统变成了一个漂亮而密实的、根本不让你打开的小盒子,而且还限制了你使用的硬件接口。1998 年:软盘没了。2012 年:光驱没了。而 12 英寸的 MacBook 只有一个单一的 USB Type-C 接口,提供了电源、蓝牙、无线网卡、外部存储、视频输出和其它的一些配件的接口。而你要是想一次连接多个外设就不得不背着一堆转接器,这真是太令人抓狂了!然后就轮到耳机插孔了,没错,这唯一一个苹果世界里留着的非专有的标准硬件接口了,也注定要消失了。(LCTT 译注:还好,虽然最新的 IPhone 7 上没有耳机插孔了,但是新发布的 Macbook 上还有)
还有一大堆其它的操作系统,比如:Amiga、BeOS、OS/2 ,如果你愿意的话,你能找到几十个操作系统。我建议你去找找看,太容易找到了。Amiga、 BeOS 和 OS/2 这些系统都值得关注,因为它们有强大的功能,比如 32 位的多任务和高级图形处理能力。但是市场的影响击败了强大的系统性能,因此技术上并不出众的 Apple 和 Windows 操作系统统治了市场的主导地位,而那些曾经的系统也逐渐销声匿迹了。
然后 Linux 系统出现了,世界也因此改变了。
### 第一款电脑
我曾经使用过的第一款电脑是 Apple IIc ,大概在 1994年左右,而那个时候 Linux 系统刚出来 3 年。这是我从一个朋友那里借来的,用起来各方面都还不错,但是很不方便。所以我自己花了将近 500 美元买了一台二手的 Tandy 牌的电脑。这对于卖电脑的人来说是一件很伤心的事,因为新电脑要花费双倍的价钱。那个时候,电脑贬值的速度非常快。这个电脑当时看起来强劲得像是个怪物:一个英特尔 386SX 的 CPU,4MB的内存,一个 107MB 的硬盘,14 英寸的彩色 CRT 显示器,运行 MS-DOS 5 和 Windows 3.1 系统。
我曾无数次的拆开那个可怜的怪物,并且多次重新安装 Windows 和 DOS 系统。因为 Windows 桌面用的比较少,所以我的大部分工作都是在 DOS 下完成的。我喜欢玩血腥暴力的视频游戏,包括 Doom、Duke Nukem、Quake 和 Heretic。啊!那些美好的,让人心动的 8 位图像!
那个时候硬件的发展一直落后于软件,因此我经常升级硬件。现在我们能买到满足我们需求的任何配置的电脑。我已经好多年都没有再更新我的任何电脑硬件了。
### 《<ruby> 比特杂志 <rp> ( </rp> <rt> Computer bits </rt> <rp> ) </rp></ruby>》
回到那些曾经辉煌的年代,电脑商店布满大街小巷,找到本地的一家网络服务提供商(ISP)也不用走遍整个街区。ISP 那个时候真的非比寻常,它们不是那种冷冰冰的令人讨论的超级大公司,而是像美国电信运营商和有线电视公司这样的好朋友。他们都非常友好,并且提供各种各样的像 BBS、文件下载、MUD (多玩家在线游戏)等的额外服务。
我花了很多的时间在电脑商店购买配件,但是很多时候我一个女人家去那里会让店里的员工感到吃惊,我真的很无语了,这怎么就会让一些人看不惯了。我现成已经是一位 58 岁的老家伙了,但是他们还是一样的看不惯我。我希望我这个女电脑迷在我死之前能被他们所接受。

那些商店的书架上摆满了《<ruby> 比特杂志 <rp> ( </rp> <rt> Computer bits </rt> <rp> ) </rp></ruby>》。有关《比特杂志》的[历史刊物](https://web.archive.org/web/20020122193349/http://computerbits.com/)可以在<ruby> 互联网档案库 <rp> ( </rp> <rt> Internet Archive </rt> <rp> ) </rp></ruby>中查到。《比特杂志》是当地一家免费报纸,有很多关于计算机方面的优秀的文章和大量的广告。可惜当时的广告没有网络版,因此大家不能再看到那些很有价值的关于计算机方面的详细信息了。你知道现在的广告商们有多么的抓狂吗?他们埋怨那些安装广告过滤器的人,致使科技新闻变成了伪装的广告。他们应该学习一下过去的广告模式,那时候的广告里有很多有价值的信息,大家都喜欢阅读。我从《比特杂志》和其它的电脑杂志的广告中学到了所有关于计算机硬件的知识。《<ruby> 电脑购买者杂志 <rp> ( </rp> <rt> Computer Shopper </rt> <rp> ) </rp></ruby>》更是非常好的学习资料,其中有上百页的广告和很多高质量的文章。

《比特杂志》的出版人 Paul Harwood 开启了我的写作生涯。我的第一篇计算机专业性质的文章就是在《比特杂志》发表的。 Paul,仿佛你一直都在我的身旁,谢谢你。
在互联网档案库中,关于《比特杂志》的分类广告信息已经几乎查询不到了。分类广告模式曾经给出版商带来巨大的收入。免费的分类广告网站 Craigslist 在这个领域独占鳌头,同时也扼杀了像《比特杂志》这种以传统的报纸和出版为主的杂志行业。
其中有一些让我最难以忘怀的记忆就是一个 12 岁左右的吊儿郎当的小屁孩,他脸上挂满了对我这种光鲜亮丽的女人所做工作的不屑和不理解的表情,他在我钟爱的电脑店里走动,递给我一本《比特杂志》,当成给初学者的一本好书。我翻开杂志,指着其中一篇我写的关于 Linux 系统的文章给他看,他说“哦,我明白了”。他尴尬的脸变成了那种正常生理上都不可能呈现的颜色,然后很仓促地夹着尾巴溜走了。(不是的,我亲爱的、诚实的读者们,他不是真的只有 12 岁,而应该是 20 来岁。他现在应该比以前更成熟懂事一些了吧!)
### 发现 Linux
我第一次了解到 Linux 系统是在《比特杂志》上,大概在 1997 年左右。我一开始用的一些 Linux操作系统版本是 Red Hat 5 和 Mandrake Linux(曼德拉草)。 Mandrake 真是太棒了,它是第一款易安装型的 Linux 系统,并且还附带图形界面和声卡驱动,因此我马上就可以玩 Tux Racer 游戏了。不像那时候大多数的 Linux 迷们,因为我之前没接触过 Unix系统,所以我学习起来比较难。但是一切都还顺利吧,因为我学到的东西都很有用。相对于我在 Windows 中的体验,我在 Windows 中学习的大部分东西都是徒劳,最终只能放弃返回到 DOS 下。
玩转电脑真是充满了太多的乐趣,后来我转行成为计算机自由顾问,去帮助一些小型公司的 IT 部门把数据迁移到 Linux 服务器上,这让 Windows 系统或多或少的失去一些用武之地。通常情况下我们都是在背地里偷偷地做这些工作的,因为那段时期微软把 Linux 称为毒瘤,诬蔑 Linux 系统是一种共产主义,用来削弱和吞噬我们身体里的珍贵血液的阴谋。
### Linux 赢了
我持续做了很多年的顾问工作,也做其它一些相关的工作,比如:电脑硬件修理和升级、布线、系统和网络管理,还有运行包括 Apple、Windows、Linux 系统在内的混合网络。Apple 和 Windows 系统故意不兼容对方,因此这两个系统真的是最头疼,也最难整合到同一网络中。但是在 Linux 系统和其它开源软件中最有趣的一件事是总有一些人能够处理这些厂商之间的兼容性问题。
现在已经大不同了。在系统间的互操作方面一直存在一些兼容性问题,而且也没有桌面 Linux 系统的 1 级 OEM 厂商。我觉得这是因为微软和苹果公司在零售行业在大力垄断造成的。也许他们这样做反而帮了我们帮大忙,因为我们可以从 ZaReason 和 System76 这样独立的 Linux 系统开发商得到更好的服务和更高性能的系统。他们对 Linux 系统都很专业,也特别欢迎我们这样的用户。
Linux 除了在零售行业的桌面版系统占有一席之地以外,从嵌入式系统到超级计算机以及分布式计算系统等各个方面都占据着主要地位。开源技术掌握着软件行业的发展方向,所有的软件行业的前沿技术,比如容器、集群以及人工智能的发展都离不开开源技术的支持。从我的第一台老式的 386SX 电脑到现在,Linux 和开源技术都取得了巨大的进步。
如果没有 Linux 系统和开源,这一切都不可能发生。
(题图来自:[wallpapersafari](http://cdn.wallpapersafari.com/32/70/uLMive.jpg) ,高清)
---
via: <https://opensource.com/life/16/7/my-linux-story-carla-schroder>
作者:[Carla Schroder](https://opensource.com/users/carlaschroder) 译者:[rusking](https://github.com/rusking) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Once upon a time, there was no Linux. No, really! It did not exist. It was not like today, with Linux everywhere. There were multiple flavors of Unix, there was Apple, and there was Microsoft Windows.
When it comes to Windows, the more things change, the more they stay the same. Despite adding 20+ gigabytes of gosh-knows-what, Windows is mostly the same. (Except you can't drop to a DOS prompt to get actual work done.) Hey, who remembers Gorilla.bas, the exploding banana game that came in DOS? Fun times! The Internet never forgets, and you can play a [Flash version on Kongregate.com](http://www.kongregate.com/games/moly/gorillas-bas).
Apple changed, evolving from a friendly system that encouraged hacking to a sleek, sealed box that you are not supposed to open, and that dictates what hardware interfaces you are allowed to use. 1998: no more floppy disk. 2012: no more optical drive. The 12-inch MacBook has only a single USB Type-C port that supplies power, Bluetooth, Wi-Fi, external storage, video output, and accessories. If you want to plug in more than one thing at a time and don't want to tote a herd of dongles and adapters around with you, too bad. Next up: The headphone jack. Yes, the one remaining non-proprietary standard hardware port in Apple-land is doomed.
There was a sizable gaggle of other operating systems such as Amiga, BeOS, OS/2, and dozens more that you can look up should you feel so inclined, which I encourage because looking things up is so easy now there is no excuse not to. Amiga, BeOS, and OS/2 were noteworthy for having advanced functionality such as 32-bit multitasking and advanced graphics handling. But marketing clout defeats higher quality, and so the less-capable Apple and Windows dominated the market while the others faded away.
Then came Linux, and the world changed.
## First PC
The first PC I ever used was an Apple IIc, somewheres around 1994, when Linux was three years old. A friend loaned it to me and it was all right, but too inflexible. Then I bought a used Tandy PC for something like $500, which was sad for the person who sold it because it cost a couple thousand dollars. Back then, computers depreciated very quickly. It was a monster: an Intel 386SX CPU, 4 megabytes RAM, a 107-megabyte hard drive, 14-inch color CRT monitor, running MS-DOS 5 and Windows 3.1.
I tore that poor thing apart multiple times and reinstalled Windows and DOS many times. Windows was marginally usable, so I did most of my work in DOS. I loved gory video games and played Doom, Duke Nukem, Quake, and Heretic. Ah, those glorious, jiggedy 8-bit graphics.
In those days the hardware was always behind the software, so I upgraded frequently. Now we have all the horsepower we need and then some. I haven't had to upgrade the hardware in any of my computers for several years.
## Computer bits
Back in those golden years, there were independent computer stores on every corner and you could hardly walk down the block without tripping over a local independent Internet service provider (ISP). ISPs were very different then. They were not horrid customer-hostile megacorporations like our good friends the American telcos and cable companies. They were nice, and offered all kinds of extra services like Bulletin Board Services (BBS), file downloads, and Multi-User Domains (MUDs), which were multi-player online games.
I spent a lot of time buying parts in the computer stores, and half the fun was shocking the store staff by being a woman. It is puzzling how this is so upsetting to some people. Now I'm an old fart of 58 and they're still not used to it. I hope that being a woman nerd will become acceptable by the time I die.
Those stores had racks of Computer Bits magazine. Check out this [old issue of Computer Bits](https://web.archive.org/web/20020122193349/http://computerbits.com/) on the Internet Archive. Computer Bits was a local free paper with good articles and tons of ads. Unfortunately, the print ads did not appear in the online edition, so you can't see how they included a wealth of detailed information. You know how advertisers are so whiny, and complain about ad blockers, and have turned tech journalism into barely-disguised advertising? They need to learn some lessons from the past. Those ads were *useful*. People *wanted* to read them. I learned everything about computer hardware from reading the ads in Computer Bits and other computer magazines. Computer Shopper was an especially fabulous resource; it had several hundred pages of ads and high-quality articles.

The publisher of Computer Bits, Paul Harwood, launched my writing career. My first ever professional writing was for Computer Bits. Paul, if you're still around, thank you!
You can see something in the Internet Archives of Computer Bits that barely exists anymore, and that is the classified ads section. Classified ads generated significant income for print publications. Craigslist killed the classifieds, which killed newspapers and publications like Computer Bits.
One of my cherished memories is when the 12-year-old twit who ran my favorite computer store, who could never get over my blatant woman-ness and could never accept that I knew what I was doing, handed me a copy of Computer Bits as a good resource for beginners. I opened it to show him one of my Linux articles and said "Oh yes, I know." He turned colors I didn't think were physiologically possible and scuttled away. (No, my fine literalists, he was not really 12, but in his early 20s. Perhaps by now his emotional maturity has caught up a little.)
### Discovering Linux
I first learned about Linux in Computer Bits magazine, maybe around 1997 or so. My first Linuxes were Red Hat 5 and Mandrake Linux. Mandrake was glorious. It was the first easy-to-install Linux, and it bundled graphics and sound drivers so I could immediately play Tux Racer. Unlike most Linux nerds at the time I did not come from a Unix background, so I had a steep learning curve. But that was alright, because everything I learned was useful. In contrast to my Windows adventures, where most of what I learned was working around its awfulness, then giving up and dropping to a DOS shell.
Playing with computers was so much fun I drifted into freelance consulting, forcing Windows computers to more or less function, and helping IT staff in small shops migrate to Linux servers. Usually we did this on the sneak, because those were the days of Microsoft calling Linux a cancer, and implying that it was a communist conspiracy to sap and impurify all of our precious bodily fluids.
### Linux won
I continued consulting for a number of years, doing a little bit of everything: Repairing and upgrading hardware, pulling cable, system and network administration, and running mixed Apple/Windows/Linux networks. Apple and Windows were absolutely hellish to integrate into mixed networks as they deliberately tried to make it impossible. One of the coolest things about Linux and FOSS is there is always someone ready and able to defeat the barriers erected by proprietary vendors.
It is very different now. There are still proprietary barriers to interoperability, and there is still no Tier 1 desktop Linux OEM vendor. In my opinion this is because Microsoft and Apple have a hard lock on retail distribution. Maybe they're doing us a favor, because you get way better service and quality from wonderful independent Linux vendors like ZaReason and System76. They're Linux experts, and they don't treat us like unwelcome afterthoughts.
Aside from the retail desktop, Linux dominates all aspects of computing from embedded to supercomputing and distributed computing. Open source dominates software development. All of the significant new frontiers in software, such as containers, clusters, and artificial intelligence are all powered by open source software. When you measure the distance from my first little old 386SX PC til now, that is phenomenal progress.
It would not have happened without Linux and open source.
## 34 Comments |
7,923 | 如何在 Ubuntu 命令行下管理浏览器书签 | https://www.maketecheasier.com/manage-browser-bookmarks-ubuntu-command-line/ | 2016-11-02T09:43:00 | [
"命令行",
"书签"
] | https://linux.cn/article-7923-1.html | 
浏览器书签虽然不常被提及,但是作为互联网浏览的一部分。没有好的书签功能,网站链接可能会丢失,下次再不能访问。这就是为什么一个好的书签管理器很重要。
所有的现代浏览器都提供了一些形式的管理工具,虽然它们严格上来讲功能较少。如果你已经厌倦了这些内置在浏览器中的主流工具,你或许想要寻找一个替代品。这里介绍 **Buku**:一个命令行下的书签管理器。它不仅可以管理你的书签,还可以给它们加密,将它们保存在一个数据库中等等。下面是如何安装它。
### 安装

Buku 不是非常流行。因此,用户需要自己编译它。然而,在 Ubuntu 上安装实际上很简单。打开终端并且使用 apt 安装`git` 和 `python3`,这两个工具在构建中很关键。
```
sudo apt python3-cryptography python3-bs4
```
装完所需的工具后,就可以拉取源码了。
```
git clone https://github.com/jarun/Buku/.
cd Buku
```
最后要安装它,只需要运行 `make` 命令。在这之后就可以在终端中输入 `buku`来运行 Buku 了。
```
sudo make install
```
**注意**:虽然这份指导针对的是 Ubuntu,但是 Buku 可以在任何 Linux 发行版中用相似的方法安装。
### 导入书签

要将书签直接导入 Buku 中,首先从浏览器中将书签导出成一个 html 文件。接着,输入下面的命令:
```
buku -i bookmarks.html
```
最后,导入的书签会添加到 Buku 的数据库中。
### 导出书签

导出书签和导入一样简单。要导出所有的书签,使用下面的命令:
```
buku -e bookmarks.html
```
它会和其他书签管理器一样,将数据库中所有的书签导出成一个 html 文件。之后就可以用它做你任何要做的事情了!
### 打开书签

要打开一个书签,首先要搜索。这需要用 `-s` 选项。运行下面的命令来搜索:
```
buku -s searchterm
```
接着一旦找到匹配的结果,输入旁边的数字,书签将会在默认的浏览器中打开了。
### 加密
不像其他的书签管理器,Buku 可以加密你的数据。这对拥有“敏感”书签的用户而言很有用的功能。要加密数据库,使用 `-l` 标志来创建一个密码。
```
buku -l
```

数据库加锁后,没有输入密码将不能打开书签。要解密它,使用 `-k` 选项。
```
buku -k
```

### 其他功能
这个书签管理器有许多不同的功能。要了解其他的功能,使用 `--help` 选项。当使用这个选项后,所有的选项以及每个功能详细内容都会列出来。这个非常有用,由于用户经常忘记东西,并且有时可以打开一个备忘单也不错。
```
buku --help
```

### 总结
即使这个工具不是浏览器的一部分,它的功能比任何现在管理器提供的功能多。尽管事实是它在命令行中运行,但是也有很好的竞争力。书签对大部分人来言并不重要,但是哪些不喜欢现有选择以及喜欢 Linux 命令行的应该看一下 Buku。
---
via: <https://www.maketecheasier.com/manage-browser-bookmarks-ubuntu-command-line/>
作者:[Derrik Diener](https://www.maketecheasier.com/author/derrikdiener/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | 
Browser bookmarks, though not discussed as often as they should be, are an integral part of browsing the Internet. Without good bookmark functionality, a website might be lost in time, and the ability to revisit it gone. That’s why it’s really important to have a good bookmark manager.
All modern web browsers offer up some form of management tool, though they seriously lack in features. If you’ve grown tired of these mainstream tools that have been packed into your browser, you might want to seek out an alternative. Introducing **Buku**: the command line-based bookmark manager. It has the ability to not only manage your bookmarks, but it can encrypt them, hold them in a database, and more. Here’s how to get going with it!
## Installation
Buku isn’t very popular. As a result, users will need to build it to use it. Still, installing it and getting it going on Ubuntu is a lot easier than it looks. Start by opening the terminal and using apt to install `git`
and `python3`
, as they are vital in building the software.
sudo apt python3-cryptography python3-bs4
After the needed tools are installed, the source code can be pulled down.
git clone https://github.com/jarun/Buku/. cd Buku
Finally, to install it, just run the make command. From here it is possible to launch Buku with buku in any terminal window
sudo make install
**Note**: though this guide focuses on Ubuntu, Buku can be built with similar directions on any Linux distribution.
## Importing Bookmarks
To import bookmarks directly into the manager, first export all bookmarks from your web browser to an html file. Then, enter the following command:
`buku -i bookmarks.html`
As a result, imported bookmarks will be added to the Buku bookmark database.
## Exporting Bookmarks
Exporting bookmarks is as simple as importing them into the database. To export all bookmarks, use this command:
`buku -e bookmarks.html`
The bookmark manager, like all others, will export all bookmarks loaded into the database to an HTML file on the system. After that, take your bookmarks and do with them what you will!
## Opening Bookmarks
To open a bookmark, first the user must search for it. This is done with the `-s`
flag. Run this to search:
`buku -s searchterm`
Then, once a bookmark matching the search has been found, enter the number next to it, and the bookmark will open in the default web browser.
## Encryption
Unlike other bookmark managers, Buku can actually encrypt your data. This is especially handy for users who have “sensitive” bookmarks. To encrypt the database, use the `-l`
flag to create a password.
`buku -l`
With the database locked, it will not be possible to access bookmarks without entering the password to decrypt it. To decrypt, use the -k flag.
`buku -k`
## Other features
This bookmark manger is stuffed with many different features. To read about how to use any of the other features, use the `--help`
switch. When this switch is used, every command switch and flag will be listed, and each feature outlined in detail. This comes in handy, as often users forget things, and it’s nice to be able to pull out a cheat-sheet sometimes.
`buku --help`
## Conclusion
Even though this tool isn’t part of any browser, its features are far above any of the current manager offerings out there. Despite the fact that it runs in the command line, it offers up some serious competition. Bookmarks might not be that important to most people, but those who dislike the current choices and love the Linux command line should give Buku a serious shot.
Our latest tutorials delivered straight to your inbox |
7,924 | 苹果新的文件系统 APFS 比 HFS+ 强在哪里? | https://www.maketecheasier.com/apple-file-system-better-than-hfs/ | 2016-11-02T13:10:00 | [
"文件系统",
"APFS",
"HFS+"
] | https://linux.cn/article-7924-1.html | 
如果你一直关注苹果最新版的 macOS 的消息,你可能已经注意到苹果文件系统 APFS。这是不太让人感冒的话题之一。然而,它是支撑了操作系统用户体验的核心结构。APFS 将在 2017 年之前完成,不过你现在可以在 Sierra(最新版的 macOS) 上面体验一番开发者预览版。
### 特色与改进
先快速科普一下,**文件系统**是操作系统用于存储和检索数据的基本结构,不同的文件系统采用不同的方式来实现这个任务。随着计算机变得越来越快,新生代的文件系统已经从计算机速度的提升中获益,以提供新功能和适应现代存储需求。
HFS+,作为今天新一代 Mac 的附带文件系统,已经 18 岁了。它的祖先 HFS 比 Tom Cruise 的兄弟情影片“壮志凌云”还要老。它有点像一辆老丰田。它仍然可以工作(也许惊人的好),但是它不再得到人们的嘉奖。
APFS 不完全是 HFS+ 的升级版,因为相对现在而言,它是一个大幅度的飞跃。虽然这对苹果用户来说是一个重大的升级,但似乎这看起来更像是苹果赶上了其它系统,而不是超越了它们。然而,更新还进展得非常慢。
### 克隆和数据完整性

APFS 使用称为写时复制(copy-on-write)的方案来生成重复文件的即时克隆。在 HFS+ 下,当用户复制文件的时候,每一个比特(二进制中的“位”)都会被复制。而 APFS 则通过操作元数据并分配磁盘空间来创建克隆。但是,在修改复制的文件之前都不会复制任何比特。当克隆体与原始副本分离的时候,那些改动(并且只有那些改动)才会被保存。
写时复制还提高了数据的完整性。在其它系统下,如果你卸载卷导致覆写操作挂起的话,你可能会发现你的文件系统有一部分与其它部分不同步。写时复制则通过将改动写入到可用的磁盘空间而不是覆盖旧文件来避免这个问题。直到写入操作成功完成前,旧文件都是正式版本。只有当新文件被成功复制时,旧文件才会被清除。
### 系统快照

快照是写时复制架构给你带来的一个主要的升级。快照是文件系统在某个时间点的一个只读的可装载映像。随着文件系统发生改动,只有改动的比特会被更改。这可以让备份更简单,更可靠。考虑到时间机器(一个苹果出品的备份工具)已经成为硬链接的痛点,这可能是一个重大的升级。
### 输入/输出的服务质量(QoS)
你可能已经在你的路由器说明书看到了服务质量(QoS)这个名词。QoS 优先分配带宽使用以避免降低优先任务的速度。在你的路由器上,它采用用户定义的规则来为指定任务提供最大的带宽。据报道,苹果的 QoS 会优先考虑用户操作,例如活跃窗口。而诸如时间机器备份这些后台任务将会被降级。所以,这意味着更少的闲暇时光了?
### 本地加密

在后斯诺登时代,加密成为众所关注的了。越来越多的苹果产品正在强调其系统安全性。内置强大的加密机制并不让人感到意外。包括 APFS 在内,苹果正在采用更加细致入微的加密方案,要么不加密,要么就将加密进行到底。用户可以使用单个密钥来为所有数据加密,或者使用多个加密密钥分别锁定单个文件和文件夹。当然,你也可以不加密,只要你对坏蛋无所忌惮。
### 固态硬盘和闪存优化

闪存优化已经被列为 APFS 的一个亮点功能,不过它的实现并没有那么振奋人心。苹果选择将一些典型的固态硬盘芯片的处理功能迁移到操作系统,而没有深度系统集成的优势。这更像是让文件系统感知固态硬盘,而不是为它们做优化。
### 动态分区调整

APFS 驱动器的逻辑分区可以动态调整自身大小。用户只需指定所需分区的数量,然后文件系统会在运行时进行磁盘分配。每个分区只占用其用于存储文件的磁盘空间。剩余的磁盘空间会由任何分区获取。这种设计很整洁,不过比起其它文件系统,这更像是元文件夹。
### 结论
这是否重要?对于开发者和高级用户来说真是棒极了。对于一般的 Mac 用户应该没有太多的外部差异。虽然升级是重大的举措,但仍然存在一些缺失的部分。本地压缩显然还没有,对用户数据进行的校验也没有。当然,2017 年还没到,一切皆有可能,让我们拭目以待。
---
编译自: <https://www.maketecheasier.com/apple-file-system-better-than-hfs/>
作者:[Alexander Fox](https://www.maketecheasier.com/author/alexfox-2-2-2/) 译者:[OneNewLife](https://github.com/OneNewLife) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | 
If you’ve been following the news from Apple’s latest release of macOS, you might have noticed some mention of Apple File System, or APFS. This is one of those wonky topics that don’t get a lot of attention. Yet, it’s the core structure underlying a user’s experience with the operating system. APFS won’t be finalized until 2017, but you can get a taste in the developer preview now available on Sierra.
## Differences and Improvements
To review quickly, a file system is the basic structure an operating system uses to store and retrieve data. Different file systems take different approaches to this task. As computers have become faster, newer file systems have taken advantage of the boost to offer new features and adapt to modern storage needs.
HFS+, the file system that ships with new Macs today, is eighteen years old. HFS, its progenitor, is older than the Tom Cruise bromance flick “Top Gun.” It’s sort of like an old Toyota. It still works (maybe surprisingly well), but it’s not winning any medals.
APFS isn’t so much an upgrade to HFS+ as it is a quantum leap forward … to the present. Though it’s a major upgrade for Apple users, it seems mostly like Apple is catching up to other systems, rather than overtaking them. Nevertheless, the update isn’t a day too soon.
## Cloning and Data Integrity
APFS uses a scheme called copy-on-write to make instant clones of duplicated files. Under HFS+ when a user duplicates a file, every single bit is copied. APFS instead creates a clone by manipulating metadata and allocating disk space. However, no bits are copied until the cloned file is modified. As the clone diverges from the original copy, those changes (and only those changes) are saved.
Copy-on-write also improves data integrity. Under other systems if your volume unmounts with overwrite operations pending, you might find part of your file system out of sync with the rest. Copy-on-write avoids the problem by writing changes to free disk space instead of overwriting old files. Until the write operation successfully completes, the old file is the canonical version. Only when the new file is successfully copied is the old file purged.
## System Snapshots
Snapshots are a major upgrade and are brought to you in part by copy-on-write architecture. A snapshot is a read-only mountable image of a file system at a point in time. As the file system changes, only modified bits are saved. This can make backup simpler and more reliable. Considering the ungainly disappointment of hard links that Time Machine has become, this could be a major upgrade.
## I/O Quality of Service
You may have seen the term Quality of Service (QoS) in your router’s setup instructions. QoS prioritizes bandwidth usage to avoid slowing down priority tasks. On your router it employs user-defined rules to give selected tasks the most bandwidth. Reportedly, Apple’s QoS would prioritize user operations such as active windows. Background tasks like Time Machine backups would get demoted. So, maybe less beach balls?
## Native Encryption
In a post-Snowden world, encryption is all the rage. And more and more Apple is emphasizing the security of its systems. Built-in, strong encryption comes as no surprise. With APFS, Apple is incorporating a more nuanced encryption scheme than its current, whole-disk-or-nothing approach. Users can use a single key to encrypt all their data or use multiple encryption keys to lock individual files and folders separately. Of course, you could also encrypt nothing, you devil-may-care rascal.
## SSD & Flash Optimization
Flash storage optimization has been listed as a headline feature of APFS, but the implementation isn’t thrilling. Rather than taking advantage of their unusual degree of system integration, Apple has instead shifted some of the functions typically handled by the SSD’s chips to the OS. It’s more like the file system is aware of SSDs rather than optimized for them.
## Dynamic Partition Resizing
Logical partitions on an APFS drive can dynamically resize themselves. Users need only specify the number of desired partitions. The file system then works out disk allocation on the fly. Each partition only occupies disk space that it’s using to store files. The rest of the disk space is up for grabs by any partition. It’s neat, but it’s a lot more like meta-folders than anything else.
## Conclusion
Does this matter? For devs and power users this is awesome. For casual Mac users there shouldn’t be much outward difference. And while the upgrade is great, there are still some missing pieces. Native compression is notably absent, as is checksumming on user data. Of course, anything could change by 2017, so watch this space.
Our latest tutorials delivered straight to your inbox |
7,928 | 俄罗斯总统普京要把微软赶出俄国 | http://news.softpedia.com/news/russian-president-vladimir-putin-wants-microsoft-out-of-the-country-509902.shtml | 2016-11-03T09:20:00 | [
"俄罗斯",
"微软"
] | https://linux.cn/article-7928-1.html | 俄罗斯已经计划通过支持本国的公司和软件来停止使用国外软件,但是最近有消息称普京总统计划加速这一进程,尽可能的快的停止使用微软的产品。

在普京看来,有很好的理由这样做:微软的软件可以被用来对它国做网络攻击,美国可以利用这些产品,比如 Windows 和 Office 来潜入到俄罗斯的系统当中。
[NBC News](http://www.nbcnews.com/nightly-news/video/exclusive-putin-targeting-microsoft-in-effort-to-nationalize-internet-798636099746?) 宣称他们从美国国土安全局得到的一份文件显示,去年俄罗斯黑客采用注入到微软 Office 文档中的木马软件中断了乌克兰电网的运行,所以普京总统担心美国利用类似的攻击来对俄罗斯发起攻击。
普京总统现在正在推行在政府和国企中停止使用外国软件,而采用可控的本国解决方案来免除间谍事件的困扰。
### 普京总统“专门”针对了微软
一个资深的美国情报来源告诉 [NBC News](http://www.nbcnews.com/nightly-news/video/exclusive-putin-targeting-microsoft-in-effort-to-nationalize-internet-798636099746?),普京总统将停止使用微软产品当做优先要处理的工作,他认为这个软件巨头会直接参与到美国政府发起的间谍活动当中。
该内线人员说:“不仅仅是因为他们是 IT 领域最重要的美国公司,而且他们也是俄罗斯人普遍认为的美国情报机构的合作伙伴。”
微软已经解释了它不会参与任何间谍活动,并且明确说明了它不会和美国政府或其它的政府合作在其软件中注入后门。
微软的公共事务总经理 Dominic Carr 说:“我们不会秘密监视任何人,我们不会和任何政府合作监视其它政府,绝不会。”
不过,要摆脱微软的软件并不能一夜之间完成,特别是俄罗斯有着数以百万计的系统运行着 Windows 和 Office,但是该国的法律会强制政府机构和企业采用本地开发的软件来替代那些由外国公司所开发的软件。
| 301 | Moved Permanently | null |
7,929 | 如何在 Ubuntu 上使用 Grafana 监控 Docker | http://linoxide.com/linux-how-to/monitor-docker-containers-grafana-ubuntu/ | 2016-11-03T10:43:00 | [
"Docker",
"监控",
"Grafana"
] | /article-7929-1.html | Grafana 是一个有着丰富指标的开源控制面板。在可视化大规模测量数据的时候是非常有用的。根据不同的指标数据,它提供了一个强大、优雅的来创建、分享和浏览数据的方式。
它提供了丰富多样、灵活的图形选项。此外,针对<ruby> 数据源 <rp> ( </rp> <rt> Data Source </rt> <rp> ) </rp></ruby>,它支持许多不同的存储后端。每个数据源都有针对特定数据源的特性和功能所定制的查询编辑器。Grafana 提供了对下述数据源的正式支持:Graphite、InfluxDB、OpenTSDB、 Prometheus、Elasticsearch 和 Cloudwatch。
每个数据源的查询语言和能力显然是不同的,你可以将来自多个数据源的数据混合到一个单一的仪表盘上,但每个<ruby> 面板 <rp> ( </rp> <rt> Panel </rt> <rp> ) </rp></ruby>被绑定到属于一个特定<ruby> 组织 <rp> ( </rp> <rt> Organization </rt> <rp> ) </rp></ruby>的特定数据源上。它支持验证登录和基于角色的访问控制方案。它是作为一个独立软件部署,使用 Go 和 JavaScript 编写的。

在这篇文章,我将讲解如何在 Ubuntu 16.04 上安装 Grafana 并使用这个软件配置 Docker 监控。
### 先决条件
* 安装好 Docker 的服务器
### 安装 Grafana
我们可以在 Docker 中构建我们的 Grafana。 有一个官方提供的 Grafana Docker 镜像。请运行下述命令来构建Grafana 容器。
```
root@ubuntu:~# docker run -i -p 3000:3000 grafana/grafana
Unable to find image 'grafana/grafana:latest' locally
latest: Pulling from grafana/grafana
5c90d4a2d1a8: Pull complete
b1a9a0b6158e: Pull complete
acb23b0d58de: Pull complete
Digest: sha256:34ca2f9c7986cb2d115eea373083f7150a2b9b753210546d14477e2276074ae1
Status: Downloaded newer image for grafana/grafana:latest
t=2016-07-27T15:20:19+0000 lvl=info msg="Starting Grafana" logger=main version=3.1.0 commit=v3.1.0 compiled=2016-07-12T06:42:28+0000
t=2016-07-27T15:20:19+0000 lvl=info msg="Config loaded from" logger=settings file=/usr/share/grafana/conf/defaults.ini
t=2016-07-27T15:20:19+0000 lvl=info msg="Config loaded from" logger=settings file=/etc/grafana/grafana.ini
t=2016-07-27T15:20:19+0000 lvl=info msg="Config overriden from command line" logger=settings arg="default.paths.data=/var/lib/grafana"
t=2016-07-27T15:20:19+0000 lvl=info msg="Config overriden from command line" logger=settings arg="default.paths.logs=/var/log/grafana"
t=2016-07-27T15:20:19+0000 lvl=info msg="Config overriden from command line" logger=settings arg="default.paths.plugins=/var/lib/grafana/plugins"
t=2016-07-27T15:20:19+0000 lvl=info msg="Path Home" logger=settings path=/usr/share/grafana
t=2016-07-27T15:20:19+0000 lvl=info msg="Path Data" logger=settings path=/var/lib/grafana
t=2016-07-27T15:20:19+0000 lvl=info msg="Path Logs" logger=settings path=/var/log/grafana
t=2016-07-27T15:20:19+0000 lvl=info msg="Path Plugins" logger=settings path=/var/lib/grafana/plugins
t=2016-07-27T15:20:19+0000 lvl=info msg="Initializing DB" logger=sqlstore dbtype=sqlite3
t=2016-07-27T15:20:20+0000 lvl=info msg="Executing migration" logger=migrator id="create playlist table v2"
t=2016-07-27T15:20:20+0000 lvl=info msg="Executing migration" logger=migrator id="create playlist item table v2"
t=2016-07-27T15:20:20+0000 lvl=info msg="Executing migration" logger=migrator id="drop preferences table v2"
t=2016-07-27T15:20:20+0000 lvl=info msg="Executing migration" logger=migrator id="drop preferences table v3"
t=2016-07-27T15:20:20+0000 lvl=info msg="Executing migration" logger=migrator id="create preferences table v3"
t=2016-07-27T15:20:20+0000 lvl=info msg="Created default admin user: [admin]"
t=2016-07-27T15:20:20+0000 lvl=info msg="Starting plugin search" logger=plugins
t=2016-07-27T15:20:20+0000 lvl=info msg="Server Listening" logger=server address=0.0.0.0:3000 protocol=http subUrl=
```
我们可以通过运行此命令确认 Grafana 容器的工作状态 `docker ps -a` 或通过这个URL访问 `http://Docker IP:3000`。
所有的 Grafana 配置设置都使用环境变量定义,在使用容器技术时这个是非常有用的。Grafana 配置文件路径为 `/etc/grafana/grafana.ini`。
### 理解配置项
Grafana 可以在它的 ini 配置文件中指定几个配置选项,或可以使用前面提到的环境变量来指定。
#### 配置文件位置
通常配置文件路径:
* 默认配置文件路径 : `$WORKING_DIR/conf/defaults.ini`
* 自定义配置文件路径 : `$WORKING_DIR/conf/custom.ini`
PS:当你使用 deb、rpm 或 docker 镜像安装 Grafana 时,你的配置文件在 `/etc/grafana/grafana.ini`。
#### 理解配置变量
现在我们看一些配置文件中的变量:
* `instance_name`:这是 Grafana 服务器实例的名字。默认值从 `${HOSTNAME}` 获取,其值是环境变量`HOSTNAME`,如果该变量为空或不存在,Grafana 将会尝试使用系统调用来获取机器名。
* `[paths]`:这些路径通常都是在 init.d 脚本或 systemd service 文件中通过命令行指定。
+ `data`:这个是 Grafana 存储 sqlite3 数据库(如果使用)、基于文件的会话(如果使用),和其他数据的路径。
+ `logs`:这个是 Grafana 存储日志的路径。
* `[server]`
+ `http_addr`:应用监听的 IP 地址,如果为空,则监听所有的接口。
+ `http_port`:应用监听的端口,默认是 3000,你可以使用下面的命令将你的 80 端口重定向到 3000 端口:`$iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3000`
+ `root_url` : 这个 URL 用于从浏览器访问 Grafana 。
+ `cert_file` : 证书文件的路径(如果协议是 HTTPS)。
+ `cert_key` : 证书密钥文件的路径(如果协议是 HTTPS)。
* `[database]`:Grafana 使用数据库来存储用户和仪表盘以及其他信息,默认配置为使用内嵌在 Grafana 主二进制文件中的 SQLite3。
+ `type`:你可以根据你的需求选择 MySQL、Postgres、SQLite3。
+ `path`:仅用于选择 SQLite3 数据库时,这个是数据库所存储的路径。
+ `host`:仅适用 MySQL 或者 Postgres。它包括 IP 地址或主机名以及端口。例如,Grafana 和 MySQL 运行在同一台主机上设置如: `host = 127.0.0.1:3306`。
+ `name`:Grafana 数据库的名称,把它设置为 Grafana 或其它名称。
+ `user`:数据库用户(不适用于 SQLite3)。
+ `password`:数据库用户密码(不适用于 SQLite3)。
+ `ssl_mode`:对于 Postgres,使用 `disable`,`require`,或 `verify-full` 等值。对于 MySQL,使用 `true`,`false`,或 `skip-verify`。
+ `ca_cert_path`:(只适用于 MySQL)CA 证书文件路径,在多数 Linux 系统中,证书可以在 `/etc/ssl/certs` 找到。
+ `client_key_path`:(只适用于 MySQL)客户端密钥的路径,只在服务端需要用户端验证时使用。
+ `client_cert_path`:(只适用于 MySQL)客户端证书的路径,只在服务端需要用户端验证时使用。
+ `server_cert_name`:(只适用于 MySQL)MySQL 服务端使用的证书的通用名称字段。如果 `ssl_mode` 设置为 `skip-verify` 时可以不设置。
* `[security]`
+ `admin_user`:这个是 Grafana 默认的管理员用户的用户名,默认设置为 admin。
+ `admin_password`:这个是 Grafana 默认的管理员用户的密码,在第一次运行时设置,默认为 admin。
+ `login_remember_days`:保持登录/记住我的持续天数。
+ `secret_key`:用于保持登录/记住我的 cookies 的签名。
### 设置监控的重要组件
我们可以使用下面的组件来创建我们的 Docker 监控系统。
* `cAdvisor`:它被称为 Container Advisor。它给用户提供了一个资源利用和性能特征的解读。它会收集、聚合、处理、导出运行中的容器的信息。你可以通过[这个文档](https://github.com/google/cadvisor)了解更多。
* `InfluxDB`:这是一个包含了时间序列、度量和分析数据库。我们使用这个数据源来设置我们的监控。cAdvisor 只展示实时信息,并不保存这些度量信息。Influx Db 帮助保存 cAdvisor 提供的监控数据,以展示非某一时段的数据。
* `Grafana Dashboard`:它可以帮助我们在视觉上整合所有的信息。这个强大的仪表盘使我们能够针对 InfluxDB 数据存储进行查询并将他们放在一个布局合理好看的图表中。
### Docker 监控的安装
我们需要一步一步的在我们的 Docker 系统中安装以下每一个组件:
#### 安装 InfluxDB
我们可以使用这个命令来拉取 InfluxDB 镜像,并部署了 influxDB 容器。
```
root@ubuntu:~# docker run -d -p 8083:8083 -p 8086:8086 --expose 8090 --expose 8099 -e PRE_CREATE_DB=cadvisor --name influxsrv tutum/influxdb:0.8.8
Unable to find image 'tutum/influxdb:0.8.8' locally
0.8.8: Pulling from tutum/influxdb
a3ed95caeb02: Already exists
23efb549476f: Already exists
aa2f8df21433: Already exists
ef072d3c9b41: Already exists
c9f371853f28: Already exists
a248b0871c3c: Already exists
749db6d368d0: Already exists
7d7c7d923e63: Pull complete
e47cc7808961: Pull complete
1743b6eeb23f: Pull complete
Digest: sha256:8494b31289b4dbc1d5b444e344ab1dda3e18b07f80517c3f9aae7d18133c0c42
Status: Downloaded newer image for tutum/influxdb:0.8.8
d3b6f7789e0d1d01fa4e0aacdb636c221421107d1df96808ecbe8e241ceb1823
-p 8083:8083 : user interface, log in with username-admin, pass-admin
-p 8086:8086 : interaction with other application
--name influxsrv : container have name influxsrv, use to cAdvisor link it.
```
你可以测试 InfluxDB 是否安装好,通过访问这个 URL `http://你的 IP 地址:8083`,用户名和密码都是 ”root“。

我们可以在这个界面上创建我们所需的数据库。

#### 安装 cAdvisor
我们的下一个步骤是安装 cAdvisor 容器,并将其链接到 InfluxDB 容器。你可以使用此命令来创建它。
```
root@ubuntu:~# docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --publish=8080:8080 --detach=true --link influxsrv:influxsrv --name=cadvisor google/cadvisor:latest -storage_driver_db=cadvisor -storage_driver_host=influxsrv:8086
Unable to find image 'google/cadvisor:latest' locally
latest: Pulling from google/cadvisor
09d0220f4043: Pull complete
151807d34af9: Pull complete
14cd28dce332: Pull complete
Digest: sha256:8364c7ab7f56a087b757a304f9376c3527c8c60c848f82b66dd728980222bd2f
Status: Downloaded newer image for google/cadvisor:latest
3bfdf7fdc83872485acb06666a686719983a1172ac49895cd2a260deb1cdde29
root@ubuntu:~#
--publish=8080:8080 : user interface
--link=influxsrv:influxsrv: link to container influxsrv
-storage_driver=influxdb: set the storage driver as InfluxDB
Specify what InfluxDB instance to push data to:
-storage_driver_host=influxsrv:8086: The ip:port of the database. Default is ‘localhost:8086’
-storage_driver_db=cadvisor: database name. Uses db ‘cadvisor’ by default
```
你可以通过访问这个地址来测试安装 cAdvisor 是否正常 `http://你的 IP 地址:8080`。 这将为你的 Docker 主机和容器提供统计信息。

#### 安装 Grafana 控制面板
最后,我们需要安装 Grafana 仪表板并连接到 InfluxDB,你可以执行下面的命令来设置它。
```
root@ubuntu:~# docker run -d -p 3000:3000 -e INFLUXDB_HOST=localhost -e INFLUXDB_PORT=8086 -e INFLUXDB_NAME=cadvisor -e INFLUXDB_USER=root -e INFLUXDB_PASS=root --link influxsrv:influxsrv --name grafana grafana/grafana
f3b7598529202b110e4e6b998dca6b6e60e8608d75dcfe0d2b09ae408f43684a
```
现在我们可以登录 Grafana 来配置数据源. 访问 `http://你的 IP 地址:3000` 或 `http://你的 IP 地址`(如果你在前面做了端口映射的话):
* 用户名 - admin
* 密码 - admin
一旦我们安装好了 Grafana,我们可以连接 InfluxDB。登录到仪表盘并且点击面板左上方角落的 Grafana 图标(那个火球)。点击<ruby> 数据源 <rp> ( </rp> <rt> Data Sources </rt> <rp> ) </rp></ruby>来配置。

现在你可以添加新的<ruby> 图形 <rp> ( </rp> <rt> Graph </rt> <rp> ) </rp></ruby>到我们默认的数据源 InfluxDB。

我们可以通过在<ruby> 测量 <rp> ( </rp> <rt> Metric </rt> <rp> ) </rp></ruby>页面编辑和调整我们的查询以调整我们的图形。


关于 Docker 监控,你可用[从此了解](https://github.com/vegasbrianc/docker-monitoring)更多信息。 感谢你的阅读。我希望你可以留下有价值的建议和评论。希望你有个美好的一天。
---
via: <http://linoxide.com/linux-how-to/monitor-docker-containers-grafana-ubuntu/>
作者:[Saheetha Shameer](http://linoxide.com/author/saheethas/) 译者:[Bestony](https://github.com/bestony) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | HTTPConnectionPool(host='linoxide.com', port=80): Max retries exceeded with url: /linux-how-to/monitor-docker-containers-grafana-ubuntu/ (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7b8327581750>, 'Connection to linoxide.com timed out. (connect timeout=10)')) | null |
7,930 | 两款免费的 Linux 桌面录制工具:SimpleScreenRecorder 和 Kazam | https://opensource.com/education/16/10/simplescreenrecorder-and-kazam | 2016-11-04T09:22:00 | [
"屏幕录制"
] | https://linux.cn/article-7930-1.html |
>
> 桌面录制工具可以帮做我们快速高效的制作教学视频和在线示范。
>
>
>
一图胜千言,但一段视频演示则可以让你不用大费口舌。我是一个“视觉学习者”,亲眼目睹一件事情的发生对我的学习大有裨益。我也曾观察发现,如果学生实际看到应用程序的设置流程或者代码的编写过程,他们就能从中受益良多。所以,录屏工具是制作教学视频的绝佳工具。在本文中我将介绍一下两款开源桌面录制工具: [SimpleScreenRecorder](http://www.maartenbaert.be/simplescreenrecorder/) 和 [Kazam](https://launchpad.net/kazam)。

### SimpleScreenRecorder
使用 SimpleScreenRecorder 能够轻松录制桌面动作,它拥有直观的用户界面以及多样的编码方式,如 MP4、OGG、[Matroska](https://www.matroska.org/technical/whatis/index.html) 或 [WebM](https://www.webmproject.org/) 格式。 SimpleScreenRecorder 遵从 GPL 协议发行,运行在 Linux 上。
在安装运行 SimpleScreenRecorder 后,你可以轻松选择录制整个桌面、指定窗口或者一个自定义的区域。我比较偏爱最后这种方式,因为这样我可以使我的学生把注意力集中在我想让他们注意的地方。你还可以在设置中选择是否隐藏光标、调整录制帧率(默认帧率为 30fps)、视频压缩比例或者调整音频后端(如 ALSA、JACK 或 PusleAudio)。
由于 SimpleScreenRecorder 使用了 libav/ffmpeg 库进行编码,故而支持多种文件格式和视频编码方式。可以使用不同的配置文件(编码更快的配置文件意味着更大的体积),包括 YouTube 和 1000kbps – 3000kbps 的 LiveStream。


配置完毕后,单击“开始录制”按钮或者使用自定义的快捷键就可以轻松开始录制屏幕啦~

你还能在设置中开启提示音功能,它会开始录制和录制结束时给你声音的提示。屏幕录制完成后,你可以对视频文件进行编辑或者直接上传到 YouTube、Vimeo 等视频网站上。
SimpleScreenRecorder 的[官方网站](http://www.maartenbaert.be/simplescreenrecorder/)上还有大量说明文档,其中包括设置、录制、上传等方面的帮助手册和针对多种Linux发行版的安装说明。
### Kazam
Kazam 桌面录制工具同样是遵循 GPL 协议的软件。同时和 SimpleScreenRecorder 一样,Kazam 易于上手,界面直观。安装运行 Kazam 之后,你可以设置选择录制整个桌面、指定窗口或是一个自定义的区域。(LCTT 译注:关于自定义区域录制一部分的内容与 SimpleScreenRecorder 介绍中的内容基本相似,略过) ,你还可以选择记录鼠标的移动轨迹。我最中意 Kazam 的一点是延时录制的功能,这在制作视频教程的时候必不可少。
在“文件|设置”菜单下可以轻松对 Kazam 进行个性化设置,比如可以选择扬声器或是麦克风中的音源、关闭倒计时提示等等。

在设置页的第二个选项卡中可以进行视频录制设置。Kazam 默认录制帧率为 15fps,编码格式为 H264(MP4)。其它可供选择的格式有 VP8(WEBM)、HUFFYUV、Lossless JPEG 以及 RAW AVI。录制好的文件会以附加一个预设的前缀来命名,并自动保存在默认目录下,你可以随时修改这些设置。

设置屏幕截图同样很简单。你可以选择 Nikon D80 或 Canon 7D 的快门音效,也可以干脆关掉他们。截图文件是自动存放的。除非你关闭这一功能。

录制好的视频将会存储在你选定的目录下,随时可以上传到你喜欢的视频分享网站或是教程网站上。
是时候利用 Linux 和录屏工具让你的课堂焕然一新了!如果你还有其他的屏幕录制工具或是使用技巧,记得在评论里与我交流哦~
### 赠品:Kap
前面提到两款软件都是 Linux 下的屏幕录制软件,这里还有一款是 Mac 下的开源录屏软件推荐给大家: [Kap](https://getkap.co/)。它是使用 Web 技术(Node.js)构建的,以 MIT 协议开源在 [GitHub](https://github.com/wulkano/kap) 上。

你可以[直接下载 dmg 镜像](https://getkap.co/download)安装(300M),也可以使用 `brew` 从 Homebrew Cask 安装:
```
$ brew update
$ brew cask install kap
```
如果你使用 Mac,不妨一试,也欢迎你对这个项目提交贡献。
---
via: <https://opensource.com/education/16/10/simplescreenrecorder-and-kazam>
作者:[Don Watkins](https://opensource.com/users/don-watkins) 译者:[HaohongWANG](https://github.com/HaohongWANG) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | A picture might be worth a thousand words, but a video demonstration can save a lot of talking. I'm a visual learner, so seeing how to do something has been very helpful in my education. I've found that students benefit from seeing exactly how an application is configured or how a code snippet is written. Desktop screen recorders are great tools for creating instructional videos. In this article, I'll look at two free, open source desktop screen recorders: [SimpleScreenRecorder](http://www.maartenbaert.be/simplescreenrecorder/) and [Kazam](https://launchpad.net/kazam).
## SimpleScreenRecorder
SimpleScreenRecorder lets you easily record desktop action. It has an untuitive interface and the ability to record in MP4, OGG, [Matroska](https://www.matroska.org/technical/whatis/index.html), or [WebM](https://www.webmproject.org/) format. SimpleScreenRecorder is released under the Gnu Public License and runs on Linux.
After installing and launching the program, you can easily configure it to capture the whole desktop, a specific window, or a select area. The latter is my personal favorite because it focuses the learner's attention on exactly where I want them to look. You can record the cursor or not, adjust the frame rate, scale the video, and adjust the audio backend, which includes three options: ALSA, JACK, and PulseAudio. Video frame rate defaults to 30fps.
Because SimpleScreenRecorder uses libav/ffmpeg libraries for encoding, it supports a variety of file formats and video codecs. Different profiles can be used (faster profiles mean bigger file sizes), including YouTube, LiveStream (1000kbps), LiveStream (2000kbps), LiveStream (3000 kbps), and high-quality intermediate.
After you've configured your system, recording is easy. You can either click on the *Start recording* button or use a selection hot key.
Sound notification can also be enabled, which is a nice feature that lets you know when the recording begins and ends. Once the recording is completed, the file can edited or uploaded to YouTube, Vimeo, or an educational learning management system.
SimpleScreenRecorder has great documentation on its website, which includes tips for configuration, recording, and uploading, as well as installation instructions for various Linux distributions.
## Kazam
The Kazam desktop screen recorder is also released under the Gnu Public License and, like SimpleScreenRecorder, it is easy to use and offers an intuitive interface. After you install and launch the program, you can configure it to capture the whole desktop, a specific window, or a select area. Recording a select area of a screen can come in handy because it focuses the learner's attention on exactly where you want them to look. You can capture the mouse pointer movement, too. I like that Kazam also has the ability to delay the capture, which can come in useful when recording tutorials.
Configuring preferences is easy under the *File* | * Preferences* menu, and audio capture sources can be selected to include speakers and microphone. Countdown splash can be turned off, too.
The second tab of preferences is for selecting video preferences. Frame rate defaults to 15fps. The default recording is set to H264(MP4), but there are other formats available, such as VP8(WEBM), HUFFYUV, LosslessJPEG, and RAW AVI. Automatic file saving is enabled by default, along with the self-selected directory where videos are saved and a default file-name prefix, which is user-configurable.
Configuring the screenshot is easy. The shutter sound is on by default, and the shutter type can be self-selected and includes the default Nikon D80 or Canon 7D. File saving is automatic unless otherwise selected.
Screencasts are easily saved to a directory of your choice, and the file is ready to upload to your favorite sharing site or your learning management system.
Here's to flipping your classroom and instruction using a Linux computer and either of these great desktop screen recorders! What other screen recording tools and tricks are useful in your classroom? Let me know about them in the comments.
## 7 Comments |
7,931 | C++ 程序员 Protocol Buffers 基础指南 | https://developers.google.com/protocol-buffers/docs/cpptutorial | 2016-11-04T10:37:00 | [
"C++",
"XML",
"Protocol Buffers"
] | https://linux.cn/article-7931-1.html | 这篇教程提供了一个面向 C++ 程序员关于 protocol buffers 的基础介绍。通过创建一个简单的示例应用程序,它将向我们展示:
* 在 `.proto` 文件中定义消息格式
* 使用 protocol buffer 编译器
* 使用 C++ protocol buffer API 读写消息
这不是一个关于在 C++ 中使用 protocol buffers 的全面指南。要获取更详细的信息,请参考 [Protocol Buffer Language Guide](https://developers.google.com/protocol-buffers/docs/proto) 和 [Encoding Reference](https://developers.google.com/protocol-buffers/docs/encoding)。
### 为什么使用 Protocol Buffers
我们接下来要使用的例子是一个非常简单的"地址簿"应用程序,它能从文件中读取联系人详细信息。地址簿中的每一个人都有一个名字、ID、邮件地址和联系电话。
如何序列化和获取结构化的数据?这里有几种解决方案:
* 以二进制形式发送/接收原生的内存数据结构。通常,这是一种脆弱的方法,因为接收/读取代码必须基于完全相同的内存布局、大小端等环境进行编译。同时,当文件增加时,原始格式数据会随着与该格式相关的软件而迅速扩散,这将导致很难扩展文件格式。
* 你可以创造一种 ad-hoc 方法,将数据项编码为一个字符串——比如将 4 个整数编码为 `12:3:-23:67`。虽然它需要编写一次性的编码和解码代码且解码需要耗费一点运行时成本,但这是一种简单灵活的方法。这最适合编码非常简单的数据。
* 序列化数据为 XML。这种方法是非常吸引人的,因为 XML 是一种适合人阅读的格式,并且有为许多语言开发的库。如果你想与其他程序和项目共享数据,这可能是一种不错的选择。然而,众所周知,XML 是空间密集型的,且在编码和解码时,它对程序会造成巨大的性能损失。同时,使用 XML DOM 树被认为比操作一个类的简单字段更加复杂。
Protocol buffers 是针对这个问题的一种灵活、高效、自动化的解决方案。使用 Protocol buffers,你需要写一个 `.proto` 说明,用于描述你所希望存储的数据结构。利用 `.proto` 文件,protocol buffer 编译器可以创建一个类,用于实现对高效的二进制格式的 protocol buffer 数据的自动化编码和解码。产生的类提供了构造 protocol buffer 的字段的 getters 和 setters,并且作为一个单元来处理读写 protocol buffer 的细节。重要的是,protocol buffer 格式支持格式的扩展,代码仍然可以读取以旧格式编码的数据。

### 在哪可以找到示例代码
示例代码被包含于源代码包,位于“examples”文件夹。可在[这里](https://developers.google.com/protocol-buffers/docs/downloads.html)下载代码。
### 定义你的协议格式
为了创建自己的地址簿应用程序,你需要从 `.proto` 开始。`.proto` 文件中的定义很简单:为你所需要序列化的每个数据结构添加一个<ruby> 消息 <rp> ( </rp> <rt> message </rt> <rp> ) </rp></ruby>,然后为消息中的每一个字段指定一个名字和类型。这里是定义你消息的 `.proto` 文件 `addressbook.proto`。
```
package tutorial;
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phone = 4;
}
message AddressBook {
repeated Person person = 1;
}
```
如你所见,其语法类似于 C++ 或 Java。我们开始看看文件的每一部分内容做了什么。
`.proto` 文件以一个 `package` 声明开始,这可以避免不同项目的命名冲突。在 C++,你生成的类会被置于与 `package` 名字一样的命名空间。
下一步,你需要定义<ruby> 消息 <rp> ( </rp> <rt> message </rt> <rp> ) </rp></ruby>。消息只是一个包含一系列类型字段的集合。大多标准的简单数据类型是可以作为字段类型的,包括 `bool`、`int32`、`float`、`double` 和 `string`。你也可以通过使用其他消息类型作为字段类型,将更多的数据结构添加到你的消息中——在以上的示例,`Person` 消息包含了 `PhoneNumber` 消息,同时 `AddressBook` 消息包含 `Person` 消息。你甚至可以定义嵌套在其他消息内的消息类型——如你所见,`PhoneNumber` 类型定义于 `Person` 内部。如果你想要其中某一个字段的值是预定义值列表中的某个值,你也可以定义 `enum` 类型——这儿你可以指定一个电话号码是 `MOBILE`、`HOME` 或 `WORK` 中的某一个。
每一个元素上的 `= 1`、`= 2` 标记确定了用于二进制编码的唯一<ruby> “标签” <rp> ( </rp> <rt> tag </rt> <rp> ) </rp></ruby>。标签数字 1-15 的编码比更大的数字少需要一个字节,因此作为一种优化,你可以将这些标签用于经常使用的元素或 `repeated` 元素,剩下 16 以及更高的标签用于非经常使用的元素或 `optional` 元素。每一个 `repeated` 字段的元素需要重新编码标签数字,因此 `repeated` 字段适合于使用这种优化手段。
每一个字段必须使用下面的修饰符加以标注:
* `required`:必须提供该字段的值,否则消息会被认为是<ruby> “未初始化的” <rp> ( </rp> <rt> uninitialized </rt> <rp> ) </rp></ruby>。如果 `libprotobuf` 以调试模式编译,序列化未初始化的消息将引起一个断言失败。以优化形式构建,将会跳过检查,并且无论如何都会写入该消息。然而,解析未初始化的消息总是会失败(通过 `parse` 方法返回 `false`)。除此之外,一个 `required` 字段的表现与 `optional` 字段完全一样。
* `optional`:字段可能会被设置,也可能不会。如果一个 `optional` 字段没被设置,它将使用默认值。对于简单类型,你可以指定你自己的默认值,正如例子中我们对电话号码的 `type` 一样,否则使用系统默认值:数字类型为 0、字符串为空字符串、布尔值为 false。对于嵌套消息,默认值总为消息的“默认实例”或“原型”,它的所有字段都没被设置。调用 accessor 来获取一个没有显式设置的 `optional`(或 `required`) 字段的值总是返回字段的默认值。
* `repeated`:字段可以重复任意次数(包括 0 次)。`repeated` 值的顺序会被保存于 protocol buffer。可以将 `repeated` 字段想象为动态大小的数组。
你可以查找关于编写 `.proto` 文件的完整指导——包括所有可能的字段类型——在 [Protocol Buffer Language Guide](https://developers.google.com/protocol-buffers/docs/proto) 里面。不要在这里面查找与类继承相似的特性,因为 protocol buffers 不会做这些。
>
> **`required` 是永久性的**
>
>
> 在把一个字段标识为 `required` 的时候,你应该特别小心。如果在某些情况下你不想写入或者发送一个 `required` 的字段,那么将该字段更改为 `optional` 可能会遇到问题——旧版本的读者(LCTT 译注:即读取、解析旧版本 Protocol Buffer 消息的一方)会认为不含该字段的消息是不完整的,从而有可能会拒绝解析。在这种情况下,你应该考虑编写特别针对于应用程序的、自定义的消息校验函数。Google 的一些工程师得出了一个结论:使用 `required` 弊多于利;他们更愿意使用 `optional` 和 `repeated` 而不是 `required`。当然,这个观点并不具有普遍性。
>
>
>
### 编译你的 Protocol Buffers
既然你有了一个 `.proto`,那你需要做的下一件事就是生成一个将用于读写 `AddressBook` 消息的类(从而包括 `Person` 和 `PhoneNumber`)。为了做到这样,你需要在你的 `.proto` 上运行 protocol buffer 编译器 `protoc`:
1. 如果你没有安装编译器,请[下载这个包](https://developers.google.com/protocol-buffers/docs/downloads.html),并按照 README 中的指令进行安装。
2. 现在运行编译器,指定源目录(你的应用程序源代码位于哪里——如果你没有提供任何值,将使用当前目录)、目标目录(你想要生成的代码放在哪里;常与 `$SRC_DIR` 相同),以及你的 `.proto` 路径。在此示例中:
```
protoc -I=$SRC_DIR --cpp_out=$DST_DIR $SRC_DIR/addressbook.proto
```
因为你想要 C++ 的类,所以你使用了 `--cpp_out` 选项——也为其他支持的语言提供了类似选项。
在你指定的目标文件夹,将生成以下的文件:
* `addressbook.pb.h`,声明你生成类的头文件。
* `addressbook.pb.cc`,包含你的类的实现。
### Protocol Buffer API
让我们看看生成的一些代码,了解一下编译器为你创建了什么类和函数。如果你查看 `addressbook.pb.h`,你可以看到有一个在 `addressbook.proto` 中指定所有消息的类。关注 `Person` 类,可以看到编译器为每个字段生成了<ruby> 读写函数 <rp> ( </rp> <rt> accessors </rt> <rp> ) </rp></ruby>。例如,对于 `name`、`id`、`email` 和 `phone` 字段,有下面这些方法:(LCTT 译注:此处原文所指文件名有误,径该之。)
```
// name
inline bool has_name() const;
inline void clear_name();
inline const ::std::string& name() const;
inline void set_name(const ::std::string& value);
inline void set_name(const char* value);
inline ::std::string* mutable_name();
// id
inline bool has_id() const;
inline void clear_id();
inline int32_t id() const;
inline void set_id(int32_t value);
// email
inline bool has_email() const;
inline void clear_email();
inline const ::std::string& email() const;
inline void set_email(const ::std::string& value);
inline void set_email(const char* value);
inline ::std::string* mutable_email();
// phone
inline int phone_size() const;
inline void clear_phone();
inline const ::google::protobuf::RepeatedPtrField< ::tutorial::Person_PhoneNumber >& phone() const;
inline ::google::protobuf::RepeatedPtrField< ::tutorial::Person_PhoneNumber >* mutable_phone();
inline const ::tutorial::Person_PhoneNumber& phone(int index) const;
inline ::tutorial::Person_PhoneNumber* mutable_phone(int index);
inline ::tutorial::Person_PhoneNumber* add_phone();
```
正如你所见到,getters 的名字与字段的小写名字完全一样,并且 setter 方法以 `set_` 开头。同时每个<ruby> 单一 <rp> ( </rp> <rt> singular </rt> <rp> ) </rp></ruby>(`required` 或 `optional`)字段都有 `has_` 方法,该方法在字段被设置了值的情况下返回 true。最后,所有字段都有一个 `clear_` 方法,用以清除字段到<ruby> 空 <rp> ( </rp> <rt> empty </rt> <rp> ) </rp></ruby>状态。
数字型的 `id` 字段仅有上述的基本<ruby> 读写函数 <rp> ( </rp> <rt> accessors </rt> <rp> ) </rp></ruby>集合,而 `name` 和 `email` 字段有两个额外的方法,因为它们是字符串——一个是可以获得字符串直接指针的`mutable_` 的 getter ,另一个为额外的 setter。注意,尽管 `email` 还没被<ruby> 设置 <rp> ( </rp> <rt> set </rt> <rp> ) </rp></ruby>,你也可以调用 `mutable_email`;因为 `email` 会被自动地初始化为空字符串。在本例中,如果你有一个单一的(`required` 或 `optional`)消息字段,它会有一个 `mutable_` 方法,而没有 `set_` 方法。
`repeated` 字段也有一些特殊的方法——如果你看看 `repeated` 的 `phone` 字段的方法,你可以看到:
* 检查 `repeated` 字段的 `_size`(也就是说,与 `Person` 相关的电话号码的个数)
* 使用下标取得特定的电话号码
* 更新特定下标的电话号码
* 添加新的电话号码到消息中,之后你便可以编辑。(`repeated` 标量类型有一个 `add_` 方法,用于传入新的值)
为了获取 protocol 编译器为所有字段定义生成的方法的信息,可以查看 [C++ generated code reference](https://developers.google.com/protocol-buffers/docs/reference/cpp-generated)。
#### 枚举和嵌套类
与 `.proto` 的枚举相对应,生成的代码包含了一个 `PhoneType` 枚举。你可以通过 `Person::PhoneType` 引用这个类型,通过 `Person::MOBILE`、`Person::HOME` 和 `Person::WORK` 引用它的值。(实现细节有点复杂,但是你无须了解它们而可以直接使用)
编译器也生成了一个 `Person::PhoneNumber` 的嵌套类。如果你查看代码,你可以发现真正的类型为 `Person_PhoneNumber`,但它通过在 `Person` 内部使用 `typedef` 定义,使你可以把 `Person_PhoneNumber` 当成嵌套类。唯一产生影响的一个例子是,如果你想要在其他文件前置声明该类——在 C++ 中你不能前置声明嵌套类,但是你可以前置声明 `Person_PhoneNumber`。
#### 标准的消息方法
所有的消息方法都包含了许多别的方法,用于检查和操作整个消息,包括:
* `bool IsInitialized() const;` :检查是否所有 `required` 字段已经被设置。
* `string DebugString() const;` :返回人类可读的消息表示,对调试特别有用。
* `void CopyFrom(const Person& from);`:使用给定的值重写消息。
* `void Clear();`:清除所有元素为空的状态。
上面这些方法以及下一节要讲的 I/O 方法实现了被所有 C++ protocol buffer 类共享的<ruby> 消息 <rp> ( </rp> <rt> Message </rt> <rp> ) </rp></ruby>接口。为了获取更多信息,请查看 [complete API documentation for Message](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.message.html#Message)。
#### 解析和序列化
最后,所有 protocol buffer 类都有读写你选定类型消息的方法,这些方法使用了特定的 protocol buffer [二进制格式](https://developers.google.com/protocol-buffers/docs/encoding)。这些方法包括:
* `bool SerializeToString(string* output) const;`:序列化消息并将消息字节数据存储在给定的字符串中。注意,字节数据是二进制格式的,而不是文本格式;我们只使用 `string` 类作为合适的容器。
* `bool ParseFromString(const string& data);`:从给定的字符创解析消息。
* `bool SerializeToOstream(ostream* output) const;`:将消息写到给定的 C++ `ostream`。
* `bool ParseFromIstream(istream* input);`:从给定的 C++ `istream` 解析消息。
这些只是两个用于解析和序列化的选择。再次说明,可以查看 `Message API reference` 完整的列表。
>
> **Protocol Buffers 和面向对象设计**
>
>
> Protocol buffer 类通常只是纯粹的数据存储器(像 C++ 中的结构体);它们在对象模型中并不是一等公民。如果你想向生成的 protocol buffer 类中添加更丰富的行为,最好的方法就是在应用程序中对它进行封装。如果你无权控制 `.proto` 文件的设计的话,封装 protocol buffers 也是一个好主意(例如,你从另一个项目中重用一个 `.proto` 文件)。在那种情况下,你可以用封装类来设计接口,以更好地适应你的应用程序的特定环境:隐藏一些数据和方法,暴露一些便于使用的函数,等等。**但是你绝对不要通过继承生成的类来添加行为。**这样做的话,会破坏其内部机制,并且不是一个好的面向对象的实践。
>
>
>
### 写消息
现在我们尝试使用 protocol buffer 类。你的地址簿程序想要做的第一件事是将个人详细信息写入到地址簿文件。为了做到这一点,你需要创建、填充 protocol buffer 类实例,并且将它们写入到一个<ruby> 输出流 <rp> ( </rp> <rt> output stream </rt> <rp> ) </rp></ruby>。
这里的程序可以从文件读取 `AddressBook`,根据用户输入,将新 `Person` 添加到 `AddressBook`,并且再次将新的 `AddressBook` 写回文件。这部分直接调用或引用 protocol buffer 类的代码会以“`// pb`”标出。
```
#include <iostream>
#include <fstream>
#include <string>
#include "addressbook.pb.h" // pb
using namespace std;
// This function fills in a Person message based on user input.
void PromptForAddress(tutorial::Person* person) {
cout << "Enter person ID number: ";
int id;
cin >> id;
person->set_id(id); // pb
cin.ignore(256, '\n');
cout << "Enter name: ";
getline(cin, *person->mutable_name()); // pb
cout << "Enter email address (blank for none): ";
string email;
getline(cin, email);
if (!email.empty()) { // pb
person->set_email(email); // pb
}
while (true) {
cout << "Enter a phone number (or leave blank to finish): ";
string number;
getline(cin, number);
if (number.empty()) {
break;
}
tutorial::Person::PhoneNumber* phone_number = person->add_phone(); //pb
phone_number->set_number(number); // pb
cout << "Is this a mobile, home, or work phone? ";
string type;
getline(cin, type);
if (type == "mobile") {
phone_number->set_type(tutorial::Person::MOBILE); // pb
} else if (type == "home") {
phone_number->set_type(tutorial::Person::HOME); // pb
} else if (type == "work") {
phone_number->set_type(tutorial::Person::WORK); // pb
} else {
cout << "Unknown phone type. Using default." << endl;
}
}
}
// Main function: Reads the entire address book from a file,
// adds one person based on user input, then writes it back out to the same
// file.
int main(int argc, char* argv[]) {
// Verify that the version of the library that we linked against is
// compatible with the version of the headers we compiled against.
GOOGLE_PROTOBUF_VERIFY_VERSION; // pb
if (argc != 2) {
cerr << "Usage: " << argv[0] << " ADDRESS_BOOK_FILE" << endl;
return -1;
}
tutorial::AddressBook address_book; // pb
{
// Read the existing address book.
fstream input(argv[1], ios::in | ios::binary);
if (!input) {
cout << argv[1] << ": File not found. Creating a new file." << endl;
} else if (!address_book.ParseFromIstream(&input)) { // pb
cerr << "Failed to parse address book." << endl;
return -1;
}
}
// Add an address.
PromptForAddress(address_book.add_person()); // pb
{
// Write the new address book back to disk.
fstream output(argv[1], ios::out | ios::trunc | ios::binary);
if (!address_book.SerializeToOstream(&output)) { // pb
cerr << "Failed to write address book." << endl;
return -1;
}
}
// Optional: Delete all global objects allocated by libprotobuf.
google::protobuf::ShutdownProtobufLibrary(); // pb
return 0;
}
```
注意 `GOOGLE_PROTOBUF_VERIFY_VERSION` 宏。它是一种好的实践——虽然不是严格必须的——在使用 C++ Protocol Buffer 库之前执行该宏。它可以保证避免不小心链接到一个与编译的头文件版本不兼容的库版本。如果被检查出来版本不匹配,程序将会终止。注意,每个 `.pb.cc` 文件在初始化时会自动调用这个宏。
同时注意在程序最后调用 `ShutdownProtobufLibrary()`。它用于释放 Protocol Buffer 库申请的所有全局对象。对大部分程序,这不是必须的,因为虽然程序只是简单退出,但是 OS 会处理释放程序的所有内存。然而,如果你使用了内存泄漏检测工具,工具要求全部对象都要释放,或者你正在写一个 Protocol Buffer 库,该库可能会被一个进程多次加载和卸载,那么你可能需要强制 Protocol Buffer 清除所有东西。
### 读取消息
当然,如果你无法从它获取任何信息,那么这个地址簿没多大用处!这个示例读取上面例子创建的文件,并打印文件里的所有内容。
```
#include <iostream>
#include <fstream>
#include <string>
#include "addressbook.pb.h" // pb
using namespace std;
// Iterates though all people in the AddressBook and prints info about them.
void ListPeople(const tutorial::AddressBook& address_book) { // pb
for (int i = 0; i < address_book.person_size(); i++) { // pb
const tutorial::Person& person = address_book.person(i); // pb
cout << "Person ID: " << person.id() << endl; // pb
cout << " Name: " << person.name() << endl; // pb
if (person.has_email()) { // pb
cout << " E-mail address: " << person.email() << endl; // pb
}
for (int j = 0; j < person.phone_size(); j++) { // pb
const tutorial::Person::PhoneNumber& phone_number = person.phone(j); // pb
switch (phone_number.type()) { // pb
case tutorial::Person::MOBILE: // pb
cout << " Mobile phone #: ";
break;
case tutorial::Person::HOME: // pb
cout << " Home phone #: ";
break;
case tutorial::Person::WORK: // pb
cout << " Work phone #: ";
break;
}
cout << phone_number.number() << endl; // ob
}
}
}
// Main function: Reads the entire address book from a file and prints all
// the information inside.
int main(int argc, char* argv[]) {
// Verify that the version of the library that we linked against is
// compatible with the version of the headers we compiled against.
GOOGLE_PROTOBUF_VERIFY_VERSION; // pb
if (argc != 2) {
cerr << "Usage: " << argv[0] << " ADDRESS_BOOK_FILE" << endl;
return -1;
}
tutorial::AddressBook address_book; // pb
{
// Read the existing address book.
fstream input(argv[1], ios::in | ios::binary);
if (!address_book.ParseFromIstream(&input)) { // pb
cerr << "Failed to parse address book." << endl;
return -1;
}
}
ListPeople(address_book);
// Optional: Delete all global objects allocated by libprotobuf.
google::protobuf::ShutdownProtobufLibrary(); // pb
return 0;
}
```
### 扩展 Protocol Buffer
或早或晚在你发布了使用 protocol buffer 的代码之后,毫无疑问,你会想要 "改善" protocol buffer 的定义。如果你想要新的 buffers 向后兼容,并且老的 buffers 向前兼容——几乎可以肯定你很渴望这个——这里有一些规则,你需要遵守。在新的 protocol buffer 版本:
* 你绝不可以修改任何已存在字段的标签数字
* 你绝不可以添加或删除任何 `required` 字段
* 你可以删除 `optional` 或 `repeated` 字段
* 你可以添加新的 `optional` 或 `repeated` 字段,但是你必须使用新的标签数字(也就是说,标签数字在 protocol buffer 中从未使用过,甚至不能是已删除字段的标签数字)。
(对于上面规则有一些[例外情况](https://developers.google.com/protocol-buffers/docs/proto#updating),但它们很少用到。)
如果你能遵守这些规则,旧代码则可以欢快地读取新的消息,并且简单地忽略所有新的字段。对于旧代码来说,被删除的 `optional` 字段将会简单地赋予默认值,被删除的 `repeated` 字段会为空。新代码显然可以读取旧消息。然而,请记住新的 `optional` 字段不会呈现在旧消息中,因此你需要显式地使用 `has_` 检查它们是否被设置或者在 `.proto` 文件在标签数字后使用 `[default = value]` 提供一个合理的默认值。如果一个 `optional` 元素没有指定默认值,它将会使用类型特定的默认值:对于字符串,默认值为空字符串;对于布尔值,默认值为 false;对于数字类型,默认类型为 0。注意,如果你添加一个新的 `repeated` 字段,新代码将无法辨别它被留空(被新代码)或者从没被设置(被旧代码),因为 `repeated` 字段没有 `has_` 标志。
### 优化技巧
C++ Protocol Buffer 库已极度优化过了。但是,恰当的用法能够更多地提高性能。这里是一些技巧,可以帮你从库中挤压出最后一点速度:
* 尽可能复用消息对象。即使它们被清除掉,消息也会尽量保存所有被分配来重用的内存。因此,如果我们正在处理许多相同类型或一系列相似结构的消息,一个好的办法是重用相同的消息对象,从而减少内存分配的负担。但是,随着时间的流逝,对象可能会膨胀变大,尤其是当你的消息尺寸(LCTT 译注:各消息内容不同,有些消息内容多一些,有些消息内容少一些)不同的时候,或者你偶尔创建了一个比平常大很多的消息的时候。你应该自己通过调用 [SpaceUsed](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.message.html#Message.SpaceUsed.details) 方法监测消息对象的大小,并在它太大的时候删除它。
* 对于在多线程中分配大量小对象的情况,你的操作系统内存分配器可能优化得不够好。你可以尝试使用 google 的 [tcmalloc](http://code.google.com/p/google-perftools/)。
### 高级用法
Protocol Buffers 绝不仅用于简单的数据存取以及序列化。请阅读 [C++ API reference](https://developers.google.com/protocol-buffers/docs/reference/cpp/index.html) 来看看你还能用它来做什么。
protocol 消息类所提供的一个关键特性就是<ruby> 反射 <rp> ( </rp> <rt> reflection </rt> <rp> ) </rp></ruby>。你不需要针对一个特殊的消息类型编写代码,就可以遍历一个消息的字段并操作它们的值。一个使用反射的有用方法是 protocol 消息与其他编码互相转换,比如 XML 或 JSON。反射的一个更高级的用法可能就是可以找出两个相同类型的消息之间的区别,或者开发某种“协议消息的正则表达式”,利用正则表达式,你可以对某种消息内容进行匹配。只要你发挥你的想像力,就有可能将 Protocol Buffers 应用到一个更广泛的、你可能一开始就期望解决的问题范围上。
反射是由 [Message::Reflection interface](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.message.html#Message.Reflection) 提供的。
---
via: <https://developers.google.com/protocol-buffers/docs/cpptutorial>
作者:[Google](https://developers.google.com/protocol-buffers/docs/cpptutorial) 译者:[cposture](https://github.com/cposture) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,932 | 新手指南:通过 Docker 在 Linux 上托管 .NET Core | http://blog.scottlogic.com/2016/09/05/hosting-netcore-on-linux-with-docker.html | 2016-11-04T21:44:30 | [
"Docker",
".Net Core"
] | https://linux.cn/article-7932-1.html | 这篇文章基于我之前的文章 [.NET Core 入门](http://blog.scottlogic.com/2016/01/20/restful-api-with-aspnet50.html)。首先,我把 RESTful API 从 .NET Core RC1 升级到了 .NET Core 1.0,然后,我增加了对 Docker 的支持并描述了如何在 Linux 生产环境里托管它。
我是首次接触 Docker 并且距离成为一名 Linux 高手还有很远的一段路程。因此,这里的很多想法是来自一个新手。

### 安装
按照 <https://www.microsoft.com/net/core> 上的介绍在你的电脑上安装 .NET Core 。这将会同时在 Windows 上安装 dotnet 命令行工具以及最新的 Visual Studio 工具。
### 源代码
你可以直接到 [GitHub](https://github.com/niksoper/aspnet5-books/tree/blog-docker) 上找最到最新完整的源代码。
### 转换到 .NET CORE 1.0
自然地,当我考虑如何把 API 从 .NET Core RC1 升级到 .NET Core 1.0 时想到的第一个求助的地方就是谷歌搜索。我是按照下面这两条非常全面的指导来进行升级的:
* [从 DNX 迁移到 .NET Core CLI](https://docs.microsoft.com/en-us/dotnet/articles/core/migrating-from-dnx)
* [从 ASP.NET 5 RC1 迁移到 ASP.NET Core 1.0](https://docs.asp.net/en/latest/migration/rc1-to-rtm.html)
当你迁移代码的时候,我建议仔细阅读这两篇指导,因为我在没有阅读第一篇指导的情况下又尝试浏览第二篇,结果感到非常迷惑和沮丧。
我不想描述细节上的改变因为你可以看 GitHub 上的[提交](https://github.com/niksoper/aspnet5-books/commit/b41ad38794c69a70a572be3ffad051fd2d7c53c0)。这儿是我所作改变的总结:
* 更新 `global.json` 和 `project.json` 上的版本号
* 删除 `project.json` 上的废弃章节
* 使用轻型 `ControllerBase` 而不是 `Controller`, 因为我不需要与 MVC 视图相关的方法(这是一个可选的改变)。
* 从辅助方法中去掉 `Http` 前缀,比如:`HttpNotFound` -> `NotFound`
* `LogVerbose` -> `LogTrace`
* 名字空间改变: `Microsoft.AspNetCore.*`
* 在 `Startup` 中使用 `SetBasePath`(没有它 `appsettings.json` 将不会被发现)
* 通过 `WebHostBuilder` 来运行而不是通过 `WebApplication.Run` 来运行
* 删除 Serilog(在写文章的时候,它不支持 .NET Core 1.0)
唯一令我真正头疼的事是需要移动 Serilog。我本可以实现自己的文件记录器,但是我删除了文件记录功能,因为我不想为了这次操作在这件事情上花费精力。
不幸的是,将有大量的第三方开发者扮演追赶 .NET Core 1.0 的角色,我非常同情他们,因为他们通常在休息时间还坚持工作但却依旧根本无法接近靠拢微软的可用资源。我建议阅读 Travis Illig 的文章 [.NET Core 1.0 发布了,但 Autofac 在哪儿](http://www.paraesthesia.com/archive/2016/06/29/netcore-rtm-where-is-autofac/)?这是一篇关于第三方开发者观点的文章。
做了这些改变以后,我可以从 `project.json` 目录恢复、构建并运行 dotnet,可以看到 API 又像以前一样工作了。
### 通过 Docker 运行
在我写这篇文章的时候, Docker 只能够在 Linux 系统上工作。在 [Windows](https://docs.docker.com/engine/installation/windows/#/docker-for-windows) 系统和 [OS X](https://docs.docker.com/engine/installation/mac/) 上有 beta 支持 Docker,但是它们都必须依赖于虚拟化技术,因此,我选择把 Ubuntu 14.04 当作虚拟机来运行。如果你还没有安装过 Docker,请按照[指导](https://docs.docker.com/engine/installation/linux/ubuntulinux/)来安装。
我最近阅读了一些关于 Docker 的东西,但我直到现在还没有真正用它来干任何事。我假设读者还没有关于 Docker 的知识,因此我会解释我所使用的所有命令。
#### HELLO DOCKER
在 Ubuntu 上安装好 Docker 之后,我所进行的下一步就是按照 <https://www.microsoft.com/net/core#docker> 上的介绍来开始运行 .NET Core 和 Docker。
首先启动一个已安装有 .NET Core 的容器。
```
docker run -it microsoft/dotnet:latest
```
`-it` 选项表示交互,所以你执行这条命令之后,你就处于容器之内了,可以如你所希望的那样执行任何 bash 命令。
然后我们可以执行下面这五条命令来在 Docker 内部运行起来微软 .NET Core 控制台应用程序示例。
```
mkdir hwapp
cd hwapp
dotnet new
dotnet restore
dotnet run
```
你可以通过运行 `exit` 来离开容器,然后运行 `Docker ps -a` 命令,这会显示你创建的那个已经退出的容器。你可以通过上运行命令 `Docker rm <container_name>` 来清除容器。
#### 挂载源代码
我的下一步骤是使用和上面相同的 `microsoft/dotnet` 镜像,但是将为我们的应用程序以[数据卷](https://docs.docker.com/engine/tutorials/dockervolumes/1)的方式挂载上源代码。
首先签出有相关提交的仓库:
```
git clone https://github.com/niksoper/aspnet5-books.git
cd aspnet5-books/src/MvcLibrary
git checkout dotnet-core-1.0
```
现在启动一个容器来运行 .NET Core 1.0,并将源代码放在 `/book` 下。注意更改 `/path/to/repo` 这部分文件来匹配你的电脑:
```
docker run -it \
-v /path/to/repo/aspnet5-books/src/MvcLibrary:/books \
microsoft/dotnet:latest
```
现在你可以在容器中运行应用程序了!
```
cd /books
dotnet restore
dotnet run
```
作为一个概念性展示这的确很棒,但是我们可不想每次运行一个程序都要考虑如何把源代码安装到容器里。
#### 增加一个 DOCKERFILE
我的下一步骤是引入一个 Dockerfile,这可以让应用程序很容易在自己的容器内启动。
我的 Dockerfile 和 `project.json` 一样位于 `src/MvcLibrary` 目录下,看起来像下面这样:
```
FROM microsoft/dotnet:latest
# 为应用程序源代码创建目录
RUN mkdir -p /usr/src/books
WORKDIR /usr/src/books
# 复制源代码并恢复依赖关系
COPY . /usr/src/books
RUN dotnet restore
# 暴露端口并运行应用程序
EXPOSE 5000
CMD [ "dotnet", "run" ]
```
严格来说,`RUN mkdir -p /usr/src/books` 命令是不需要的,因为 `COPY` 会自动创建丢失的目录。
Docker 镜像是按层建立的,我们从包含 .NET Core 的镜像开始,添加另一个从源代码生成应用程序,然后运行这个应用程序的层。
添加了 Dockerfile 以后,我通过运行下面的命令来生成一个镜像,并使用生成的镜像启动一个容器(确保在和 Dockerfile 相同的目录下进行操作,并且你应该使用自己的用户名)。
```
docker build -t niksoper/netcore-books .
docker run -it niksoper/netcore-books
```
你应该看到程序能够和之前一样的运行,不过这一次我们不需要像之前那样安装源代码,因为源代码已经包含在 docker 镜像里面了。
#### 暴露并发布端口
这个 API 并不是特别有用,除非我们需要从容器外面和它进行通信。 Docker 已经有了暴露和发布端口的概念,但这是两件完全不同的事。
据 Docker [官方文档](https://docs.docker.com/engine/reference/builder/#/expose):
>
> `EXPOSE` 指令通知 Docker 容器在运行时监听特定的网络端口。`EXPOSE` 指令不能够让容器的端口可被主机访问。要使可被访问,你必须通过 `-p` 标志来发布一个端口范围或者使用 `-P` 标志来发布所有暴露的端口
>
>
>
`EXPOSE` 指令只是将元数据添加到镜像上,所以你可以如文档中说的认为它是镜像消费者。从技术上讲,我本应该忽略 `EXPOSE 5000` 这行指令,因为我知道 API 正在监听的端口,但把它们留下很有用的,并且值得推荐。
在这个阶段,我想直接从主机访问这个 API ,因此我需要通过 `-p` 指令来发布这个端口,这将允许请求从主机上的端口 5000 转发到容器上的端口 5000,无论这个端口是不是之前通过 Dockerfile 暴露的。
```
docker run -d -p 5000:5000 niksoper/netcore-books
```
通过 `-d` 指令告诉 docker 在分离模式下运行容器,因此我们不能看到它的输出,但是它依旧会运行并监听端口 5000。你可以通过 `docker ps` 来证实这件事。
因此,接下来我准备从主机向容器发起一个请求来庆祝一下:
```
curl http://localhost:5000/api/books
```
它不工作。
重复进行相同 `curl` 请求,我看到了两个错误:要么是 `curl: (56) Recv failure: Connection reset by peer`,要么是 `curl: (52) Empty reply from server`。
我返回去看 docker run 的[文档](https://docs.docker.com/engine/reference/run/#/expose-incoming-ports),然后再次检查我所使用的 `-p` 选项以及 Dockerfile 中的 `EXPOSE` 指令是否正确。我没有发现任何问题,这让我开始有些沮丧。
重新振作起来以后,我决定去咨询当地的一个 Scott Logic DevOps 大师 - Dave Wybourn(也在[这篇 Docker Swarm 的文章](http://blog.scottlogic.com/2016/08/30/docker-1-12-swarm-mode-round-robin.html)里提到过),他的团队也曾遇到这个实际问题。这个问题是我没有配置过 [Kestral](https://docs.asp.net/en/latest/fundamentals/servers.html#kestrel),这是一个全新的轻量级、跨平台 web 服务器,用于 .NET Core 。
默认情况下, Kestrel 会监听 `http://localhost:5000`。但问题是,这儿的 `localhost` 是一个回路接口。
据[维基百科](https://en.wikipedia.org/wiki/Localhost):
>
> 在计算机网络中,localhost 是一个代表本机的主机名。本地主机可以通过网络回路接口访问在主机上运行的网络服务。通过使用回路接口可以绕过任何硬件网络接口。
>
>
>
当运行在容器内时这是一个问题,因为 `localhost` 只能够在容器内访问。解决方法是更新 `Startup.cs` 里的 `Main` 方法来配置 Kestral 监听的 URL:
```
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseUrls("http://*:5000") // 在所有网络接口上监听端口 5000
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
```
通过这些额外的配置,我可以重建镜像,并在容器中运行应用程序,它将能够接收来自主机的请求:
```
docker build -t niksoper/netcore-books .
docker run -d -p 5000:5000 niksoper/netcore-books
curl -i http://localhost:5000/api/books
```
我现在得到下面这些相应:
```
HTTP/1.1 200 OK
Date: Tue, 30 Aug 2016 15:25:43 GMT
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
Server: Kestrel
[{"id":"1","title":"RESTful API with ASP.NET Core MVC 1.0","author":"Nick Soper"}]
```
### 在产品环境中运行 KESTREL
[微软的介绍](https://docs.asp.net/en/latest/publishing/linuxproduction.html#why-use-a-reverse-proxy-server):
>
> Kestrel 可以很好的处理来自 ASP.NET 的动态内容,然而,网络服务部分的特性没有如 IIS,Apache 或者 Nginx 那样的全特性服务器那么好。反向代理服务器可以让你不用去做像处理静态内容、缓存请求、压缩请求、SSL 端点这样的来自 HTTP 服务器的工作。
>
>
>
因此我需要在我的 Linux 机器上把 Nginx 设置成一个反向代理服务器。微软介绍了如何[发布到 Linux 生产环境下](https://docs.asp.net/en/latest/publishing/linuxproduction.html)的指导教程。我把说明总结在这儿:
1. 通过 `dotnet publish` 来给应用程序产生一个自包含包。
2. 把已发布的应用程序复制到服务器上
3. 安装并配置 Nginx(作为反向代理服务器)
4. 安装并配置 [supervisor](http://supervisord.org/)(用于确保 Nginx 服务器处于运行状态中)
5. 安装并配置 [AppArmor](https://wiki.ubuntu.com/AppArmor)(用于限制应用的资源使用)
6. 配置服务器防火墙
7. 安全加固 Nginx(从源代码构建和配置 SSL)
这些内容已经超出了本文的范围,因此我将侧重于如何把 Nginx 配置成一个反向代理服务器。自然地,我通过 Docker 来完成这件事。
### 在另一个容器中运行 NGINX
我的目标是在第二个 Docker 容器中运行 Nginx 并把它配置成我们的应用程序容器的反向代理服务器。
我使用的是[来自 Docker Hub 的官方 Nginx 镜像](https://hub.docker.com/_/nginx/)。首先我尝试这样做:
```
docker run -d -p 8080:80 --name web nginx
```
这启动了一个运行 Nginx 的容器并把主机上的 8080 端口映射到了容器的 80 端口上。现在在浏览器中打开网址 `http://localhost:8080` 会显示出 Nginx 的默认登录页面。
现在我们证实了运行 Nginx 是多么的简单,我们可以关闭这个容器。
```
docker rm -f web
```
### 把 NGINX 配置成一个反向代理服务器
可以通过像下面这样编辑位于 `/etc/nginx/conf.d/default.conf` 的配置文件,把 Nginx 配置成一个反向代理服务器:
```
server {
listen 80;
location / {
proxy_pass http://localhost:6666;
}
}
```
通过上面的配置可以让 Nginx 将所有对根目录的访问请求代理到 `http://localhost:6666`。记住这里的 `localhost` 指的是运行 Nginx 的容器。我们可以在 Nginx容器内部利用卷来使用我们自己的配置文件:
```
docker run -d -p 8080:80 \
-v /path/to/my.conf:/etc/nginx/conf.d/default.conf \
nginx
```
注意:这把一个单一文件从主机映射到容器中,而不是一个完整目录。
### 在容器间进行通信
Docker 允许内部容器通过共享虚拟网络进行通信。默认情况下,所有通过 Docker 守护进程启动的容器都可以访问一种叫做“桥”的虚拟网络。这使得一个容器可以被另一个容器在相同的网络上通过 IP 地址和端口来引用。
你可以通过<ruby> 监测 <rp> ( </rp> <rt> inspect </rt> <rp> ) </rp></ruby>容器来找到它的 IP 地址。我将从之前创建的 `niksoper/netcore-books` 镜像中启动一个容器并<ruby> 监测 <rp> ( </rp> <rt> inspect </rt> <rp> ) </rp></ruby>它:
```
docker run -d -p 5000:5000 --name books niksoper/netcore-books
docker inspect books
```

我们可以看到这个容器的 IP 地址是 `"IPAddress": "172.17.0.3"`。
所以现在如果我创建下面的 Nginx 配置文件,并使用这个文件启动一个 Nginx 容器, 它将代理请求到我的 API :
```
server {
listen 80;
location / {
proxy_pass http://172.17.0.3:5000;
}
}
```
现在我可以使用这个配置文件启动一个 Nginx 容器(注意我把主机上的 8080 端口映射到了 Nginx 容器上的 80 端口):
```
docker run -d -p 8080:80 \
-v ~/dev/nginx/my.nginx.conf:/etc/nginx/conf.d/default.conf \
nginx
```
一个到 `http://localhost:8080` 的请求将被代理到应用上。注意下面 `curl` 响应的 `Server` 响应头:

### DOCKER COMPOSE
在这个地方,我为自己的进步而感到高兴,但我认为一定还有更好的方法来配置 Nginx,可以不需要知道应用程序容器的确切 IP 地址。另一个当地的 Scott Logic DevOps 大师 Jason Ebbin 在这个地方进行了改进,并建议使用 [Docker Compose](https://docs.docker.com/compose/)。
概况描述一下,Docker Compose 使得一组通过声明式语法互相连接的容器很容易启动。我不想再细说 Docker Compose 是如何工作的,因为你可以在[之前的文章](http://blog.scottlogic.com/2016/01/25/playing-with-docker-compose-and-erlang.html)中找到。
我将通过一个我所使用的 `docker-compose.yml` 文件来启动:
```
version: '2'
services:
books-service:
container_name: books-api
build: .
reverse-proxy:
container_name: reverse-proxy
image: nginx
ports:
- "9090:8080"
volumes:
- ./proxy.conf:/etc/nginx/conf.d/default.conf
```
*这是版本 2 语法,所以为了能够正常工作,你至少需要 1.6 版本的 Docker Compose。*
这个文件告诉 Docker 创建两个服务:一个是给应用的,另一个是给 Nginx 反向代理服务器的。
### BOOKS-SERVICE
这个与 `docker-compose.yml` 相同目录下的 Dockerfile 构建的容器叫做 `books-api`。注意这个容器不需要发布任何端口,因为只要能够从反向代理服务器访问它就可以,而不需要从主机操作系统访问它。
### REVERSE-PROXY
这将基于 nginx 镜像启动一个叫做 `reverse-proxy` 的容器,并将位于当前目录下的 `proxy.conf` 文件挂载为配置。它把主机上的 9090 端口映射到容器中的 8080 端口,这将允许我们在 `http://localhost:9090` 上通过主机访问容器。
`proxy.conf` 文件看起来像下面这样:
```
server {
listen 8080;
location / {
proxy_pass http://books-service:5000;
}
}
```
这儿的关键点是我们现在可以通过名字引用 `books-service`,因此我们不需要知道 `books-api` 这个容器的 IP 地址!
现在我们可以通过一个运行着的反向代理启动两个容器(`-d` 意味着这是独立的,因此我们不能看到来自容器的输出):
```
docker compose up -d
```
验证我们所创建的容器:
```
docker ps
```
最后来验证我们可以通过反向代理来控制该 API :
```
curl -i http://localhost:9090/api/books
```
### 怎么做到的?
Docker Compose 通过创建一个新的叫做 `mvclibrary_default` 的虚拟网络来实现这件事,这个虚拟网络同时用于 `books-api` 和 `reverse-proxy` 容器(名字是基于 `docker-compose.yml` 文件的父目录)。
通过 `docker network ls` 来验证网络已经存在:

你可以使用 `docker network inspect mvclibrary_default` 来看到新的网络的细节:

注意 Docker 已经给网络分配了子网:`"Subnet": "172.18.0.0/16"`。`/16` 部分是无类域内路由选择(CIDR),完整的解释已经超出了本文的范围,但 CIDR 只是表示 IP 地址范围。运行 `docker network inspect bridge` 显示子网:`"Subnet": "172.17.0.0/16"`,因此这两个网络是不重叠的。
现在用 `docker inspect books-api` 来确认应用程序的容器正在使用该网络:

注意容器的两个别名(`"Aliases"`)是容器标识符(`3c42db680459`)和由 `docker-compose.yml` 给出的服务名(`books-service`)。我们通过 `books-service` 别名在自定义 Nginx 配置文件中来引用应用程序的容器。这本可以通过 `docker network create` 手动创建,但是我喜欢用 Docker Compose,因为它可以干净简洁地将容器创建和依存捆绑在一起。
### 结论
所以现在我可以通过几个简单的步骤在 Linux 系统上用 Nginx 运行应用程序,不需要对主机操作系统做任何长期的改变:
```
git clone https://github.com/niksoper/aspnet5-books.git
cd aspnet5-books/src/MvcLibrary
git checkout blog-docker
docker-compose up -d
curl -i http://localhost:9090/api/books
```
我知道我在这篇文章中所写的内容不是一个真正的生产环境就绪的设备,因为我没有写任何有关下面这些的内容,绝大多数下面的这些主题都需要用单独一篇完整的文章来叙述。
* 安全考虑比如防火墙和 SSL 配置
* 如何确保应用程序保持运行状态
* 如何选择需要包含的 Docker 镜像(我把所有的都放入了 Dockerfile 中)
* 数据库 - 如何在容器中管理它们
对我来说这是一个非常有趣的学习经历,因为有一段时间我对探索 ASP.NET Core 的跨平台支持非常好奇,使用 “Configuratin as Code” 的 Docker Compose 方法来探索一下 DevOps 的世界也是非常愉快并且很有教育意义的。
如果你对 Docker 很好奇,那么我鼓励你来尝试学习它 或许这会让你离开舒适区,不过,有可能你会喜欢它?
---
via: <http://blog.scottlogic.com/2016/09/05/hosting-netcore-on-linux-with-docker.html>
作者:[Nick Soper](http://blog.scottlogic.com/nsoper) 译者:[ucasFL](https://github.com/ucasFL) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,935 | 怎样在 RHEL、CentOS 和 Fedora 上安装 Git 及设置 Git 账号 | http://www.tecmint.com/install-git-centos-fedora-redhat/ | 2016-11-06T17:54:00 | [
"Git"
] | https://linux.cn/article-7935-1.html | 对于新手来说,Git 是一个自由、开源、高效的分布式版本控制系统(VCS),它是基于速度、高性能以及数据一致性而设计的,以支持从小规模到大体量的软件开发项目。
Git 是一个可以让你追踪软件改动、版本回滚以及创建另外一个版本的目录和文件的软件仓库。

Git 主要是用 C 语言来写的,混杂了少量的 Perl 脚本和各种 shell 脚本。它主要在 Linux 内核上运行,并且有以下列举的卓越的性能:
* 易于上手
* 运行速度飞快,且大部分操作在本地进行,因此,它极大的提升了那些需要与远程服务器通信的集中式系统的速度。
* 高效
* 提供数据一致性检查
* 支持低开销的本地分支
* 提供非常便利的暂存区
* 可以集成其它工具来支持多种工作流
在这篇操作指南中,我们将介绍在 CentOS/RHEL 7/6 和 Fedora 20-24 Linux 发行版上安装 Git 的必要步骤以及怎么配置 Git,以便于你可以快速开始工作。
### 使用 Yum 安装 Git
我们将从系统默认的仓库安装 Git,并通过运行以下 [YUM 包管理器](/article-2272-1.html) 的更新命令来确保你系统的软件包都是最新的:
```
# yum update
```
接着,通过以下命令来安装 Git:
```
# yum install git
```
在 Git 成功安装之后,你可以通过以下命令来显示 Git 安装的版本:
```
# git --version
```

*检查 Git 安装的版本*
注意:从系统默认仓库安装的 Git 会是比较旧的版本。如果你想拥有最新版的 Git,请考虑使用以下说明来编译源代码进行安装。
### 从源代码安装 Git
开始之前,你首先需要从系统默认仓库安装所需的软件依赖包,以及从源代码构建二进制文件所需的实用工具:
```
# yum groupinstall "Development Tools"
# yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel
```
安装所需的软件依赖包之后,转到官方的 [Git 发布页面](https://github.com/git/git/releases),抓取最新版的 Git 并使用下列命令编译它的源代码:
```
# wget https://github.com/git/git/archive/v2.10.1.tar.gz -O git.tar.gz
# tar -zxf git.tar.gz
# cd git-2.10.1/
# make configure
# ./configure --prefix=/usr/local
# make install
# git --version
```

*检查 Git 的安装版本*
**推荐阅读:** [Linux 下 11 个最好用的 Git 客户端和 Git 仓库查看器](http://www.tecmint.com/best-gui-git-clients-git-repository-viewers-for-linux/)。
### 在 Linux 设置 Git 账户
在这个环节中,我们将介绍如何使用正确的用户信息(如:姓名、邮件地址)和 `git config` 命令来设置 Git 账户,以避免出现提交错误。
注意:确保将下面的 `username` 替换为在你的系统上创建和使用的 Git 用户的真实名称。
你可以使用下面的 [useradd 命令](http://www.tecmint.com/add-users-in-linux/) 创建一个 Git 用户,其中 `-m` 选项用于在 `/home` 目录下创建用户主目录,`-s` 选项用于指定用户默认的 shell。
```
# useradd -m -s /bin/bash username
# passwd username
```
现在,将新用户添加到 `wheel` 用户组以启用其使用 `sudo` 命令的权限:
```
# usermod username -aG wheel
```

*创建 Git 用户账号*
然后通过以下命令使用新用户配置 Git:
```
# su username
$ sudo git config --global user.name "Your Name"
$ sudo git config --global user.email "[email protected]"
```
现在通过下面的命令校验 Git 的配置。
```
$ sudo git config --list
```
如果配置没有错误的话,你应该能够看到类似以下详细信息的输出:
```
user.name=username
user.email= [email protected]
```

*在 Linux 设置 Git 用户*
### 总结
在这个简单的教程中,我们已经了解怎么在你的 Linux 系统上安装 Git 以及配置它。我相信你应该可以驾轻就熟。
---
via: <http://www.tecmint.com/install-git-centos-fedora-redhat/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[OneNewLife](https://github.com/OneNewLife) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,936 | 使用命令行生成高强度密码 | https://www.rosehosting.com/blog/generate-password-linux-command-line/ | 2016-11-07T12:14:43 | [
"密码"
] | https://linux.cn/article-7936-1.html | 
设置一个高强度的密码是非常重要的,这样才能够很好的保护自己的账号或者服务器以及确保自己的数据的安全。通常来说,一个高强度密码至少有 14 个字符,包括大小写字母、数字和特殊字符,并且要牢记永远不用那些字典中的单词。使用长密码比短密码要来的安全,因为密码越长越难猜测。在本文中,我将给你介绍几个不同方法,让你可以在 Linux 命令行下生成一个高强度密码。
### 使用 openssl 生成高强度密码
这里使用 openssl 的 rand 方法,它会生成一个 14 位字符的随机字符:
```
openssl rand -base64 14
```
### 使用 urandom 生成高强度密码
这里我们将使用 `tr` 条件来过滤 `/dev/urandom` 的输出,从而删掉那些不想要的字符,并打印出第一个出现的 14 位字符。
```
< /dev/urandom tr -dc A-Za-z0-9 | head -c14; echo
```
### 使用 pwgen 生成高强度密码
`pwgen` 是一个生成随机、无特殊含义但可以正常拼读的密码。
安装 `pwgen`,运行:
```
sudo apt-get install pwgen
```
安装好之后,使用以下命令来生成一个 14 位随机字符:
```
pwgen 14 1
```
你也可以使用以下标记:
* -c 或 --capitalize 生成的密码中至少包含一个大写字母
* -A 或 --no-capitalize 生成的密码中不含大写字母
* -n 或 --numerals 生成的密码中至少包含一个数字
* -0 或 --no-numerals 生成的密码中不含数字
* -y 或 --symbols 生成的密码中至少包含一个特殊字符
* -s 或 --secure 生成一个完全随机的密码
* -B 或 --ambiguous 生成的密码中不含<ruby> 易混淆字符 <rp> ( </rp> <rt> ambiguous characters </rt> <rp> ) </rp></ruby>
* -h 或 --help 输出帮助信息
* -H 或 --sha1=path/to/file[#seed] 使用指定文件的 sha1 哈希值作为随机生成器
* -C 按列输出生成的密码
* -1 不按列输出生成的密码
* -v 或 --no-vowels 不使用任何元音,以免意外生成让人讨厌的单词
### 使用 gpg 生成高强度密码
我们也可以使用 `gpg` 工具来生成一个 14 位字符的密码:
```
gpg --gen-random --armor 1 14
```
### 其它方法
当然,可能还有很多方法可以生成一个高强度密码。比方说,你可以添加以下 bash shell 方法到 `~/.bashrc` 文件:
```
genpasswd() {
strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 14 | tr -d '\n'; echo
}
```
当你想要生成一个高强度的随机密码时,运行 `genpasswd` 就好了。
---
via: <https://www.rosehosting.com/blog/generate-password-linux-command-line/>
作者:[RoseHosting](www.rosehosting.com) 译者:[GHLandy](https://github.com/GHLandy) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | We’ll show you, How to generate a strong password from the command line in Linux. Having a strong password in Linux, is the most important thing you can do to protect your account or server and to keep your data secure. Common thinking is that a strong password should be comprised of at least 14 characters, including lowercase and uppercase alphabetic characters, numbers and symbols and should never be based on a dictionary word. Using a long password is much more secure that using a short one, the longer the password the harder it is to guess. In this post, we will take a look at a several different ways to generate a strong password using the Linux command line.
Table of Contents
## 1. Generate a strong password with openssl
This method uses the openssl rand function and it will generate 14 characters random string:
openssl rand -base64 14
## 2. Generate a strong password with urandom
In this method we will filter the `/dev/urandom`
output with `tr`
to delete unwanted characters and print the first 14 characters:
< /dev/urandom tr -dc A-Za-z0-9 | head -c14; echo
## 3. Generate a strong password with pwgen
`pwgen`
is a tool that generates random, meaningless but pronounceable passwords.
To install `pwgen`
run:
sudo apt-get install pwgen
Once the installation is complete, use the following command to generate a random string of 14 characters:
pwgen 14 1
You can also use some of the following flags:
-c or --capitalize Include at least one capital letter in the password -A or --no-capitalize Don't include capital letters in the password -n or --numerals Include at least one number in the password -0 or --no-numerals Don't include numbers in the password -y or --symbols Include at least one special symbol in the password -s or --secure Generate completely random passwords -B or --ambiguous Don't include ambiguous characters in the password -h or --help Print a help message -H or --sha1=path/to/file[#seed] Use sha1 hash of given file as a (not so) random generator -C Print the generated passwords in columns -1 Don't print the generated passwords in columns -v or --no-vowels Do not use any vowels so as to avoid accidental nasty words
## 4. Generate a strong password with gpg
We can also use the `gpg`
tool to generate a strong 14 characters password:
gpg --gen-random --armor 1 14
Of course, there are many other ways to generate a strong password. For example, you can add the following bash shell function to your `~/.bashrc`
file:
genpasswd() { strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 14 | tr -d '\n'; echo }
and when you need to generate a strong random password just type `genpasswd`
If you have any questions regarding the process of generating a strong password from the command line, feel free to comment below or sign up for [our hosting services](https://www.rosehosting.com/hosting-services.html) and contact our [EPIC Support Team](https://www.rosehosting.com/support.html). They are available 24/7 and they will take care of your request immediately. You can always asks our support team to generate a random and strong password from the command line in Linux, for your.
**PS**. If you liked this post on how to generate a random password from the command line in Linux, please share it with your friends on the social networks using the sharing buttons or simply leave a reply below. Thanks.
Hi there,
just to share the information, i noticed that the solution 4 based on “gpg –gen-random –armor 1 14” often gives passwords ending by “=”.
So i would’nt say it’s “fully random”. But anyway, it’s better than nothing or a fully manual process.
Best Regards
Reply |
7,937 | 怎样在 CentOS 里下载 RPM 包及其所有依赖包 | https://www.ostechnix.com/download-rpm-package-dependencies-centos/ | 2016-11-07T17:25:00 | [
"RPM",
"软件包"
] | https://linux.cn/article-7937-1.html | 
前几天我尝试去创建一个仅包含我们经常在 CentOS 7 下使用的软件的本地仓库。当然,我们可以使用 curl 或者 wget 下载任何软件包,然而这些命令并不能下载要求的依赖软件包。你必须去花一些时间而且手动的去寻找和下载被安装的软件所依赖的软件包。然而,我们并不是必须这样。在这个简短的教程中,我将会带领你以两种方式下载软件包及其所有依赖包。我已经在 CentOS 7 下进行了测试,不过这些相同的步骤或许在其他基于 RPM 管理系统的发行版上也可以工作,例如 RHEL,Fedora 和 Scientific Linux。
### 方法 1 利用 “Downloadonly” 插件下载 RPM 软件包及其所有依赖包
我们可以通过 yum 命令的 “Downloadonly” 插件下载 RPM 软件包及其所有依赖包。
为了安装 Downloadonly 插件,以 root 身份运行以下命令。
```
yum install yum-plugin-downloadonly
```
现在,运行以下命令去下载一个 RPM 软件包。
```
yum install --downloadonly <package-name>
```
默认情况下,这个命令将会下载并把软件包保存到 `/var/cache/yum/` 的 `rhel-{arch}-channel/packageslocation` 目录,不过,你也可以下载和保存软件包到任何位置,你可以通过 `–downloaddir` 选项来指定。
```
yum install --downloadonly --downloaddir=<directory> <package-name>
```
例子:
```
yum install --downloadonly --downloaddir=/root/mypackages/ httpd
```
终端输出:
```
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.excellmedia.net
* epel: epel.mirror.angkasa.id
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-40.el7.centos.4 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-40.el7.centos.4 for package: httpd-2.4.6-40.el7.centos.4.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-40.el7.centos.4.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.4.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.4.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-40.el7.centos.4 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================================
Installing:
httpd x86_64 2.4.6-40.el7.centos.4 updates 2.7 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7 base 103 k
apr-util x86_64 1.5.2-6.el7 base 92 k
httpd-tools x86_64 2.4.6-40.el7.centos.4 updates 83 k
mailcap noarch 2.1.41-2.el7 base 31 k
Transaction Summary
=======================================================================================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 3.0 M
Installed size: 10 M
Background downloading packages, then exiting:
(1/5): apr-1.4.8-3.el7.x86_64.rpm | 103 kB 00:00:01
(2/5): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:01
(3/5): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:01
(4/5): httpd-tools-2.4.6-40.el7.centos.4.x86_64.rpm | 83 kB 00:00:01
(5/5): httpd-2.4.6-40.el7.centos.4.x86_64.rpm | 2.7 MB 00:00:09
---------------------------------------------------------------------------------------------------------------------------------------
Total 331 kB/s | 3.0 MB 00:00:09
exiting because "Download Only" specified
```

现在去你指定的目录位置下,你将会看到那里有下载好的软件包和依赖的软件。在我这种情况下,我已经把软件包下载到 `/root/mypackages/` 目录下。
让我们来查看一下内容。
```
ls /root/mypackages/
```
样本输出:
```
apr-1.4.8-3.el7.x86_64.rpm
apr-util-1.5.2-6.el7.x86_64.rpm
httpd-2.4.6-40.el7.centos.4.x86_64.rpm
httpd-tools-2.4.6-40.el7.centos.4.x86_64.rpm
mailcap-2.1.41-2.el7.noarch.rpm
```

正如你在上面输出所看到的, httpd软件包已经被依据所有依赖性下载完成了 。
请注意,这个插件适用于 `yum install/yum update`, 但是并不适用于 `yum groupinstall`。默认情况下,这个插件将会下载仓库中最新可用的软件包。然而你可以通过指定版本号来下载某个特定的软件版本。
例子:
```
yum install --downloadonly --downloaddir=/root/mypackages/ httpd-2.2.6-40.el7
```
此外,你也可以如下一次性下载多个包:
```
yum install --downloadonly --downloaddir=/root/mypackages/ httpd vsftpd
```
### 方法 2 使用 “Yumdownloader” 工具来下载 RPM 软件包及其所有依赖包
“Yumdownloader” 是一款简单,但是却十分有用的命令行工具,它可以一次性下载任何 RPM 软件包及其所有依赖包。
以 root 身份运行如下命令安装 “Yumdownloader” 工具。
```
yum install yum-utils
```
一旦安装完成,运行如下命令去下载一个软件包,例如 httpd。
```
yumdownloader httpd
```
为了根据所有依赖性下载软件包,我们使用 `--resolve` 参数:
```
yumdownloader --resolve httpd
```
默认情况下,Yumdownloader 将会下载软件包到当前工作目录下。
为了将软件下载到一个特定的目录下,我们使用 `--destdir` 参数:
```
yumdownloader --resolve --destdir=/root/mypackages/ httpd
```
或者,
```
yumdownloader --resolve --destdir /root/mypackages/ httpd
```
终端输出:
```
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.excellmedia.net
* epel: epel.mirror.angkasa.id
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-40.el7.centos.4 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-40.el7.centos.4 for package: httpd-2.4.6-40.el7.centos.4.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-40.el7.centos.4.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.4.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.4.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-40.el7.centos.4 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
(1/5): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:01
(2/5): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:02
(3/5): apr-1.4.8-3.el7.x86_64.rpm | 103 kB 00:00:02
(4/5): httpd-tools-2.4.6-40.el7.centos.4.x86_64.rpm | 83 kB 00:00:03
(5/5): httpd-2.4.6-40.el7.centos.4.x86_64.rpm | 2.7 MB 00:00:19
```

让我们确认一下软件包是否被下载到我们指定的目录下。
```
ls /root/mypackages/
```
终端输出:
```
apr-1.4.8-3.el7.x86_64.rpm
apr-util-1.5.2-6.el7.x86_64.rpm
httpd-2.4.6-40.el7.centos.4.x86_64.rpm
httpd-tools-2.4.6-40.el7.centos.4.x86_64.rpm
mailcap-2.1.41-2.el7.noarch.rpm
```

不像 Downloadonly 插件,Yumdownload 可以下载一组相关的软件包。
```
yumdownloader "@Development Tools" --resolve --destdir /root/mypackages/
```
在我看来,我喜欢 Yumdownloader 更胜于 Yum 的 Downloadonly 插件。但是,两者都是十分简单易懂而且可以完成相同的工作。
这就是今天所有的内容,如果你觉得这份引导教程有用,清在你的社交媒体上面分享一下去让更多的人知道。
干杯!
---
via: <https://www.ostechnix.com/download-rpm-package-dependencies-centos/>
作者:[SK](http://ostechnix.tradepub.com/free/w_make272/prgm.cgi?a=1) 译者:[LinuxBars](https://github.com/LinuxBars) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 403 | Forbidden | null |
7,938 | Wire:一个极酷、专注于个人隐私的开源聊天应用程序已经来到了 Linux 上 | https://itsfoss.com/wire-messaging-linux/ | 2016-11-08T10:16:49 | [
"Wire"
] | https://linux.cn/article-7938-1.html | 
回到大约两年前,一些曾开发 [Skype](https://www.skype.com/en/) 的开发人员发行了一个漂亮的新聊天应用个程序:[Wire](https://wire.com/)。当我说它漂亮的时候,只是谈论它的“外貌”。Wire 具有一个许多其他聊天应用程序所没有的整洁优美的“外貌”,但这并不是它最大的卖点。
从一开始,Wire 就推销自己是[世界上最注重隐私的聊天应用程序](http://www.ibtimes.co.uk/wire-worlds-most-private-messaging-app-offers-total-encryption-calls-texts-1548964)。无论是文本、语音电话,还是图表、图像等基本的内容,它都提供端到端的加密。
WhatsApp 也提供‘端到端加密’,但是考虑一下它的所有者 [Facebook 为了吸引用户而把 WhatsApp 的数据分享出去](https://techcrunch.com/2016/08/25/whatsapp-to-share-user-data-with-facebook-for-ad-targeting-heres-how-to-opt-out/)。我不太相信 WhatsApp 以及它的加密手段。
使 Wire 对于我们这些 FOSS(自由/开源软件)爱好者来说更加重要的是,几个月前 [Wire 开源了](http://www.infoworld.com/article/3099194/security/wire-open-sources-messaging-client-woos-developers.html)。几个月下来我们见到了一个用于 Linux 的 beta 版本 Wire 桌面应用程序。
除了一个包装器以外,桌面版的 Wire 并没有比 web 版多任何东西。感谢 [Electron 开源项目](http://electron.atom.io/)提供了一种开发跨平台桌面应用程序的简单方式。许多其他应用程序也通过使用 Electron 为 Linux 带去了一个本地桌面应用程序,包括 [Skype](https://itsfoss.com/skpe-alpha-linux/)。
### WIRE 的特性:
在我们了解有关 Linux 版 Wire 应用程序的更多信息之前,让我们先快速看一下它的一些主要特性。
* 开源应用程序
* 针对所有类型内容的全加密
* 无广告,无数据收集,无数据分享
* 支持文本,语音以及视频聊天
* 支持群聊和群电话
* [音频过滤器](https://medium.com/colorful-conversations/the-tune-for-this-summer-audio-filters-eca8cb0b4c57#.c8gvs143k)(不需要吸入氦元素,只需要使用过滤器就可以用有趣的声音说话)
* 不需要电话号码,可以使用邮箱登录
* 优美、现代化的界面
* 跨平台聊天应用程序,iOS,Android,Web,Mac,Windows 和 Linux 客户机均有相应版本
* 欧洲法保护(欧洲法比美国法更注重隐私)
Wire 有一些更棒的特性,尤其是和[Snapchat](https://www.snapchat.com/)类似的音频过滤器。
### 在 Linux 上安装 WIRE
在安装 Wire 到 Linux 上之前,让我先警告你它目前还处于 beta 阶段。所以,如果你遇到一些故障,请不要生气。
Wire 有一个 64 位系统可使用的 .deb 客户端。如果你有一台 [32 位或者 64 位系统](https://itsfoss.com/32-bit-64-bit-ubuntu/)的电脑,你可以使用这些技巧来找到它。你可以从下面的链接下载 .deb 文件。
* [下载 Linux 版 Wire [Beta]](https://wire.com/download/)
如果感兴趣的话,你也可以看一看它的源代码:
* [桌面版 Wire 源代码](https://github.com/wireapp/wire-desktop)
这是 Wire 的默认界面,看起来像 [elementary OS Loki](https://itsfoss.com/tag/elementary-os-loki/):

你看,他们甚至还弄了一个机器人:)
你已经开始使用 Wire 了吗?如果是,你的体验是什么样的?如果没有,你将尝试一下吗?因为它现在是[开源的](https://itsfoss.com/tag/open-source)并且可以在 Linux 上使用。
---
via: <https://itsfoss.com/wire-messaging-linux/>
作者:[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 译者:[ucasFL](https://github.com/ucasFL) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,939 | 通过 docker-compose 进行快速原型设计 | http://blog.alexellis.io/rapid-prototype-docker-compose/ | 2016-11-08T11:14:00 | [
"容器",
"docker-compose",
"Docker"
] | https://linux.cn/article-7939-1.html | 在这篇文章中,我们将考察一个 Node.js 开发原型,该原型用于从英国三个主要折扣网店查找“Raspberry PI Zero”的库存。
我写好了代码,然后经过一晚的鼓捣把它部署在 Aure 上的 Ubuntu 虚拟机上。Docker 和 docker-compose 工具使得部署和更新过程非常快。

### 还记得链接指令(link)吗?
如果你已经阅读过 [Hands-on Docker tutorial](http://blog.alexellis.io/handsondocker),那么你应该已经可以使用命令行链接 Docker 容器。通过命令行将 Node.js 的计数器链接到 Redis 服务器,其命令可能如下所示:
```
$ docker run -d -P --name redis1
$ docker run -d hit_counter -p 3000:3000 --link redis1:redis
```
现在假设你的应用程序分为三层:
* Web 前端
* 处理长时间运行任务的批处理层
* Redis 或者 mongo 数据库
通过`--link`的显式链接只是管理几个容器是可以的,但是可能会因为我们向应用程序添加更多层或容器而失控。
### 加入 docker-compose

*Docker Compose logo*
docker-compose 工具是标准 Docker 工具箱的一部分,也可以单独下载。 它提供了一组丰富的功能,通过纯文本 YAML 文件配置所有应用程序的部件。
上面的例子看起来像这样:
```
version: "2.0"
services:
redis1:
image: redis
hit_counter:
build: ./hit_counter
ports:
- 3000:3000
```
从 Docker 1.10 开始,我们可以利用网络覆盖(network overlays)来帮助我们在多个主机上进行扩展。 在此之前,链接仅能工作在单个主机上。 `docker-compose scale` 命令可以用来在需要时带来更多的计算能力。
>
> 查看 docker.com 上的 [docker-compose](https://docs.docker.com/compose/compose-file/) 参考
>
>
>
### 真实工作示例:Raspberry PI 库存警示

*新的 Raspberry PI Zero v1.3 图片,由 Pimoroni 提供*
Raspberry PI Zero 嗡嗡作响 - 它是一个极小的微型计算机,具有 1GHz CPU 和 512MB RAM,可以运行完整的Linux、Docker、Node.js、Ruby 和其他许多流行的开源工具。 PI Zero 最好的优点之一就是它成本只有 5 美元。 这也意味着它销售的速度非常之快。
*如果你想在 PI 上尝试 Docker 和 Swarm,请查看下面的教程:[Docker Swarm on the PI Zero](http://blog.alexellis.io/dockerswarm-pizero/)*
### 原始网站:whereismypizero.com
我发现一个网页,它使用屏幕抓取以找出 4-5 个最受欢迎的折扣网店是否有库存。
* 网站包含静态 HTML 网页
* 向每个折扣网店发出一个 XMLHttpRequest 访问 /public/api/
* 服务器向每个网店发出 HTTP 请求并执行抓屏
每一次对 /public/api/ 的调用,其执行花 3 秒钟,而使用 Apache Bench(ab),我每秒只能完成 0.25 个请求。
### 重新发明轮子
零售商似乎并不介意 whereismypizero.com 抓取他们的网站的商品库存信息,所以我开始从头写一个类似的工具。 我尝试通过缓存和解耦 web 层来处理更多的抓取请求。 Redis 是执行这项工作的完美工具。 它允许我设置一个自动过期的键/值对(即一个简单的缓存),还可以通过 pub/sub 在 Node.js 进程之间传输消息。
>
> 复刻或者追踪放在 github 上的代码: [alexellis/pi*zero*stock](https://github.com/alexellis/pi_zero_stock)
>
>
>
如果之前使用过 Node.js,你肯定知道它是单线程的,并且任何 CPU 密集型任务,如解析 HTML 或 JSON 都可能导致速度放缓。一种缓解这种情况的方法是使用一个工作进程和 Redis 消息通道作为它和 web 层之间的连接组织。
* Web 层
+ 使用 200 代表缓冲命中(该商店的 Redis 键存在)
+ 使用 202 代表高速缓存未命中(该商店的 Redis 键不存在,因此发出消息)
+ 因为我们只是读一个 Redis 键,响应时间非常快。
* 库存抓取器
+ 执行 HTTP 请求
+ 用于在不同类型的网店上抓屏
+ 更新 Redis 键的缓存失效时间为 60 秒
+ 另外,锁定一个 Redis 键,以防止对网店过多的 HTTP 请求。
```
version: "2.0"
services:
web:
build: ./web/
ports:
- "3000:3000"
stock_fetch:
build: ./stock_fetch/
redis:
image: redis
```
*来自示例的 docker-compose.yml 文件*
一旦本地正常工作,再向 Azure 的 Ubuntu 16.04 镜像云部署就轻车熟路,只花了不到 5 分钟。 我登录、克隆仓库并键入`docker-compose up -d`, 这就是所有的工作 - 快速实现整个系统的原型不会比这几个步骤更多。 任何人(包括 whereismypizero.com 的所有者)只需两行命令就可以部署新解决方案:
```
$ git clone https://github.com/alexellis/pi_zero_stock
$ docker-compose up -d
```
更新网站很容易,只需要一个`git pull`命令,然后执行`docker-compose up -d`命令,该命令需要带上`--build`参数。
如果你仍然手动链接你的 Docker 容器,请自己或使用如下我的代码尝试 Docker Compose:
>
> 复刻或者追踪在 github 上的代码: [alexellis/pi*zero*stock](https://github.com/alexellis/pi_zero_stock)
>
>
>
### 一睹测试网站芳容
目前测试网站使用 docker-compose 部署:[stockalert.alexellis.io](http://stockalert.alexellis.io/)

*预览于 2016 年 5 月 16 日*
---
via: <http://blog.alexellis.io/rapid-prototype-docker-compose/>
作者:[Alex Ellis](http://blog.alexellis.io/author/alex/) 译者:[firstadream](https://github.com/firstadream) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,940 | 标志性文本编辑器 Vim 迎来其 25 周年纪念日 | https://opensource.com/life/16/11/happy-birthday-vim-25 | 2016-11-08T15:03:35 | [
"vim"
] | /article-7940-1.html | 让我们把时钟往回拨一点。不,别停…再来一点……好了!在 25 年前,当你的某些专家同事还在蹒跚学步时,Bram Moolenaar 已经开始为他的 Amiga 计算机开发一款文本编辑器。他曾经是 Unix 上的 vi 用户,但 Amiga 上却没有与其类似的编辑器。在三年的开发之后,1991 年 11 月 2 日,他发布了“<ruby> 仿 vi 编辑器 <rp> ( </rp> <rt> Vi IMitation </rt> <rp> ) </rp></ruby>”(也就是 [Vim](http://www.vim.org/))的第一个版本。
两年之后,随着 2.0 版本的发布,Vim 的功能集已经超过了 vi,所以这款编辑器的全称也被改为了“<ruby> vi 增强版 <rp> ( </rp> <rt> Vi IMproved </rt> <rp> ) </rp></ruby>”。现在,刚刚度过 25 岁生日的 Vim,已经可以在绝大部分平台上运行——Windows、OS/2、OpenVMS、BSD、Android、iOS——并且已在 OS X 及很多 Linux 发行版上成为标配软件。它受到了许多赞誉,也受到了许多批评,不同组织或开发者也会围绕它来发起争论,甚至有些面试官会问:“你用 Emacs 还是 Vim?”Vim 已拥有自由许可证,它基于<ruby> <a href="http://vimdoc.sourceforge.net/htmldoc/uganda.html#license"> 慈善软件证书 </a> <rp> ( </rp> <rt> charityware license </rt> <rp> ) </rp></ruby>(“帮助乌干达的可怜儿童”)发布,该证书与 GPL 兼容。

Vim 是一个灵活的、可扩展的编辑器,带有一个强大的插件系统,被深入集成到许多开发工具,并且可以编辑上百种编程语言或文件类型的文件。 在 Vim 诞生二十五年后,Bram Moolenaar 仍然在主导开发并维护它——这真是一个壮举!Vim 曾经在超过 20 年的时间里数次间歇中断开发,但在 2016 年 9 月,它发布了 [8.0 版本](/article-7766-1.html),添加了许多新功能,为现代程序员用户提供了更多方便。很多年来,Vim 在官网上售卖 T 恤及 logo 贴纸,所得的销售款为支持 [ICCF](http://iccf-holland.org/)——一个帮助乌干达儿童的德国慈善机构做出了巨大贡献。Vim 所支持的慈善项目深受 Moolenaar 喜爱,Mooleaar 本人也去过乌干达,在基巴莱的一个儿童中心做志愿者。
Vim 在开源历史上记下了有趣的一笔:一个工程,在 25 年中,坚持由一个稳定的核心贡献者维护,拥有超多的用户,但很多人从未了解过它的历史。如果你想简单的了解 Vim,[请访问它的网站](http://www.vim.org/),或者你可以读一读 [Vim 入门的一些小技巧](https://opensource.com/life/16/7/tips-getting-started-vim),或者在 Opensource.com 阅读一位 [Vim 新用户的故事](https://opensource.com/business/16/8/7-reasons-love-vim)。
---
via: <https://opensource.com/life/16/11/happy-birthday-vim-25>
作者:[D Ruth Bavousett](https://opensource.com/users/druthb) 译者:[StdioA](https://github.com/StdioA) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | HTTPSConnectionPool(host='opensource.com', port=443): Read timed out. (read timeout=10) | null |
7,942 | 如何在 Arch Linux 的终端里设定 WiFi 网络 | http://www.linuxandubuntu.com/home/how-to-setup-a-wifi-in-arch-linux-using-terminal | 2016-11-09T08:01:00 | [
"WiFi"
] | https://linux.cn/article-7942-1.html | 
如果你使用的是其他 Linux 发行版 而不是 Arch CLI,那么可能会不习惯在终端里设置 WiFi。尽管整个过程有点简单,不过我还是要讲一下。在这篇文章里,我将带领新手们通过一步步的设置向导,把你们的 Arch Linux 接入到你的 WiFi 网络里。
在 Linux 里有很多程序来设置无线连接,我们可以用 `ip` 和 `iw` 来配置因特网连接,但是对于新手来说有点复杂。所以我们会使用 `netctl` 命令,这是一个基于命令行的工具,用来通过配置文件来设置和管理网络连接。
注意:所有的设定都需要 root 权限,或者你也可以使用 `sudo` 命令来完成。
### 搜索网络
运行下面的命令来查看你的网络接口:
```
iwconfig
```
运行如下命令启用你的网络接口,如果没有启用的话:
```
ip link set interface up
```
运行下面的命令搜索可用的 WiFi 网络。可以向下翻页来查看。
```
iwlist interface scan | less
```
**注意:** 命令里的 interface 是之前用 `iwconfig` 获取到的实际网络接口。
扫描完,如果不使用该接口可以运行如下命令关闭:
```
ip link set interface down
```
### 使用 netctl 配置 Wi-Fi:
在使用 `netctl` 设置连接之前,你必须先检查一下你的网卡在 Linux 下的兼容性。
运行命令:
```
lspci -k
```
这条命令是用来检查内核是否加载了你的无线网卡驱动。输出必须是像这样的:

如果内核没有加载驱动,你就必须使用有线连接来安装一下。这里是 Linux 无线网络的官方维基页面:<https://wireless.wiki.kernel.org/>。
如果你的无线网卡和 Linux 兼容,你可以使用 `netctl configuration`。
`netctl` 使用配置文件,这是一个包含连接信息的文件。创建这个文件有简单和困难两种方式。
#### 简单方式 – Wifi-menu
如果你想用 `wifi-menu`,必须安装 `dialog`。
1. 运行命令: `wifi-menu`
2. 选择你的网络

3. 输入正确的密码并等待

如果没有连接失败的信息,你可以用下面的命令确认下:
```
ping -c 3 www.google.com
```
哇!如果你看到正在 ping,意味着网络设置成功。你现在已经在 Arch Linux 下连上 WiFi 了。如果有任何问题,可以倒回去重来。也许漏了什么。
#### 困难方式
比起上面的 `wifi-menu` 命令,这种方式会难一点点,所以我叫做困难方式。在上面的命令里,网络配置会自动生成。而在困难方式里,我们将手动修改配置文件。不过不要担心,也没那么难。那我们开始吧!
1. 首先第一件事,你必须要知道网络接口的名字,通常会是 `wlan0` 或 `wlp2s0`,但是也有很多例外。要确认你自己的网络接口,输入 `iwconfig` 命令并记下来。
[](http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/scan-wifi-networks-in-arch-linux-cli_orig.png)
2. 运行命令:
```
cd /etc/netctl/examples
```
在这个目录里,有很多不同的配置文件例子。
3. 拷贝将用到的配置文件例子到 `/etc/netctl/your_profile`
```
cp /etc/netctl/examples/wireless-wpa /etc/netctl/your_profile
```
4. 你可以用这个命令来查看配置文件内容: `cat /etc/netctl/your_profile`

5. 用 `vi` 或者 `nano` 编辑你的配置文件的下面几个部分:
```
nano /etc/netctl/your_profile
```
```
- `Interface`:比如说 `wlan0`
- `ESSID`:你的无线网络名字
- `key`:你的无线网络密码
```
**注意:**
如果你不知道怎么用 `nano`,打开文件后,编辑要修改的地方,完了按 `ctrl+o`,然后回车,然后按 `ctrl+x`。

### 运行 netctl
1. 运行命令:
```
cd /etc/netctl
ls
```
你一定会看到 `wifi-menu` 生成的配置文件,比如 `wlan0-SSID`;或者你选择了困难方式,你一定会看到你自己创建的配置文件。
2. 运行命令启动连接配置:`netctl start your_profile`。
3. 用下面的命令测试连接:
```
ping -c 3 www.google.com
```
输出看上去像这样: 
4. 最后,你必须运行下面的命令:`netctl enable your_profile`。
```
netctl enable your_profile
```
这样将创建并激活一个 systemd 服务,然后开机时自动启动。然后欢呼吧!你在你的 Arch Linux 里配置好 wifi 网络啦。
### 其他工具
你还可以使用其他程序来设置无线连接:
iw:
1. `iw dev wlan0 link` – 状态
2. `iw dev wlan0 scan` – 搜索网络
3. `iw dev wlan0 connect your_essid` – 连接到开放网络
4. `iw dev wlan0 connect your_essid key your_key` - 使用 16 进制密钥连接到 WEP 加密的网络
wpa\_supplicant
* <https://wiki.archlinux.org/index.php/WPA_supplicant>
Wicd
* <https://wiki.archlinux.org/index.php/wicd>
NetworkManager
* <https://wiki.archlinux.org/index.php/NetworkManager>
### 总结
会了吧!我提供了在 **Arch Linux** 里接入 WiFI 网络的三种方式。这里有一件事我再强调一下,当你执行第一条命令的时候,请记住你的网络接口名字。在接下来搜索网络的命令里,请使用你的网络接口名字比如 `wlan0` 或 `wlp2s0`(上一个命令里得到的),而不是用 interface 这个词。如果你碰到任何问题,可以在下面的评论区里直接留言给我。然后别忘了在你的朋友圈里和大家分享这篇文章哦。谢谢!
---
via: <http://www.linuxandubuntu.com/home/how-to-setup-a-wifi-in-arch-linux-using-terminal>
作者:[Mohd Sohail](http://www.linuxandubuntu.com/contact-us.html) 译者:[zpl1025](https://github.com/zpl1025) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,943 | Linux 与 Windows 的设备驱动模型对比:架构、API 和开发环境比较 | http://xmodulo.com/linux-vs-windows-device-driver-model.html | 2016-11-09T13:06:00 | [
"设备",
"驱动"
] | https://linux.cn/article-7943-1.html | 
>
> 名词缩写:
>
>
> * <ruby> API 应用程序接口 <rp> ( </rp> <rt> Application Program Interface </rt> <rp> ) </rp></ruby>
> * <ruby> ABI 应用系统二进制接口 <rp> ( </rp> <rt> Application Binary Interface </rt> <rp> ) </rp></ruby>
>
>
>
设备驱动是操作系统的一部分,它能够通过一些特定的编程接口便于硬件设备的使用,这样软件就可以控制并且运行那些设备了。因为每个驱动都对应不同的操作系统,所以你就需要不同的 Linux、Windows 或 Unix 设备驱动,以便能够在不同的计算机上使用你的设备。这就是为什么当你雇佣一个驱动开发者或者选择一个研发服务商提供者的时候,查看他们为各种操作系统平台开发驱动的经验是非常重要的。

驱动开发的第一步是理解每个操作系统处理它的驱动的不同方式、底层驱动模型、它使用的架构、以及可用的开发工具。例如,Linux 驱动程序模型就与 Windows 非常不同。虽然 Windows 提倡驱动程序开发和操作系统开发分别进行,并通过一组 ABI 调用来结合驱动程序和操作系统,但是 Linux 设备驱动程序开发不依赖任何稳定的 ABI 或 API,所以它的驱动代码并没有被纳入内核中。每一种模型都有自己的优点和缺点,但是如果你想为你的设备提供全面支持,那么重要的是要全面的了解它们。
在本文中,我们将比较 Windows 和 Linux 设备驱动程序,探索不同的架构,API,构建开发和分发,希望让您比较深入的理解如何开始为每一个操作系统编写设备驱动程序。
### 1. 设备驱动架构
Windows 设备驱动程序的体系结构和 Linux 中使用的不同,它们各有优缺点。差异主要受以下原因的影响:Windows 是闭源操作系统,而 Linux 是开源操作系统。比较 Linux 和 Windows 设备驱动程序架构将帮助我们理解 Windows 和 Linux 驱动程序背后的核心差异。
#### 1.1. Windows 驱动架构
虽然 Linux 内核分发时带着 Linux 驱动,而 Windows 内核则不包括设备驱动程序。与之不同的是,现代 Windows 设备驱动程序编写使用 Windows 驱动模型(WDM),这是一种完全支持即插即用和电源管理的模型,所以可以根据需要加载和卸载驱动程序。
处理来自应用的请求,是由 Windows 内核的中被称为 I/O 管理器的部分来完成的。I/O 管理器的作用是是转换这些请求到<ruby> I/O 请求数据包 <rp> ( </rp> <rt> IO Request Packets </rt> <rp> ) </rp></ruby>(IRP),IRP 可以被用来在驱动层识别请求并且传输数据。
Windows 驱动模型 WDM 提供三种驱动, 它们形成了三个层:
* <ruby> 过滤 <rp> ( </rp> <rt> Filter </rt> <rp> ) </rp></ruby>驱动提供关于 IRP 的可选附加处理。
* <ruby> 功能 <rp> ( </rp> <rt> Function </rt> <rp> ) </rp></ruby>驱动是实现接口和每个设备通信的主要驱动。
* <ruby> 总线 <rp> ( </rp> <rt> Bus </rt> <rp> ) </rp></ruby>驱动服务不同的配适器和不同的总线控制器,来实现主机模式控制设备。
一个 IRP 通过这些层就像它们经过 I/O 管理器到达底层硬件那样。每个层能够独立的处理一个 IRP 并且把它们送回 I/O 管理器。在硬件底层中有硬件抽象层(HAL),它提供一个通用的接口到物理设备。
#### 1.2. Linux 驱动架构
相比于 Windows 设备驱动,Linux 设备驱动架构根本性的不同就是 Linux 没有一个标准的驱动模型也没有一个干净分隔的层。每一个设备驱动都被当做一个能够自动的从内核中加载和卸载的模块来实现。Linux 为即插即用设备和电源管理设备提供一些方式,以便那些驱动可以使用它们来正确地管理这些设备,但这并不是必须的。
模式输出那些它们提供的函数,并通过调用这些函数和传入随意定义的数据结构来沟通。请求来自文件系统或网络层的用户应用,并被转化为需要的数据结构。模块能够按层堆叠,在一个模块进行处理之后,另外一个再处理,有些模块提供了对一类设备的公共调用接口,例如 USB 设备。
Linux 设备驱动程序支持三种设备:
* 实现一个字节流接口的<ruby> 字符 <rp> ( </rp> <rt> Character </rt> <rp> ) </rp></ruby>设备。
* 用于存放文件系统和处理多字节数据块 IO 的<ruby> 块 <rp> ( </rp> <rt> Block </rt> <rp> ) </rp></ruby>设备。
* 用于通过网络传输数据包的<ruby> 网络 <rp> ( </rp> <rt> Network </rt> <rp> ) </rp></ruby>接口。
Linux 也有一个硬件抽象层(HAL),它实际扮演了物理硬件的设备驱动接口。
### 2. 设备驱动 API
Linux 和 Windows 驱动 API 都属于事件驱动类型:只有当某些事件发生的时候,驱动代码才执行——当用户的应用程序希望从设备获取一些东西,或者当设备有某些请求需要告知操作系统。
#### 2.1. 初始化
在 Windows 上,驱动被表示为 `DriverObject` 结构,它在 `DriverEntry` 函数的执行过程中被初始化。这些入口点也注册一些回调函数,用来响应设备的添加和移除、驱动卸载和处理新进入的 IRP。当一个设备连接的时候,Windows 创建一个设备对象,这个设备对象在设备驱动后面处理所有应用请求。
相比于 Windows,Linux 设备驱动生命周期由内核模块的 `module_init` 和 `module_exit` 函数负责管理,它们分别用于模块的加载和卸载。它们负责注册模块来通过使用内核接口来处理设备的请求。这个模块需要创建一个设备文件(或者一个网络接口),为其所希望管理的设备指定一个数字识别号,并注册一些当用户与设备文件交互的时候所使用的回调函数。
#### 2.2. 命名和声明设备
##### 在 Windows 上注册设备
Windows 设备驱动在新连接设备时是由回调函数 `AddDevice` 通知的。它接下来就去创建一个<ruby> 设备对象 <rp> ( </rp> <rt> device object </rt> <rp> ) </rp></ruby>,用于识别该设备的特定的驱动实例。取决于驱动的类型,设备对象可以是<ruby> 物理设备对象 <rp> ( </rp> <rt> Physical Device Object </rt> <rp> ) </rp></ruby>(PDO),<ruby> 功能设备对象 <rp> ( </rp> <rt> Function Device Object </rt> <rp> ) </rp></ruby>(FDO),或者<ruby> 过滤设备对象 <rp> ( </rp> <rt> Filter Device Object </rt> <rp> ) </rp></ruby>(FIDO)。设备对象能够堆叠,PDO 在底层。
设备对象在这个设备连接在计算机期间一直存在。`DeviceExtension` 结构能够被用于关联到一个设备对象的全局数据。
设备对象可以有如下形式的名字 `\Device\DeviceName`,这被系统用来识别和定位它们。应用可以使用 `CreateFile` API 函数来打开一个有上述名字的文件,获得一个可以用于和设备交互的句柄。
然而,通常只有 PDO 有自己的名字。未命名的设备能够通过设备级接口来访问。设备驱动注册一个或多个接口,以 128 位全局唯一标识符(GUID)来标示它们。用户应用能够使用已知的 GUID 来获取一个设备的句柄。
##### 在 Linux 上注册设备
在 Linux 平台上,用户应用通过文件系统入口访问设备,它通常位于 `/dev` 目录。在模块初始化的时候,它通过调用内核函数 `register_chrdev` 创建了所有需要的入口。应用可以发起 `open` 系统调用来获取一个文件描述符来与设备进行交互。这个调用后来被发送到回调函数,这个调用(以及将来对该返回的文件描述符的进一步调用,例如 `read`、`write` 或`close`)会被分配到由该模块安装到 `file_operations` 或者 `block_device_operations`这样的数据结构中的回调函数。
设备驱动模块负责分配和保持任何需要用于操作的数据结构。传送进文件系统回调函数的 `file` 结构有一个 `private_data` 字段,它可以被用来存放指向具体驱动数据的指针。块设备和网络接口 API 也提供类似的字段。
虽然应用使用文件系统的节点来定位设备,但是 Linux 在内部使用一个<ruby> 主设备号 <rp> ( </rp> <rt> major numbers </rt> <rp> ) </rp></ruby>和<ruby> 次设备号 <rp> ( </rp> <rt> minor numbers </rt> <rp> ) </rp></ruby>的概念来识别设备及其驱动。主设备号被用来识别设备驱动,而次设备号由驱动使用来识别它所管理的设备。驱动为了去管理一个或多个固定的主设备号,必须首先注册自己或者让系统来分配未使用的设备号给它。
目前,Linux 为<ruby> 主次设备对 <rp> ( </rp> <rt> major-minor pairs </rt> <rp> ) </rp></ruby>使用一个 32 位的值,其中 12 位分配主设备号,并允许多达 4096 个不同的设备。主次设备对对于字符设备和块设备是不同的,所以一个字符设备和一个块设备能使用相同的设备对而不导致冲突。网络接口是通过像 eth0 的符号名来识别,这些又是区别于主次设备的字符设备和块设备的。
#### 2.3. 交换数据
Linux 和 Windows 都支持在用户级应用程序和内核级驱动程序之间传输数据的三种方式:
* <ruby> 缓冲型输入输出 <rp> ( </rp> <rt> Buffered Input-Output </rt> <rp> ) </rp></ruby>它使用由内核管理的缓冲区。对于写操作,内核从用户空间缓冲区中拷贝数据到内核分配的缓冲区,并且把它传送到设备驱动中。读操作也一样,由内核将数据从内核缓冲区中拷贝到应用提供的缓冲区中。
* <ruby> 直接型输入输出 <rp> ( </rp> <rt> Direct Input-Output </rt> <rp> ) </rp></ruby> 它不使用拷贝功能。代替它的是,内核在物理内存中钉死一块用户分配的缓冲区以便它可以一直留在那里,以便在数据传输过程中不被交换出去。
* <ruby> 内存映射 <rp> ( </rp> <rt> Memory mapping </rt> <rp> ) </rp></ruby> 它也能够由内核管理,这样内核和用户空间应用就能够通过不同的地址访问同样的内存页。
##### Windows 上的驱动程序 I/O 模式
支持缓冲型 I/O 是 WDM 的内置功能。缓冲区能够被设备驱动通过在 IRP 结构中的 `AssociatedIrp.SystemBuffer` 字段访问。当需要和用户空间通讯的时候,驱动只需从这个缓冲区中进行读写操作。
Windows 上的直接 I/O 由<ruby> 内存描述符列表 <rp> ( </rp> <rt> memory descriptor lists </rt> <rp> ) </rp></ruby>(MDL)介导。这种半透明的结构是通过在 IRP 中的 `MdlAddress` 字段来访问的。它们被用来定位由用户应用程序分配的缓冲区的物理地址,并在 I/O 请求期间钉死不动。
在 Windows 上进行数据传输的第三个选项称为 `METHOD_NEITHER`。 在这种情况下,内核需要传送用户空间的输入输出缓冲区的虚拟地址给驱动,而不需要确定它们有效或者保证它们映射到一个可以由设备驱动访问的物理内存地址。设备驱动负责处理这些数据传输的细节。
##### Linux 上的驱动程序 I/O 模式
Linux 提供许多函数例如,`clear_user`、`copy_to_user`、`strncpy_from_user` 和一些其它的用来在内核和用户内存之间进行缓冲区数据传输的函数。这些函数保证了指向数据缓存区指针的有效,并且通过在内存区域之间安全地拷贝数据缓冲区来处理数据传输的所有细节。
然而,块设备的驱动对已知大小的整个数据块进行操作,它可以在内核和用户地址区域之间被快速移动而不需要拷贝它们。这种情况是由 Linux 内核来自动处理所有的块设备驱动。块请求队列处理传送数据块而不用多余的拷贝,而 Linux 系统调用接口来转换文件系统请求到块请求中。
最终,设备驱动能够从内核地址区域分配一些存储页面(不可交换的)并且使用 `remap_pfn_range` 函数来直接映射这些页面到用户进程的地址空间。然后应用能获取这些缓冲区的虚拟地址并且使用它来和设备驱动交流。
### 3. 设备驱动开发环境
#### 3.1. 设备驱动框架
##### Windows 驱动程序工具包
Windows 是一个闭源操作系统。Microsoft 提供 Windows 驱动程序工具包以方便非 Microsoft 供应商开发 Windows 设备驱动。工具包中包含开发、调试、检验和打包 Windows 设备驱动等所需的所有内容。
<ruby> Windows 驱动模型 <rp> ( </rp> <rt> Windows Driver Model </rt> <rp> ) </rp></ruby>(WDM)为设备驱动定义了一个干净的接口框架。Windows 保持这些接口的源代码和二进制的兼容性。编译好的 WDM 驱动通常是前向兼容性:也就是说,一个较旧的驱动能够在没有重新编译的情况下在较新的系统上运行,但是它当然不能够访问系统提供的新功能。但是,驱动不保证后向兼容性。
##### Linux 源代码
和 Windows 相对比,Linux 是一个开源操作系统,因此 Linux 的整个源代码是用于驱动开发的 SDK。没有驱动设备的正式框架,但是 Linux 内核包含许多提供了如驱动注册这样的通用服务的子系统。这些子系统的接口在内核头文件中描述。
尽管 Linux 有定义接口,但这些接口在设计上并不稳定。Linux 不提供有关前向和后向兼容的任何保证。设备驱动对于不同的内核版本需要重新编译。没有稳定性的保证可以让 Linux 内核进行快速开发,因为开发人员不必去支持旧的接口,并且能够使用最好的方法解决手头的这些问题。
当为 Linux 写<ruby> 树内 <rp> ( </rp> <rt> in-tree </rt> <rp> ) </rp></ruby>(指当前 Linux 内核开发主干)驱动程序时,这种不断变化的环境不会造成任何问题,因为它们作为内核源代码的一部分,与内核本身同步更新。然而,闭源驱动必须单独开发,并且在<ruby> 树外 <rp> ( </rp> <rt> out-of-tree </rt> <rp> ) </rp></ruby>,必须维护它们以支持不同的内核版本。因此,Linux 鼓励设备驱动程序开发人员在树内维护他们的驱动。
#### 3.2. 为设备驱动构建系统
Windows 驱动程序工具包为 Microsoft Visual Studio 添加了驱动开发支持,并包括用来构建驱动程序代码的编译器。开发 Windows 设备驱动程序与在 IDE 中开发用户空间应用程序没有太大的区别。Microsoft 提供了一个企业 Windows 驱动程序工具包,提供了类似于 Linux 命令行的构建环境。
Linux 使用 Makefile 作为树内和树外系统设备驱动程序的构建系统。Linux 构建系统非常发达,通常是一个设备驱动程序只需要少数行就产生一个可工作的二进制代码。开发人员可以使用任何 [IDE](/article-7704-1.html),只要它可以处理 Linux 源代码库和运行 `make` ,他们也可以很容易地从终端手动编译驱动程序。
#### 3.3. 文档支持
Windows 对于驱动程序的开发有良好的文档支持。Windows 驱动程序工具包包括文档和示例驱动程序代码,通过 MSDN 可获得关于内核接口的大量信息,并存在大量的有关驱动程序开发和 Windows 底层的参考和指南。
Linux 文档不是描述性的,但整个 Linux 源代码可供驱动开发人员使用缓解了这一问题。源代码树中的 Documentation 目录描述了一些 Linux 的子系统,但是有[几本书](http://xmodulo.com/go/linux_device_driver_books)介绍了关于 Linux 设备驱动程序开发和 Linux 内核概览,它们更详细。
Linux 没有提供设备驱动程序的指定样本,但现有生产级驱动程序的源代码可用,可以用作开发新设备驱动程序的参考。
#### 3.4. 调试支持
Linux 和 Windows 都有可用于追踪调试驱动程序代码的日志机制。在 Windows 上将使用 `DbgPrint` 函数,而在 Linux 上使用的函数称为 `printk`。然而,并不是每个问题都可以通过只使用日志记录和源代码来解决。有时断点更有用,因为它们允许检查驱动代码的动态行为。交互式调试对于研究崩溃的原因也是必不可少的。
Windows 通过其内核级调试器 `WinDbg` 支持交互式调试。这需要通过一个串行端口连接两台机器:一台计算机运行被调试的内核,另一台运行调试器和控制被调试的操作系统。Windows 驱动程序工具包包括 Windows 内核的调试符号,因此 Windows 的数据结构将在调试器中部分可见。
Linux 还支持通过 `KDB` 和 `KGDB` 进行的交互式调试。调试支持可以内置到内核,并可在启动时启用。之后,可以直接通过物理键盘调试系统,或通过串行端口从另一台计算机连接到它。KDB 提供了一个简单的命令行界面,这是唯一的在同一台机器上来调试内核的方法。然而,KDB 缺乏源代码级调试支持。KGDB 通过串行端口提供了一个更复杂的接口。它允许使用像 GDB 这样标准的应用程序调试器来调试 Linux 内核,就像任何其它用户空间应用程序一样。
### 4. 设备驱动分发
#### 4.1. 安装设备驱动
在 Windows 上安装的驱动程序,是由被称为为 INF 的文本文件描述的,通常存储在 `C:\Windows\INF` 目录中。这些文件由驱动供应商提供,并且定义哪些设备由该驱动程序服务,哪里可以找到驱动程序的二进制文件,和驱动程序的版本等。
当一个新设备插入计算机时,Windows 通过查看已经安装的驱动程序并且选择适当的一个加载。当设备被移除的时候,驱动会自动卸载它。
在 Linux 上,一些驱动被构建到内核中并且保持永久的加载。非必要的驱动被构建为内核模块,它们通常是存储在 `/lib/modules/kernel-version` 目录中。这个目录还包含各种配置文件,如 `modules.dep`,用于描述内核模块之间的依赖关系。
虽然 Linux 内核可以在自身启动时加载一些模块,但通常模块加载由用户空间应用程序监督。例如,`init` 进程可能在系统初始化期间加载一些模块,`udev` 守护程序负责跟踪新插入的设备并为它们加载适当的模块。
#### 4.2. 更新设备驱动
Windows 为设备驱动程序提供了稳定的二进制接口,因此在某些情况下,无需与系统一起更新驱动程序二进制文件。任何必要的更新由 Windows Update 服务处理,它负责定位、下载和安装适用于系统的最新版本的驱动程序。
然而,Linux 不提供稳定的二进制接口,因此有必要在每次内核更新时重新编译和更新所有必需的设备驱动程序。显然,内置在内核中的设备驱动程序会自动更新,但是树外模块会产生轻微的问题。 维护最新的模块二进制文件的任务通常用 [DKMS](http://xmodulo.com/build-kernel-module-dkms-linux.html) 来解决:这是一个当安装新的内核版本时自动重建所有注册的内核模块的服务。
#### 4.3. 安全方面的考虑
所有 Windows 设备驱动程序在 Windows 加载它们之前必须被数字签名。在开发期间可以使用自签名证书,但是分发给终端用户的驱动程序包必须使用 Microsoft 信任的有效证书进行签名。供应商可以从 Microsoft 授权的任何受信任的证书颁发机构获取<ruby> 软件出版商证书 <rp> ( </rp> <rt> Software Publisher Certificate </rt> <rp> ) </rp></ruby>。然后,此证书由 Microsoft 交叉签名,并且生成的交叉证书用于在发行之前签署驱动程序包。
Linux 内核也能配置为在内核模块被加载前校验签名,并禁止不可信的内核模块。被内核所信任的公钥集在构建时是固定的,并且是完全可配置的。由内核执行的检查,这个检查严格性在构建时也是可配置的,范围从简单地为不可信模块发出警告,到拒绝加载有效性可疑的任何东西。
### 5. 结论
如上所示,Windows 和 Linux 设备驱动程序基础设施有一些共同点,例如调用 API 的方法,但更多的细节是相当不同的。最突出的差异源于 Windows 是由商业公司开发的封闭源操作系统这个事实。这使得 Windows 上有好的、文档化的、稳定的驱动 ABI 和正式框架,而在 Linux 上,更多的是源代码做了一个有益的补充。文档支持也在 Windows 环境中更加发达,因为 Microsoft 具有维护它所需的资源。
另一方面,Linux 不会使用框架来限制设备驱动程序开发人员,并且内核和产品级设备驱动程序的源代码可以在需要的时候有所帮助。缺乏接口稳定性也有其作用,因为它意味着最新的设备驱动程序总是使用最新的接口,内核本身承载较小的后向兼容性负担,这带来了更干净的代码。
了解这些差异以及每个系统的具体情况是为您的设备提供有效的驱动程序开发和支持的关键的第一步。我们希望这篇文章对 Windows 和 Linux 设备驱动程序开发做的对比,有助于您理解它们,并在设备驱动程序开发过程的研究中,将此作为一个伟大的起点。
---
via: <http://xmodulo.com/linux-vs-windows-device-driver-model.html>
作者:[Dennis Turpitka](http://xmodulo.com/author/dennis) 译者:[FrankXinqi &YangYang](https://github.com/FrankXinqi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,945 | Adobe 的新任首席信息官(CIO)对于开始一个新领导职位的建议 | https://enterprisersproject.com/article/2016/9/adobes-new-cio-shares-leadership-advice-starting-new-role | 2016-11-10T13:56:21 | [] | https://linux.cn/article-7945-1.html | 
我目前的几个月在一家十分受人尊敬的基于云的技术公司担任新的 CIO 一职。我的首要任务之一就是熟悉组织的人、文化和当务之急的事件。
作为这一目标的一部分,我访问了所有主要的网站。而在印度,上任不到两个月时,我被问道:“你打算做什么?你的计划是什么?” 我回答道,这个问题不会让经验丰富的 CIO 们感到吃惊:我现在仍然处于探索模式,我在做的主要是聆听和学习。
我从来没有在入职时制定一份蓝图说我要做什么。我知道一些 CIO 们拥有一本关于他要怎么做的”剧本“。他会煽动整个组织将他的计划付诸行动。
是的,在有些地方是完全崩坏了并无法发挥作用的情况下,这种行动可能是有意义的。但是,当我进入到一个公司时,我的策略是先开始一个探索的过程。我不想带入任何先入为主的观念,比如什么事应该是什么样子的,哪些工作和哪些是有冲突的,而哪些不是。
以下是我作为新任命的领导人的指导原则:
### 了解你的人
这意味着建立关系,它包括你的 IT 职员,你的客户和你的销售人员。他们的清单上最重要的是什么?他们想要你关注什么?什么产品受到好评?什么产品不好?客户体验是怎样的?了解如何帮助每一个人变得更好将决定你提供服务的方式。
如果你的部门就像我的一样,是分布在几层楼中的,你可以考虑召开一个见面会,利用午餐或者小型技术研讨会的时间,让大家可以进行自我介绍并讨论下他们正在进行的工作,如果他们愿意的话还可以分享一些他们的家庭小故事。如果你有一个公开的办公室政策,你得确保每一个人都很好的了解它了。如果你有跨国跨州的的员工,你应该尽快的去拜访一下。
### 了解你的产品和公司文化
来到 Adobe 后最让我震惊的是我们的产品组合是如此的广泛。我们有一个横贯三个云的提供解决方案和服务的平台——Adobe 创新云、文档云和营销云——和对每一个产品的丰富的组合。除非你去了解你的产品和学会如何为他们提供支持,否则你永远也不知道你的新公司有着多么多的机会。在 Adobe 我们给我们的零号客户使用许多数字媒体和数字市场解决方案,所以我们可以将我们的第一手经验分享给我们的客户。
### 了解客户
从很早开始,我们就收到客户的会面请求。与客户会面是一种很好的方式来启发你对 IT 机构未来的的思考,包括各种我们可以改进的地方,如技术、客户和消费者。
### 对未来的计划
作为一个新上任的领导者,我有一个全新的视角用以考虑组织的未来,而不会有挑战和障碍来干扰我。
CIO 们所需要做的就是推动 IT 进化到下一代。当我会见我的员工时,我问他们我们三到五年后的未来可以做什么,以便我们可以开始尽早定位。这意味着开始讨论方案和当务之急的事。
从那以后,它使领导小组团结在一起,所以我们能够共同来组建我们的下一代体系——它的使命、愿景、组织模式和操作规范。如果你开始从内而外的改变,那么它会渗透到业务和其他你所做的一切事情上。
贯穿整个过程,我对他人都表现一种开明的态度,这不是一个自上而下的命令。也许我对我们当前要做的事有一个自己的看法,但是我们必须使看法保持一致,我们是一个团队,我们应该共同找出我们需要做的事。
---
via: <https://enterprisersproject.com/article/2016/9/adobes-new-cio-shares-leadership-advice-starting-new-role>
作者:[Cynthia Stoddard](https://enterprisersproject.com/user/cynthia-stoddard) 译者:[Chao-zhi](https://github.com/Chao-zhi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | I’m currently a few months into a new CIO role at a highly-admired, cloud-based technology company. One of my first tasks was to get to know the organization’s people, culture, and priorities.
As part of that goal, I am visiting all the major IT sites. While In India, less than two months into the job, I was asked directly: “What are you going to do? What is your plan?” My response, which will not surprise seasoned CIOs, was that I was still in discovery mode, and I was there to listen and learn.
I’ve never gone into an organization with a set blueprint for what I’ll do. I know some CIOs have a playbook for how they will operate. They’ll come in and blow the whole organization up and put their set plan in motion.
Yes, there may be situations where things are massively broken and not working, so that course of action makes sense. Once I’m inside a company, however, my strategy is to go through a discovery process. I don’t want to have any preconceived notions about the way things should be or what’s working versus what’s not.
Here are my guiding principles as a newly-appointed leader:
**Get to know your people**
This means building relationships, and it includes your IT staff as well as your business users and your top salespeople. What are the top things on their lists? What do they want you to focus on? What’s working well? What’s not? How is the customer experience? Knowing how you can help everyone be more successful will help you shape the way you deliver services to them.
If your department is spread across several floors, as mine is, consider meet-and-greet lunches or mini-tech fairs so people can introduce themselves, discuss what they’re working on, and share stories about their family, if they feel comfortable doing that. If you have an open-door office policy, make sure they know that as well. If your staff spreads across countries or continents, get out there and visit as soon as you reasonably can.
**Get to know your products and company culture**
One of the things that surprised me coming into to Adobe was how broad our product portfolio is. We have a platform of solutions and services across three clouds – Adobe Creative Cloud, Document Cloud and Marketing Cloud – and a vast portfolio of products within each. You’ll never know how much opportunity your new company presents until you get to know your products and learn how to support all of them. At Adobe we use many of our digital media and digital marketing solutions as Customer Zero, so we have first-hand experiences to share with our customers
**Get to know customers**
Very early on, I started getting requests to meet with customers. Meeting with customers is a great way to jump-start your thinking into the future of the IT organization, which includes the different types of technologies, customers, and consumers we could have going forward.
**Plan for the future**
As a new leader, I have a fresh perspective and can think about the future of the organization without getting distracted by challenges or obstacles.
What CIOs need to do is jump-start IT into its next generation. When I meet my staff, I’m asking them what we want to be three to five years out so we can start positioning ourselves for that future. That means discussing the initiatives and priorities.
After that, it makes sense to bring the leadership team together so you can work to co-create the next generation of the organization – its mission, vision, modes of alignment, and operating norms. If you start changing IT from the inside out, it will percolate into business and everything else you do.
Through this whole process, I’ve been very open with people that this is not going to be a top-down directive. I have ideas on priorities and what we need to focus on, but we have to be in lockstep, working as a team and figuring out what we want to do jointly.
## Comments
it's critical to comprehend the present condition of the IT business. The part of the CIO is intensely affected by how IT procedure, new PC frameworks and an undertaking's steadily changing targets and objectives adjust. Clearly, you esteem the general population and give them considerations, that is the critical part of CIO!
Here, here! I echo Cynthia's advice and wisdom for on-boarding onto a new CIO leadership challenge. I have used a simple "listen, look and learn" approach during my first 90 days. |
7,946 | 病毒过后,系统管理员投向了 Linux | https://opensource.com/life/16/3/my-linux-story-soumya-sarkar | 2016-11-10T14:34:15 | [
"Linux",
"病毒"
] | https://linux.cn/article-7946-1.html | 
我开源事业的第一笔,是我在 2001 年作为一名兼职系统管理员,为大学工作的时候。成为了那个以教学为目的,不仅仅在大学中,还在学术界的其他领域建立商业案例研究的小组的一份子。
随着团队的发展,渐渐地开始需要一个由文件服务、intranet 应用,域登录等功能构建而成的健壮的局域网。 我们的 IT 基础设施主要由跑着 Windows 98 的计算机组成,这些计算机对于大学的 IT 实验室来说已经太老了,就重新分配给了我们部门。
### 初探 Linux
一天,作为大学IT采购计划的一部分,我们部门收到了一台 IBM 服务器。 我们计划将其用作 Internet 网关,域控制站,文件服务器和备份服务器,以及 intranet 应用程序主机。
拆封后,我们注意到它附带了红帽 Linux 的 CD。 我们的 22 人团队(包括我)对 Linux 一无所知。 经过几天的研究,我找到了一位朋友的朋友,一位以 Linux RTOS (Linux 的实时操作系统领域)编程为生的人,求助他如何安装。
光看着那朋友用 CD 驱动器载入第一张安装 CD 并进入 Anaconda 安装系统,我的头都晕了。 大约一个小时,我们完成了基本的安装,但仍然没有可用的 internet 连接。
又花了一个小时的折腾才使我们连接到互联网,但仍没有域登录或 Internet 网关功能。 经过一个周末的折腾,我们可以让我们的 Windows 98 机器作为 Linux PC 的代理,终于构出了一个正常工作的共享互联环境。 但域登录还需要一段时间。
我们用龟速的电话调制解调器下载了 [Samba](https://www.samba.org/),并手动配置它作为域控制站。文件服务也通过 NFS Kernel Server 开启了,随后为 Windows 98 的网络邻居创建了用户目录并进行了必要的调整和配置。
这个设置完美运行了一段时间,直到最终我们决定开始使用 Intranet 应用管理时间表和一些别的东西。 这个时候,我已经离开了该组织,并把大部分系统管理员的东西交给了接替我的人。
### 再遇 Linux
2004 年,我又重新装回了 Linux。我的妻子经营的一份独立员工安置业务,使用来自 Monster.com 等服务的数据来打通客户与求职者的交流渠道。
作为我们两人中的计算机好点的那个,在计算机和互联网出故障的时候,维修就成了我的分内之事。我们还需要用许多工具尝试,从堆积如山的简历中筛选出她每天必须看的。
Windows [BSoD](https://en.wikipedia.org/wiki/Blue_Screen_of_Death)(蓝屏) 早已司空见惯,但只要我们的付费数据是安全的,那就还算可以容忍。为此我将不得不每周花几个小时去做备份。
一天,我们的电脑中了毒,并且通过简单的方法无法清除。我们并不了解磁盘上的数据发生了些什么。当磁盘彻底挂掉后,我们插入了一周前的辅助备份磁盘,但是一周后它也挂了。我们的第二个备份直接拒绝启动。是时候寻求专业帮助了,所以我们把电脑送到一家靠谱的维修店。两天以后,我们被告知一些恶意软件或病毒已经将某些种类的文件擦除殆尽,其中包括我们的付费数据。
这是对我妻子的商业计划的一个巨大的打击,同时意味着丢失合同并耽误了账单。我曾短期出国工作,并在台湾的 [Computex 2004](https://en.wikipedia.org/wiki/Computex_Taipei) 购买了我的第一台笔记本电脑。 预装的是 Windows XP,但我还是想换成 Linux。 我知道 Linux 已经为桌面端做好了准备,[Mandrake Linux](https://en.wikipedia.org/wiki/Mandriva_Linux) (曼德拉草) 是一个很不错的选择。 我第一次安装就很顺利。所有工作都执行的非常漂亮。我使用 [OpenOffice](http://www.openoffice.org/) 来满足我写作,演示文稿和电子表格的需求。
我们为我们的计算机买了新的硬盘驱动器,并为其安装了 Mandrake Linux。用 OpenOffice 替换了 Microsoft Office。 我们依靠 Web 邮件来满足邮件需求,并在 2004 年的 11 月迎来了 [Mozilla Firefox](https://www.mozilla.org/en-US/firefox/new/)。我的妻子马上从中看到了好处,因为没有崩溃或病毒/恶意软件感染!更重要的是,我们告别了困扰 Windows 98 和 XP 的频繁崩溃问题。 她一直使用这个发行版。
而我,开始尝试其他的发行版。 我爱上了 distro-hopping (LCTT 译注:指在不同版本的 Linux 发行版之间频繁切换的 Linux 用户)和第一时间尝试新发行版的感觉。我也经常会在 Apache 和 NGINX 上尝试和测试 Web 应用程序,如 Drupal、Joomla 和 WordPress。现在我们 2006 年出生的儿子,在 Linux 下成长。 也对 Tux Paint,Gcompris 和 SMPlayer 非常满意。
---
via: <https://opensource.com/life/16/3/my-linux-story-soumya-sarkar>
作者:[Soumya Sarkar](https://opensource.com/users/ssarkarhyd) 译者:[martin2011qi](https://github.com/martin2011qi) 校对:[wxy](https://github.com/wxy)
| 200 | OK | My first brush with open source came while I was working for my university as a part-time system administrator in 2001. I was part of a small group that created business case studies for teaching not just in the university, but elsewhere in academia.
As the team grew, the need for a robust LAN setup with file serving, intranet applications, domain logons, etc. emerged. Our IT infrastructure consisted mostly of bootstrapped Windows 98 computers that had become too old for the university's IT labs and were reassigned to our department.
## Discovering Linux
One day, as part of the university's IT procurement plan, our department received an IBM server. We planned to use it as an Internet gateway, domain controller, file and backup server, and intranet application host.
Upon unboxing, we noticed that it came with Red Hat Linux CDs. No one on our 22-person team (including me) knew anything about Linux. After a few days of research, I met a friend of a friend who did Linux RTOS programming for a living. I asked him for some help installing it.
It was heady stuff as I watched the friend load up the CD drive with the first of the installation CDs and boot into the Anaconda install system. In about an hour we had completed the basic installation, but still had no working internet connection.
Another hour of tinkering got us connected to the Internet, but we still weren't anywhere near domain logons or Internet gateway functionality. After another weekend of tinkering, we were able to instruct our Windows 98 terminals to accept the IP of the the Linux PC as the proxy so that we had a working shared Internet connection. But domain logons were still some time away.
We downloaded [Samba](https://www.samba.org/) over our awfully slow phone modem connection and hand configured it to serve as the domain controller. File services were also enabled via NFS Kernel Server and creating user directories and making the necessary adjustments and configurations on Windows 98 in Network Neighborhood.
This setup ran flawlessly for quite some time, and we eventually decided to get started with Intranet applications for timesheet management and some other things. By this time, I was leaving the organization and had handed over most of the sys admin stuff to someone who replaced me.
## A second Linux experience
In 2004, I got into Linux once again. My wife ran an independent staff placement business that used data from services like Monster.com to connect clients with job seekers.
Being the more computer literate of the two of us, it was my job to set things right with the computer or Internet when things went wrong. We also needed to experiment with a lot of tools for sifting through the mountains of resumes and CVs she had to go through on a daily basis.
Windows [BSoD](https://en.wikipedia.org/wiki/Blue_Screen_of_Death)s were a routine affair, but that was tolerable as long as the data we paid for was safe. I had to spend a few hours each week creating backups.
One day, we had a virus that simply would not go away. Little did we know what was happening to the data on the slave disk. When it finally failed, we plugged in the week-old slave backup and it failed a week later. Our second backup simply refused to boot up. It was time for professional help, so we took our PC to a reputable repair shop. After two days, we learned that some malware or virus had wiped certain file types, including our paid data, clean.
This was a body blow to my wife's business plans and meant lost contracts and delayed invoice payments. I had in the interim travelled abroad on business and purchased my first laptop computer from [Computex 2004](https://en.wikipedia.org/wiki/Computex_Taipei) in Taiwan. It had Windows XP pre-installed, but I wanted to replace it with Linux. I had read that Linux was ready for the desktop and that [Mandrake Linux](https://en.wikipedia.org/wiki/Mandriva_Linux) was a good choice. My first attempt at installation went without a glitch. Everything worked beautifully. I used [OpenOffice](http://www.openoffice.org/) for my writing, presentation, and spreadsheet needs.
We got new hard drives for our computer and installed Mandrake Linux on them. OpenOffice replaced Microsoft Office. We relied on webmail for mailing needs, and [Mozilla Firefox](https://www.mozilla.org/en-US/firefox/new/) was a welcome change in November 2004. My wife saw the benefits immediately, as there were no crashes or virus/malware infections. More importantly, we bade goodbye to the frequent crashes that plagued Windows 98 and XP. She continued to use the same distribution.
I, on the other hand, started playing around with other distributions. I love distro-hopping and trying out new ones every once in a while. I also regularly try and test out web applications like Drupal, Joomla, and WordPress on Apache and NGINX stacks. And now our son, who was born in 2006, grew up on Linux. He's very happy with Tux Paint, Gcompris, and SMPlayer.
## 13 Comments |
7,947 | 怎样用 Tar 和 OpenSSL 给文件和目录加密及解密 | http://www.tecmint.com/encrypt-decrypt-files-tar-openssl-linux/ | 2016-11-10T18:01:00 | [
"加密",
"OpenSSL",
"tar"
] | https://linux.cn/article-7947-1.html | 当你有重要的敏感数据的时候,给你的文件和目录额外加一层保护是至关重要的,特别是当你需要通过网络与他人传输数据的时候。
由于这个原因,我在寻找一个可疑在 Linux 上加密及解密文件和目录的实用程序,幸运的是我找到了一个用 tar(Linux 的一个压缩打包工具)和 OpenSSL 来解决的方案。借助这两个工具,你真的可以毫不费力地创建和加密 tar 归档文件。

在这篇文章中,我们将了解如何使用 OpenSSL 创建和加密 tar 或 gz(gzip,另一种压缩文件)归档文件:
牢记使用 OpenSSL 的常规方式是:
```
# openssl command command-options arguments
```
### 在 Linux 中加密文件
要加密当前工作目录的内容(根据文件的大小,这可能需要一点时间):
```
# tar -czf - * | openssl enc -e -aes256 -out secured.tar.gz
```
上述命令的解释:
1. `enc` - openssl 命令使用加密进行编码
2. `-e` – 用来加密输入文件的 `enc` 命令选项,这里是指前一个 tar 命令的输出
3. `-aes256` – 加密用的算法
4. `-out` – 用于指定输出文件名的 `enc` 命令选项,这里文件名是 `secured.tar.gz`
### 在 Linux 中解密文件
要解密上述 tar 归档内容,使用以下命令。
```
# openssl enc -d -aes256 -in secured.tar.gz | tar xz -C test
```
上述命令的解释:
1. `-d` – 用于解密文件
2. `-C` – 提取内容到 `test` 子目录
下图展示了加解密过程,以及当你尝试执行以下操作时会发生什么:
1. 以传统方式提取 tar 包的内容
2. 使用了错误的密码的时候
3. 当你输入正确的密码的时候

*在 Linux 中加密和解密 Tar 归档文件*
当你在本地网络或因特网工作的时候,你可以随时通过加密来保护你和他人共享的重要文本或文件,这有助于降低将其暴露给恶意攻击者的风险。
我们研究了一种使用 OpenSSL(一个 openssl 命令行工具)加密 tar 包的简单技术,你可以参考它的<ruby> 手册页 <rp> ( </rp> <rt> man page </rt> <rp> ) </rp></ruby>来获取更多信息和有用的命令。
---
via: <http://www.tecmint.com/encrypt-decrypt-files-tar-openssl-linux/>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[OneNewLife](https://github.com/OneNewLife) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,949 | 在 Linux 下使用 TCP 封装器来加强网络服务安全 | http://www.tecmint.com/secure-linux-tcp-wrappers-hosts-allow-deny-restrict-access/ | 2016-11-11T10:24:00 | [
"TCP wrapper"
] | https://linux.cn/article-7949-1.html | 在这篇文章中,我们将会讲述什么是 <ruby> TCP 封装器 <rp> ( </rp> <rt> TCP wrappers </rt> <rp> ) </rp></ruby>以及如何在一台 Linux 服务器上配置他们来[限制网络服务的权限](/article-7719-1.html)。在开始之前,我们必须澄清 TCP 封装器并不能消除对于正确[配置防火墙](/article-4425-1.html)的需要。
就这一点而言,你可以把这个工具看作是一个[基于主机的访问控制列表](/article-3966-1.html),而且并不能作为你的系统的[终极安全措施](http://www.tecmint.com/linux-server-hardening-security-tips/)。通过使用一个防火墙和 TCP 封装器,而不是只偏爱其中的一个,你将会确保你的服务不会被出现单点故障。

### 正确理解 hosts.allow 和 hosts.deny 文件
当一个网络请求到达你的主机的时候,TCP 封装器会使用 `hosts.allow` 和 `hosts.deny` (按照这样的顺序)来决定客户端是否应该被允许使用一个提供的服务。.
在默认情况下,这些文件内容是空的,或者被注释掉,或者根本不存在。所以,任何请求都会被允许通过 TCP 过滤器而且你的系统被置于依靠防火墙来提供所有的保护。因为这并不是我们想要的。由于在一开始我们就介绍过的原因,清确保下面两个文件都存在:
```
# ls -l /etc/hosts.allow /etc/hosts.deny
```
两个文件的编写语法规则是一样的:
```
<services> : <clients> [: <option1> : <option2> : ...]
```
在文件中,
1. `services` 指当前规则对应的服务,是一个逗号分割的列表。
2. `clients` 指被规则影响的主机名或者 IP 地址,逗号分割的。下面的通配符也可以接受:
1. `ALL` 表示所有事物,应用于`clients`和`services`。
2. `LOCAL` 表示匹配在正式域名中没有完全限定主机名(FQDN)的机器,例如 `localhost`。
3. `KNOWN` 表示主机名,主机地址,或者用户是已知的(即可以通过 DNS 或其它服务解析到)。
4. `UNKNOWN` 和 `KNOWN` 相反。
5. `PARANOID` 如果进行反向 DNS 查找彼此返回了不同的地址,那么连接就会被断开(首先根据 IP 去解析主机名,然后根据主机名去获得 IP 地址)。
3. 最后,一个冒号分割的动作列表表示了当一个规则被触发的时候会采取什么操作。
你应该记住 `/etc/hosts.allow` 文件中允许一个服务接入的规则要优先于 `/etc/hosts.deny` 中的规则。另外还有,如果两个规则应用于同一个服务,只有第一个规则会被纳入考虑。
不幸的是,不是所有的网络服务都支持 TCP 过滤器,为了查看一个给定的服务是否支持他们,可以执行以下命令:
```
# ldd /path/to/binary | grep libwrap
```
如果以上命令执行以后得到了以下结果,那么它就可以支持 TCP 过滤器,`sshd` 和 `vsftpd` 作为例子,输出如下所示。

*查找 TCP 过滤器支持的服务*
### 如何使用 TCP 过滤器来限制服务的权限
当你编辑 `/etc/hosts.allow` 和 `/etc/hosts.deny` 的时候,确保你在最后一个非空行后面通过回车键来添加一个新的行。
为了使得 [SSH 和 FTP](http://www.tecmint.com/block-ssh-and-ftp-access-to-specific-ip-and-network-range/) 服务只允许 `localhost` 和 `192.168.0.102` 并且拒绝所有其他用户,在 `/etc/hosts.deny` 添加如下内容:
```
sshd,vsftpd : ALL
ALL : ALL
```
而且在 `/etc/hosts.allow` 文件中添加如下内容:
```
sshd,vsftpd : 192.168.0.102,LOCAL
```
这些更改会立刻生效并且不需要重新启动。
在下图中你会看到,在最后一行中删掉 `LOCAL` 后,FTP 服务器会对于 `localhost` 不可用。在我们添加了通配符以后,服务又变得可用了。

*确认 FTP 权限*
为了允许所有服务对于主机名中含有 `example.com` 都可用,在 `hosts.allow` 中添加如下一行:
```
ALL : .example.com
```
而为了禁止 `10.0.1.0/24` 的机器访问 `vsftpd` 服务,在 `hosts.deny` 文件中添加如下一行:
```
vsftpd : 10.0.1.
```
在最后的两个例子中,注意到客户端列表每行开头和结尾的**点**。这是用来表示 “所有名字或者 IP 中含有那个字符串的主机或客户端”
这篇文章对你有用吗?你有什么问题或者评论吗?请你尽情在下面留言交流。
---
via: <http://www.tecmint.com/secure-linux-tcp-wrappers-hosts-allow-deny-restrict-access/>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[LinuxBars](https://linuxbar.org/) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,950 | 拥有开源项目部门的公司可以从四个方面获益 | https://opensource.com/business/16/9/4-big-ways-companies-benefit-having-open-source-program-offices | 2016-11-11T12:48:13 | [
"开源"
] | /article-7950-1.html | 
在我的第一篇关于<ruby> 开源项目部门 <rp> ( </rp> <rt> program office </rt> <rp> ) </rp></ruby>的系列文章中,我深入剖析了[什么是开源项目部门,为什么你的公司需要一个开源项目部门](https://opensource.com/business/16/5/whats-open-source-program-office)。接着我又说到了[谷歌是如何创建一种新的开源项目部门的](https://opensource.com/business/16/8/google-open-source-program-office)。而这篇文章,我将阐述拥有一个开源项目部门的好处。
乍一看,非软件开发公司会更加热情的去拥抱开源项目部门的一个重要原因是他们并没有什么损失。毕竟,他们并不需要依靠这些软件产品来获得收益。比如,Facebook 可以很轻易的释放出一个 “分布式键值数据存储” 作为开源项目,是因为他们并没有售卖一个叫做 “企业级键值数据存储” 的产品。这回答了关于风险的问题,但是并没有回答他们如何通过向开源生态共献代码而获益的问题。让我们逐个来推测和探讨其中可能的原因。你会发现开源项目供应商的许多动机都是相同的,但是也有些许不同。
### 招聘
招聘可能是一个将开源项目部门推销给上层管理部门的最容易方法。向他们展示与招聘相关的成本,以及投资回报率,然后解释如何与天才工程师发展关系,从而与那些对这些项目感兴趣并且十分乐意在其中工作的天才开发者们建立联系。不需要我多说了,你懂的!
### 技术影响
曾几何时,那些没有专门从事软件销售的公司是难以直接对他们软件供应商的开发周期施加影响力的,尤其当他们并不是一个大客户时。开源完全改变了这一点,它将用户与供应商放在了一个更公平的竞争环境中。随着开源开发的兴起,任何人,假如他们愿意投入时间和资源的话,都可以将技术推向一个选定的方向。但是这些公司发现,虽然将投资用于开发上会带来丰硕的成果,但是总体战略的努力却更加有效——对比一下 bug 的修复和软件的构建——大多数公司都将 bug 的修复推给上游的开源项目,但是一些公司开始认识到通过更深层次的回报承诺和更快的功能开发来协调持久的工作,将会更有利于业务。通过开源项目部门模式,公司的职员能够从开源社区中准确嗅出战略重心,然后投入开发资源。
对于快速增长的公司,如 Google 和 Facebook,其对现有的开源项目提供的领导力仍然不足以满足业务的膨胀。面对激烈的增长和建立超大规模系统所带来的挑战,许多大型企业开始构建仅供内部使用的高度定制的软件栈。除非他们能说服别人在一些基础设施项目上达成合作。因此,虽然他们保持在诸如 Linux 内核,Apache 和其他现有项目领域的投资,他们也开始推出自己的大型项目。Facebook 发布了 Cassandra,Twitter 创造了 Mesos,并且甚至谷歌也创建了 Kubernetes 项目。这些项目已成为行业创新的主要平台,证实了该举措是相关公司引人注目的成功。(请注意,Facebook 在它需要创造一个新软件项目来解决更大规模的问题之后,已经在内部停止使用 Cassandra 了,但是,这时 Cassandra 已经变得流行,而 DataStax 公司接过了开发任务)。所有这些项目已经促使了开发商、相关的项目、以及最终用户构成的整个生态加速增长和发展。
没有与公司战略举措取得一致的开源项目部门不可能成功的。不这样做的话,这些公司依然会试图单独地解决这些问题,而且更慢。不仅拥有这些项目可以帮助内部解决业务问题,它们也帮助这些公司逐渐成为行业巨头。当然,谷歌成为行业巨头好多年了,但是 Kubernetes 的发展确保了软件的质量,并且在容器技术未来的发展方向上有着直接的话语权,并且远超之前就有的话语权。这些公司目前还是闻名于他们超大规模的基础设施和硅谷的中坚份子。鲜为人知,但是更为重要的是它们与技术生产人员的亲密度。开源项目部门凭借技术建议和与有影响力的开发者的关系,再加上在社区治理和人员管理方面深厚的专业知识来引领这些工作,并最大限度地发挥其影响力,
### 市场营销能力
与技术的影响齐头并进的是每个公司谈论他们在开源方面的努力。通过传播这些与项目和社区有关的消息,一个开源项目部门能够通过有针对性的营销活动来提供最大的影响。营销在开放源码领域一直是一个肮脏的词汇,因为每个人都有一个由企业营销造成的糟糕的经历。在开源社区中,营销呈现出一种与传统方法截然不同的形式,它会更注重于我们的社区已经在战略方向上做了什么。因此,一个开源项目部门不可能去宣传一些根本还没有发布任何代码的项目,但是他们会讨论他们创造什么软件和参与了其他什么举措。基本上,不会有“雾件(vaporware)”。
想想谷歌的开源项目部门作出的第一份工作。他们不只是简单的贡献代码给 Linux 内核或其他项目,他们更多的是谈论它,并经常在开源会议主题演讲。他们不仅仅是把钱给写开源代码的代码的学生,他们还创建了一个全球计划——“Google Summer of Code”,现在已经成为一种开源发展的文化试金石。这些市场营销的作用在 Kubernetes 开发完成之前就奠定了谷歌在开源世界巨头的地位。最终使得,谷歌在创建 GPLv3 授权协议期间拥有重要影响力,并且在科技活动中公司的发言人和开源项目部门的代表人成为了主要人物。开源项目部门是协调这些工作的最好的实体,并可以为母公司提供真正的价值。
### 改善内部流程
改善内部流程听起来不像一个大好处,但克服混乱的内部流程对于每一个开源项目部门都是一个挑战,不论是对软件供应商还是公司内的部门。而软件供应商必须确保他们的流程不与他们发布的产品重叠(例如,不小心开源了他们的商业售卖软件),用户更关心的是侵犯了知识产权(IP)法:专利、版权和商标。没有人想只是因为释放软件而被起诉。没有一个活跃的开源项目部门去管理和协调这些许可和其他法律问题的话,大公司在开源流程和管理上会面临着巨大的困难。为什么这个很重要呢?如果不同的团队释放的软件是在不兼容的许可证下,那么这不仅是一个坑爹的尴尬,它还将对实现最基本的目标改良协作产生巨大的障碍。
考虑到还有许多这样的公司仍在飞快的增长,如果无法建立基本流程规则的话,将可以预见到它们将会遇到阻力。我见过一个罗列着批准、未经批准的许可证的巨大的电子表格,以及指导如何(或如何不)创建开源社区而遵守法律限制。关键是当开发者需要做出决定时要有一个可以依据的东西,并且每次当开发人员想要为一个开源社区贡献代码时,可以不产生大量的法律开销,和效率低下的知识产权检查。
有一个活跃的开放源码项目部门,负责维护许可规则和源的贡献,以及建立培训项目工程师,有助于避免潜在的法律缺陷和昂贵的诉讼。毕竟,良好的开源项目合作可以减少由于某人没有看许可证而导致公司赔钱这样的事件。好消息是,公司已经可以较少的担心关于专有的知识产权与软件供应商冲突的事。坏消息是,它们的法律问题不够复杂,尤其是当他们需要直接面对软件供应商的阻力时。
你的组织是如何受益于拥有一个开源项目部门的?可以在评论中与我们分享。
*本文作者 John Mark Walker 是 Dell EMC 的产品管理总监,负责管理 ViPR 控制器产品及 CoprHD 开源社区。他领导过包括 ManageIQ 在内的许多开源社区。*
---
via: <https://opensource.com/business/16/9/4-big-ways-companies-benefit-having-open-source-program-offices>
作者:[John Mark Walker](https://opensource.com/users/johnmark) 译者:[chao-zhi](https://github.com/chao-zhi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | HTTPSConnectionPool(host='opensource.com', port=443): Read timed out. (read timeout=10) | null |
7,951 | 轻轻几个点击,在 AWS 和 Azure 上搭建 Docker 数据中心 | https://blog.docker.com/2016/06/docker-datacenter-aws-azure-cloud/ | 2016-11-11T18:02:00 | [
"Azure",
"AWS",
"数据中心",
"Docker"
] | https://linux.cn/article-7951-1.html | 通过几个点击即可在 “AWS 快速起步”和“Azure 市场”上高效搭建产品级 Docker 数据中心。
通过 AWS 快速起步的 CloudFormation 模板和在 Azure 市场上的预编译模板来部署 Docker 数据中心使得比以往在公有云基础设施下的部署企业级的 CaaS Docker 环境更加容易。
Docker 数据中心 CaaS 平台为各种规模的企业的敏捷应用部署提供了容器和集群的编排和管理,使之更简单、安全和可伸缩。使用新为 Docker 数据中心预编译的云模板,开发者和 IT 运维人员可以无缝的把容器化的应用迁移到亚马逊 EC2 或者微软的 Azure 环境而无需修改任何代码。现在,企业可以快速实现更高的计算和运营效率,可以通过短短几步操作实现支持 Docker 的容器管理和编排。

### 什么是 Docker 数据中心?
Docker 数据中心包括了 <ruby> Docker 通用控制面板 <rp> ( </rp> <rt> Docker Universal Control Plane </rt> <rp> ) </rp></ruby>(UCP),<ruby> Docker 可信注册库 <rp> ( </rp> <rt> Docker Trusted Registry </rt> <rp> ) </rp></ruby>(UTR)和<ruby> 商用版 Docker 引擎 <rp> ( </rp> <rt> CS Docker Engine </rt> <rp> ) </rp></ruby>,并带有与客户的应用服务等级协议相匹配的商业支持服务。
* Docker 通用控制面板(UCP),一种企业级的集群管理方案,帮助客户通过单个管理面板管理整个集群
* Docker 可信注册库(DTR), 一种镜像存储管理方案,帮助客户安全存储和管理 Docker 镜像
* 商用版的 Docker 引擎

### 在 AWS 上快速布置 Docker 数据中心
秉承 Docker 与 AWS 最佳实践,参照 AWS 快速起步教程来,你可以在 AWS 云上快速部署 Docker 容器。Docker 数据中心快速起步基于模块化和可定制的 CloudFormation 模板,客户可以在其之上增加额外功能或者为自己的 Docker 部署修改模板。
* [AWS 的 Docker 数据中心应用说明](https://youtu.be/aUx7ZdFSkXU)
#### 架构

AWS Cloudformation 的安装过程始于创建 AWS 资源,这些 AWS 需要的资源包括:VPC、安全组、公有与私有子网、因特网网关、NAT 网关与 S3 bucket。
然后,AWS Cloudformation 启动第一个 UCP 控制器实例,紧接着,安装 Docker 引擎和 UCP 容器。它把第一个 UCP 控制器创建的根证书备份到 S3。一旦第一个 UCP 控制器成功运行,其他 UCP 控制器、UCP 集群节点和第一个 DTR 复制的进程就会被触发。和第一个 UCP 控制器节点类似,其他所有节点创建进程也都由商用版 Docker 引擎开始,然后安装并运行 UCP 和 DTR 容器以加入集群。两个弹性负载均衡器(ELB),一个分配给 UCP,另外一个为 DTR 服务,它们启动并自动完成配置来在两个可用区(AZ)之间提供弹性负载均衡。
除这些之外,如有需要,UCP 控制器和节点在 ASG 中启动并提供扩展功能。这种架构确保 UCP 和 DTR 两者都部署在两个 AZ 上以增强弹性与高可靠性。在公有或者私有 HostedZone 上,Route53 用来动态注册或者配置 UCP 和 DTR。

#### 快速起步模板的核心功能如下:
* 创建 VPC、不同 AZ 上的私有和公有子网、ELB、NAT 网关、因特网网关、自动伸缩组,它们全部基于 AWS 最佳实践
* 为 DDC 创建一个 S3 bucket,其用于证书备份和 DTR 映像存储(DTR 需要额外配置)
* 在客户的 VPC 范畴,跨多 AZ 部署 3 个 UCP 控制器
* 创建预配置正常检测的 UCP ELB
* 创建一个 DNS 记录并关联到 UCP ELB
* 创建可伸缩的 UCP 节点集群
* 在 VPC 范畴内,跨多 AZ 创建 3 个 DTR 副本
* 创建一个预配置正常检测的 DTR
* 创建一个 DNS 记录,并关联到 DTR ELB
* [下载 AWS 快速指南](https://s3.amazonaws.com/quickstart-reference/docker/latest/doc/docker-datacenter-on-the-aws-cloud.pdf)
### 在 AWS 使用 Docker 数据中心
1. 登录 [Docker Store](https://store.docker.com/login?next=%2Fbundles%2Fdocker-datacenter%2Fpurchase?plan=free-trial) 获取 [30 天免费试用](https://store.docker.com/login?next=%2Fbundles%2Fdocker-datacenter%2Fpurchase?plan=free-trial)或者[联系销售](https://goto.docker.com/contact-us.html)
2. 确认之后,看到提示“Launch Stack”后,客户会被重定向到 AWS Cloudformation 入口
3. 确认启动 Docker 的 AWS 区域
4. 提供启动参数
5. 确认并启动
6. 启动完成之后,点击输出标签可以看到 UCP/DTR 的 URL、缺省用户名、密码和 S3 bucket 的名称
* [Docker 数据中心需要 2000 美刀信用担保](https://aws.amazon.com/mp/contactdocker/)
### 在 Azure 使用 Azure 市场的预编译模板部署
在 Azure 市场上,Docker 数据中心是一个预先编译的模板,客户可以在 Azure 横跨全球的数据中心即起即用。客户可以根据自己需求从 Azure 提供的各种 VM 中选择适合自己的 VM 部署 Docker 数据中心。
#### 架构

Azure 部署过程始于输入一些基本用户信息,如 ssh 登录的管理员用户名(系统级管理员)和资源组名称。你可以把资源组理解为一组有生命周期和部署边界的资源集合。你可以在这个链接了解更多关于资源组的信息:<http://azure.microsoft.com/en-us/documentation/articles/resource-group-overview/> 。
下一步,输入集群详细信息,包括:UCP 控制器 VM 大小、控制器个数(缺省为 3 个)、UCP 节点 VM 大小、UCP 节点个数(缺省 1,最大值为 10)、DTR 节点 VM 大小、DTR 节点个数、虚拟网络名和地址(例如:10.0.0.1/19)。关于网络,客户可以配置 2 个子网:第一个子网分配给 UCP 控制器 ,第二个分配给 DTC 和 UCP 节点。
最后,点击 OK 完成部署。对于小集群,服务开通需要大约 15-19 分钟,大集群更久些。


#### 如何在 Azure 部署
1. 注册 [Docker 数据中心 30 天试用](https://store.docker.com/login?next=%2Fbundles%2Fdocker-datacenter%2Fpurchase?plan=free-trial)许可或者[联系销售](https://goto.docker.com/contact-us.html)
2. [跳转到微软 Azure 市场的 Docker 数据中心](https://azure.microsoft.com/en-us/marketplace/partners/docker/dockerdatacenterdocker-datacenter/)
3. [查看部署文档](https://success.docker.com/Datacenter/Apply/Docker_Datacenter_on_Azure)
---
通过注册获取 Docker 数据中心许可证开始,然后你就能够通过 AWS 或者 Azure 模板搭建自己的数据中心。
* [获取 30 天试用许可证](http://www.docker.com/trial)
* [通过视频理解 Docker 数据中心架构](https://www.youtube.com/playlist?list=PLkA60AVN3hh8tFH7xzI5Y-vP48wUiuXfH)
* [观看演示视频](https://www.youtube.com/playlist?list=PLkA60AVN3hh8a8JaIOA5Q757KiqEjPKWr)
* [获取 AWS 提供的部署 Docker 数据中心的 75 美元红包奖励](https://aws.amazon.com/quickstart/promo/)
了解有关 Docker 的更多信息:
* 初识 Docker? 尝试一下 10 分钟[在线学习课程](https://docs.docker.com/engine/understanding-docker/)
* 分享镜像,自动构建,或用一个[免费的 Docker Hub 账号](https://hub.docker.com/)尝试更多
* 阅读 [Docker 1.12 发行说明](https://docs.docker.com/release-notes/)
* 订阅 [Docker Weekly](https://www.docker.com/subscribe_newsletter/)
* 报名参加即将到来的 [Docker Online Meetups](http://www.meetup.com/Docker-Online-Meetup/)
* 参加即将发生的 [Docker Meetups](https://www.docker.com/community/meetup-groups)
* 观看 [DockerCon EU2015](https://www.youtube.com/playlist?list=PLkA60AVN3hh87OoVra6MHf2L4UR9xwJkv)视频
* 开始为 [Docker](https://docs.docker.com/contributing/contributing/) 贡献力量
---
via: <https://blog.docker.com/2016/06/docker-datacenter-aws-azure-cloud/>
作者:[Trisha McCanna](https://blog.docker.com/author/trisha/) 译者:[firstadream](https://github.com/firstadream) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,952 | 98% 的开发者在工作中使用了开源软件 | http://opensourceforu.com/2016/11/98-percent-developers-use-open-source-at-work/ | 2016-11-12T16:38:40 | [
"开发人员"
] | https://linux.cn/article-7952-1.html | 
开源每天都会达到新的高度。但是一个新的研究表明超过 98% 的开发者在工作中使用开源工具。
Git 仓库管理软件 [GitLab](https://about.gitlab.com/2016/11/02/global-developer-survey-2016/) 进行了一项调查披露了一些关于开源接受度的有趣事实。针对开发人员群体的调查表明 98% 的开发者更喜欢在工作中使用开源,91% 选择在工作和个人项目中选择使用相同的开发工具。此外,92% 的人认为分布式版本控制系统(Git 仓库)在工作中很重要。
在所有的偏好编程语言中,JavaScript 占了 51% 的受访者比例。它后面是 Python、PHP、Java、Swift 和Objective-C。86% 的开发者认为安全是代码的主要判断标准。
GitLab 首席执行官兼联合创始人 Sid Sijbrandij 在一次声明中表示:“尽管过程驱动的开发技术在过去已经取得了成功,但开发人员正在寻找一种更自然的软件开发革新以促进项目生命周期内的协作和信息共享。”
这份报告来自 GitLab 在 7 月 6 日和 27 日之间对使用其存储库平台的 362 家初创企业和企业的 CTO、开发人员和 DevOps 专业人士的调查。
---
via: <http://opensourceforu.com/2016/11/98-percent-developers-use-open-source-at-work/>
作者:[JAGMEET SINGH](http://opensourceforu.com/author/jagmeet-singh/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,953 | 用 dpkg 命令在 Debian 系的 Linux系统中管理软件包 | http://www.2daygeek.com/dpkg-command-examples/ | 2016-11-12T17:40:57 | [
"dpkg",
"包管理器"
] | https://linux.cn/article-7953-1.html | [dpkg](https://wiki.debian.org/Teams/Dpkg) 意即 <ruby> Debian 包管理器 <rp> ( </rp> <rt> Debian PacKaGe manager </rt> <rp> ) </rp></ruby>。dpkg 是一个可以安装、构建、删除及管理 Debian 软件包的命令行工具。dpkg 将 Aptitude(首选而更用户友好)作为执行所有操作的前端界面。

其它的一些工具如 dpkg-deb 和 dpkg-query 等也使用 dpkg 作为执行某些操作的前端。
现在大多数系统管理员使用 Apt、[Apt-Get](http://www.2daygeek.com/apt-get-apt-cache-command-examples/) 及 Aptitude 等工具,不用费心就可以轻松地管理软件。
尽管如此,必要的时候还是需要用 dpkg 来安装某些软件。其它的一些在 Linux 系统上广泛使用的包管理工具还有 [yum](/article-2272-1.html)、[dnf](/article-5718-1.html)、[apt-get](/article-4933-1.html)、[rpm](/article-7455-1.html)、[Zypper](/article-5606-1.html)、pacman、urpmi 等等。
现在,我要在装有 Ubuntu 15.10 的机器上用一些实例讲解最常用的 dpkg 命令。
### 1) dpkg 常见命令的语法及 dpkg 文件位置
下面是 dpkg 常见命令的语法及 dpkg 相关文件的位置,如果想深入了解,这些对你肯定大有益处。
```
### dpkg 命令的语法
$ dpkg -[command] [.deb package name]
$ dpkg -[command] [package name]
### dpkg 相关文件的位置
$ /var/lib/dpkg
### 这个文件包含了被 dpkg 命令(install、remove 等)所修改的包的信息
$ /var/lib/dpkg/status
### 这个文件包含了可用包的列表
$ /var/lib/dpkg/status
```
### 2) 安装/升级软件
在基于 Debian 的系统里,比如 Debian、Mint、Ubuntu 和 elementryOS,用以下命令来安装/升级 .deb 软件包。这里我要用 `atom-amd64.deb` 文件安装 Atom。要是已经安装了 Atom,就会升级它。要么就会安装一个新的 Atom。
```
### 安装或升级 dpkg 软件包
$ sudo dpkg -i atom-amd64.deb
Selecting previously unselected package atom.
(Reading database ... 426102 files and directories currently installed.)
Preparing to unpack atom-amd64.deb ...
Unpacking atom (1.5.3) over (1.5.3) ...
Setting up atom (1.5.3) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu1) ...
Processing triggers for bamfdaemon (0.5.2~bzr0+15.10.20150627.1-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
Processing triggers for mime-support (3.58ubuntu1) ...
```
### 3) 从文件夹里安装软件
在基于 Debian 的系统里,用下列命令从目录中逐个安装软件。这会安装 `/opt/software` 目录下的所有以 .deb 为后缀的软件。
```
$ sudo dpkg -iR /opt/software
Selecting previously unselected package atom.
(Reading database ... 423303 files and directories currently installed.)
Preparing to unpack /opt/software/atom-amd64.deb ...
Unpacking atom (1.5.3) ...
Setting up atom (1.5.3) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu1) ...
Processing triggers for bamfdaemon (0.5.2~bzr0+15.10.20150627.1-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
Processing triggers for mime-support (3.58ubuntu1) ...
```
### 4) 显示已安装软件列表
以下命令可以列出 Debian 系的系统中所有已安装的软件,同时会显示软件版本和描述信息。
```
$ dpkg -l
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===========================-==================================-============-================================================================
ii account-plugin-aim 3.12.10-0ubuntu2 amd64 Messaging account plugin for AIM
ii account-plugin-facebook 0.12+15.10.20150723-0ubuntu1 all GNOME Control Center account plugin for single signon - facebook
ii account-plugin-flickr 0.12+15.10.20150723-0ubuntu1 all GNOME Control Center account plugin for single signon - flickr
ii account-plugin-google 0.12+15.10.20150723-0ubuntu1 all GNOME Control Center account plugin for single signon
ii account-plugin-jabber 3.12.10-0ubuntu2 amd64 Messaging account plugin for Jabber/XMPP
ii account-plugin-salut 3.12.10-0ubuntu2 amd64 Messaging account plugin for Local XMPP (Salut)
.
.
```
### 5) 查看指定的已安装软件
用以下命令列出指定的一个已安装软件,同时会显示软件版本和描述信息。
```
$ dpkg -l atom
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==========-=========-===================-============================================
ii atom 1.5.3 amd64 A hackable text editor for the 21st Century.
```
### 6) 查看软件安装目录
以下命令可以在基于 Debian 的系统上查看软件的安装路径。
```
$ dpkg -L atom
/.
/usr
/usr/bin
/usr/bin/atom
/usr/share
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/atom
/usr/share/pixmaps
/usr/share/pixmaps/atom.png
/usr/share/doc
```
### 7) 查看 deb 包内容
下列命令可以查看 deb 包内容。它会显示 .deb 包中的一系列文件。
```
$ dpkg -c atom-amd64.deb
drwxr-xr-x root/root 0 2016-02-13 02:13 ./
drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/
drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/bin/
-rwxr-xr-x root/root 3067 2016-02-13 02:13 ./usr/bin/atom
drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/
drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/lintian/
drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/lintian/overrides/
-rw-r--r-- root/root 299 2016-02-13 02:13 ./usr/share/lintian/overrides/atom
drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/pixmaps/
-rw-r--r-- root/root 643183 2016-02-13 02:13 ./usr/share/pixmaps/atom.png
drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/doc/
.
.
```
### 8) 显示软件的详细信息
以下命令可以显示软件的详细信息,如软件名、软件类别、版本、维护者、软件架构、依赖的软件、软件描述等等。
```
$ dpkg -s atom
Package: atom
Status: install ok installed
Priority: optional
Section: devel
Installed-Size: 213496
Maintainer: GitHub <[email protected]>Architecture: amd64
Version: 1.5.3
Depends: git, gconf2, gconf-service, libgtk2.0-0, libudev0 | libudev1, libgcrypt11 | libgcrypt20, libnotify4, libxtst6, libnss3, python, gvfs-bin, xdg-utils, libcap2
Recommends: lsb-release
Suggests: libgnome-keyring0, gir1.2-gnomekeyring-1.0
Description: A hackable text editor for the 21st Century.
Atom is a free and open source text editor that is modern, approachable, and hackable to the core.</[email protected]>
```
### 9) 查看文件属于哪个软件
用以下命令来查看文件属于哪个软件。
```
$ dpkg -S /usr/bin/atom
atom: /usr/bin/atom
```
### 10) 移除/删除软件
以下命令可以用来移除/删除一个已经安装的软件,但不删除配置文件。
```
$ sudo dpkg -r atom
(Reading database ... 426404 files and directories currently installed.)
Removing atom (1.5.3) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu1) ...
Processing triggers for bamfdaemon (0.5.2~bzr0+15.10.20150627.1-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
Processing triggers for mime-support (3.58ubuntu1) ...
```
### 11) 清除软件
以下命令可以用来移除/删除包括配置文件在内的所有文件。
```
$ sudo dpkg -P atom
(Reading database ... 426404 files and directories currently installed.)
Removing atom (1.5.3) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu1) ...
Processing triggers for bamfdaemon (0.5.2~bzr0+15.10.20150627.1-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
Processing triggers for mime-support (3.58ubuntu1) ...
```
### 12) 了解更多
用以下命令来查看更多关于 dpkg 的信息。
```
$ dpkg -help
或
$ man dpkg
```
开始体验 dpkg 吧。
---
via: <http://www.2daygeek.com/dpkg-command-examples/>
作者:[MAGESH MARUTHAMUTHU](http://www.2daygeek.com/author/magesh/) 译者:[GitFuture](https://github.com/GitFuture) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,954 | 删除一个目录下部分类型之外的所有文件的三种方法 | http://www.tecmint.com/delete-all-files-in-directory-except-one-few-file-extensions/ | 2016-11-13T17:08:25 | [
"文件",
"删除"
] | https://linux.cn/article-7954-1.html | 有的时候,你可能会遇到这种情况,你需要删除一个目录下的所有文件,或者只是简单的通过删除除了一些指定类型(以指定扩展名结尾)之外的文件来清理一个目录。
在这篇文章,我们将会向你展现如何通过 `rm`、 `find` 和 `globignore` 命令删除一个目录下除了指定文件扩展名或者类型的之外的文件。

在我们进一步深入之前,让我们开始简要的了解一下 Linux 中的一个重要的概念 —— 文件名模式匹配,它可以让我们解决眼前的问题。
在 Linux 下,一个 shell 模式是一个包含以下特殊字符的字符串,称为通配符或者元字符:
1. `*` – 匹配 0 个或者多个字符
2. `?` – 匹配任意单个字符
3. `[序列]` – 匹配序列中的任意一个字符
4. `[!序列]` – 匹配任意一个不在序列中的字符
我们将在这儿探索三种可能的办法,包括:
### 使用扩展模式匹配操作符删除文件
下来列出了不同的扩展模式匹配操作符,这些模式列表是一个用 `|` 分割包含一个或者多个文件名的列表:
1. `*(模式列表)` – 匹配 0 个或者多个出现的指定模式
2. `?(模式列表)` – 匹配 0 个或者 1 个出现的指定模式
3. `@(模式列表)` – 匹配 1 个或者多个出现的指定模式
4. `!(模式列表)` – 匹配除了一个指定模式之外的任何内容
为了使用它们,需要像下面一样打开 extglob shell 选项:
```
# shopt -s extglob
```
**1. 输入以下命令,删除一个目录下除了 filename 之外的所有文件**
```
$ rm -v !("filename")
```

*删除 Linux 下除了一个文件之外的所有文件*
**2. 删除除了 filename1 和 filename2 之外的所有文件**
```
$ rm -v !("filename1"|"filename2")
```

*在 Linux 下删除除了一些文件之外的所有文件*
**3. 下面的例子显示如何通过交互模式删除除了 `.zip` 之外的所有文件**
```
$ rm -i !(*.zip)
```

*在 Linux 下删除除了 Zip 文件之外的所有文件*
**4. 接下来,通过如下的方式你可以删除一个目录下除了所有的`.zip` 和 `.odt` 文件的所有文件,并且在删除的时候,显示正在删除的文件:**
```
$ rm -v !(*.zip|*.odt)
```

*删除除了指定文件扩展的所有文件*
一旦你已经执行了所有需要的命令,你还可以使用如下的方式关闭 extglob shell 选项。
```
$ shopt -u extglob
```
### 使用 Linux 下的 find 命令删除文件
在这种方法下,我们可以[只使用 find 命令](http://www.tecmint.com/35-practical-examples-of-linux-find-command/)的适当的选项或者采用管道配合 `xargs` 命令,如下所示:
```
$ find /directory/ -type f -not -name 'PATTERN' -delete
$ find /directory/ -type f -not -name 'PATTERN' -print0 | xargs -0 -I {} rm {}
$ find /directory/ -type f -not -name 'PATTERN' -print0 | xargs -0 -I {} rm [options] {}
```
**5. 下面的命令将会删除当前目录下除了 `.gz` 之外的所有文件**
```
$ find . -type f -not -name '*.gz' -delete
```

*find 命令 —— 删除 .gz 之外的所有文件*
**6. 使用管道和 xargs,你可以通过如下的方式修改上面的例子:**
```
$ find . -type f -not -name '*gz' -print0 | xargs -0 -I {} rm -v {}
```

*使用 find 和 xargs 命令删除文件*
**7. 让我们看一个额外的例子,下面的命令行将会删除掉当前目录下除了 `.gz`、 `.odt` 和 `.jpg` 之外的所有文件:**
```
$ find . -type f -not \(-name '*gz' -or -name '*odt' -or -name '*.jpg' \) -delete
```

*删除除了指定扩展文件的所有文件*
### 通过 bash 中的 GLOBIGNORE 变量删除文件
然而,最后的方法,只适用于 bash。 `GLOBIGNORE` 变量存储了一个<ruby> 路径名展开 <rp> ( </rp> <rt> pathname expansion </rt> <rp> ) </rp></ruby>功能的忽略模式(或文件名)列表,以冒号分隔。
为了使用这种方法,切换到要删除文件的目录,像下面这样设置 `GLOBIGNORE` 变量:
```
$ cd test
$ GLOBIGNORE=*.odt:*.iso:*.txt
```
在这种情况下,除了 `.odt`、 `.iso` 和 `.txt` 之外的所有文件,都将从当前目录删除。
现在,运行如下的命令清空这个目录:
```
$ rm -v *
```
之后,关闭 `GLOBIGNORE` 变量:
```
$ unset GLOBIGNORE
```

*使用 bash 变量 GLOBIGNORE 删除文件*
注:为了理解上面的命令行采用的标识的意思,请参考我们在每一个插图中使用的命令对应的 man 手册。
就这些了!如果你知道有实现相同目录的其他命令行技术,不要忘了通过下面的反馈部分分享给我们。
---
via: <http://www.tecmint.com/delete-all-files-in-directory-except-one-few-file-extensions/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[yangmingming](https://github.com/yangmingming) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,955 | 2016 年 Linux 下五个最佳视频编辑软件 | https://itsfoss.com/best-video-editing-software-linux/ | 2016-11-14T08:55:00 | [
"视频"
] | https://linux.cn/article-7955-1.html | 
概要: 在这篇文章中,Tiwo 讨论了 Linux 下最佳视频编辑器的优缺点和在基于 Ubuntu 的发行版中的安装方法。
在过去,我们已经在类似的文章中讨论了 [Linux 下最佳图像管理应用软件](/article-7462-1.html),[Linux 上四个最佳的现代开源代码编辑器](/article-7468-1.html)。今天,我们来看看 Linux 下的最佳视频编辑软件。
当谈及免费的视频编辑软件,Windows Movie Maker 和 iMovie 是大多数人经常推荐的。
不幸的是,它们在 GNU/Linux 下都是不可用的。但是你不必担心这个,因为我们已经为你收集了一系列最佳的视频编辑器。
### Linux下最佳的视频编辑应用程序
接下来,让我们来看看 Linux 下排名前五的最佳视频编辑软件:
#### 1. Kdenlive

[Kdenlive](https://kdenlive.org/) 是一款来自于 KDE 的自由而开源的视频编辑软件,它提供双视频监视器、多轨时间轴、剪辑列表、可自定义的布局支持、基本效果和基本转换的功能。
它支持各种文件格式和各种摄像机和相机,包括低分辨率摄像机(Raw 和 AVI DV 编辑):mpeg2、mpeg4 和 h264 AVCHD(小型摄像机和摄像机);高分辨率摄像机文件,包括 HDV 和 AVCHD 摄像机;专业摄像机,包括 XDCAM-HD<sup> TM</sup> 流、IMX<sup> TM</sup> (D10)流、DVCAM(D10)、DVCAM、DVCPRO<sup> TM</sup> 、DVCPRO50<sup> TM</sup> 流和 DNxHD<sup> TM</sup> 流等等。
你可以在命令行下运行下面的命令安装 :
```
sudo apt-get install kdenlive
```
或者,打开 Ubuntu 软件中心,然后搜索 Kdenlive。
#### 2. OpenShot

[OpenShot](http://www.openshot.org/) 是我们这个 Linux 视频编辑软件列表中的第二选择。 OpenShot 可以帮助您创建支持过渡、效果、调整音频电平的电影,当然,它也支持大多数格式和编解码器。
您还可以将电影导出到 DVD,上传到 YouTube、Vimeo、Xbox 360 和许多其他常见的格式。 OpenShot 比 Kdenlive 更简单。 所以如果你需要一个简单界面的视频编辑器,OpenShot 会是一个不错的选择。
最新的版本是 2.0.7。您可以从终端窗口运行以下命令安装 OpenShot 视频编辑器:
```
sudo apt-get install openshot
```
它需要下载 25 MB,安装后需要 70 MB 硬盘空间。
#### 3. Flowblade Movie Editor

[Flowblade Movie Editor](http://jliljebl.github.io/flowblade/) 是一个用于 Linux 的多轨非线性视频编辑器。它是自由而开源的。 它配备了一个时尚而现代的用户界面。
它是用 Python 编写的,旨在提供一个快速、精确的功能。 Flowblade 致力于在 Linux 和其他自由平台上提供最好的体验。 所以现在没有 Windows 和 OS X 版本。
要在 Ubuntu 和其他基于 Ubuntu 的系统上安装 Flowblade,请使用以下命令:
```
sudo apt-get install flowblade
```
#### 4. Lightworks

如果你要寻找一个有更多功能的视频编辑软件,这会是答案。 [Lightworks](https://www.lwks.com/) 是一个跨平台的专业的视频编辑器,在 Linux、Mac OS X 和 Windows 系统下都可用。
它是一个获奖的专业的[非线性编辑](https://en.wikipedia.org/wiki/Non-linear_editing_system)(NLE)软件,支持高达 4K 的分辨率以及标清和高清格式的视频。
该应用程序有两个版本:Lightworks 免费版和 Lightworks 专业版。不过免费版本不支持 Vimeo(H.264 / MPEG-4)和 YouTube(H.264 / MPEG-4) - 高达 2160p(4K UHD)、蓝光和 H.264 / MP4 导出选项,以及可配置的位速率设置,但是专业版本支持。
* Lightworks 免费版
* Lightworks 专业版
专业版本有更多的功能,例如更高的分辨率支持,4K 和蓝光支持等。
##### 怎么安装Lightworks?
不同于其他的视频编辑器,安装 Lightwork 不像运行单个命令那么直接。别担心,这不会很复杂。
* 第1步 – 你可以从 [Lightworks 下载页面](https://www.lwks.com/index.php?option=com_lwks&view=download&Itemid=206)下载安装包。这个安装包大约 79.5MB。*请注意:这里没有32 位 Linux 的支持。*
* 第2步 – 一旦下载,你可以使用 [Gdebi 软件包安装器](https://itsfoss.com/gdebi-default-ubuntu-software-center/)来安装。Gdebi 会自动下载依赖关系 : 
* 第3步 – 现在你可以从 Ubuntu 仪表板或您的 Linux 发行版菜单中打开它。
* 第4步 – 当你第一次使用它时,需要一个账号。点击 “Not Registerd?” 按钮来注册。别担心,它是免费的。
* 第5步 – 在你的账号通过验证后,就可以登录了。
现在,Lightworks 可以使用了。
需要 Lightworks 的视频教程? 在 [Lightworks 视频教程页](https://www.lwks.com/videotutorials)得到它们。
#### 5. Blender

Blender 是一个专业的,工业级的开源、跨平台的视频编辑器。在 3D 作品的制作中,是非常受欢迎的。 Blender 已被用于几部好莱坞电影的制作,包括蜘蛛侠系列。
虽然最初是设计用于制作 3D 模型,但它也可以用于各种格式的视频编辑和输入能力。 该视频编辑器包括:
* 实时预览、亮度波形、色度矢量示波器和直方图显示
* 音频混合、同步、擦除和波形可视化
* 多达 32 个插槽用于添加视频、图像、音频、场景、面具和效果
* 速度控制、调整图层、过渡、关键帧、过滤器等
最新的版本可以从 [Blender 下载页](https://www.blender.org/download/)下载.
### 哪一个是最好的视频编辑软件?
如果你需要一个简单的视频编辑器,OpenShot、Kdenlive 和 Flowblade 是一个不错的选择。这些软件是适合初学者的,并且带有标准规范的系统。
如果你有一个高性能的计算机,并且需要高级功能,你可以使用 Lightworks。如果你正在寻找更高级的功能, Blender 可以帮助你。
这就是我写的 5 个最佳的视频编辑软件,它们可以在 Ubuntu、Linux Mint、Elementary 和其他 Linux 发行版下使用。 请与我们分享您最喜欢的视频编辑器。
---
via: <https://itsfoss.com/best-video-editing-software-linux/>
作者:[Tiwo Satriatama](https://itsfoss.com/author/tiwo/) 译者:[DockerChen](https://github.com/DockerChen) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | 

Looking for the **best video editing software for Linux? **You're at the perfect place.
We have focused on listing some of the **best free video editors** suitable for beginners and professionals.
**Some of the applications mentioned here are not open source. They have been included in the context of Linux usage.**
**Non-FOSS Warning!**If you want FOSS-only, please refer to this list of [open source video editors](https://itsfoss.com/open-source-video-editors/).
## 1. Kdenlive

- Cross-platform
- Multi-track video editing
- A wide range of audio and video format supported
- Configurable interface and shortcuts
- Plenty of effects and transitions
- Proxy editing
- Automatic save
- Good hardware support
- Keyframeable effects
[Kdenlive](https://kdenlive.org/) is a free and open-source video editing software from KDE that provides support for **dual video monitors, a multi-track timeline, clip list, customizable layout support, basic effects, and basic transitions.**
It supports a wide variety of file formats from a wide range of camcorders and cameras, including *raw, avi, dv, mpeg2, mpeg4, h.264, AVCHD, HDV*, and more.
It may not be the most modern user experience, but it offers **most of the essential features fit for beginners and professionals**.
**Pros**
- All-purpose video editor
- Not too complicated for those who are familiar with video editing
**Cons**
- It may still be confusing if you are looking for something basic
- KDE applications are infamous for being bloated
**Installing Kdenlive**
Kdenlive is available for all major Linux distributions. You can simply search for it in your software center. Various packages including **AppImage **and** Flatpak** are available in the [download section of Kdenlive website](https://kdenlive.org/download/).
You can also install it from the terminal for Debian and Ubuntu-based Linux distributions using the command below:
`sudo apt install kdenlive`
**Suggested Read 📖**
[7 Best Linux Photo Management SoftwareLooking for a replacement for the good-old Picasa on Linux? Take a look at best photo management applications available for Linux.](https://itsfoss.com/linux-photo-management-software/)

## 2. OpenShot

- Cross-platform support
- Support for a wide range of video, audio, and image formats
- Powerful curve-based Keyframe animations
- Desktop integration with drag and drop support
- Unlimited tracks or layers
- Video transitions with real-time previews
- 3D animated titles and effects
- Time-mapping and speed changes on clips
[OpenShot](https://www.openshot.org/) is another multipurpose video editor for Linux. OpenShot can help you create videos with transitions and effects, and adjust audio levels. Of course, it supports most formats and codecs.
OpenShot is a tad bit simpler than Kdenlive. So if you need **a video editor with a simple UI**, OpenShot is a good choice.
There is also a neat documentation to [get you started with OpenShot](https://www.openshot.org/user-guide/).
**Pros**
- All-purpose video editor for average video editing needs
**Cons**
- The user interface is simple, but it may take a bit of a learning curve if you are extremely new
- It may not be suitable for all kinds of professionals.
**Installing OpenShot**
OpenShot is also available in the repositories of all major Linux distributions. You can simply search for it in your software center. You can also get it from its [official website](https://www.openshot.org/download/).
My favorite way to install OpenShot is to use the following command on Debian and Ubuntu-based Linux distributions:
`sudo apt install openshot-qt`
## 3. Shotcut

- Cross-platform support
- Support for a wide range of video, audio, and image formats
- Native timeline editing
- Mix and match resolutions and frame rates within a project
- Multitrack timeline with thumbnails and waveforms
- Unlimited undo and redo for playlist edits, including a history view
- External monitoring on an extra system display/monitor
- Good hardware support
[Shotcut](https://www.shotcut.org/) is another video editor for Linux that can be put in the same league as Kdenlive and OpenShot. While it does provide similar features as the other two discussed above, Shotcut is a **bit more advanced, with support for 4K videos**.
Support for a number of audio and video formats, transitions, and effects are some of the numerous features of Shotcut. An external monitor is also supported here.
The user interface may not be easy to navigate around for new users. But, there is a collection of official video tutorials available to [get you started with Shotcut](https://www.shotcut.org/tutorials/).
**Pros**
- All-purpose video editor for common video editing needs
- Support for 4K videos
**Cons**
- Too many features reduce the simplicity of the software
**Installing Shotcut**
Shotcut is available as an AppImage, Snap, and as a Flatpak. You may not be able to get it from the official repositories, so those are your best options.
For other platforms, you can explore its [download page](https://www.shotcut.org/download/).
## 4. Flowblade

- Lightweight application
- Supports
[proxy editing](https://jliljebl.github.io/flowblade/webhelp/proxy.html) - Drag and drop support
- Support for a wide range of video, audio, and image formats
- Video transitions and filters
- Multitrack timeline with thumbnails and waveforms
[Flowblade](https://jliljebl.github.io/flowblade/) is a multitrack non-linear video editor for Linux. Like the above-discussed ones, this too is free and open-source software. It comes with a **stylish and modern user interface.**
Written in Python, it is designed to be fast and precise. Flowblade has focused on providing the **best possible experience on Linux as an exclusive**.
You also get a decent [documentation](https://jliljebl.github.io/flowblade/webhelp/help.html) to help you use all of its features.
**Pros**
- Lightweight
- Good for general purpose video editing
**Cons**
- Not available on other platforms
**Installing Flowblade**
Flowblade should be available in the repositories of all major Linux distributions. You can install it from the software center. More information is available on its [download page](https://jliljebl.github.io/flowblade/download.html).
To install Flowblade in Ubuntu and Ubuntu-based systems, use the command below:
`sudo apt install flowblade`
**Suggested Read 📖**
[8 Best Open Source Code Editors for LinuxLooking for the best text editors in Linux for coding? Here’s a list of the best code open source code editors for Linux.](https://itsfoss.com/best-modern-open-source-code-editors-for-linux/)

## 5. Lightworks
- Cross-platform
- Simple & intuitive User Interface
- Easy timeline editing & trimming
- Real-time ready to use audio & video FX
- Access amazing royalty-free audio & video content
- Lo-Res Proxy workflows for 4K
- Export video for YouTube/Vimeo, SD/HD, up to 4K
- Drag and drop support
- Wide variety of audio and video effects and filters
If you looking for video editing software that has more features, and fit for professional work, this is the answer. [Lightworks](https://www.lwks.com/) is a cross-platform professional video editor, available for Linux, macOS, and Windows.
It is a [non-linear editing](https://en.wikipedia.org/wiki/Non-linear_editing_system) (NLE) software that supports resolutions up to 4K as well as video in SD and HD formats.
Lightworks is available for Linux, however it is **not open source**.
This application has three versions:
**Lightworks Free****Lightworks Create****Lightworks Pro**
Pro version has more features, such as higher resolution support, 4K and Blue Ray support, etc.
Extensive documentation is available on its [website](https://www.lwks.com/index.php?option=com_lwks&view=download&Itemid=206&tab=4). You can also refer to videos at [Lightworks video tutorials page](https://www.lwks.com/videotutorials) to learn more.
**Pros**
- Professional, feature-rich video editor
**Cons**
- Limited free version
**Installing Lightworks**
You need to sign up for a free account to get started using Lightworks. It provides a DEB package to download and install.
You should follow its [official installation instructions](https://lwks.com/guides/how-to-install-and-uninstall-lightworks-for-linux/) to proceed.
## 6. Blender

[Blender](https://www.blender.org/) is a **professional, industry-grade, open source, cross-platform video editor**. It is popular for 3D works. Blender has been used in several Hollywood movies, including the Spider-Man series.
Although originally designed for 3D modeling, it can also be used for video editing and has input capabilities with a variety of formats.
**Pros**
- Cross-platform
- Professional grade editing
**Cons**
- Complicated
- Mainly for 3D animation, not focused on regular video editing
**Installing Blender**
You can find it on the official repositories. But, to get the latest version you should opt for Flatpak or other packages available from its [download page](https://www.blender.org/download/).
**Suggested Read 📖**
[Using Flatpak on Ubuntu and Other Linux Distributions [Complete Guide]Flatpak is a universal packaging format from Fedora. Enabling Flatpak will give you access to the easy installation of many Linux applications. Here’s how to use Flatpak in Ubuntu and other Linux distributions.](https://itsfoss.com/flatpak-guide/)

## 7. Cinelerra GG Infinity

- Advanced timeline.
- Motion tracking support.
- Video stabilization.
- Hardware acceleration.
- Allows background rendering over a network with several connected computers.
- HiDPI 4K Monitor Support.
- Keyframe Support.
Cinelerra is a decade-old popular open-source video editor. However, it has several branches (in other words – different versions). I am not sure if that is a good thing, but you get different features (and abilities) on each of them.
[Cinelerra GG](https://www.cinelerra-gg.org/) is the most actively maintained edition with modern features, with new features constantly added. The original edition is an ancient video editor which is no longer being maintained.
**Install Cinelerra GG**
You will not find this in the repositories. So, head to its official website to download the AppImage or any other supported package.
## 8. DaVinci Resolve

- High-performance playback engine
- Advanced Trimming
- Audio Overlays
- Multicam Editing allows editing footage from multiple cameras in real-time
- Timeline curve editor
- Non-linear editing for VFX
If you want film-grade video editing, use the tool the professionals use. [DaVinci Resolve](https://www.blackmagicdesign.com/products/davinciresolve/) from Blackmagic is what professionals are using for editing movies and tv shows.
Unlike the Adobe suite, this is one excellent option that is truly cross-platform.
DaVinci Resolve is not your regular video editor. It’s a full-fledged editing tool that provides editing, color correction, and professional audio post-production in a single application.
DaVinci Resolve is **not open sourc**e. Like LightWorks, it provides a free version for Linux and the pro version costs **$300.**
**Pros**
- Cross-platform
- Professional grade video editor
**Cons**
- Not suitable for average editing
- Not open source
- Some features are not available in the free version
**Installing DaVinci Resolve**
You can download DaVinci Resolve for Linux from [its website](https://www.blackmagicdesign.com/products/davinciresolve/). You’ll have to register, even for the free version.
## 9. VidCutter

- Cross-platform app
- Supports most of the common video formats such as: AVI, MP4, MPEG 1/2, WMV, MP3, MOV, 3GP, FLV, etc.
- Simple interface
- Trims and merges the videos
Unlike all the other video editors discussed here, [VidCutter](https://github.com/ozmartian/vidcutter) is utterly simple. It doesn’t do much except splitting and merging videos. But sometimes that’s what you need and VidCutter gives you just that.
**Pros**
- Cross-platform
- Good for simple split and merge
**Cons**
- Not suitable for regular video editing
- Crashes often
**Installing VidCutter**
It is available as a Flatpak, Snap, AppImage and can be installed using a PPA.
If you want to use the PPA, you can get it using the following command:
```
sudo add-apt-repository ppa:ozmartian/apps
sudo apt-get update
sudo apt-get install vidcutter
```
For other Linux distributions and packages, you can head to its [GitHub page](https://github.com/ozmartian/vidcutter/releases).
## Which is the best video editing software for Linux?
There are some [online video editing tools](https://www.veed.io/tools/video-editor) available that could be used from your web browser in Linux. However, the comfort of a native tool is a different thing altogether.
If you require an editor for simply cutting and joining videos, go with **VidCutter**.
If you require something more than that, **OpenShot** or **Kdenlive** is a good choice. These are suitable for beginners and are systems with standard specifications.
If you have a high-end computer and need advanced features you can go out with **Lightworks** or **DaVinci Resolve**. If you are looking for more advanced features for 3D works, **Blender** has got your back.
💬 *What do you think is the best video editing software for Linux? Share your thoughts in the comments down below.* |
7,956 | 为满足当今和未来 IT 需求,培训员工还是雇佣新人? | https://enterprisersproject.com/article/2016/6/training-vs-hiring-meet-it-needs-today-and-tomorrow | 2016-11-14T16:25:52 | [
"培训"
] | https://linux.cn/article-7956-1.html | 
在数字化时代,由于 IT 工具不断更新,技术公司紧随其后,对 IT 技能的需求也不断变化。对于企业来说,寻找和雇佣那些拥有令人垂涎能力的创新人才,是非常不容易的。同时,培训内部员工来使他们接受新的技能和挑战,需要一定的时间,而时间要求常常是紧迫的。
[Sandy Hill](https://enterprisersproject.com/user/sandy-hill) 对 IT 涉及到的多项技术都很熟悉。她作为 [Pegasystems](https://www.pega.com/pega-can?&utm_source=google&utm_medium=cpc&utm_campaign=900.US.Evaluate&utm_term=pegasystems&gloc=9009726&utm_content=smAXuLA4U%7Cpcrid%7C102822102849%7Cpkw%7Cpegasystems%7Cpmt%7Ce%7Cpdv%7Cc%7C) 项目的 IT 总监,负责多个 IT 团队,从应用的部署到数据中心的运营都要涉及。更重要的是,Pegasystems 开发帮助销售、市场、服务以及运营团队流水化操作,以及客户联络的应用。这意味着她需要掌握使用 IT 内部资源的最佳方法,面对公司客户遇到的 IT 挑战。

**TEP(企业家项目):这些年你是如何调整培训重心的?**
**Hill**:在过去的几年中,我们经历了爆炸式的发展,现在我们要实现更多的全球化进程。因此,培训目标是确保每个人都在同一起跑线上。
我们主要的关注点在培养员工使用新产品和工具上,这些新产品和工具能够推动创新,提高工作效率。例如,我们使用了之前没有的资产管理系统。因此我们需要为全部员工做培训,而不是雇佣那些已经知道该产品的人。当我们正在发展的时候,我们也试图保持紧张的预算和稳定的职员总数。所以,我们更愿意在内部培训而不是雇佣新人。
**TEP:说说培训方法吧,怎样帮助你的员工发展他们的技能?**
**Hill**:我要求每一位员工制定一个技术性的和非技术性的训练目标。这作为他们绩效评估的一部分。他们的技术性目标需要与他们的工作职能相符,非技术岗目标则随意,比如着重发展一项软技能,或是学一些专业领域之外的东西。我每年对职员进行一次评估,看看差距和不足之处,以使团队保持全面发展。
**TEP:你的训练计划能够在多大程度上减轻招聘工作量, 保持职员的稳定性?**
**Hill**:使我们的职员保持学习新技术的兴趣,可以让他们不断提高技能。让职员知道我们重视他们并且让他们在擅长的领域成长和发展,以此激励他们。
**TEP:你们发现哪些培训是最有效的?**
**HILL**:我们使用几种不同的培训方法,认为效果很好。对新的或特殊的项目,我们会由供应商提供培训课程,作为项目的一部分。要是这个方法不能实现,我们将进行脱产培训。我们也会购买一些在线的培训课程。我也鼓励职员每年参加至少一次会议,以了解行业的动向。
**TEP:哪些技能需求,更适合雇佣新人而不是培训现有员工?**
**Hill**:这和项目有关。最近有一个项目,需要使用 OpenStack,而我们根本没有这方面的专家。所以我们与一家从事这一领域的咨询公司合作。我们利用他们的专业人员运行该项目,并现场培训我们的内部团队成员。让内部员工学习他们需要的技能,同时还要完成他们的日常工作,是一项艰巨的任务。
顾问帮助我们确定我们需要的员工人数。这样我们就可以对员工进行评估,看是否存在缺口。如果存在人员上的缺口,我们还需要额外的培训或是员工招聘。我们也确实雇佣了一些合同工。另一个选择是对一些全职员工进行为期六至八周的培训,但我们的项目模式不容许这么做。
**TEP:最近雇佣的员工,他们的那些技能特别能够吸引到你?**
**Hill**:在最近的招聘中,我更看重软技能。除了扎实的技术能力外,他们需要能够在团队中进行有效的沟通和工作,要有说服他人,谈判和解决冲突的能力。
IT 人常常独来独往,不擅社交。然而如今IT 与整个组织结合越来越紧密,为其他业务部门提供有用的更新和状态报告的能力至关重要,可展示 IT 部门存在的重要性。
---
via: <https://enterprisersproject.com/article/2016/6/training-vs-hiring-meet-it-needs-today-and-tomorrow>
作者:[Paul Desmond](https://enterprisersproject.com/user/paul-desmond) 译者:[Cathon](https://github.com/Cathon) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | In the digital era, IT skills requirements are in a constant state of flux thanks to the constant change of the tools and technologies companies need to keep pace. It’s not easy for companies to find and hire talent with coveted skills that will enable them to innovate. Meanwhile, training internal staff to take on new skills and challenges takes time that is often in short supply.
[Sandy Hill](https://enterprisersproject.com/user/sandy-hill) is quite familiar with the various skills required across a variety of IT disciplines. As the director of IT for [Pegasystems](https://www.pega.com/pega-can?&utm_source=google&utm_medium=cpc&utm_campaign=900.US.Evaluate&utm_term=pegasystems&gloc=9009726&utm_content=smAXuLA4U|pcrid|102822102849|pkw|pegasystems|pmt|e|pdv|c|), she is responsible for IT teams involved in areas ranging from application development to data center operations. What’s more, Pegasystems develops applications to help sales, marketing, service and operations teams streamline operations and connect with customers, which means she has to grasp the best way to use IT resources internally, and the IT challenges the company’s customers face.
**The Enterprisers Project (TEP): How has the emphasis you put on training changed in recent years?**
**Hill**: We’ve been growing exponentially over the past couple of years so now we’re implementing more global processes and procedures. With that comes the training aspect of making sure everybody is on the same page.
Most of our focus has shifted to training staff on new products and tools that get implemented to drive innovation and enhance end user productivity. For example, we’ve implemented an asset management system; we didn’t have one before. So we had to do training globally instead of hiring someone who already knew the product. As we’re growing, we’re also trying to maintain a tight budget and flat headcount. So we’d rather internally train than try to hire new people.
**TEP: Describe your approach to training. What are some of the ways you help employees evolve their skills?**
**Hill**: I require each staff member to have a technical and non-technical training goal, which are tracked and reported on as part of their performance review. Their technical goal needs to align within their job function, and the non-technical goal can be anything from focusing on sharpening one of their soft skills to learning something outside of their area of expertise. I perform yearly staff evaluations to see where the gaps and shortages are so that teams remain well-rounded.
**TEP: To what extent have your training initiatives helped quell recruitment and retention issues?**
**Hill**: Keeping our staff excited about learning new technologies keeps their skill sets sharp. Having the staff know that we value them, and we are vested in their professional growth and development motivates them.
**TEP: What sorts of training have you found to be most effective?**
**Hill**: We use several different training methods that we’ve found to be effective. With new or special projects, we try to incorporate a training curriculum led by the vendor as part of the project rollout. If that’s not an option, we use off-site training. We also purchase on-line training packages, and I encourage my staff to attend at least one conference per year to keep up with what’s new in the industry.
**TEP: For what sorts of skills have you found it’s better to hire new people than train existing staff?**
**Hill**: It depends on the project. In one recent initiative, trying to implement OpenStack, we didn’t have internal expertise at all. So we aligned with a consulting firm that specialized in that area. We utilized their expertise on-site to help run the project and train internal team members. It was a massive undertaking to get internal people to learn the skills they needed while also doing their day-to-day jobs.
The consultant helped us determine the headcount we needed to be proficient. This allowed us to assess our staff to see if gaps remained, which would require additional training or hiring. And we did end up hiring some of the contractors. But the alternative was to send some number of FTEs (full-time employees) for 6 to 8 weeks of training, and our pipeline of projects wouldn’t allow that.
**TEP: In thinking about some of your most recent hires, what skills did they have that are especially attractive to you?**
**Hill**: In recent hires, I’ve focused on soft skills. In addition to having solid technical skills, they need to be able to communicate effectively, work in teams and have the ability to persuade, negotiate and resolve conflicts.
IT people in general kind of keep to themselves; they’re often not the most social people. Now, where IT is more integrated throughout the organization, the ability to give useful updates and status reports to other business units is critical to show that IT is an active presence and to be successful.
*Download “ IT Talent Crisis: Proven Advice from CIOs and HR Leaders” to learn the unique ways CIOs and industry experts are navigating their own talent management struggles, and 12 actionable tips for surviving the IT talent crisis.* |
7,958 | 宽松开源许可证的崛起意味着什么 | http://www.cio.com/article/3120235/open-source-tools/what-the-rise-of-permissive-open-source-licenses-means.html | 2016-11-15T08:56:02 | [
"开源",
"许可证",
"GPL",
"MIT"
] | https://linux.cn/article-7958-1.html | 为什么像 GNU GPL 这样的限制性许可证越来越不受青睐。

“如果你用了任何开源软件, 那么你软件的其他部分也必须开源。” 这是微软前 CEO 巴尔默 2001 年说的, 尽管他说的不对, 还是引发了人们对自由软件的 FUD (<ruby> 恐惧, 不确定和怀疑 <rp> ( </rp> <rt> fear, uncertainty and doubt </rt> <rp> ) </rp></ruby>)。 大概这才是他的意图。
对开源软件的这些 FUD 主要与开源许可有关。 现在有许多不同的许可证, 当中有些限制比其他的更严格(也有人称“更具保护性”)。 诸如 GNU 通用公共许可证 (GPL) 这样的限制性许可证使用了 copyleft 的概念。 copyleft 赋予人们自由发布软件副本和修改版的权力, 只要衍生工作保留同样的权力。 bash 和 GIMP 等开源项目就是使用了 GPL(v3)。 还有一个 AGPL( Affero GPL) 许可证, 它为网络上的软件(如 web service)提供了 copyleft 许可。
这意味着, 如果你使用了这种许可的代码, 然后加入了你自己的专有代码, 那么在一些情况下, 整个代码, 包括你的代码也就遵从这种限制性开源许可证。 Ballmer 说的大概就是这类的许可证。
但宽松许可证不同。 比如, 只要保留版权声明和许可声明且不要求开发者承担责任, MIT 许可证允许任何人任意使用开源代码, 包括修改和出售。 另一个比较流行的宽松开源许可证是 Apache 许可证 2.0,它还包含了贡献者向用户提供专利授权相关的条款。 使用 MIT 许可证的有 JQuery、.NET Core 和 Rails , 使用 Apache 许可证 2.0 的软件包括安卓, Apache 和 Swift。
两种许可证类型最终都是为了让软件更有用。 限制性许可证促进了参与和分享的开源理念, 使每一个人都能从软件中得到最大化的利益。 而宽松许可证通过允许人们任意使用软件来确保人们能从软件中得到最多的利益, 即使这意味着他们可以使用代码, 修改它, 据为己有,甚至以专有软件出售,而不做任何回报。
开源许可证管理公司黑鸭子软件的数据显示, 去年使用最多的开源许可证是限制性许可证 GPL 2.0,份额大约 25%。 宽松许可证 MIT 和 Apache 2.0 次之, 份额分别为 18% 和 16%, 再后面是 GPL 3.0, 份额大约 10%。 这样来看, 限制性许可证占 35%, 宽松许可证占 34%, 几乎是平手。
但这份当下的数据没有揭示发展趋势。黑鸭子软件的数据显示, 从 2009 年到 2015 年的六年间, MIT 许可证的份额上升了 15.7%, Apache 的份额上升了 12.4%。 在这段时期, GPL v2 和 v3 的份额惊人地下降了 21.4%。 换言之, 在这段时期里, 大量软件从限制性许可证转到宽松许可证。
这个趋势还在继续。 黑鸭子软件的[最新数据](https://www.blackducksoftware.com/top-open-source-licenses)显示, MIT 现在的份额为 26%, GPL v2 为 21%, Apache 2 为 16%, GPL v3 为 9%。 即 30% 的限制性许可证和 42% 的宽松许可证--与前一年的 35% 的限制许可证和 34% 的宽松许可证相比, 发生了重大的转变。 对 GitHub 上使用许可证的[调查研究](https://github.com/blog/1964-open-source-license-usage-on-github-com)证实了这种转变。 它显示 MIT 以压倒性的 45% 占有率成为最流行的许可证, 与之相比, GPL v2 只有 13%, Apache 11%。

### 引领趋势
从限制性许可证到宽松许可证,这么大的转变背后是什么呢? 是公司害怕如果使用了限制性许可证的软件,他们就会像巴尔默说的那样,失去自己私有软件的控制权了吗? 事实上, 可能就是如此。 比如, Google 就[禁用了 Affero GPL 软件](http://www.theregister.co.uk/2011/03/31/google_on_open_source_licenses/)。
[Instructional Media + Magic](http://immagic.com/) 的主席 Jim Farmer, 是一个教育开源技术的开发者。 他认为很多公司为避免法律问题而不使用限制性许可证。 “问题就在于复杂性。 许可证的复杂性越高, 被他人因为某行为而告上法庭的可能性越高。 高复杂性更可能带来诉讼”, 他说。
他补充说, 这种对限制性许可证的恐惧正被律师们驱动着, 许多律师建议自己的客户使用 MIT 或 Apache 2.0 许可证的软件, 并明确反对使用 Affero 许可证的软件。
他说, 这会对软件开发者产生影响, 因为如果公司都避开限制性许可证软件的使用,开发者想要自己的软件被使用, 就更会把新的软件使用宽松许可证。
但 SalesAgility(开源 SuiteCRM 背后的公司)的 CEO Greg Soper 认为这种到宽松许可证的转变也是由一些开发者驱动的。 “看看像 Rocket.Chat 这样的应用。 开发者本可以选择 GPL 2.0 或 Affero 许可证, 但他们选择了宽松许可证,” 他说。 “这样可以给这个应用最大的机会, 因为专有软件厂商可以使用它, 不会伤害到他们的产品, 且不需要把他们的产品也使用开源许可证。 这样如果开发者想要让第三方应用使用他的应用的话, 他有理由选择宽松许可证。”
Soper 指出, 限制性许可证致力于帮助开源项目获得成功,方式是阻止开发者拿了别人的代码、做了修改,但不把结果回报给社区。 “Affero 许可证对我们的产品健康发展很重要, 因为如果有人利用了我们的代码开发,做得比我们好, 却又不把代码回报回来, 就会扼杀掉我们的产品,” 他说。 “ 对 Rocket.Chat 则不同, 因为如果它使用 Affero, 那么它会污染公司的知识产权, 所以公司不会使用它。 不同的许可证有不同的使用案例。”
曾在 Gnome、OpenOffice 工作过,现在是 LibreOffice 的开源开发者的 Michael Meeks 同意 Jim Farmer 的观点,认为许多公司确实出于对法律的担心,而选择使用宽松许可证的软件。 “copyleft 许可证有风险, 但同样也有巨大的益处。 遗憾的是人们都听从律师的, 而律师只是讲风险, 却从不告诉你有些事是安全的。”
巴尔默发表他的错误言论已经过去 15 年了, 但它产生的 FUD 还是有影响--即使从限制性许可证到宽松许可证的转变并不是他的目的。
---
via: <http://www.cio.com/article/3120235/open-source-tools/what-the-rise-of-permissive-open-source-licenses-means.html>
作者:[Paul Rubens](http://www.cio.com/author/Paul-Rubens/) 译者:[willcoderwang](https://github.com/willcoderwang) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,959 | 如何在 Linux 中将文件编码转换为 UTF-8 | http://www.tecmint.com/convert-files-to-utf-8-encoding-in-linux/ | 2016-11-15T09:42:24 | [
"编码",
"iconv",
"UTF-8"
] | https://linux.cn/article-7959-1.html | 在这篇教程中,我们将解释字符编码的含义,然后给出一些使用命令行工具将使用某种字符编码的文件转化为另一种编码的例子。最后,我们将一起看一看如何在 Linux 下将使用各种字符编码的文件转化为 UTF-8 编码。

你可能已经知道,计算机除了二进制数据,是不会理解和存储字符、数字或者任何人类能够理解的东西的。一个二进制位只有两种可能的值,也就是 `0` 或 `1`,`真`或`假`,`是`或`否`。其它的任何事物,比如字符、数据和图片,必须要以二进制的形式来表现,以供计算机处理。
简单来说,字符编码是一种可以指示电脑来将原始的 0 和 1 解释成实际字符的方式,在这些字符编码中,字符都以一串数字来表示。
字符编码方案有很多种,比如 ASCII、ANCI、Unicode 等等。下面是 ASCII 编码的一个例子。
```
字符 二进制
A 01000001
B 01000010
```
在 Linux 中,命令行工具 `iconv` 用来将使用一种编码的文本转化为另一种编码。
你可以使用 `file` 命令,并添加 `-i` 或 `--mime` 参数来查看一个文件的字符编码,这个参数可以让程序像下面的例子一样输出字符串的 mime (Multipurpose Internet Mail Extensions) 数据:
```
$ file -i Car.java
$ file -i CarDriver.java
```

*在 Linux 中查看文件的编码*
iconv 工具的使用方法如下:
```
$ iconv option
$ iconv options -f from-encoding -t to-encoding inputfile(s) -o outputfile
```
在这里,`-f` 或 `--from-code` 表明了输入编码,而 `-t` 或 `--to-encoding` 指定了输出编码。
为了列出所有已有编码的字符集,你可以使用以下命令:
```
$ iconv -l
```

*列出所有已有编码字符集*
### 将文件从 ISO-8859-1 编码转换为 UTF-8 编码
下面,我们将学习如何将一种编码方案转换为另一种编码方案。下面的命令将会将 ISO-8859-1 编码转换为 UTF-8 编码。
考虑如下文件 `input.file`,其中包含这几个字符:
```
� � � �
```
我们从查看这个文件的编码开始,然后来查看文件内容。最后,我们可以把所有字符转换为 UTF-8 编码。
在运行 `iconv` 命令之后,我们可以像下面这样检查输出文件的内容,和它使用的字符编码。
```
$ file -i input.file
$ cat input.file
$ iconv -f ISO-8859-1 -t UTF-8//TRANSLIT input.file -o out.file
$ cat out.file
$ file -i out.file
```

*在 Linux 中将 ISO-8859-1 转化为 UTF-8*
注意:如果输出编码后面添加了 `//IGNORE` 字符串,那些不能被转换的字符将不会被转换,并且在转换后,程序会显示一条错误信息。
好,如果字符串 `//TRANSLIT` 被添加到了上面例子中的输出编码之后 (`UTF-8//TRANSLIT`),待转换的字符会尽量采用形译原则。也就是说,如果某个字符在输出编码方案中不能被表示的话,它将会被替换为一个形状比较相似的字符。
而且,如果一个字符不在输出编码中,而且不能被形译,它将会在输出文件中被一个问号标记 `?` 代替。
### 将多个文件转换为 UTF-8 编码
回到我们的主题。如果你想将多个文件甚至某目录下所有文件转化为 UTF-8 编码,你可以像下面一样,编写一个简单的 shell 脚本,并将其命名为 `encoding.sh`:
```
#!/bin/bash
### 将 values_here 替换为输入编码
FROM_ENCODING="value_here"
### 输出编码 (UTF-8)
TO_ENCODING="UTF-8"
### 转换命令
CONVERT=" iconv -f $FROM_ENCODING -t $TO_ENCODING"
### 使用循环转换多个文件
for file in *.txt; do
$CONVERT "$file" -o "${file%.txt}.utf8.converted"
done
exit 0
```
保存文件,然后为它添加可执行权限。在待转换文件 (\*.txt) 所在的目录中运行这个脚本。
```
$ chmod +x encoding.sh
$ ./encoding.sh
```
重要事项:你也可以使这个脚本变得更通用,比如转换任意特定的字符编码到另一种编码。为了达到这个目的,你只需要改变 `FROM_ENCODING` 及 `TO_ENCODING` 变量的值。别忘了改一下输出文件的文件名 `"${file%.txt}.utf8.converted"`.
若要了解更多信息,可以查看 `iconv` 的<ruby> 手册页 <rp> ( </rp> <rt> man page </rt> <rp> ) </rp></ruby>。
```
$ man iconv
```
将这篇指南总结一下,理解字符编码的概念、了解如何将一种编码方案转换为另一种,是一个电脑用户处理文本时必须要掌握的知识,程序员更甚。
最后,你可以在下面的评论部分中与我们联系,提出问题或反馈。
---
via: <http://www.tecmint.com/convert-files-to-utf-8-encoding-in-linux/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[StdioA](https://github.com/StdioA) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,960 | 在 Kali Linux 下实战 Nmap(网络安全扫描器) | http://www.tecmint.com/nmap-network-security-scanner-in-kali-linux/ | 2016-11-16T11:11:00 | [
"nmap",
"网络安全",
"扫描"
] | https://linux.cn/article-7960-1.html | 在这第二篇 Kali Linux 文章中, 将讨论称为 ‘[nmap](http://www.tecmint.com/nmap-command-examples/)‘ 的网络工具。虽然 nmap 不是 Kali 下唯一的一个工具,但它是最[有用的网络映射工具](http://www.tecmint.com/bcc-best-linux-performance-monitoring-tools/)之一。
* [第一部分-为初学者准备的 Kali Linux 安装指南](/article-7986-1.html)

Nmap, 是 Network Mapper 的缩写,由 Gordon Lyon 维护(更多关于 Mr. Lyon 的信息在这里: <http://insecure.org/fyodor/>) ,并被世界各地许多的安全专业人员使用。
这个工具在 Linux 和 Windows 下都能使用,并且是用命令行驱动的。相对于那些令人害怕的命令行,对于 nmap,在这里有一个美妙的图形化前端叫做 zenmap。
强烈建议个人去学习 nmap 的命令行版本,因为与图形化版本 zenmap 相比,它提供了更多的灵活性。
对服务器进行 nmap 扫描的目的是什么?很好的问题。Nmap 允许管理员快速彻底地了解网络上的系统,因此,它的名字叫 Network MAPper 或者 nmap。
Nmap 能够快速找到活动的主机和与该主机相关联的服务。Nmap 的功能还可以通过结合 Nmap 脚本引擎(通常缩写为 NSE)进一步被扩展。
这个脚本引擎允许管理员快速创建可用于确定其网络上是否存在新发现的漏洞的脚本。已经有许多脚本被开发出来并且包含在大多数的 nmap 安装中。
提醒一句 - 使用 nmap 的人既可能是善意的,也可能是恶意的。应该非常小心,确保你不要使用 nmap 对没有明确得到书面许可的系统进行扫描。请在使用 nmap 工具的时候注意!
#### 系统要求
1. [Kali Linux](/article-7986-1.html) (nmap 可以用于其他操作系统,并且功能也和这个指南里面讲的类似)。
2. 另一台计算机,并且装有 nmap 的计算机有权限扫描它 - 这通常很容易通过软件来实现,例如通过 [VirtualBox](http://www.tecmint.com/install-virtualbox-on-redhat-centos-fedora/) 创建虚拟机。
1. 想要有一个好的机器来练习一下,可以了解一下 Metasploitable 2。
2. 下载 MS2 :[Metasploitable2](https://sourceforge.net/projects/metasploitable/files/Metasploitable2/)。
3. 一个可以工作的网络连接,或者是使用虚拟机就可以为这两台计算机建立有效的内部网络连接。
### Kali Linux – 使用 Nmap
使用 nmap 的第一步是登录 Kali Linux,如果需要,就启动一个图形会话(本系列的第一篇文章安装了 [Kali Linux 的 Enlightenment 桌面环境](/article-7986-1.html))。
在安装过程中,安装程序将提示用户输入用来登录的“root”用户和密码。 一旦登录到 Kali Linux 机器,使用命令`startx`就可以启动 Enlightenment 桌面环境 - 值得注意的是 nmap 不需要运行桌面环境。
```
# startx
```

*在 Kali Linux 中启动桌面环境*
一旦登录到 Enlightenment,将需要打开终端窗口。通过点击桌面背景,将会出现一个菜单。导航到终端可以进行如下操作:应用程序 -> 系统 -> 'Xterm' 或 'UXterm' 或 '根终端'。
作者是名为 '[Terminator](http://www.tecmint.com/terminator-a-linux-terminal-emulator-to-manage-multiple-terminal-windows/)' 的 shell 程序的粉丝,但是这可能不会显示在 Kali Linux 的默认安装中。这里列出的所有 shell 程序都可用于使用 nmap 。

*在 Kali Linux 下启动终端*
一旦终端启动,nmap 的乐趣就开始了。 对于这个特定的教程,将会创建一个 Kali 机器和 Metasploitable机器之间的私有网络。
这会使事情变得更容易和更安全,因为私有的网络范围将确保扫描保持在安全的机器上,防止易受攻击的 Metasploitable 机器被其他人攻击。
### 怎样在我的网络上找到活动主机
在此示例中,这两台计算机都位于专用的 192.168.56.0/24 网络上。 Kali 机器的 IP 地址为 192.168.56.101,要扫描的 Metasploitable 机器的 IP 地址为 192.168.56.102。
假如我们不知道 IP 地址信息,但是可以通过快速 nmap 扫描来帮助确定在特定网络上哪些是活动主机。这种扫描称为 “简单列表” 扫描,将 `-sL`参数传递给 nmap 命令。
```
# nmap -sL 192.168.56.0/24
```

*Nmap – 扫描网络上的活动主机*
悲伤的是,这个初始扫描没有返回任何活动主机。 有时,这是某些操作系统处理[端口扫描网络流量](http://www.tecmint.com/audit-network-performance-security-and-troubleshooting-in-linux/)的一个方法。
### 在我的网络中找到并 ping 所有活动主机
不用担心,在这里有一些技巧可以使 nmap 尝试找到这些机器。 下一个技巧会告诉 nmap 尝试去 ping 192.168.56.0/24 网络中的所有地址。
```
# nmap -sn 192.168.56.0/24
```

*Nmap – Ping 所有已连接的活动网络主机*
这次 nmap 会返回一些潜在的主机来进行扫描! 在此命令中,`-sn` 禁用 nmap 的尝试对主机端口扫描的默认行为,只是让 nmap 尝试 ping 主机。
### 找到主机上的开放端口
让我们尝试让 nmap 端口扫描这些特定的主机,看看会出现什么。
```
# nmap 192.168.56.1,100-102
```

*Nmap – 在主机上扫描网络端口*
哇! 这一次 nmap 挖到了一个金矿。 这个特定的主机有相当多的[开放网络端口](http://www.tecmint.com/find-open-ports-in-linux/)。
这些端口全都代表着在此特定机器上的某种监听服务。 我们前面说过,192.168.56.102 的 IP 地址会分配给一台易受攻击的机器,这就是为什么在这个主机上会有这么多[开放端口](http://www.tecmint.com/find-open-ports-in-linux/)。
在大多数机器上打开这么多端口是非常不正常的,所以赶快调查这台机器是个明智的想法。管理员可以检查下网络上的物理机器,并在本地查看这些机器,但这不会很有趣,特别是当 nmap 可以为我们更快地做到时!
### 找到主机上监听端口的服务
下一个扫描是服务扫描,通常用于尝试确定机器上什么[服务监听在特定的端口](http://www.tecmint.com/find-linux-processes-memory-ram-cpu-usage/)。
Nmap 将探测所有打开的端口,并尝试从每个端口上运行的服务中获取信息。
```
# nmap -sV 192.168.56.102
```

*Nmap – 扫描网络服务监听端口*
请注意这次 nmap 提供了一些关于 nmap 在特定端口运行的建议(在白框中突出显示),而且 nmap 也试图确认运行在这台机器上的[这个操作系统的信息](http://www.tecmint.com/commands-to-collect-system-and-hardware-information-in-linux/)和它的主机名(也非常成功!)。
查看这个输出,应该引起网络管理员相当多的关注。 第一行声称 VSftpd 版本 2.3.4 正在这台机器上运行! 这是一个真正的旧版本的 VSftpd。
通过查找 ExploitDB,对于这个版本早在 2001 年就发现了一个非常严重的漏洞(ExploitDB ID – 17491)。
### 发现主机上上匿名 ftp 登录
让我们使用 nmap 更加清楚的查看这个端口,并且看看可以确认什么。
```
# nmap -sC 192.168.56.102 -p 21
```

*Nmap – 扫描机器上的特定端口*
使用此命令,让 nmap 在主机上的 FTP 端口(`-p 21`)上运行其默认脚本(`-sC`)。 虽然它可能是、也可能不是一个问题,但是 nmap 确实发现在这个特定的服务器[是允许匿名 FTP 登录的](http://www.tecmint.com/setup-ftp-anonymous-logins-in-linux/)。
### 检查主机上的漏洞
这与我们早先知道 VSftd 有旧漏洞的知识相匹配,应该引起一些关注。 让我们看看 nmap有没有脚本来尝试检查 VSftpd 漏洞。
```
# locate .nse | grep ftp
```

*Nmap – 扫描 VSftpd 漏洞*
注意 nmap 已有一个 NSE 脚本已经用来处理 VSftpd 后门问题!让我们尝试对这个主机运行这个脚本,看看会发生什么,但首先知道如何使用脚本可能是很重要的。
```
# nmap --script-help=ftp-vsftd-backdoor.nse
```

*了解 Nmap NSE 脚本使用*
通过这个描述,很明显,这个脚本可以用来试图查看这个特定的机器是否容易受到先前识别的 ExploitDB 问题的影响。
让我们运行这个脚本,看看会发生什么。
```
# nmap --script=ftp-vsftpd-backdoor.nse 192.168.56.102 -p 21
```

*Nmap – 扫描易受攻击的主机*
耶!Nmap 的脚本返回了一些危险的消息。 这台机器可能面临风险,之后可以进行更加详细的调查。虽然这并不意味着机器缺乏对风险的抵抗力和可以被用于做一些可怕/糟糕的事情,但它应该给网络/安全团队带来一些关注。
Nmap 具有极高的选择性,非常平稳。 到目前为止已经做的大多数扫描, nmap 的网络流量都保持适度平稳,然而以这种方式扫描对个人拥有的网络可能是非常耗时的。
Nmap 有能力做一个更积极的扫描,往往一个命令就会产生之前几个命令一样的信息。 让我们来看看积极的扫描的输出(注意 - 积极的扫描会触发[入侵检测/预防系统](http://www.tecmint.com/protect-apache-using-mod_security-and-mod_evasive-on-rhel-centos-fedora/)!)。
```
# nmap -A 192.168.56.102
```

*Nmap – 在主机上完成网络扫描*
注意这一次,使用一个命令,nmap 返回了很多关于在这台特定机器上运行的开放端口、服务和配置的信息。 这些信息中的大部分可用于帮助确定[如何保护本机](http://www.tecmint.com/security-and-hardening-centos-7-guide/)以及评估网络上可能运行的软件。
这只是 nmap 可用于在主机或网段上找到的许多有用信息的很短的一个列表。强烈敦促个人在个人拥有的网络上继续[以nmap](http://www.tecmint.com/nmap-command-examples/) 进行实验。(不要通过扫描其他主机来练习!)。
有一个关于 Nmap 网络扫描的官方指南,作者 Gordon Lyon,可从[亚马逊](http://amzn.to/2eFNYrD)上获得。
方便的话可以留下你的评论和问题(或者使用 nmap 扫描器的技巧)。
---
via: <http://www.tecmint.com/nmap-network-security-scanner-in-kali-linux/>
作者:[Rob Turner](http://www.tecmint.com/author/robturner/) 译者:[DockerChen](https://github.com/DockerChen) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,961 | 在 Linux 上检测硬盘上的坏道和坏块 | http://www.tecmint.com/check-linux-hard-disk-bad-sectors-bad-blocks/ | 2016-11-16T16:15:00 | [
"磁盘",
"smartmontools",
"e2fsck"
] | https://linux.cn/article-7961-1.html | 让我们从坏道和坏块的定义开始说起,它们是一块磁盘或闪存上不再能够被读写的部分,一般是由于磁盘表面特定的[物理损坏](http://www.tecmint.com/defragment-linux-system-partitions-and-directories/)或闪存晶体管失效导致的。
随着坏道的继续积累,它们会对你的磁盘或闪存容量产生令人不快或破坏性的影响,甚至可能会导致硬件失效。
同时还需要注意的是坏块的存在警示你应该开始考虑买块新磁盘了,或者简单地将坏块标记为不可用。
因此,在这篇文章中,我们通过几个必要的步骤,使用特定的[磁盘扫描工具](http://www.tecmint.com/ncdu-a-ncurses-based-disk-usage-analyzer-and-tracker/)让你能够判断 Linux 磁盘或闪存是否存在坏道。

以下就是步骤:
### 在 Linux 上使用坏块工具检查坏道
坏块工具可以让用户扫描设备检查坏道或坏块。设备可以是一个磁盘或外置磁盘,由一个如 `/dev/sdc` 这样的文件代表。
首先,通过超级用户权限执行 [fdisk 命令](http://www.tecmint.com/fdisk-commands-to-manage-linux-disk-partitions/)来显示你的所有磁盘或闪存的信息以及它们的分区信息:
```
$ sudo fdisk -l<br>
```

*列出 Linux 文件系统分区*
然后用如下命令检查你的 Linux 硬盘上的坏道/坏块:
```
$ sudo badblocks -v /dev/sda10 > badsectors.txt
```

*在 Linux 上扫描硬盘坏道*
上面的命令中,badblocks 扫描设备 `/dev/sda10`(记得指定你的实际设备),`-v` 选项让它显示操作的详情。另外,这里使用了输出重定向将操作结果重定向到了文件 `badsectors.txt`。
如果你在你的磁盘上发现任何坏道,卸载磁盘并像下面这样让系统不要将数据写入回报的扇区中。
你需要执行 `e2fsck`(针对 ext2/ext3/ext4 文件系统)或 `fsck` 命令,命令中还需要用到 `badsectors.txt` 文件和设备文件。
`-l` 选项告诉命令将在指定的文件 `badsectors.txt` 中列出的扇区号码加入坏块列表。
```
------------ 针对 for ext2/ext3/ext4 文件系统 ------------
$ sudo e2fsck -l badsectors.txt /dev/sda10
或
------------ 针对其它文件系统 ------------
$ sudo fsck -l badsectors.txt /dev/sda10
```
### 在 Linux 上使用 Smartmontools 工具扫描坏道
这个方法对带有 S.M.A.R.T(<ruby> 自我监控分析报告技术 <rp> ( </rp> <rt> Self-Monitoring, Analysis and Reporting Technology </rt> <rp> ) </rp></ruby>)系统的现代磁盘(ATA/SATA 和 SCSI/SAS 硬盘以及固态硬盘)更加的可靠和高效。S.M.A.R.T 系统能够帮助检测,报告,以及可能记录它们的健康状况,这样你就可以找出任何可能出现的硬件失效。
你可以使用以下命令安装 `smartmontools`:
```
------------ 在基于 Debian/Ubuntu 的系统上 ------------
$ sudo apt-get install smartmontools
------------ 在基于 RHEL/CentOS 的系统上 ------------
$ sudo yum install smartmontools
```
安装完成之后,使用 `smartctl` 控制磁盘集成的 S.M.A.R.T 系统。你可以这样查看它的手册或帮助:
```
$ man smartctl
$ smartctl -h
```
然后执行 `smartctrl` 命令并在命令中指定你的设备作为参数,以下命令包含了参数 `-H` 或 `--health` 以显示 SMART 整体健康自我评估测试结果。
```
$ sudo smartctl -H /dev/sda10
```

*检查 Linux 硬盘健康*
上面的结果指出你的硬盘很健康,近期内不大可能发生硬件失效。
要获取磁盘信息总览,使用 `-a` 或 `--all` 选项来显示关于磁盘所有的 SMART 信息,`-x` 或 `--xall` 来显示所有关于磁盘的 SMART 信息以及非 SMART 信息。
在这个教程中,我们涉及了有关[磁盘健康诊断](http://www.tecmint.com/defragment-linux-system-partitions-and-directories/)的重要话题,你可以下面的反馈区来分享你的想法或提问,并且记得多回来看看。
---
via: <http://www.tecmint.com/check-linux-hard-disk-bad-sectors-bad-blocks/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[alim0x](https://github.com/alim0x) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,964 | 如何在 Linux 中压缩及解压缩 .bz2 文件 | http://www.tecmint.com/linux-compress-decompress-bz2-files-using-bzip2 | 2016-11-17T11:20:34 | [
"bzip2",
"压缩"
] | https://linux.cn/article-7964-1.html | 对文件进行压缩,可以通过使用较少的字节对文件中的数据进行编码来显著地减小文件的大小,并且在跨网络的[文件的备份和传送](/article-4503-1.html)时很有用。 另一方面,解压文件意味着将文件中的数据恢复到初始状态。

Linux 中有几个[文件压缩和解压缩工具](http://www.tecmint.com/command-line-archive-tools-for-linux/),比如gzip、7-zip、Lrzip、[PeaZip](http://www.tecmint.com/peazip-linux-file-manager-and-file-archive-tool/) 等等。
本篇教程中,我们将介绍如何在 Linux 中使用 bzip2 工具压缩及解压缩`.bz2`文件。
bzip2 是一个非常有名的压缩工具,并且在大多数主流 Linux 发行版上都有,你可以在你的发行版上用合适的命令来安装它。
```
$ sudo apt install bzip2 [On Debian/Ubuntu]
$ sudo yum install bzip2 [On CentOS/RHEL]
$ sudo dnf install bzip2 [On Fedora 22+]
```
使用 bzip2 的常规语法是:
```
$ bzip2 option(s) filenames
```
### 如何在 Linux 中使用“bzip2”压缩文件
你可以如下压缩一个文件,使用`-z`标志启用压缩:
```
$ bzip2 filename
或者
$ bzip2 -z filename
```
要压缩一个`.tar`文件,使用的命令为:
```
$ bzip2 -z backup.tar
```
重要:bzip2 默认会在压缩及解压缩文件时删除输入文件(原文件),要保留输入文件,使用`-k`或者`--keep`选项。
此外,`-f`或者`--force`标志会强制让 bzip2 覆盖已有的输出文件。
```
------ 要保留输入文件 ------
$ bzip2 -zk filename
$ bzip2 -zk backup.tar
```
你也可以设置块的大小,从 100k 到 900k,分别使用`-1`或者`--fast`到`-9`或者`--best`:
```
$ bzip2 -k1 Etcher-linux-x64.AppImage
$ ls -lh Etcher-linux-x64.AppImage.bz2
$ bzip2 -k9 Etcher-linux-x64.AppImage
$ bzip2 -kf9 Etcher-linux-x64.AppImage
$ ls -lh Etcher-linux-x64.AppImage.bz2
```
下面的截屏展示了如何使用选项来保留输入文件,强制 bzip2 覆盖输出文件,并且在压缩中设置块的大小。

*在 Linux 中使用 bzip2 压缩文件*
### 如何在 Linux 中使用“bzip2”解压缩文件
要解压缩`.bz2`文件,确保使用`-d`或者`--decompress`选项:
```
$ bzip2 -d filename.bz2
```
注意:这个文件必须是`.bz2`的扩展名,上面的命令才能使用。
```
$ bzip2 -vd Etcher-linux-x64.AppImage.bz2
$ bzip2 -vfd Etcher-linux-x64.AppImage.bz2
$ ls -l Etcher-linux-x64.AppImage
```

*在 Linux 中解压 bzip2 文件*
要浏览 bzip2 的帮助及 man 页面,输入下面的命令:
```
$ bzip2 -h
$ man bzip2
```
最后,通过上面简单的阐述,我相信你现在已经可以在 Linux 中压缩及解压缩`bz2`文件了。然而,有任何的问题和反馈,可以在评论区中留言。
重要的是,你可能想在 Linux 中查看一些重要的 [tar 命令示例](/article-7802-1.html),以便学习使用 tar 命令来[创建压缩归档文件](http://www.tecmint.com/compress-files-and-finding-files-in-linux/)。
---
via: <http://www.tecmint.com/linux-compress-decompress-bz2-files-using-bzip2>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,965 | JavaScript 小模块的开销 | https://nolanlawson.com/2016/08/15/the-cost-of-small-modules/ | 2016-11-17T13:44:16 | [
"JavaScript",
"模块"
] | https://linux.cn/article-7965-1.html | **更新(2016/10/30)**:我写完这篇文章之后,我在[这个基准测试中发了一个错误](https://github.com/nolanlawson/cost-of-small-modules/pull/8),会导致 Rollup 比它预期的看起来要好一些。不过,整体结果并没有明显的不同(Rollup 仍然击败了 Browserify 和 Webpack,虽然它并没有像 Closure 十分好),所以我只是更新了图表。该基准测试包括了 [RequireJS 和 RequireJS Almond 打包器](https://github.com/nolanlawson/cost-of-small-modules/pull/5),所以文章中现在也包括了它们。要看原始帖子,可以查看[历史版本](https://web.archive.org/web/20160822181421/https://nolanlawson.com/2016/08/15/the-cost-of-small-modules/)。

大约一年之前,我在将一个大型 JavaScript 代码库重构为更小的模块时发现了 Browserify 和 Webpack 中一个令人沮丧的事实:
>
> “代码越模块化,代码体积就越大。:< ”
>
>
> - Nolan Lawson
>
>
>
过了一段时间,Sam Saccone 发布了一些关于 [Tumblr](https://docs.google.com/document/d/1E2w0UQ4RhId5cMYsDcdcNwsgL0gP_S6SDv27yi1mCEY/edit) 和 [Imgur](https://github.com/perfs/audits/issues/1) 页面加载性能的出色的研究。其中指出:
>
> “超过 400 ms 的时间单纯的花费在了遍历 Browserify 树上。”
>
>
> - Sam Saccone
>
>
>
在本篇文章中,我将演示小模块可能会根据你选择的<ruby> 打包器 <rp> ( </rp> <rt> bundler </rt> <rp> ) </rp></ruby>和<ruby> 模块系统 <rp> ( </rp> <rt> module system </rt> <rp> ) </rp></ruby>而出现高得惊人的性能开销。此外,我还将解释为什么这种方法不但影响你自己代码的模块,也会影响依赖项中的模块,这也正是第三方代码在性能开销上很少提及的方面。
### 网页性能
一个页面中包含的 JavaScript 脚本越多,页面加载也将越慢。庞大的 JavaScript 包会导致浏览器花费更多的时间去下载、解析和执行,这些都将加长载入时间。
即使当你使用如 Webpack [code splitting](https://webpack.github.io/docs/code-splitting.html)、Browserify [factor bundles](https://github.com/substack/factor-bundle) 等工具将代码分解为多个包,该开销也仅仅是被延迟到页面生命周期的晚些时候。JavaScript 迟早都将有一笔开销。
此外,由于 JavaScript 是一门动态语言,同时流行的 [CommonJS](http://www.commonjs.org/) 模块也是动态的,所以这就使得在最终分发给用户的代码中剔除无用的代码变得异常困难。譬如你可能只使用到 jQuery 中的 $.ajax,但是通过载入 jQuery 包,你将付出整个包的代价。
JavaScript 社区对这个问题提出的解决办法是提倡 [小模块](http://substack.net/how_I_write_modules) 的使用。小模块不仅有许多 [美好且实用的好处](http://dailyjs.com/2015/07/02/small-modules-complexity-over-size/) 如易于维护,易于理解,易于集成等,而且还可以通过鼓励包含小巧的功能而不是庞大的库来解决之前提到的 jQuery 的问题。
所以在小模块下,你将不需要这样:
```
var _ = require('lodash')
_.uniq([1,2,2,3])
```
而是可以如此:
```
var uniq = require('lodash.uniq')
uniq([1,2,2,3])
```
### 包与模块
需要强调的是这里我提到的“模块”并不同于 npm 中的“包”的概念。当你从 npm 安装一个包时,它会将该模块通过公用 API 展现出来,但是在这之下其实是一个许多模块的聚合物。
例如,我们来看一个包 [is-array](https://www.npmjs.com/package/is-array),它没有别的依赖,并且只包含 [一个 JavaScript 文件](https://github.com/retrofox/is-array/blob/d79f1c90c824416b60517c04f0568b5cd3f8271d/index.js#L6-L33),所以它只有一个模块。这算是足够简单的。
现在来看一个稍微复杂一点的包,如 [once](https://www.npmjs.com/package/once)。它有一个依赖的包 [wrappy](https://www.npmjs.com/package/wrappy)。[两](https://github.com/isaacs/once/blob/2ad558657e17fafd24803217ba854762842e4178/once.js#L1-L21) [个](https://github.com/npm/wrappy/blob/71d91b6dc5bdeac37e218c2cf03f9ab55b60d214/wrappy.js#L6-L33) 包都各自包含一个模块,所以总模块数为 2。至此,也还算好。
现在来一起看一个更为令人迷惑的例子:[qs](https://www.npmjs.com/package/qs)。因为它没有依赖的包,所以你可能就认为它只有一个模块,然而事实上,它有四个模块!
你可以用一个我写的工具 [browserify-count-modules](https://www.npmjs.com/package/browserify-count-modules) 来统计一个 Browserify 包的总模块数:
```
$ npm install qs
$ browserify node_modules/qs | browserify-count-modules
4
```
这说明了一个包可以包含一个或者多个模块。这些模块也可以依赖于其他的包,而这些包又将附带其自己所依赖的包与模块。由此可以确定的事就是任何一个包将包含至少一个模块。
### 模块膨胀
一个典型的网页应用中会包含多少个模块呢?我在一些流行的使用 Browserify 的网站上运行 browserify-count-moduleson 并且得到了以下结果:
* [requirebin.com](http://requirebin.com/): 91 个模块
* [keybase.io](https://keybase.io/): 365 个模块
* [m.reddit.com](http://m.reddit.com/): 1050 个模块
* [Apple.com](http://images.apple.com/ipad-air-2/): 1060 个模块 (新增。 [感谢 Max!](https://twitter.com/denormalize/status/765300194078437376))
顺带一提,我写过的最大的开源站点 [Pokedex.org](https://pokedex.org/) 包含了 4 个包,共 311 个模块。
让我们先暂时忽略这些 JavaScript 包的实际大小,我认为去探索一下一定数量的模块本身开销会是一件有意思的事。虽然 Sam Saccone 的文章 [“2016 年 ES2015 转译的开销”](https://github.com/samccone/The-cost-of-transpiling-es2015-in-2016#the-cost-of-transpiling-es2015-in-2016) 已经广为流传,但是我认为他的结论还未到达足够深度,所以让我们挖掘的稍微再深一点吧。
### 测试环节!
我构造了一个能导入 100、1000 和 5000 个其他小模块的测试模块,其中每个小模块仅仅导出一个数字。而父模块则将这些数字求和并记录结果:
```
// index.js
var total = 0
total += require('./module_0')
total += require('./module_1')
total += require('./module_2')
// etc.
console.log(total)
// module_1.js
module.exports = 1
```
我测试了五种打包方法:Browserify、带 [bundle-collapser](https://www.npmjs.com/package/bundle-collapser) 插件的 Browserify、Webpack、Rollup 和 Closure Compiler。对于 Rollup 和 Closure Compiler 我使用了 ES6 模块,而对于 Browserify 和 Webpack 则用的是 CommonJS,目的是为了不涉及其各自缺点而导致测试的不公平(由于它们可能需要做一些转译工作,如 Babel 一样,而这些工作将会增加其自身的运行时间)。
为了更好地模拟一个生产环境,我对所有的包采用带 `-mangle` 和 `-compress` 参数的 `Uglify` ,并且使用 gzip 压缩后通过 GitHub Pages 用 HTTPS 协议进行传输。对于每个包,我一共下载并执行 15 次,然后取其平均值,并使用 `performance.now()` 函数来记录载入时间(未使用缓存)与执行时间。
### 包大小
在我们查看测试结果之前,我们有必要先来看一眼我们要测试的包文件。以下是每个包最小处理后但并未使用 gzip 压缩时的体积大小(单位:Byte):
| | 100 个模块 | 1000 个模块 | 5000 个模块 |
| --- | --- | --- | --- |
| browserify | 7982 | 79987 | 419985 |
| browserify-collapsed | 5786 | 57991 | 309982 |
| webpack | 3954 | 39055 | 203052 |
| rollup | 671 | 6971 | 38968 |
| closure | 758 | 7958 | 43955 |
| | 100 个模块 | 1000 个模块 | 5000 个模块 |
| --- | --- | --- | --- |
| browserify | 1649 | 13800 | 64513 |
| browserify-collapsed | 1464 | 11903 | 56335 |
| webpack | 693 | 5027 | 26363 |
| rollup | 300 | 2145 | 11510 |
| closure | 302 | 2140 | 11789 |
Browserify 和 Webpack 的工作方式是隔离各个模块到各自的函数空间,然后声明一个全局载入器,并在每次 `require()` 函数调用时定位到正确的模块处。下面是我们的 Browserify 包的样子:
```
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o
```
而 Rollup 和 Closure 包看上去则更像你亲手写的一个大模块。这是 Rollup 打包的包:
```
(function () {
'use strict';
var total = 0
total += 0
total += 1
total += 2
// etc.
```
如果你清楚在 JavaScript 中使用嵌套函数与在关联数组查找一个值的固有开销, 那么你将很容易理解出现以下测试的结果的原因。
### 测试结果
我选择在搭载 Android 5.1.1 与 Chrome 52 的 Nexus 5(代表中低端设备)和运行 iOS 9 的第 6 代 iPod Touch(代表高端设备)上进行测试。
这是 Nexus 5 下的测试结果([查看表格](https://gist.github.com/nolanlawson/e84ad060a20f0cb7a7c32308b6b46abe)):

这是 iPod Touch 下的测试结果([查看表格](https://gist.github.com/nolanlawson/45ed2c7fa53da035dfc1e153763b9f93)):

在 100 个模块时,各包的差异是微不足道的,但是一旦模块数量达到 1000 个甚至 5000 个时,差异将会变得非常巨大。iPod Touch 在不同包上的差异并不明显,而对于具有一定年代的 Nexus 5 来说,Browserify 和 Webpack 明显耗时更多。
与此同时,我发现有意思的是 Rollup 和 Closure 的运行开销对于 iPod 而言几乎可以忽略,并且与模块的数量关系也不大。而对于 Nexus 5 来说,运行的开销并非完全可以忽略,但 Rollup/Closure 仍比 Browserify/Webpack 低很多。后者若未在几百毫秒内完成加载则将会占用主线程的好几帧的时间,这就意味着用户界面将冻结并且等待直到模块载入完成。
值得注意的是前面这些测试都是在千兆网速下进行的,所以在网络情况来看,这只是一个最理想的状况。借助 Chrome 开发者工具,我们可以认为地将 Nexus 5 的网速限制到 3G 水平,然后来看一眼这对测试产生的影响([查看表格](https://gist.github.com/nolanlawson/6269d304c970174c21164288808392ea)):

一旦我们将网速考虑进来,Browserify/Webpack 和 Rollup/Closure 的差异将变得更为显著。在 1000 个模块规模(接近于 Reddit 1050 个模块的规模)时,Browserify 花费的时间比 Rollup 长大约 400 毫秒。然而 400 毫秒已经不是一个小数目了,正如 Google 和 Bing 指出的,亚秒级的延迟都会 [对用户的参与产生明显的影响](http://radar.oreilly.com/2009/06/bing-and-google-agree-slow-pag.html) 。
还有一件事需要指出,那就是这个测试并非测量 100 个、1000 个或者 5000 个模块的每个模块的精确运行时间。因为这还与你对 `require()` 函数的使用有关。在这些包中,我采用的是对每个模块调用一次 `require()` 函数。但如果你每个模块调用了多次 `require()` 函数(这在代码库中非常常见)或者你多次动态调用 `require()` 函数(例如在子函数中调用 `require()` 函数),那么你将发现明显的性能退化。
Reddit 的移动站点就是一个很好的例子。虽然该站点有 1050 个模块,但是我测量了它们使用 Browserify 的实际执行时间后发现比“1000 个模块”的测试结果差好多。当使用那台运行 Chrome 的 Nexus 5 时,我测出 Reddit 的 Browserify require() 函数耗时 2.14 秒。而那个“1000 个模块”脚本中的等效函数只需要 197 毫秒(在搭载 i7 处理器的 Surface Book 上的桌面版 Chrome,我测出的结果分别为 559 毫秒与 37 毫秒,虽然给出桌面平台的结果有些令人惊讶)。
这结果提示我们有必要对每个模块使用多个 `require()` 函数的情况再进行一次测试。不过,我并不认为这对 Browserify 和 Webpack 会是一个公平的测试,因为 Rollup 和 Closure 都会将重复的 ES6 库导入处理为一个的顶级变量声明,同时也阻止了顶层空间以外的其他区域的导入。所以根本上来说,Rollup 和 Closure 中一个导入和多个导入的开销是相同的,而对于 Browserify 和 Webpack,运行开销随 `require()` 函数的数量线性增长。
为了我们这个分析的目的,我认为最好假设模块的数量是性能的短板。而事实上,“5000 个模块”也是一个比“5000 个 `require()` 函数调用”更好的度量标准。
### 结论
首先,bundle-collapser 对 Browserify 来说是一个非常有用的插件。如果你在产品中还没使用它,那么你的包将相对来说会略大且运行略慢(虽然我得承认这之间的差异非常小)。另一方面,你还可以转换到 Webpack 以获得更快的包而不需要额外的配置(其实我非常不愿意这么说,因为我是个顽固的 Browserify 粉)。
不管怎样,这些结果都明确地指出 Webpack 和 Browserify 相较 Rollup 和 Closure Compiler 而言表现都稍差,并且性能差异随着模块大小的增大而增大。不幸的是,我并不确定 [Webpack 2](https://gist.github.com/sokra/27b24881210b56bbaff7) 是否能解决这些问题,因为尽管他们将 [从 Rollup 中借鉴一些想法](http://www.2ality.com/2015/12/webpack-tree-shaking.html),但是看起来他们的关注点更多在于 [tree-shaking 方面](http://www.2ality.com/2015/12/bundling-modules-future.html) 而不是在于 scope-hoisting 方面。(更新:一个更好的名字称为<ruby> 内联 <rp> ( </rp> <rt> inlining </rt> <rp> ) </rp></ruby>,并且 Webpack 团队 [正在做这方面的工作](https://github.com/webpack/webpack/issues/2873#issuecomment-240067865)。)
给出这些结果之后,我对 Closure Compiler 和 Rollup 在 JavaScript 社区并没有得到过多关注而感到惊讶。我猜测或许是因为(前者)需要依赖 Java,而(后者)仍然相当不成熟并且未能做到开箱即用(详见 [Calvin’s Metcalf 的评论](https://github.com/rollup/rollup/issues/552) 中作的不错的总结)。
即使没有足够数量的 JavaScript 开发者加入到 Rollup 或 Closure 的队伍中,我认为 npm 包作者们也已准备好了去帮助解决这些问题。如果你使用 npm 安装 lodash,你将会发其现主要的导入是一个巨大的 JavaScript 模块,而不是你期望的 Lodash 的<ruby> 超模块 <rp> ( </rp> <rt> hyper-modular </rt> <rp> ) </rp></ruby>特性(`require('lodash/uniq')`,`require('lodash.uniq')` 等等)。对于 PouchDB,我们做了一个类似的声明以 [使用 Rollup 作为预发布步骤](http://pouchdb.com/2016/01/13/pouchdb-5.2.0-a-better-build-system-with-rollup.html),这将产生对于用户而言尽可能小的包。
同时,我创建了 [rollupify](https://github.com/nolanlawson/rollupify) 来尝试将这过程变得更为简单一些,只需拖动到已存在的 Browserify 工程中即可。其基本思想是在你自己的项目中使用<ruby> 导入 <rp> ( </rp> <rt> import </rt> <rp> ) </rp></ruby>和<ruby> 导出 <rp> ( </rp> <rt> export </rt> <rp> ) </rp></ruby>(可以使用 [cjs-to-es6](https://github.com/nolanlawson/cjs-to-es6) 来帮助迁移),然后使用 `require()` 函数来载入第三方包。这样一来,你依旧可以在你自己的代码库中享受所有模块化的优点,同时能导出一个适当大小的大模块来发布给你的用户。不幸的是,你依旧得为第三方库付出一些代价,但是我发现这是对于当前 npm 生态系统的一个很好的折中方案。
所以结论如下:**一个大的 JavaScript 包比一百个小 JavaScript 模块要快**。尽管这是事实,我依旧希望我们社区能最终发现我们所处的困境————提倡小模块的原则对开发者有利,但是对用户不利。同时希望能优化我们的工具,使得我们可以对两方面都有利。
### 福利时间!三款桌面浏览器
通常来说我喜欢在移动设备上运行性能测试,因为在这里我们能更清楚的看到差异。但是出于好奇,我也分别在一台搭载 i7 的 Surface Book 上的 Chrome 52、Edge 14 和 Firefox 48 上运行了测试。这分别是它们的测试结果:
Chrome 52 ([查看表格](https://gist.github.com/nolanlawson/4f79258dc05bbd2c14b85cf2196c6ef0))

Edge 14 ([查看表格](https://gist.github.com/nolanlawson/726fa47e0723b45e4ee9ecf0cf2fcddb))

Firefox 48 ([查看表格](https://gist.github.com/nolanlawson/7eed17e6ffa18752bf99a9d4bff2941f))

我在这些结果中发现的有趣的地方如下:
1. bundle-collapser 总是与 slam-dunk 完全不同。
2. Rollup 和 Closure 的下载时间与运行时间之比总是非常高,它们的运行时间基本上微不足道。ChakraCore 和 SpiderMonkey 运行最快,V8 紧随其后。
如果你的 JavaScript 非常大并且是延迟加载,那么第二点将非常重要。因为如果你可以接受等待网络下载的时间,那么使用 Rollup 和 Closure 将会有避免界面线程冻结的优点。也就是说,它们将比 Browserify 和 Webpack 更少出现界面阻塞。
更新:在这篇文章的回应中,JDD 已经 [给 Webpack 提交了一个 issue](https://github.com/webpack/webpack/issues/2873)。还有 [一个是给 Browserify 的](https://github.com/substack/node-browserify/issues/1379)。
更新 2:[Ryan Fitzer](https://github.com/nolanlawson/cost-of-small-modules/pull/5) 慷慨地增加了 RequireJS 和包含 [Almond](https://github.com/requirejs/almond) 的 RequireJS 的测试结果,两者都是使用 AMD 而不是 CommonJS 或者 ES6。
测试结果表明 RequireJS 具有 [最大的包大小](https://gist.github.com/nolanlawson/511e0ce09fed29fed040bb8673777ec5) 但是令人惊讶的是它的运行开销 [与 Rollup 和 Closure 非常接近](https://gist.github.com/nolanlawson/4e725df00cd1bc9673b25ef72b831c8b)。这是在运行 Chrome 52 的 Nexus 5 下限制网速为 3G 的测试结果:

更新 3: 我写了一个 [optimize-js](http://github.com/nolanlawson/optimize-js) ,它会减少一些函数内的函数的解析成本。
---
via: <https://nolanlawson.com/2016/08/15/the-cost-of-small-modules/>
作者:[Nolan](https://nolanlawson.com/) 译者:[Yinr](https://github.com/Yinr) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | **Update (30 Oct 2016):** since I wrote this post, [a bug was found in the benchmark](https://github.com/nolanlawson/cost-of-small-modules/pull/8) which caused Rollup to appear slightly better than it would otherwise. However, the overall results are not substantially different (Rollup still beats Browserify and Webpack, although it’s not quite as good as Closure anymore), so I’ve merely updated the charts and tables. Additionally, the benchmark now includes [the RequireJS and RequireJS Almond bundlers](https://github.com/nolanlawson/cost-of-small-modules/pull/5), so those have been added as well. To see the original blog post without these edits, check out [this archived version](https://web.archive.org/web/20160822181421/https://nolanlawson.com/2016/08/15/the-cost-of-small-modules/).
**Update (21 May 2018):** This blog post analyzed older versions of Webpack, Browserify, and other module bundlers. Later versions of these bundlers added support for features like [module concatenation](https://webpack.js.org/plugins/module-concatenation-plugin/) and [flat packing](https://github.com/goto-bus-stop/browser-pack-flat), which address most of the concerns raised in this blog post. You can get an idea for the performance improvement from these methods in [these](https://github.com/nolanlawson/cost-of-small-modules/pull/9) [PRs](https://github.com/nolanlawson/cost-of-small-modules/pull/10).
About a year ago I was refactoring a large JavaScript codebase into smaller modules, when I discovered a depressing fact about Browserify and Webpack:
“The more I modularize my code, the bigger it gets. 😕”
–[Nolan Lawson]
Later on, Sam Saccone published some excellent research on [Tumblr](https://docs.google.com/document/d/1E2w0UQ4RhId5cMYsDcdcNwsgL0gP_S6SDv27yi1mCEY/edit) and [Imgur](https://github.com/perfs/audits/issues/1)‘s page load performance, in which he noted:
“Over 400ms is being spent simply walking the Browserify tree.”
–[Sam Saccone]
In this post, I’d like to demonstrate that small modules can have a surprisingly high performance cost depending on your choice of bundler and module system. Furthermore, I’ll explain why this applies not only to the modules in your own codebase, but also to the modules *within dependencies*, which is a rarely-discussed aspect of the cost of third-party code.
### Web perf 101
The more JavaScript included on a page, the slower that page tends to be. Large JavaScript bundles cause the browser to spend more time downloading, parsing, and executing the script, all of which lead to slower load times.
Even when breaking up the code into multiple bundles – Webpack [code splitting](https://webpack.github.io/docs/code-splitting.html), Browserify [factor bundles](https://github.com/substack/factor-bundle), etc. – the cost is merely delayed until later in the page lifecycle. Sooner or later, the JavaScript piper must be paid.
Furthermore, because JavaScript is a dynamic language, and because the prevailing [CommonJS](http://www.commonjs.org/) module system is also dynamic, it’s fiendishly difficult to extract unused code from the final payload that gets shipped to users. You might only need jQuery’s `$.ajax`
, but by including jQuery, you pay the cost of the entire library.
The JavaScript community has responded to this problem by advocating the use of [small modules](http://substack.net/how_I_write_modules). Small modules have a lot of [aesthetic and practical benefits](http://dailyjs.com/2015/07/02/small-modules-complexity-over-size/) – easier to maintain, easier to comprehend, easier to plug together – but they also solve the jQuery problem by promoting the inclusion of small bits of functionality rather than big “kitchen sink” libraries.
So in the “small modules” world, instead of doing:
var _ = require('lodash') _.uniq([1,2,2,3])
You might do:
var uniq = require('lodash.uniq') uniq([1,2,2,3])
Rich Harris has already articulated why the “small modules” pattern is [inherently beginner-unfriendly](https://medium.com/@Rich_Harris/small-modules-it-s-not-quite-that-simple-3ca532d65de4), even though it tends to make life easier for library maintainers. However, there’s also a hidden performance cost to small modules that I don’t think has been adequately explored.
### Packages vs modules
It’s important to note that, when I say “modules,” I’m not talking about “packages” in the npm sense. When you install a package from npm, it might only expose a single module in its public API, but under the hood it could actually be a conglomeration of many modules.
For instance, consider a package like [is-array](https://www.npmjs.com/package/is-array). It has no dependencies and only contains [one JavaScript file](https://github.com/retrofox/is-array/blob/d79f1c90c824416b60517c04f0568b5cd3f8271d/index.js#L6-L33), so it has one module. Simple enough.
Now consider a slightly more complex package like [once](https://www.npmjs.com/package/once), which has exactly one dependency: [wrappy](https://www.npmjs.com/package/wrappy). [Both](https://github.com/isaacs/once/blob/2ad558657e17fafd24803217ba854762842e4178/once.js#L1-L21) [packages](https://github.com/npm/wrappy/blob/71d91b6dc5bdeac37e218c2cf03f9ab55b60d214/wrappy.js#L6-L33) contain one module, so the total module count is 2. So far, so good.
Now let’s consider a more deceptive example: [qs](https://www.npmjs.com/package/qs). Since it has zero dependencies, you might assume it only has one module. But in fact, it has four!
You can confirm this by using a tool I wrote called [browserify-count-modules](https://www.npmjs.com/package/browserify-count-modules), which simply counts the total number of modules in a Browserify bundle:
$ npm install qs $ browserify node_modules/qs | browserify-count-modules 4
What’s going on here? Well, if you look at the [source for qs](https://github.com/ljharb/qs/tree/988dbe421b74236f32433c9d083c7e9849a42b4e/lib), you’ll see that it contains four JavaScript files, representing four JavaScript modules which are ultimately included in the Browserify bundle.
This means that a given *package* can actually contain one or more *modules*. These modules can also depend on other packages, which might bring in their own packages and modules. The only thing you can be sure of is that each package contains *at least* one module.
### Module bloat
How many modules are in a typical web application? Well, I ran `browserify-count-modules`
on a few popular Browserify-using sites, and came up with these numbers:
[requirebin.com](http://requirebin.com): 91 modules[keybase.io](https://keybase.io): 365 modules[m.reddit.com](http://m.reddit.com): 1050 modules[Apple.com](http://images.apple.com/ipad-air-2/): 1060 modules (*Added.*)[Thanks, Max!](https://twitter.com/denormalize/status/765300194078437376)
For the record, my own [Pokedex.org](https://pokedex.org) (the largest open-source site I’ve built) contains 311 modules across four bundle files.
Ignoring for a moment the raw size of those JavaScript bundles, I think it’s interesting to explore the cost of the *number of modules* themselves. Sam Saccone has already blown this story wide open in [“The cost of transpiling es2015 in 2016”](https://github.com/samccone/The-cost-of-transpiling-es2015-in-2016#the-cost-of-transpiling-es2015-in-2016), but I don’t think his findings have gotten nearly enough press, so let’s dig a little deeper.
### Benchmark time!
I put together [a small benchmark](https://github.com/nolanlawson/cost-of-small-modules) that constructs a JavaScript module importing 100, 1000, and 5000 other modules, each of which merely exports a number. The parent module just sums the numbers together and logs the result:
// index.js var total = 0 total += require('./module_0') total += require('./module_1') total += require('./module_2') // etc. console.log(total)
// module_0.js module.exports = 0
// module_1.js module.exports = 1
(And so on.)
I tested five bundling methods: Browserify, Browserify with the [bundle-collapser](https://www.npmjs.com/package/bundle-collapser) plugin, Webpack, Rollup, and Closure Compiler. For Rollup and Closure Compiler I used ES6 modules, whereas for Browserify and Webpack I used CommonJS, so as not to unfairly disadvantage them (since they would need a transpiler like Babel, which adds its own overhead).
In order to best simulate a production environment, I used Uglify with the `--mangle`
and `--compress`
settings for all bundles, and served them gzipped over HTTPS using GitHub Pages. For each bundle, I downloaded and executed it 15 times and took the median, noting the (uncached) load time and execution time using `performance.now()`
.
### Bundle sizes
Before we get into the benchmark results, it’s worth taking a look at the bundle files themselves. Here are the byte sizes (minified but ungzipped) for each bundle ([chart view](https://nolanlawson.com/wp-content/uploads/2016/08/min.png)):
100 modules | 1000 modules | 5000 modules | |
---|---|---|---|
browserify | 7982 | 79987 | 419985 |
browserify-collapsed | 5786 | 57991 | 309982 |
webpack | 3955 | 39057 | 203054 |
rollup | 1265 | 13865 | 81851 |
closure | 758 | 7958 | 43955 |
rjs | 29234 | 136338 | 628347 |
rjs-almond | 14509 | 121612 | 613622 |
And the minified+gzipped sizes ([chart view](https://nolanlawson.com/wp-content/uploads/2016/08/mingz.png)):
100 modules | 1000 modules | 5000 modules | |
---|---|---|---|
browserify | 1650 | 13779 | 63554 |
browserify-collapsed | 1464 | 11837 | 55536 |
webpack | 688 | 4850 | 24635 |
rollup | 629 | 4604 | 22389 |
closure | 302 | 2140 | 11807 |
rjs | 7940 | 19017 | 62674 |
rjs-almond | 2732 | 13187 | 56135 |
What stands out is that the Browserify and Webpack versions are much larger than the Rollup and Closure Compiler versions (* update: especially before gzipping, which still matters since that’s what the browser executes*). If you take a look at the code inside the bundles, it becomes clear why.
The way Browserify and Webpack work is by isolating each module into its own function scope, and then declaring a top-level runtime loader that locates the proper module whenever `require()`
is called. Here’s what our Browserify bundle looks like:
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ module.exports = 0 },{}],2:[function(require,module,exports){ module.exports = 1 },{}],3:[function(require,module,exports){ module.exports = 10 },{}],4:[function(require,module,exports){ module.exports = 100 // etc.
Whereas the Rollup and Closure bundles look more like what you might hand-author if you were just writing one big module. Here’s Rollup:
(function () { 'use strict'; var module_0 = 0 var module_1 = 1 // ... total += module_0 total += module_1 // etc.
The important thing to notice is that every module in Webpack and Browserify gets its own function scope, and is loaded at runtime when `require()`
d from the main script. Rollup and Closure Compiler, on the other hand, just hoist everything into a single function scope (creating variables and namespacing them as necessary).
If you understand the inherent cost of functions-within-functions in JavaScript, and of looking up a value in an associative array, then you’ll be in a good position to understand the following benchmark results.
### Results
**Update:** as noted above, results have been re-run with corrections and the addition of the r.js and r.js Almond bundlers. For the full tabular data, see [this gist](https://gist.github.com/nolanlawson/4ba818c772be3a56cb0039551598194c).
I ran this benchmark on a Nexus 5 with Android 5.1.1 and Chrome 52 (to represent a low- to mid-range device) as well as an iPod Touch 6th generation running iOS 9 (to represent a high-end device).
Here are the results for the Nexus 5:
And here are the results for the iPod Touch:
At 100 modules, the variance between all the bundlers is pretty negligible, but once we get up to 1000 or 5000 modules, the difference becomes severe. The iPod Touch is hurt the least by the choice of bundler, but the Nexus 5, being an aging Android phone, suffers a lot under Browserify and Webpack.
I also find it interesting that both Rollup and Closure’s execution cost is essentially free for the iPod, regardless of the number of modules. And in the case of the Nexus 5, the runtime costs aren’t free, but they’re still much cheaper for Rollup/Closure than for Browserify/Webpack, the latter of which chew up the main thread for several frames if not hundreds of milliseconds, meaning that the UI is frozen just waiting for the module loader to finish running.
Note that both of these tests were run on a fast Gigabit connection, so in terms of network costs, it’s really a best-case scenario. Using the Chrome Dev Tools, we can manually throttle that Nexus 5 down to 3G and see the impact:
Once we take slow networks into account, the difference between Browserify/Webpack and Rollup/Closure is even more stark. In the case of 1000 modules (which is close to Reddit’s count of 1050), Browserify takes about 400 milliseconds longer than Rollup. And that 400ms is no small potatoes, since Google and Bing have both noted that sub-second delays have an [appreciable impact on user engagement](http://radar.oreilly.com/2009/06/bing-and-google-agree-slow-pag.html).
One thing to note is that this benchmark doesn’t measure the precise execution cost of 100, 1000, or 5000 modules *per se*, since that will depend on your usage of `require()`
. Inside of these bundles, I’m calling `require()`
once per module, but if you are calling `require()`
multiple times per module (which is the norm in most codebases) or if you are calling `require()`
multiple times on-the-fly (i.e. `require()`
within a sub-function), then you could see severe performance degradations.
Reddit’s mobile site is a good example of this. Even though they have 1050 modules, I clocked their real-world Browserify execution time as much worse than the “1000 modules” benchmark. When profiling on that same Nexus 5 running Chrome, I measured 2.14 seconds for Reddit’s Browserify `require()`
function, and 197 milliseconds for the equivalent function in the “1000 modules” script. (In desktop Chrome on an i7 Surface Book, I also measured it at 559ms vs 37ms, which is pretty astonishing given we’re talking *desktop*.)
This suggests that it may be worthwhile to run the benchmark again with multiple `require()`
s per module, although in my opinion it wouldn’t be a fair fight for Browserify/Webpack, since Rollup/Closure both resolve duplicate ES6 imports into a single hoisted variable declaration, and it’s also impossible to `import`
from anywhere but the top-level scope. So in essence, the cost of a single `import`
for Rollup/Closure is the same as the cost of *n* `import`
s, whereas for Browserify/Webpack, the execution cost will increase linearly with *n* `require()`
s.
For the purposes of this analysis, though, I think it’s best to just assume that the number of modules is only a *lower* bound for the performance hit you might feel. In reality, the “5000 modules” benchmark may be a better yardstick for “5000 `require()`
calls.”
### Conclusions
First off, the `bundle-collapser`
plugin seems to be a valuable addition to Browserify. If you’re not using it in production, then your bundle will be a bit larger and slower than it would be otherwise (although I must admit the difference is slight). Alternatively, you could switch to Webpack and get an even faster bundle without any extra configuration. (Note that it pains me to say this, since I’m a diehard Browserify fanboy.)
However, these results clearly show that Webpack and Browserify both underperform compared to Rollup and Closure Compiler, and that the gap widens the more modules you add. Unfortunately I’m not sure [Webpack 2](https://gist.github.com/sokra/27b24881210b56bbaff7) will solve any of these problems, because although they’ll be [borrowing some ideas from Rollup](http://www.2ality.com/2015/12/webpack-tree-shaking.html), they seem to be more focused on the [tree-shaking aspects](http://www.2ality.com/2015/12/bundling-modules-future.html) and not the scope-hoisting aspects. *( Update: a better name is “inlining,” and the Webpack team is working on it.)*
Given these results, I’m surprised Closure Compiler and Rollup aren’t getting much traction in the JavaScript community. I’m guessing it’s due to the fact that (in the case of the former) it has a Java dependency, and (in the case of the latter) it’s still fairly immature and doesn’t quite work out-of-the-box yet (see [Calvin’s Metcalf’s comments](https://github.com/rollup/rollup/issues/552) for a good summary).
Even without the average JavaScript developer jumping on the Rollup/Closure bandwagon, though, I think npm package authors are already in a good position to help solve this problem. If you `npm install lodash`
, you’ll notice that the main export is one giant JavaScript module, rather than what you might expect given Lodash’s hyper-modular nature (`require('lodash/uniq')`
, `require('lodash.uniq')`
, etc.). For PouchDB, we made a similar decision to [use Rollup as a prepublish step](http://pouchdb.com/2016/01/13/pouchdb-5.2.0-a-better-build-system-with-rollup.html), which produces the smallest possible bundle in a way that’s invisible to users.
I also created [rollupify](https://github.com/nolanlawson/rollupify) to try to make this pattern a bit easier to just drop-in to existing Browserify projects. The basic idea is to use `import`
s and `export`
s within your own project ([cjs-to-es6](https://github.com/nolanlawson/cjs-to-es6) can help migrate), and then use `require()`
for third-party packages. That way, you still have all the benefits of modularity within your own codebase, while exposing more-or-less one big module to your users. Unfortunately, you still pay the costs for third-party modules, but I’ve found that this is a good compromise given the current state of the npm ecosystem.
So there you have it: one horse-sized JavaScript duck is faster than a hundred duck-sized JavaScript horses. Despite this fact, though, I hope that our community will eventually realize the pickle we’re in – advocating for a “small modules” philosophy that’s good for developers but bad for users – and improve our tools, so that we can have the best of both worlds.
### Bonus round! Three desktop browsers
Normally I like to run performance tests on mobile devices, since that’s where you see the clearest differences. But out of curiosity, I also ran this benchmark on Chrome 54, Edge 14, and Firefox 48 on an i5 Surface Book using Windows 10 RS1. Here are the results:
**Chrome 54**
**Edge 14** ([tabular results](https://gist.github.com/nolanlawson/726fa47e0723b45e4ee9ecf0cf2fcddb))
**Firefox 48** ([tabular results](https://gist.github.com/nolanlawson/7eed17e6ffa18752bf99a9d4bff2941f))
The only interesting tidbits I’ll call out in these results are:
`bundle-collapser`
is definitely not a slam-dunk in all cases.- The ratio of network-to-execution time is always extremely high for Rollup and Closure; their runtime costs are basically zilch. ChakraCore and SpiderMonkey eat them up for breakfast, and V8 is not far behind.
This latter point could be extremely important if your JavaScript is largely lazy-loaded, because if you can afford to wait on the network, then using Rollup and Closure will have the additional benefit of not clogging up the UI thread, i.e. they’ll introduce less jank than Browserify or Webpack.
**Update:** in response to this post, JDD has [opened an issue on Webpack](https://github.com/webpack/webpack/issues/2873). There’s also [one on Browserify](https://github.com/substack/node-browserify/issues/1379).
**Update 2:** [Ryan Fitzer](https://github.com/nolanlawson/cost-of-small-modules/pull/5) has generously added RequireJS and RequireJS with [Almond](https://github.com/requirejs/almond) to the benchmark, both of which use AMD instead of CommonJS or ES6.
Testing shows that RequireJS has [the largest bundle sizes](https://gist.github.com/nolanlawson/511e0ce09fed29fed040bb8673777ec5) but surprisingly its runtime costs are [very close to Rollup and Closure](https://gist.github.com/nolanlawson/4e725df00cd1bc9673b25ef72b831c8b). (See updated results above for details.)
**Update 3:** I wrote [optimize-js](http://github.com/nolanlawson/optimize-js), which alleviates some of the performance costs of parsing functions-within-functions.
Posted by kimbynd on August 15, 2016 at 10:57 AM
It’d be interesting to see a comparison with JSPM/System JS, and accounting for caching of modules, saving multiple network requests
Reply
Posted by Nolan Lawson on August 21, 2016 at 8:06 AM
JSPM/SystemJS uses Rollup under the hood. As for caching of modules, these are single bundles, so there’s only one network request.
Reply
Posted by jetpl on August 16, 2016 at 2:33 AM
Agree, would be great if you could prepare a comparison based also on JSPM/System JS.
Thanks for a great article.
Reply
Posted by Nolan Lawson on August 17, 2016 at 7:34 AM
Seems JSPM/SystemJS uses Rollup under the hood.
Reply
Posted by dino on September 3, 2016 at 4:20 PM
JSPM uses rollup for any ES modules, your own package and maybe some 3rd party, but most 3rd party modules are imported in commonJS or UMD module formats.
JSPM build command will list the module which had been optimised with rollup.
JSPM offers can override a package definition (which where to find the main module where is source directory, etc.) to use its ES module if the npm package include them.
Posted by tobielangel on August 16, 2016 at 3:36 AM
Yes. Scope-hoisting is critical. It’s a complex but doable AST transform. It’s sort of disappointing (but not very surprising) to see Google nailing this close to a decade ago, and very little happening in the JS community on that topic since.
Reply
Posted by Nolan Lawson on August 17, 2016 at 7:33 AM
I think the reason is that priority #1 with Webpack and (especially) Browserify was compatibility with the Node ecosystem. They needed to be able to use a large percentage of npm’s 300,000 packages in order to gain traction.
That meant implementing
`require()`
to a T despite all its faults (dynamic, not-top-scoped, try/catchable), plus implementing a heck of a lot of Node-isms – calvinmetcalf/immediate and feross/buffer are a testament to how complex it is to migrate Node APIs like`process.nextTick`
and`Buffer`
to the browser.But now that we’ve got a large number of npm’s 300,000 modules available in the browser, it’s time to optimize. Step #1 unfortunately may be to try to convince popular package authors to switch from CommonJS to ES6 modules, or maybe to write a Rollup-like optimizer for CommonJS that bails out with an unoptimizable pattern is used.
Reply
Posted by tobielangel on August 27, 2016 at 2:47 AM
Oh that’s interesting. I don’t recall constructs outside of dynamic module names that were common and that would have prevented module hoisting. But that was nearly 5 years ago and my memory’s kind of fuzzy at this point. iirc, I was also hawkish about preventing features that might have made the system less optimizable for perf.
Posted by Vasco on August 18, 2016 at 10:29 AM
Do you mean that GWT supported this ?
Reply
Posted by Nolan Lawson on August 18, 2016 at 4:45 PM
Think he meant Google Closure Compiler.
Posted by tobielangel on August 27, 2016 at 2:48 AM
What nolan said.
Posted by garbas on August 16, 2016 at 6:49 AM
would this be possible to extend to Elm?
Reply
Posted by timmywil on August 16, 2016 at 7:16 AM
This is neither here nor there, but you can use jQuery.ajax on its own either through the use of AMD (or a module bundler that can consume AMD).
Reply
Posted by timmywil on August 16, 2016 at 7:21 AM
Oh, besides AMD, you can use the custom build system and just include ajax.
Reply
Posted by CouchDB Weekly News, August 18, 2016 – CouchDB Blog on August 18, 2016 at 9:06 AM
[…] The cost of small modules, Nolan […]
Reply
Posted by dtothefp on August 18, 2016 at 11:37 AM
I agree that Rollup style bundles are much more effective by throwing all your modules into a single closure scope. Although we encountered many problems when implementing Rollup in anything more than a trivial project. To get it to play well with non es6 dependencies requires confusing config and issues on their GH suggest that it won’t even work for React/Redux projects https://github.com/rollup/rollup-plugin-commonjs/issues/29. Also from placing issues on multiple plugins and receiving little to no response without these issues ever being closed was frustrating and suggests the project is not actively maintained.
If you have some magic bullets for Rollup it would be great to learn them but otherwise it doesn’t seem mature enough
Reply
Posted by Hanter on August 18, 2016 at 10:22 PM
I stoped reading at “The way Browserify and Webpack work is by isolating each module into its own function scope”. This is true for webpack in dev-mode. Have you ever tried
“webpack -p” for production mode?
https://webpack.github.io/docs/cli.html
Reply
Posted by Sean Vieira on August 19, 2016 at 2:17 PM
Does the same individual module wrapping, just orders them so that more commonly required ones have smaller numbers.
Reply
Posted by Nolan Lawson on August 19, 2016 at 6:06 PM
Yup, I didn’t use
`--production`
, but in this case it shouldn’t make a difference because each module is used exactly once. I ran it just now and verified that the only difference is that`--production`
orders the`require()`
s based on numeric order (because that’s the order they’re used) rather than the default lexicographic order (i.e. 1,2,3,4,5,… instead of 1,10,2,20,3,30,…).The bundle size will end up being the same, and the different ordering may have a teensy impact on runtime perf depending on how the underlying hashmap optimizes access order, but ought to be largely the same (although of course, it’s worth testing. :)).
Posted by Nolan Lawson on August 20, 2016 at 2:46 PM
I’ve added
`webpack -p`
to the build script, don’t see much change in the results.Posted by foljs on August 21, 2016 at 3:23 PM
@Hanter >I stoped reading at “The way Browserify and Webpack work is by isolating each module into its own function scope”.
I stopped reading when I read your rude comment about when you stopped reading. Someone takes the time to write a large post on an important performance issue, and the only think you can contribute is a knee jerk pedantic correction, and for something that’s inconsequential at that.
Besides, if you haven’t “stopped reading” articles before their end, you might have learned by now that an article can contain one or more factual errors or misconceptions, and still have valuable insights and information.
Reply
Posted by Web Development Reading List #150: Less Code, GitHub’s Security, And The Morals Of Science – Smashing Magazine on August 19, 2016 at 2:36 AM
[…] Lawson wrote about the cost of small modules14, analyzing how much code is used when you build your codebase with a lot of small modules. The […]
Reply
Posted by Joe Zimmerman on August 20, 2016 at 9:10 PM
Yea, saw Rollup a while back but it seemed very immature so I didn’t think much of it. Advertised the tree shaking a lot, which I figured would either not work as well as advertised or would get added to the big name bundlers. The single scope thing also scared the heck out of me, so I decided ignore it. I’m hoping ES2015 will be fully ready to use in browsers soon plus HTTP2 so we can just forget this whole mess.
Reply
Posted by Nolan Lawson on August 21, 2016 at 8:11 AM
I suspect bundling will always be faster than native ES6 modules in the browser, even in an H2 world. Khan Engineering has a blog post on this, but what it comes down to is the benefits of gzip operating on one big bundle.
Rollup’s tree-shaking and scope-hoisting work great in my experience; where it gets tricky is all the hard edge cases that Browserify/Webpack have already solved, such as
`global`
,`process.nextTick()`
,`Buffer`
, etc. Rollup has plugins, but not all of them are complete, and there’s a lot of configuration.Reply
Posted by tkane2000 on August 22, 2016 at 6:01 AM
Can we assume a direct correlation between bundle size and load time or am I missing something here?
Reply
Posted by Nolan Lawson on August 22, 2016 at 6:20 PM
Yes, that’s a pretty fair assumption. Although “load” in this case also includes script parsing time, which will be longer for more complex scripts (regardless of length).
Reply
Posted by wmadden on August 23, 2016 at 12:49 AM
What about webpack/ES6 modules? You pointed out yourself that language level optimizations with CommonJS modules are next to impossible, then you pit two CommonJS compilers against ES6 module compilers. That seems a bit silly.
Anyway, is WebPack’s performance really so poor in and of itself, or is it a consequence of using CommonJS modules?
Reply
Posted by Nolan Lawson on August 23, 2016 at 11:08 AM
Yes, I probably could have called this article “The Cost of CommonJS.” Current Webpack plans to fix the issues I described will probably only apply to dependencies that export ES6 modules, not CJS.
OTOH Closure claims to be able to apply some of these optimizations to CJS, but I’m a bit skeptical because there are edge cases it undoubtedly can’t handle due to CJS’s dynamic nature (conditional exports/imports, try/catch imports/exports,
`var mymodule = exports; mymodule.foo = 'bar';`
etc.).Reply
Posted by srcspider on August 23, 2016 at 1:29 AM
With webpack you
shouldbe using require.ensure and only distributing the minimal required code per page (which shouldn’t really be that big). So… the so called performance comparison is a bit unfair. Yes X performs better when you have 1000, but Y prevents you from having 1000 to begin with.Reply
Posted by Nolan Lawson on August 23, 2016 at 11:16 AM
I don’t feel it’s an unfair characterization. As I say in the post,
`require.ensure`
, code-splitting, etc. can only delay the cost of the bundled modules. And the cost still exists, even for a small number of modules.The point of my article is that our bundlers are not free, although arguably they should be. Even with code-splitting, in the ideal case you’d split 1000 modules into 500 and 500 (for example), but within those 500-sized bundles, you wouldn’t be paying an extra execution cost just for the runtime module resolution algorithm. Rollup and Closure prove this is possible.
Reply
Posted by jagretz on August 24, 2016 at 10:47 AM
Just wanted to say thank you for the awesome post! Very informative, updated with links to corresponding updates, and you’ve responded to many comments. Great article Nolan!
Reply
Posted by Nolan Lawson on September 23, 2016 at 2:53 PM
Thank you! :)
Reply
Posted by Chema Balsas (@jbalsas) on August 26, 2016 at 5:16 AM
Closure Compiler is now available in JS flavour at https://github.com/google/closure-compiler-js ;)
Reply
Posted by zaenk on September 2, 2016 at 12:19 AM
wow, this article is getting old so quickly! :D
Reply
Posted by Nolan Lawson on September 23, 2016 at 2:52 PM
It’s worth testing, but my understanding is that the JS version is a port of the Java version, meaning that the output should be the same.
Posted by lr on September 3, 2016 at 11:34 AM
How about Lasso?
Reply
Posted by Alex on September 5, 2016 at 10:35 PM
I wonder if Brunch would do any better/worse than webpack?
Reply
Posted by Revision 276 – Große Module, kleine Module? Viel Code, wenig Code? | Working Draft on September 14, 2016 at 10:00 PM
[…] unterschiedlich viel Respekt zollen) weiter bestehen und verwendet werden, obwohl auch diese ihre ganz eigenen Probleme haben. Am Ende diskutieren wir über den Weg der Zukunft: kleine Module? Große Module mit […]
Reply
Posted by adityavohra7 on September 19, 2016 at 1:51 PM
Sorry for the incredibly long comment. I might followup with an actual blog post if people would like a better place to discuss things.
While I greatly appreciate the research and findings in this blog post from a strictly performance perspective, I have some gripes with this statement – “Given these results, I’m surprised Closure Compiler and Rollup aren’t getting much traction in the JavaScript community.”
It’s quite possible I’m wrong about some of these (and I’d love to be corrected). Here are a few things I’ve found personally that have made it hard to work with Closure Compiler:
It’s relatively hard to integrate third party libraries
Say I want to bundle/compile third party libraries with my project’s source. Closure Compiler has some quirks (which allow it to optimize code better) that make it hard to do so. For example, Closure minifies string literal object keys and identifier object keys differently. Not a lot (if any) modern open source library authors would keep that in mind when writing libraries. This makes third party libraries incompatible with compilation by Closure in ADVANCED compilation mode (the mode one would use to achieve max compression).
http://blog.persistent.info/2015/05/teaching-closure-compiler-about-react.html talks about how a custom compiler pass had to be written to teach Closure about React constructs. And considering Closure doesn’t provide a command line option to specify command line passes, they probably forked Closure to implement a custom command line runner. I personally like to steer away from maintaining forks of giant projects (however small the differences).
So if you’re not bundling third party libraries, you’re probably going to pre-load them onto your website’s pages and use externs as described here – https://developers.google.com/closure/compiler/docs/api-tutorial3. The Closure folks have made externs for some common open source libraries available online – https://github.com/google/closure-compiler/wiki/Externs-For-Common-Libraries. The latest jQuery externs are for v1.9. jQuery is now at v3.1. The latest React externs are for v0.13.2. React is now at v15 (with a change in how they version things). And if you can’t find externs for the third party library you want to use, you’re going to have to write and maintain them yourself, and keep them up to date with updates to the library.
Devs might have to wait a fair bit between JS changes in dev
Your benchmarks don’t mention how long it takes to compile the bundles produced from 100, 1000, and 5000 modules for the various bundlers used. More importantly, you don’t talk about how long a dev would have to wait between any JS changes if they were using Closure and were compiling a giant codebase (if you’re using ES6 with Closure, you’re probably compiling your code even in dev and using sourcemaps). Closure doesn’t support incremental compilation whereas Webpack and other bundlers do. Waiting more than a couple of seconds between JS changes is a red flag. With incremental building, you wait on the order of milliseconds.
Further, the more advanced the compiled bundle in its optimizations (inlining, moving code around, dead code elimination), the poorer the sourcemaps. If devs can’t set breakpoints easily, that’s a red flag.
Closure JS isn’t exactly canonical JS
Non-ES6 Closure JS involves using Closure primitives such as goog.provide, goog.require, goog.module, etc. to declare dependencies between files/namespaces. No other compiler understands these constructs out of the box. So you’re bound to the Closure Compiler as long as you continue writing JS that includes any of these constructs. Also, not a lot of people will care about any JS you open source if it uses Google Closure primitives.
If you choose to use ES6 and compile that with Closure, you’re still restricted in terms of what you can use. https://github.com/google/closure-compiler/wiki/ECMAScript6 shows what ES6 features Closure supports. The Closure folks admit that “supporting the entire ES6 specification is a non-goal for the Closure Compiler”. They do support a lot, but there might come a point where you want to use some ES6 features that Closure doesn’t support. Even the ES6 features that are supported have some Closure quirks (object shorthand notation, what modern linters like eslint recommend, minify differently with Closure than other compilers).
There isn’t enough open source tooling around Closure Compiler
Google open sourced the compiler, but they didn’t open source any of the tooling the company probably uses internally to support the usage of the compiler.
As an example, the compiler doesn’t do any file discovery whatsoever. It needs to be passed in all the JS files you want it to compile as individual command line arguments. This means you need to figure out what files the compiler needs to be called with are. What’s worse is that the order of the JS inputs to the Closure Compiler matters (unless you pass in certain other flags). Closure does support glob patterns as a means to specify inputs, which helps with this issue a little. But you basically need to write and maintain all the logic that passes the right arguments to Closure in the right order.
http://plovr.com/ is an open source project that can be used as a wrapper around the Closure Compiler. But that project lags behind in its updates of the bundled Closure Compiler by at least a few months, and it doesn’t support the resolution of ES6 modules.
Reply
Posted by adityavohra7 on September 19, 2016 at 2:01 PM
s/”And considering Closure doesn’t provide a command line option to specify command line passes”/”And considering Closure doesn’t provide a command line option to specify custom compiler passes”
Reply
Posted by Front-End Performance Checklist 2017 (PDF, Apple Pages) – Smashing Magazine on December 21, 2016 at 2:34 AM
[…] ECMAScript 2015 modules into one big CommonJS module — because small modules can have a surprisingly high performance cost101 depending on your choice of bundler and module […]
Reply
Posted by Angular 4 réduit la taille du code généré, et ajoute des fonctionnalités on March 27, 2017 at 1:55 AM
[…] significatif lors de l’exécution d’un template. On va également retrouver des versions « Flat » des modules Angular, ou encore disposer d’une plus grande souplesse lors de l’utilisation […]
Reply
Posted by Angular4.0.0リリース その特徴とは | 株式会社 Cadenza先端技術研究所 on April 9, 2017 at 6:20 AM
[…] Flat ES Modulesの重要性に対して The cost of small modulesを参照してください。 […]
Reply
Posted by Angular 4 – estude isso on April 13, 2017 at 12:57 PM
[…] Leia mais sobre a importância dos módulos Flat ES “The cost of small modules”. […]
Reply
Posted by Revision 276: Große Module, kleine Module? Viel Code, wenig Code? | Working Draft on September 4, 2018 at 5:30 AM
[…] unterschiedlich viel Respekt zollen) weiter bestehen und verwendet werden, obwohl auch diese ihre ganz eigenen Probleme haben. Am Ende diskutieren wir über den Weg der Zukunft: kleine Module? Große Module mit […]
Reply
Posted by Things I’ve been wrong about, things I’ve been right about | Read the Tea Leaves on January 1, 2019 at 3:46 PM
[…] “The cost of small modules” was one of my most-read posts of 2016, and in terms of the overall conclusions, I was right. JavaScript compilation and initial execution are expensive, as has been covered quite well by Addy Osmani in “The cost of JavaScript”. […]
Reply
Posted by jsinjs on June 10, 2019 at 5:49 AM
Would be very interesting to see this compared with bit.dev (https://bit.dev) – which makes it a lot easier and lightweight to share more components
Reply
Posted by How to write about web performance | Read the Tea Leaves on September 12, 2021 at 9:06 AM
[…] instance, I wrote about how bundlers like Rollup produced smaller JavaScript files than bundlers like Webpack, and Webpack eventually improved its implementation. I filed a bug on […]
Reply
Posted by Jimmy on January 20, 2022 at 11:16 AM
You did a comparison with
total += require(‘./module_0’)
total += require(‘./module_1’)
total += require(‘./module_2’)
what if you had use the extension instead?
total += require(‘./module_0.js’)
total += require(‘./module_1.js’)
total += require(‘./module_2.js’)
Then it would not have to 2nd guess each and every file and save you from guessing what you meant by the path
is it real file? no is path + .js a real file? no, is it a folder then? yes, then load index.js
what is the cost of being explicit vs implicit?
Reply
Posted by What is flat bundling and why is Rollup better at this than Webpack? - PhotoLens on February 24, 2022 at 8:42 PM
[…] and will also evaluate faster because there’s less indirection (more information on that — The cost of small modules). The trade-off is that this behaviour relies on ES2015 module semantics, and it means that some of […]
Reply
Posted by Bower와 npm의 차이점은 무엇입니까? - 다양한 이야기들 on September 20, 2022 at 4:22 PM
[…] 8월 현재 Webpack과 롤업은 Browserify보다 낫다는 평가를 받고 […]
Reply
Posted by What is the difference between Bower and npm? on November 28, 2022 at 1:45 PM
[…] that Webpack and rollup are widely regarded to be better than Browserify as of Aug […]
Reply
Posted by Link from August 22nd, 2016 at 5:01pm on February 17, 2024 at 12:11 PM
[…] “Small modules can have a surprisingly high performance cost depending on your choice of bundler and module system.” https://nolanlawson.com/2016/08/15/the-cost-of-small-modules/ […]
Reply |
7,969 | 我成为软件工程师的原因和经历 | https://opensource.com/life/16/4/my-open-source-story-gloria-bwandungi | 2016-11-19T09:51:00 | [
"软件工程师"
] | https://linux.cn/article-7969-1.html | 
1989 年乌干达首都,坎帕拉。
我明智的父母决定与其将我留在家里添麻烦,不如把我送到叔叔的办公室学学电脑。几天后,我和另外六、七个小孩,还有一台放置在课桌上的崭新电脑,一起置身于 21 层楼的一间狭小房屋中。很明显我们还不够格去碰那家伙。在长达三周无趣的 DOS 命令学习后,美好时光来到,终于轮到我来输 **copy doc.txt d:** 啦。
那将文件写入五英寸软盘的奇怪的声音,听起来却像音乐般美妙。那段时间,这块软盘简直成为了我的至宝。我把所有可以拷贝的东西都放在上面了。然而,1989 年的乌干达,人们的生活十分“正统”,相比较而言,捣鼓电脑、拷贝文件还有格式化磁盘就称不上“正统”。于是我不得不专注于自己接受的教育,远离计算机科学,走入建筑工程学。
之后几年里,我和同龄人一样,干过很多份工作也学到了许多技能。我教过幼儿园的小朋友,也教过大人如何使用软件,在服装店工作过,还在教堂中担任过引座员。在我获取堪萨斯大学的学位时,我正在技术管理员的手下做技术助理,听上去比较神气,其实也就是搞搞学生数据库而已。
当我 2007 年毕业时,计算机技术已经变得不可或缺。建筑工程学的方方面面都与计算机科学深深的交织在一起,所以我们不经意间学了些简单的编程知识。我对于这方面一直很着迷,但我不得不成为一位“正统”的工程师,由此我发展了一项秘密的私人爱好:写科幻小说。
在我的故事中,我以我笔下的女主角的形式存在。她们都是编程能力出众的科学家,总是卷入冒险,并用自己的技术发明战胜那些渣渣们,有时甚至要在现场发明新方法。我提到的这些“新技术”,有的是基于真实世界中的发明,也有些是从科幻小说中读到的。这就意味着我需要了解这些技术的原理,而且我的研究使我关注了许多有趣的 reddit 版块和电子杂志。
### 开源:巨大的宝库
那几周在 DOS 命令上花费的经历对我影响巨大,我在一些非专业的项目上耗费心血,并占据了宝贵的学习时间。Geocities 刚向所有 Yahoo! 用户开放时,我就创建了一个网站,用于发布一些用小型数码相机拍摄的个人图片。我建立多个免费网站,帮助家人和朋友解决一些他们所遇到的电脑问题,还为教堂搭建了一个图书馆数据库。
这意味着,我需要一直研究并尝试获取更多的信息,使它们变得更棒。互联网上帝保佑我,让开源进入我的视野。突然之间,30 天试用期和 license 限制对我而言就变成了过去式。我可以完全不受这些限制,继续使用 GIMP、Inkscape 和 OpenOffice。
### 是正经做些事情的时候了
我很幸运,有商业伙伴喜欢我的经历。她也是个想象力丰富的人,期待更高效、更便捷的互联世界。我们根据我们以往成功道路中经历的弱点制定了解决方案,但执行却成了一个问题。我们都缺乏给产品带来活力的能力,每当我们试图将想法带到投资人面前时,这表现的尤为突出。
我们需要学习编程。于是 2015 年夏末,我们来到 Holberton 学校。那是一所座落于旧金山,由社区推进,基于项目教学的学校。
一天早晨我的商业伙伴来找我,以她独有的方式(每当她有疯狂想法想要拉我入伙时),进行一场对话。
**Zee**: Gloria,我想和你说点事,在你说“不”前能先听我说完吗?
**Me**: 不行。
**Zee**: 为做全栈工程师,咱们申请上一所学校吧。
**Me**: 什么?
**Zee**: 就是这,看!就是这所学校,我们要申请这所学校来学习编程。
**Me**: 我不明白。我们不是正在网上学 Python 和…
**Zee**: 这不一样。相信我。
**Me**: 那…
**Zee**: 这就是不信任我了。
**Me**: 好吧 … 给我看看。
### 抛开偏见
我读到的和我们在网上看的的似乎很相似。这简直太棒了,以至于让人觉得不太真实,但我们还是决定尝试一下,全力以赴,看看结果如何。
要成为学生,我们需要经历四步选择,不过选择的依据仅仅是天赋和动机,而不是学历和编程经历。筛选便是课程的开始,通过它我们开始学习与合作。
根据我和我伙伴的经验, Holberton 学校的申请流程比其他的申请流程有趣太多了,就像场游戏。如果你完成了一项挑战,就能通往下一关,在那里有别的有趣的挑战正等着你。我们创建了 Twitter 账号,在 Medium 上写博客,为创建网站而学习 HTML 和 CSS, 打造了一个充满活力的在线社区,虽然在此之前我们并不知晓有谁会来。
在线社区最吸引人的就是大家有多种多样的使用电脑的经验,而背景和性别不是社区创始人(我们私下里称他们为“The Trinity”)做出选择的因素。大家只是喜欢聚在一块儿交流。我们都行进在通过学习编程来提升自己计算机技术的旅途上。
相较于其他的的申请流程,我们不需要泄露很多的身份信息。就像我的伙伴,她的名字里看不出她的性别和种族。直到最后一个步骤,在视频聊天的时候, The Trinity 才知道她是一位有色人种女性。迄今为止,促使她达到这个级别的只是她的热情和才华。肤色和性别并没有妨碍或者帮助到她。还有比这更酷的吗?
获得录取通知书的晚上,我们知道生活将向我们的梦想转变。2016 年 1 月 22 日,我们来到巴特瑞大街 98 号,去见我们的同学们 [Hippokampoiers](https://twitter.com/hippokampoiers),这是我们的初次见面。很明显,在见面之前,“The Trinity”已经做了很多工作,聚集了一批形形色色的人,他们充满激情与热情,致力于成长为全栈工程师。
这所学校有种与众不同的体验。每天都是向某一方面编程的一次竭力的冲锋。交给我们的工程,并不会有很多指导,我们需要使用一切可以使用的资源找出解决方案。[Holberton 学校](https://www.holbertonschool.com/) 认为信息来源相较于以前已经大大丰富了。MOOC(大型开放式课程)、教程、可用的开源软件和项目,以及线上社区等等,为我们完成项目提供了足够的知识。加之宝贵的导师团队来指导我们制定解决方案,这所学校变得并不仅仅是一所学校;我们已经成为了求学者的团体。任何对软件工程感兴趣并对这种学习方法感兴趣的人,我都强烈推荐这所学校。在这里的经历会让人有些悲喜交加,但是绝对值得。
### 开源问题
我最早使用的开源系统是 [Fedora](https://en.wikipedia.org/wiki/Fedora_(operating_system)),一个 [Red Hat](https://www.redhat.com/) 赞助的项目。与 一名IRC 成员交流时,她推荐了这款免费的操作系统。 虽然在此之前,我还未独自安装过操作系统,但是这激起了我对开源的兴趣和日常使用计算机时对开源软件的依赖性。我们提倡为开源贡献代码,创造并使用开源的项目。我们的项目就在 Github 上,任何人都可以使用或是向它贡献出自己的力量。我们也会使用或以自己的方式为一些既存的开源项目做出贡献。在学校里,我们使用的大部分工具是开源的,例如 Fedora、[Vagrant](https://www.vagrantup.com/)、[VirtualBox](https://www.virtualbox.org/)、[GCC](https://gcc.gnu.org/) 和 [Discourse](https://www.discourse.org/),仅举几例。
在向软件工程师行进的路上,我始终憧憬着有朝一日能为开源社区做出一份贡献,能与他人分享我所掌握的知识。
### 多样性问题
站在教室里,和 29 位求学者交流心得,真是令人陶醉。学员中 40% 是女性, 44% 是有色人种。当你是一位有色人种且为女性,并身处于这个以缺乏多样性而著名的领域时,这些数字就变得非常重要了。这是高科技圣地麦加上的绿洲,我到达了。
想要成为一个全栈工程师是十分困难的,你甚至很难了解这意味着什么。这是一条充满挑战但又有丰富回报的旅途。科技推动着未来飞速发展,而你也是美好未来很重要的一部分。虽然媒体在持续的关注解决科技公司的多样化的问题,但是如果能认清自己,清楚自己的背景,知道自己为什么想成为一名全栈工程师,你便能在某一方面迅速成长。
不过可能最重要的是,告诉大家,女性在计算机的发展史上扮演过多么重要的角色,以帮助更多的女性回归到科技界,而且在给予就业机会时,不会因性别等因素而感到犹豫。女性的才能将会共同影响科技的未来,以及整个世界的未来。
---
via: <https://opensource.com/life/16/4/my-open-source-story-gloria-bwandungi>
作者:[Gloria Bwandungi](https://opensource.com/users/nappybrain) 译者:[martin2011qi](https://github.com/martin2011qi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | The year was 1989. The city was Kampala, Uganda.
In their infinite wisdom, my parents decided that instead of all the troublemaking I was getting into at home, they would send me off to my uncle's office to learn how to use a computer. A few days later, I found myself on the 21st floor in a cramped room with six or seven other teens and a brand new computer on a desk perpendicular to the teacher's desk. It was made abundantly clear that we were not skilled enough to touch it. After three frustrating weeks of writing and perfecting DOS commands, the magic moment happened. It was my turn to type **copy doc.txt d:**.
The alien scratching noises that etched a simple text file onto the five-inch floppy sounded like beautiful music. For a while, that floppy disk was my most prized possession. I copied everything I could onto it. However, in 1989, Ugandans tended to take life pretty seriously, and messing around with computers, copying files, and formatting disks did not count as serious. I had to focus on my education, which led me away from computer science and into architectural engineering.
Like any young person of my generation, a multitude of job titles and skills acquisition filled the years in between. I taught kindergarten, taught adults how to use software, worked in a clothing store, and served as a paid usher in a church. While I earned my degree at the University of Kansas, I worked as a tech assistant to the technical administrator, which is really just a fancy title for someone who messes around with the student database.
By the time I graduated in 2007, technology had become inescapable. Every aspect of architectural engineering was deeply intertwined with computer science, so we all inadvertently learned simple programming skills. For me, that part was always more fascinating. But because I had to be a serious engineer, I developed a secret hobby: writing science fiction.
In my stories, I lived vicariously through the lives of my heroines. They were scientists with amazing programming skills who were always getting embroiled in adventures and fighting tech scallywags with technology they invented, sometimes inventing them on the spot. Sometimes the new tech I came up with was based on real-world inventions. Other times it was the stuff I read about or saw in the science fiction I consumed. This meant that I had to understand how the tech worked and my research led me to some interesting subreddits and e-zines.
## Open source: The ultimate goldmine
Throughout my experiences, the fascinating weeks I'd spent writing out DOS commands remained a prominent influence, bleeding into little side projects and occupying valuable study time. As soon as Geocities became available to all Yahoo! Users, I created a website where I published blurry pictures that I'd taken on a tiny digital camera. I created websites for free, helped friends and family fix issues they had with their computers, and created a library database for a church.
This meant that I was always researching and trying to find more information about how things could be made better. The Internet gods blessed me and open source fell into my lap. Suddenly, 30-day trials and restrictive licenses became a ghost of computing past. I could continue to create using GIMP, Inkscape, and OpenOffice.
## Time to get serious
I was fortunate to have a business partner who saw the magic in my stories. She too is a dreamer and visionary who imagines a better connected world that functions efficiently and conveniently. Together, we came up with several solutions to pain points we experienced in the journey to success, but implementation had been a problem. We both lacked the skills to make our products come to life, something that was made evident every time we approached investors with our ideas.
We needed to learn to program. So, at the end of the summer in 2015, we embarked on a journey that would lead us right to the front steps of [Holberton School](https://www.holbertonschool.com/), a community-driven, project-based school in San Francisco.
My business partner came to me one morning and started a conversation the way she does when she has a new crazy idea that I'm about to get sucked into.
**Zee:** Gloria, I'm going to tell you something and I want you to listen first before you say no.
**Me:** No.
**Zee:** We're going to be applying to go to a school for full-stack engineers.
**Me:** What?
**Zee:** Here, look! We're going to learn how to program by applying to this school.
**Me:** I don't understand. We're doing online courses in Python and...
**Zee:** This is different. Trust me.
**Me:** What about the...
**Zee:** That's not trusting me.
**Me:** Fine. Show me.
## Removing the bias
What I read sounded similar to something we had seen online. It was too good to be true, but we decided to give it a try, jump in with both feet, and see what would come out of it.
To become students, we had to go through a four-step selection process based solely on talent and motivation, not on the basis of educational degree or programming experience. The selection process is the beginning of the curriculum, so we started learning and collaborating through it.
It has been my experience—and that of my business partner—that the process of applying for anything was an utter bore compared to the application process Holberton School created. It was like a game. If you completed a challenge, you got to go to the next level, where another fascinating challenge awaited. We created Twitter accounts, blogged on Medium, learned HTML and CSS in order to create a website, and created a vibrant community online even before we knew who was going to get to go.
The most striking thing about the online community was how varied our experience with computers was, and how our background and gender did not factor into the choices that were being made by the founders (who we secretly called "The Trinity"). We just enjoyed being together and talking to each other. We were all smart people on a journey to increasing our nerd cred by learning how to code.
For much of the application process, our identities were not very evident. For example, my business partner's name does not indicate her gender or race. It was during the final step, a video chat, that The Trinity even knew she was a woman of color. Thus far, only her enthusiasm and talent had propelled her through the levels. The color of her skin and her gender did not hinder nor help her. How cool is that?
The night we got our acceptance letters, we knew our lives were about to change in ways we had only dreamt of. On the 22nd of January 2016, we walked into 98 Battery Street to meet our fellow [Hippokampoiers](https://twitter.com/hippokampoiers) for the first time. It was evident then, as it had been before, that the Trinity had started something amazing. They had assembled a truly diverse collection of passionate and enthusiastic people who had dedicated themselves to become full-stack engineers.
The school is an experience like no other. Every day is an intense foray into some facet of programming. We're handed a project and, with a little guidance, we use every resource available to us to find the solution. The premise that Holberton School is built upon is that information is available to us in more places than we've ever had before. MOOCs, tutorials, the availability of open source software and projects, and online communities are all bursting at the seams with knowledge that shakes up some of the projects we have to complete. And with the support of the invaluable team of mentors to guide us to solutions, the school becomes more than just a school; we've become a community of learners. I would highly recommend this school for anyone who is interested in software engineering and is also interested in the learning style. The next class is in October 2016 and is accepting new [applications](https://www.holbertonschool.com/). It's both terrifying and exhilarating, but so worth it.
## Open source matters
My earliest experience with an open source operating system was [Fedora](https://en.wikipedia.org/wiki/Fedora_(operating_system)), a [Red Hat](https://www.redhat.com/)-sponsored project. During a panicked conversation with an IRC member, she recommended this free OS. I had never installed my own OS before, but it sparked my interest in open source and my dependence on open source software for my computing needs. We are advocates for open source contribution, creation, and use. Our projects are on GitHub where anyone can use or contribute to them. We also have the opportunity to access existing open source projects to use or contribute to in our own way. Many of the tools that we use at school are open source, such as Fedora, [Vagrant](https://www.vagrantup.com/), [VirtualBox](https://www.virtualbox.org/), [GCC](https://gcc.gnu.org/), and [Discourse](https://www.discourse.org/), to name a few.
As I continue on my journey to becoming a software engineer, I still dream of a time when I will be able to contribute to the open source community and be able to share my knowledge with others.
## Diversity Matters
Standing in the room and talking to 29 other bright-eyed learners was intoxicating. 40% of the people there were women and 44% were people of color. These numbers become very important when you are a woman of color in a field that has been famously known for its lack of diversity. It was an oasis in the tech Mecca of the world. I knew I had arrived.
The notion of becoming a full-stack engineer is daunting, and you may even struggle to know what that means. It is a challenging road to travel with immeasurable rewards to reap. The future is run by technology, and you are an important part of that bright future. While the media continues to trip over handling the issue of diversity in tech companies, know that whoever you are, whatever your background is, whatever your reasons might be for becoming a full-stack engineer, you can find a place to thrive.
But perhaps most importantly, a strong reminder of the role of women in the history of computing can help more women return to the tech world, and they can be fully engaged without hesitation due to their gender or their capabilities as women. Their talents will help shape the future not just of tech, but of the world.
## 7 Comments |
7,970 | 在 Linux 中查看你的时区 | http://www.tecmint.com/check-linux-timezone | 2016-11-19T10:00:00 | [
"时间",
"时区"
] | https://linux.cn/article-7970-1.html | 在这篇短文中,我们将向你简单介绍几种 Linux 下查看系统时区的简单方法。在 Linux 机器中,尤其是生产服务器上的时间管理技能,是在系统管理中一个极其重要的方面。
Linux 包含多种可用的时间管理工具,比如 `date` 或 `timedatectlcommands`,你可以用它们来获取当前系统时区,也可以[将系统时间与 NTP 服务器同步](http://www.tecmint.com/install-ntp-server-in-centos/),来自动地、更精确地进行时间管理。
好,我们一起来看几种查看我们的 Linux 系统时区的不同方法。

### 1、我们从使用传统的 `date` 命令开始
使用下面的命令,来看一看我们的当前时区:
```
$ date
```
或者,你也可以使用下面的命令。其中 `%Z` 格式可以输出字符形式的时区,而 `%z` 输出数字形式的时区:
```
$ date +”%Z %z”
```

*查看 Linux 时区*
注意:`date` 的手册页中包含很多输出格式,你可以利用它们,来替换你的 `date` 命令的输出内容:
```
$ man date
```
### 2、接下来,你同样可以用 `timedatectl` 命令
当你不带任何参数运行它时,这条命令可以像下图一样,输出系统时间概览,其中包含当前时区:
```
$ timedatectl
```
然后,你可以在命令中提供一条管道,然后用 [grep 命令](http://www.tecmint.com/12-practical-examples-of-linux-grep-command/) 来像下面一样,只过滤出时区信息:
```
$ timedatectl | grep “Time zone”
```

*查看当前 Linux 时区*
同样,我们可以学习如何使用 timedatectl 来[设置 Linux 时区](http://www.tecmint.com/set-time-timezone-and-synchronize-time-using-timedatectl-command/)。
### 3、进一步,显示文件 /etc/timezone 的内容
使用 [cat 工具](http://www.tecmint.com/13-basic-cat-command-examples-in-linux/)显示文件 `/etc/timezone` 的内容,来查看你的时区:
```
$ cat /etc/timezone
```

*在 Linux 中查看时区*
对于 RHEL/CentOS/Fedora 用户,这里还有一条可以起到同样效果的命令:
```
$ grep ZONE /etc/sysconfig/clock
```
就这些了!别忘了在下面的反馈栏中分享你对于这篇文章中的看法。重要的是:你应该通过这篇 Linux 时区管理指南来学习更多系统时间管理的知识,因为它含有很多易于操作的实例。
---
via: <http://www.tecmint.com/check-linux-timezone>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[StdioA](https://github.com/StdioA) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,971 | Linux 基金会主席说,微软还弄不死 Linux | http://news.softpedia.com/news/microsoft-can-t-kill-linux-right-now-the-linux-foundation-director-says-510327.shtml | 2016-11-19T10:51:00 | [
"微软",
"Linux基金会"
] | https://linux.cn/article-7971-1.html | 本周,[微软宣布它成为了 Linux 基金会的白金成员](/article-7966-1.html),这距其前 CEO 巴尔默将 Linux 称之为“癌症”才 15 年。
虽然此举对微软来说意义重大,但是并不是开源界的每个人都认为这对于 Linux 来说是好的变化,特别是这家位于雷德蒙的软件巨头向来被视作开源和 Linux 的敌人。
对于微软在开源领域的扩张中,业界有各种不同的观点,但就反对者而言,其最终的看法可以归结为微软试图减慢 Linux 的发展速度并最终扼杀它。

### Jim 说,没啥阴谋
虽然这看起来像是一个巨大的阴谋,但是 Linux 基金会主席 Jim Zemlin 在“[计算机世界](http://www.computerworld.com/article/3142453/open-source-tools/microsoft-really-has-changed-linux-foundation-chief-says.html#tk.rss_all)”的采访中解释说,微软现在是一家完全不同的公司,它对摧毁 Linux 根本不感兴趣。
“首先,当你加入到 Linux 基金会当中,你就负有支持我们的组织的使命的责任,也就是说支持 Linux 和开源的发展”,他说道,“微软不仅致力于成为我们的组织成员,而且我可以告诉你,他们已经在做很多事情了。”
“现在一切都在云上,每个人都有计算机,有太多的软件,即使是微软这样的巨头也不可能以一己之力全部搞定。这不可能。”
以白金会员加入 Linux 基金会并不是微软唯一做的事情,该软件巨头之前就一直通过开源其产品来尝试接近 Linux,比如 .NET、PowerShell 和新的 Edge 浏览器的引擎部分。
甚至,连微软的拳头产品 Windows 10 都带有 Ubuntu 子系统,这被视作该公司努力将两个世界融合在一起的举措。
当然,如果微软继续在 Linux 世界继续扩展,这将是一个大的机遇,所以让我们期待将来有更多的新的变化。
| 301 | Moved Permanently | null |
7,972 | 通过安装扩展让 KDE Plasma 5 桌面看起来感觉就像 Windows 10 桌面 | https://iwf1.com/make-kde-plasma-5-desktop-look-feel-like-windows-10-using-these-extensions/ | 2016-11-20T11:16:00 | [
"桌面",
"主题"
] | https://linux.cn/article-7972-1.html | 
通过一些步骤,我将告诉你如何把 KDE Plasma 5 桌面变成 Windows 10 桌面。
除了菜单, KDE Plasma 桌面的许多地方已经和 Win 10 桌面非常像了。因此,只需要一点点改动就可以使二者看起来几乎是一样。
### 开始菜单
让 KDE Plasma 桌面看起来像 Win 10 桌面的首要以及可能最有标志性的环节是实现 Win 10 的 ‘开始’ 菜单。
通过安装 [Zren's Tiled Menu](https://github.com/Zren/plasma-applets/tree/master/tiledmenu),这很容易实现。
#### 安装
1、 在 KDE Plasma 桌面上单击右键 -><ruby> 解锁窗口部件 <rp> ( </rp> <rt> Unlock Widgets </rt> <rp> ) </rp></ruby>
2、 在 KDE Plasma 桌面上单击右键 -> <ruby> 增添窗口部件 <rp> ( </rp> <rt> Add Widgets </rt> <rp> ) </rp></ruby>
3、 获取新窗口部件 -> <ruby> 下载新的 Plasma 窗口部件 <rp> ( </rp> <rt> Download New Plasma Widgets </rt> <rp> ) </rp></ruby>
4、 搜索“Tiled Menu” -> <ruby> 安装 <rp> ( </rp> <rt> Install </rt> <rp> ) </rp></ruby>
#### 激活
1、 在你当前的菜单按钮上单击右键 -> <ruby> 替代…… <rp> ( </rp> <rt> Alternatives… </rt> <rp> ) </rp></ruby>
2、 选择 "TIled Mune" ->点击<ruby> 切换 <rp> ( </rp> <rt> Switch </rt> <rp> ) </rp></ruby>

*KDE Tiled 菜单扩展*
### 主题
弄好菜单以后,下一个你可能需要的就是主题。幸运的是, [K10ne](https://store.kde.org/p/1153465/) 提供了一个 WIn 10 主题体验。
#### 安装:
1、 从 Plasma 桌面菜单打开“<ruby> 系统设置 <rp> ( </rp> <rt> System Settings </rt> <rp> ) </rp></ruby>” -> <ruby> 工作空间主题 <rp> ( </rp> <rt> Workspace Theme </rt> <rp> ) </rp></ruby>
2、 从侧边栏选择“<ruby> 桌面主题 <rp> ( </rp> <rt> Desktop Theme </rt> <rp> ) </rp></ruby>” -> <ruby> 获取新主题 <rp> ( </rp> <rt> Get new Theme </rt> <rp> ) </rp></ruby>
3、 搜索“K10ne” -> <ruby> 安装 <rp> ( </rp> <rt> Install </rt> <rp> ) </rp></ruby>
#### 激活
1、 从 Plasma 桌面菜单选择“<ruby> 系统设置 <rp> ( </rp> <rt> System Settings </rt> <rp> ) </rp></ruby>” -> <ruby> 工作空间主题 <rp> ( </rp> <rt> Workspace Theme </rt> <rp> ) </rp></ruby>
2、 从侧边栏选择“<ruby> 桌面主题 <rp> ( </rp> <rt> Desktop Theme </rt> <rp> ) </rp></ruby>” -> “K10ne”
3、 <ruby> 应用 <rp> ( </rp> <rt> Apply </rt> <rp> ) </rp></ruby>
### 任务栏
最后,为了有一个更加完整的体验,你可能也想拥有一个更加 Win 10 风格的任务栏,
这次,你需要的安装包,叫做“Icons-only Task Manager”, 在大多数 Linux 发行版中,通常会默认安装。如果没有安装,需要通过你的系统的合适通道来获取它。
#### 激活
1、在 Plasma 桌面上单击右键 -> <ruby> 打开窗口部件 <rp> ( </rp> <rt> Unlock Widgets </rt> <rp> ) </rp></ruby>
2、在 Plasma 桌面上单击右键 -> <ruby> 增添部件 <rp> ( </rp> <rt> Add Widgets </rt> <rp> ) </rp></ruby>
3、把“Icons-only Task Manager”拖放到你的桌面面板的合适位置。
---
via: <https://iwf1.com/make-kde-plasma-5-desktop-look-feel-like-windows-10-using-these-extensions/>
作者:[Liron](https://iwf1.com/tag/linux) 译者:[ucasFL](https://github.com/ucasFL) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,973 | Ubuntu 14.04/16.04 与 Windows 10 周年版 Ubuntu Bash 性能对比 | https://www.phoronix.com/scan.php?page=article&item=windows10-anv-wsl&num=1 | 2016-11-20T14:38:00 | [
"Windows",
"WSL"
] | /article-7973-1.html | 
今年初,当 Microsoft 和 Canonical 发布 [Windows 10 Bash 和 Ubuntu 用户空间](http://www.phoronix.com/scan.php?page=news_item&px=Ubuntu-User-Space-On-Win10),我尝试做了一些初步性能测试 [Ubuntu on Windows 10 对比 原生 Ubuntu](http://www.phoronix.com/scan.php?page=article&item=windows-10-lxcore&num=1),这次我发布更多的,关于原生纯净的 Ubuntu 和基于 Windows 10 的基准对比。

Windows 的 Linux 子系统测试完成了所有测试,并随着 Windows 10周年更新放出。 默认的 Ubuntu 用户空间还是 Ubuntu 14.04,但是已经可以升级到 16.04。所以测试首先在 14.04 测试,完成后将系统升级升级到 16.04 版本并重复所有测试。完成所有基于 Windows 的 Ubuntu 子系统测试后,我在同样的系统上干净地安装了 Ubuntu 14.04.5 和 Ubuntu 16.04 LTS 来做性能对比。

配置为 Intel i5 6600K Skylake,16G 内存和 256G 东芝 ssd,测试过程中每个操作系统都采用其原生默认配置和软件包。

*http://openbenchmarking.org/embed.php?i=1608096-LO-BASHWINDO87&sha=09989b3&p=2*
这次 Ubuntu/Bash on Windows 和原生 Ubuntu 对比测试,采用开源软件 [Phoronix 测试套件](http://www.phoronix-test-suite.com/),完全自动化并可重复测试。

首先是 SQLite 嵌入式数据库基准测试。这方面开箱即用的 Ubuntu/Bash on Windows 性能是相当的慢,但是如果将环境从 14.04 升级到 16.04 LTS,性能会快很多。然而,对于繁重磁盘操作的任务,原生 Ubuntu Linux 几乎比 Windows 的子系统 Linux 快了近 2 倍。


编译测试作为额外的繁重磁盘操作测试显示,定制的 Windows 子系统真的成倍的限制了 Ubuntu 性能。
接下来,是一些使用 Stream 的基本的系统内存速度测试:



奇怪的是,这些 Stream 内存的基准测试显示 Ubuntu on Windows 的性能比原生的 Ubuntu 好!这个现象同时发生在基于同样的 Windows 却环境不同的 14.04 和 16.04 LTS 上。
接下来,是一些繁重 CPU 操作测试。

通过 Dolfyn 科学测试,Ubuntu On Windows 和原生 Ubuntu 之间的性能其实是相当接近的。 对于 Ubuntu 16.04,由于较新的 GCC 编译器性能衰减,两个平台上的性能都较慢。


透过 Fhourstones 测试和 John The Ripper 测试表明,通过在 Windows 的 Linux 子系统运行的 Ubuntu 的性能可以非常接近裸机 Ubuntu Linux 性能!

类似于 Stream 测试,x264 结果是另一个奇怪的情况,其中最好的性能实际上是使用 Linux 子系统的 Ubuntu On Windows!


计时编译基准测试非常利于裸机 Ubuntu Linux。这是应该是由于大型程序编译需要大量读写磁盘,在先前测试已经发现了,这是基于 Windows 的 Linux 子系统缓慢的一大领域。



许多其他的通用开源基准测试表明,严格的针对 CPU 的测试,Windows 子系统的 Ubuntu 的性能是很接近的,甚至是与原生安装在实际硬件中的 Ubuntu Linux 相等。
最新的 Windows 的 Linux 子系统,测试结果实际上相当令人印象深刻。让人沮丧的仅仅只是持续缓慢的磁盘/文件系统性能,但是对于受 CPU 限制的工作负载,结果是非常引人注目的。还有很罕见的情况, x264 和 Stream 测试,Ubuntu On Windows 上的性能看起来明显优于运行在实际硬件上 的Ubuntu Linux。
总的来说,体验是十分愉快的,并且在 Ubuntu/Bash on Windows 也没有遇到任何其他的 bug。如果你有还兴趣了解更多关于 Windows 和 Linux 的基准测试,欢迎留言讨论。
---
via: <https://www.phoronix.com/scan.php?page=article&item=windows10-anv-wsl&num=1>
作者:[Michael Larabel](http://www.michaellarabel.com/) 译者:[VicYu/Vic020](http://vicyu.net) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | HTTPSConnectionPool(host='www.phoronix.com', port=443): Read timed out. (read timeout=10) | null |
7,974 | 如何在 Linux 中恢复一个删除了的文件 | http://www.tecmint.com/recover-deleted-file-in-linux/ | 2016-11-21T17:31:00 | [
"恢复",
"删除"
] | https://linux.cn/article-7974-1.html | 你曾经是否遇到这样的事?当你发现的时候,你已经通过删除键,或者在命令行中使用 `rm` 命令,错误的删除了一个不该删除的文件。
在第一种情况下,你可以到垃圾箱,[搜索那个文件](http://www.tecmint.com/linux-find-command-to-search-multiple-filenames-extensions/),然后把它复原到原始位置。但是第二种情况又该怎么办呢?你可能知道,Linux 命令行不会把删除的文件转移到任何位置,而是直接把它们移除了,biu~,它们就不复存在了。
在这篇文章里,将分享一个很有用的技巧来避免此事发生。同时,也会分享一个工具,不小心删除了某些不该删除的文件时,也许用得上。

### 把删除创建为 `rm -i` 的别名
当 `-i` 选项配合 `rm` 命令(也包括其他[文件处理命令比如 cp 或者 mv](http://www.tecmint.com/progress-monitor-check-progress-of-linux-commands/))使用时,在删除文件前会出现一个提示。
这同样也可以运用到当[复制,移动或重命名一个文件](http://www.tecmint.com/rename-multiple-files-in-linux/),当所在位置已经存在一个和目标文件同名的文件时。
这个提示会给你第二次机会来考虑是否真的要删除该文件 - 如果你在这个提示上选择确定,那么文件就被删除了。这种情况下,很抱歉,这个技巧并不能防止你的粗心大意。
为了 `rm -i` 别名替代 `rm` ,这样做:
```
alias rm='rm -i'
```
运行 `alias` 命令可以确定 `rm` 现在已经被别名了:

*为 rm 增加别名*
然而,这只能在当前用户的当前 shell 上有效。为了永久改变,你必须像下面展示的这样把它保存到 `~/.bashrc` 中(一些版本的 Linux 系统可能是 `~/.profile`)。

*在 Linux 中永久增添别名*
为了让 `~/.bashrc`(或 `~/.profile`)中所做的改变立即生效,从当前 shell 中运行文件:
```
. ~/.bashrc
```

*在 Linux 中激活别名*
### 取证工具-Foremost
但愿你对于你的文件足够小心,当你要从外部磁盘或 USB 设备中恢复丢失的文件时,你只需使用这个工具即可。
然而,当你意识到你意外的删除了系统中的一个文件并感到恐慌时-不用担心。让我们来看一看 `foremost`,一个用来处理这种状况的取证工具。
要在 CentOS/RHEL 7 中安装 Foremost,需要首先启用 Repoforge:
```
# rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
# yum install foremost
```
然而在 Debian 及其衍生系统中,需这样做:
```
# aptitude install foremost
```
安装完成后,我们做一个简单的测试吧。首先删除 `/boot/images` 目录下一个名为 `nosdos.jpg` 的图像文件:
```
# cd images
# rm nosdos.jpg
```
要恢复这个文件,如下所示使用 `foremost`(要先确认所在分区 - 本例中, `/boot` 位于 `/dev/sda1` 分区中)。
```
# foremost -t jpg -i /dev/sda1 -o /home/gacanepa/rescued
```
其中,`/home/gacanepa/rescued` 是另外一个磁盘中的目录 - 请记住,把文件恢复到被删除文件所在的磁盘中不是一个明智的做法。
如果在恢复过程中,占用了被删除文件之前所在的磁盘分区,就可能无法恢复文件。另外,进行文件恢复操作前不要做任何其他操作。
当 `foremost` 执行完成以后,恢复的文件(如果可以恢复)将能够在目录 ·/home/gacanepa/rescue/jpg` 中找到。
### 总结
在这篇文章中,我们阐述了如何避免意外删除一个不该删除的文件,以及万一这类事情发生,如何恢复文件。还要警告一下, `foremost` 可能运行很长时间,时间长短取决于分区的大小。
如果您有什么问题或想法,和往常一样,不要犹豫,告诉我们。可以给我们留言。
---
via: <http://www.tecmint.com/recover-deleted-file-in-linux/>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[ucasFL](https://github.com/ucasFL) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,975 | 如何使用 Apache 控制命令检查它的模块是否已经启用或加载 | http://www.tecmint.com/check-apache-modules-enabled | 2016-11-21T18:16:54 | [
"Apache",
"apachectl",
"apache2ctl"
] | https://linux.cn/article-7975-1.html | 本篇中,我们会简要地讨论 Apache 服务器前端以及如何列出或查看已经启用的 Apache 模块。

Apache 基于模块化的理念而构建,这样就可以让 web 管理员添加不同的模块来扩展主要的功能及[增强性能](http://www.tecmint.com/apache-performance-tuning/)。
常见的 Apache 模块有:
1. mod\_ssl – 提供了 [HTTPS 功能](http://www.tecmint.com/install-lets-encrypt-ssl-certificate-to-secure-apache-on-rhel-centos/)。
2. mod\_rewrite – 可以用正则表达式匹配 url 样式,并且使用 [.htaccess 技巧](http://www.tecmint.com/apache-htaccess-tricks/)来进行透明转发,或者提供 HTTP 状态码回应。
3. mod\_security – 用于[保护 Apache 免于暴力破解或者 DDoS 攻击](http://www.tecmint.com/protect-apache-using-mod_security-and-mod_evasive-on-rhel-centos-fedora/)。
4. mod\_status - 用于[监测 Apache 的负载及页面统计](http://www.tecmint.com/monitor-apache-web-server-load-and-page-statistics/)。
在 Linux 中 `apachectl` 或者 `apache2ctl`用于控制 Apache 服务器,是 Apache 的前端。
你可以用下面的命令显示 `apache2ctl` 的使用信息:
```
$ apache2ctl help
或者
$ apachectl help
```
```
Usage: /usr/sbin/httpd [-D name] [-d directory] [-f file]
[-C "directive"] [-c "directive"]
[-k start|restart|graceful|graceful-stop|stop]
[-v] [-V] [-h] [-l] [-L] [-t] [-S]
Options:
-D name : define a name for use in directives
-d directory : specify an alternate initial ServerRoot
-f file : specify an alternate ServerConfigFile
-C "directive" : process directive before reading config files
-c "directive" : process directive after reading config files
-e level : show startup errors of level (see LogLevel)
-E file : log startup errors to file
-v : show version number
-V : show compile settings
-h : list available command line options (this page)
-l : list compiled in modules
-L : list available configuration directives
-t -D DUMP_VHOSTS : show parsed settings (currently only vhost settings)
-S : a synonym for -t -D DUMP_VHOSTS
-t -D DUMP_MODULES : show all loaded modules
-M : a synonym for -t -D DUMP_MODULES
-t : run syntax check for config files
```
`apache2ctl` 可以工作在两种模式下,SysV init 模式和直通模式。在 SysV init 模式下,`apache2ctl` 用如下的简单的单命令形式:
```
$ apachectl command
或者
$ apache2ctl command
```
比如要启动并检查它的状态,运行这两个命令。如果你是普通用户,使用 [sudo 命令](http://www.tecmint.com/su-vs-sudo-and-how-to-configure-sudo-in-linux/)来以 root 用户权限来运行:
```
$ sudo apache2ctl start
$ sudo apache2ctl status
```
```
tecmint@TecMint ~ $ sudo apache2ctl start
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1\. Set the 'ServerName' directive globally to suppress this message
httpd (pid 1456) already running
tecmint@TecMint ~ $ sudo apache2ctl status
Apache Server Status for localhost (via 127.0.0.1)
Server Version: Apache/2.4.18 (Ubuntu)
Server MPM: prefork
Server Built: 2016-07-14T12:32:26
-------------------------------------------------------------------------------
Current Time: Tuesday, 15-Nov-2016 11:47:28 IST
Restart Time: Tuesday, 15-Nov-2016 10:21:46 IST
Parent Server Config. Generation: 2
Parent Server MPM Generation: 1
Server uptime: 1 hour 25 minutes 41 seconds
Server load: 0.97 0.94 0.77
Total accesses: 2 - Total Traffic: 3 kB
CPU Usage: u0 s0 cu0 cs0
.000389 requests/sec - 0 B/second - 1536 B/request
1 requests currently being processed, 4 idle workers
__W__...........................................................
................................................................
......................
Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process
```
当在直通模式下,`apache2ctl` 可以用下面的语法带上所有 Apache 的参数:
```
$ apachectl [apache-argument]
$ apache2ctl [apache-argument]
```
可以用下面的命令列出所有的 Apache 参数:
```
$ apache2 help [在基于Debian的系统中]
$ httpd help [在RHEL的系统中]
```
### 检查启用的 Apache 模块
因此,为了检测你的 Apache 服务器启动了哪些模块,在你的发行版中运行适当的命令,`-t -D DUMP_MODULES` 是一个用于显示所有启用的模块的 Apache 参数:
```
--------------- 在基于 Debian 的系统中 ---------------
$ apache2ctl -t -D DUMP_MODULES
或者
$ apache2ctl -M
```
```
--------------- 在 RHEL 的系统中 ---------------
$ apachectl -t -D DUMP_MODULES
或者
$ httpd -M
$ apache2ctl -M
```
```
[root@tecmint httpd]# apachectl -M
Loaded Modules:
core_module (static)
mpm_prefork_module (static)
http_module (static)
so_module (static)
auth_basic_module (shared)
auth_digest_module (shared)
authn_file_module (shared)
authn_alias_module (shared)
authn_anon_module (shared)
authn_dbm_module (shared)
authn_default_module (shared)
authz_host_module (shared)
authz_user_module (shared)
authz_owner_module (shared)
authz_groupfile_module (shared)
authz_dbm_module (shared)
authz_default_module (shared)
ldap_module (shared)
authnz_ldap_module (shared)
include_module (shared)
....
```
就是这样!在这篇简单的教程中,我们解释了如何使用 Apache 前端工具来列出启动的 Apache 模块。记住你可以在下面的反馈表中给我们留下你的问题或者留言。
---
via: <http://www.tecmint.com/check-apache-modules-enabled>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,977 | 完整指南:在 Linux 上使用 Calibre 创建电子书 | https://itsfoss.com/create-ebook-calibre-linux/ | 2016-11-22T10:44:50 | [
"电子书",
"Calibre"
] | https://linux.cn/article-7977-1.html | 
摘要:这份初学者指南是告诉你如何在 Linux 上用 Calibre 工具快速创建一本电子书。
自从亚马逊在多年前开始销售电子书,电子书已经有了质的飞跃发展并且变得越来越流行。好消息是电子书非常容易使用自由开源的工具来被创建。
在这个教程中,我会告诉你如何在 Linux 上创建一本电子书。
### 在 Linux 上创建一本电子书
要创建一本电子书,你可能需要两个软件:一个文本处理器(当然,我使用的是 [LibreOffice](https://www.libreoffice.org/))和 Calibre 。[Calibre](http://calibre-ebook.com/) 是一个非常优秀的电子书阅读器,也是一个电子书库的程序。你可以使用它来[在 Linux 上打开 ePub 文件](https://itsfoss.com/open-epub-books-ubuntu-linux/)或者管理你收集的电子书。(LCTT 译注:LibreOffice 是 Linux 上用来处理文本的软件,类似于 Windows 的 Office 软件)
除了这些软件之外,你还需要准备一个电子书封面(1410×2250)和你的原稿。
### 第一步
首先,你需要用你的文本处理器程序打开你的原稿。 Calibre 可以自动的为你创建一个书籍目录。要使用到这个功能,你需要在你的原稿中设置每一章的标题样式为 “Heading 1”,在 LibreOffice 中要做到这个只需要高亮标题并且在段落样式下拉框中选择“Heading 1”即可。

如果你想要有子章节,并且希望他们也被加入到目录中,只需要设置这些子章节的标题为 Heading 2。
做完这些之后,保存你的文档为 HTML 格式文件。
### 第二步
在 Calibre 程序里面,点击“<ruby> 添加书籍 <rp> ( </rp> <rt> Add books </rt> <rp> ) </rp></ruby>”按钮。在对话框出现后,你可以打开你刚刚存储的 HTML 格式文件,将它加入到 Calibre 中。

### 第三步
一旦这个 HTML 文件加入到 Calibre 库中,选择这个新文件并且点击“<ruby> 编辑元数据 <rp> ( </rp> <rt> Edit Metadata </rt> <rp> ) </rp></ruby>”按钮。在这里,你可以添加下面的这些信息:<ruby> 标题 <rp> ( </rp> <rt> Title </rt> <rp> ) </rp></ruby>、 <ruby> 作者 <rp> ( </rp> <rt> Author </rt> <rp> ) </rp></ruby>、<ruby> 封面图片 <rp> ( </rp> <rt> cover image </rt> <rp> ) </rp></ruby>、 <ruby> 描述 <rp> ( </rp> <rt> description </rt> <rp> ) </rp></ruby>和其它的一些信息。当你填完之后,点击“Ok”。

### 第四步
现在点击“<ruby> 转换书籍 <rp> ( </rp> <rt> Covert books </rt> <rp> ) </rp></ruby>”按钮。
在新的窗口中,这里会有一些可选项,但是你不会需要使用它们。

在新窗口的右上部选择框中,选择 epub 文件格式。Calibre 也有创建 mobi 文件格式的其它选项,但是我发现创建那些文件之后经常出现我意料之外的事情。

### 第五步
在左边新的对话框中,点击“<ruby> 外观 <rp> ( </rp> <rt> Look & Feel </rt> <rp> ) </rp></ruby>”。然后勾选中“<ruby> 移除段落间空白 <rp> ( </rp> <rt> Remove spacing between paragraphs </rt> <rp> ) </rp></ruby>”。

接下来,我们会创建一个内容目录。如果不打算在你的书中使用目录,你可以跳过这个步骤。选中“<ruby> 内容目录 <rp> ( </rp> <rt> Table of Contents </rt> <rp> ) </rp></ruby>” 标签。接下来,点击“<ruby> 一级目录 <rp> ( </rp> <rt> Level 1 TOC (XPath expression) </rt> <rp> ) </rp></ruby>”右边的魔术棒图标。

在这个新的窗口中,在“<ruby> 匹配 HTML 标签 <rp> ( </rp> <rt> Match HTML tags with tag name </rt> <rp> ) </rp></ruby>”下的下拉菜单中选择“h1”。点击“OK” 来关闭这个窗口。如果你有子章节,在“<ruby> 二级目录 <rp> ( </rp> <rt> (Level 2 TOC XPath expression) </rt> <rp> ) </rp></ruby>”下选择“h2”。

在我们开始生成电子书前,选择输出 EPUB 文件。在这个新的页面,选择“<ruby> 插入目录 <rp> ( </rp> <rt> Insert inline Table of Contents </rt> <rp> ) </rp></ruby>”选项。

现在你需要做的是点击“OK”来开始生成电子书。除非你的是一个大文件,否则生成电子书的过程一般都完成的很快。
到此为止,你就已经创建一本电子书了。
对一些特别的用户比如他们知道如何写 CSS 样式文件(LCTT 译注:CSS 文件可以用来美化 HTML 页面),Calibre 给了这类用户一个选项来为文章增加 CSS 样式。只需要回到“<ruby> 外观 <rp> ( </rp> <rt> Look & Feel </rt> <rp> ) </rp></ruby>”部分,选择“<ruby> 风格 <rp> ( </rp> <rt> styling </rt> <rp> ) </rp></ruby>”标签选项。但如果你想创建一个 mobi 格式的文件,因为一些原因,它是不能接受 CSS 样式文件的。

好了,是不是感到非常容易?我希望这个教程可以帮助你在 Linux 上创建电子书。
---
via: <https://itsfoss.com/create-ebook-calibre-linux/>
作者:[John Paul](https://itsfoss.com/author/john/) 译者:[chenzhijun](https://github.com/chenzhijun) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | 

**Brief**: This beginner’s guide shows you **how to quickly create an ebook with Calibre tool in Linux**.
Ebooks have been growing by leaps and bounds in popularity since Amazon started selling them several years ago. The good news is that they are very easy to create with Free and Open-Source tools.
In this tutorial, I’ll show you how to create an eBook in Linux.
## Creating an eBook in Linux

To create an eBook, you’ll need two pieces of software: a word processor (I’ll be using [LibreOffice](https://www.libreoffice.org/), of course) and Calibre.
[Calibre ](http://calibre-ebook.com/)is a great ebook reader and library program. You can use it to [open ePub files in Linux](https://itsfoss.com/open-epub-books-ubuntu-linux/) or manage your eBooks collection.
Besides this software, you also need an eBook cover (1410×2250) and your manuscript.
### Step 1
First, you need to open your manuscript with your word processor. Calibre can automatically create a table of contents (TOC) for you. To do so, you need to set the chapter titles into your manuscript to **Heading 1**.
Just highlight the chapter titles and select “Heading 1” from the paragraph style dropdown box.

If you plan to have subchapters and want them to be added to the TOC, then make all those titles Heading 2.
Now, save your document as an HTML file.
### Step 2
In Calibre, click the “**Add books**” button. After the dialog box appears, you can browse to where your HTML file is located and add it to the program.

### Step 3
Once the new HTML file is added to the Calibre library, select the new file and click the “**Edit metadata**” button.

From here you can add the following information: Title, Author, cover image, description and more. When you’re done, click “OK”.

### Step 4
Now click the “**Convert books**” button.
In the new windows, there are quite a few options available, but you don’t need to use them all.

From the top right of the new screen, you select epub. Calibre also gives you the option to create a mobi file, but I found that those files didn’t always work the way I wanted them to.

### Step 5
Click the “**Look & Feel**” tab from the left side of the new dialog box. Now, select the “**Remove spacing between paragraphs**”.

Next, we will create the table of contents. If don’t plan to use a table of contents in your book, you skip this step. Select the Table of Contents tab. From there, click on the select the wand icon to the right of “Level 1 TOC (XPath expression)”.

In the new window, select “h1” from the drop down menu under “Match HTML tags with tag name”. Click “OK” to close the window. If you set up sub-chapters, set the “Level 2 TOC (XPath expression)” to h2.

Before we start the conversion, select EPUB Output. On the new page, select the “Insert inline Table of Contents” option.

Now all you have to do is click “OK” to start the conversion process. Unless you have a huge file, the conversion should finish fairly quickly.
There you go, you just created a quick eBook.
For the more advanced users who know how to write CSS, Calibre gives your the option to add CSS styling to your text. Just go to the “Look & Feel” section and select the styling tab. If you try to do this with mobi, it won’t accept all of the styling for some reason.

Well, that was fairly easy, isn’t it? I hope this tutorial helped you to **create eBooks in Linux**.
Let me know in the comments if you have any questions. If you found this article interesting, please take a minute to share it on social media. |
7,979 | 现在 Linux 运行在 99.6% 的 TOP500 超级计算机上 | https://itsfoss.com/linux-99-percent-top-500-supercomputers | 2016-11-23T09:59:00 | [
"Linux",
"超算",
"TOP500"
] | https://linux.cn/article-7979-1.html | 
*简介:虽然 Linux 在桌面操作系统只有 2% 的市场占有率,但是对于超级计算机来说,Linux 用 99% 的市场占有率轻松地获取了统治地位。*
**Linux 运行在超过 99% 的 TOP500 超级计算机上**,这并不会让人感到惊讶。2015 年我们报道过[“Linux 正运行在超过 97% 的 TOP500 超级计算机上”](https://itsfoss.com/linux-runs-97-percent-worlds-top-500-supercomputers/),今年 Linux 表现得更好。
这些信息是由独立组织 [Top500](https://twitter.com/share?text=%23Linux+now+runs+on+more+than+99%25+of+top+500+%23supercomputers+in+the+world&via=itsfoss&related=itsfoss&url=https://itsfoss.com/linux-99-percent-top-500-supercomputers/) 收集的,每两年他们会公布已知的最快的 500 台超级计算机的细节。你可以[打开这个网站,用以下条件筛选所需要的信息](https://www.top500.org/statistics/sublist/):国家、使用的操作系统类型、所有者等。别担心,我将会从这份表格中筛选整理出今年几个有趣的事实。
### Linux 运行在 500 台超级计算机中的 498 台
如果要将上面的百分比细化到具体数量的话,500 台超级计算机中的 498 台运行着 Linux。剩余的两台超级计算机运行着基于 Unix 的操作系统。直到去年,还有一台超级计算机上在运行 Windows,今年的列表中没有出现 Windows 的身影。或许,这些超级计算机没一台能运行 Windows 10(一语双关)。
总结一下今年表单上 TOP500 超级计算机所运行操作系统情况:
* Linux: 498
* Unix: 2
* Windows: 0
还有一份总结,它清晰展现了每年 Linux 在 TOP500 超级计算机的份额的变化情况。
* 2012 年: 94%
* [2013](https://itsfoss.com/95-percent-worlds-top-500-supercomputers-run-linux/) 年: 95%
* [2014](https://itsfoss.com/97-percent-worlds-top-500-supercomputers-run-linux/) 年: 97%
* [2015](https://itsfoss.com/linux-runs-97-percent-worlds-top-500-supercomputers/) 年: 97.2%
* 2016 年: 99.6%
* 2017 年: ???
另外,最快的前380台超级计算机运行着 Linux,包括在中国的那台最快的超级计算机。排名第 386 和第 387 的超级计算机运行着 Unix,它们同样来自中国。(←\_←)
### 其他关于最快的超级计算机的有趣数据

除去 Linux,我在表单中还找到了几个有趣的数据想跟你分享。
* 全球最快的超级计算机是[神威太湖之光](https://en.wikipedia.org/wiki/Sunway_TaihuLight). 它位于中国的[国家超级计算无锡中心](https://www.top500.org/site/50623)。它有着 93PFlops 的速度。
* 全球第二快的超级计算机是中国的[天河二号](https://en.wikipedia.org/wiki/Tianhe-2),第三的位置则属于美国的 Titan。
* 在速度前十的超级计算机中,美国占据了 5 台,日本和中国各有 2 台,瑞士有 1 台。
* 美国和中国都各有 171 台超级计算机进入了 TOP500 的榜单中。
* 日本有 27 台,法国有 20 台,印度、俄罗斯和沙特阿拉伯各有 5 台进入了榜单中。
有趣的事实,不是吗?你能点击[这里](https://www.top500.org/statistics/sublist/)筛选出属于自己的榜单来获得更多信息。现在我很开心来宣传 Linux 运行在 99% 的 TOP500 超级计算机上,期待下一年能有 100% 的更好成绩。
当你在阅读这篇文章时,请在社交平台上分享这篇文章,这是 Linux 的一个成就,我们引以为豪~ :P
---
via: <https://itsfoss.com/linux-99-percent-top-500-supercomputers>
作者:[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 译者:[ypingcn](https://github.com/ypingcn) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,980 | 谁需要 GUI?—— Linux 终端生存之道 | http://www.networkworld.com/article/3091139/linux/who-needs-a-gui-how-to-live-in-a-linux-terminal.html#slide1 | 2016-11-22T21:43:00 | [
"命令行",
"终端"
] | https://linux.cn/article-7980-1.html |
>
> 完全在 Linux 终端中生存并不容易,但这绝对是可行的。
>
>
>

### 处理常见功能的最佳 Linux shell 应用
你是否曾想像过完完全全在 Linux 终端里生存?没有图形桌面,没有现代的 GUI 软件,只有文本 —— 在 Linux shell 中,除了文本还是文本。这可能并不容易,但这是绝对可行的。[我最近尝试完全在 Linux shell 中生存30天](http://www.networkworld.com/article/3083268/linux/30-days-in-a-terminal-day-0-the-adventure-begins.html)。下边提到的就是我最喜欢用的 shell 应用,可以用来处理大部分的常用电脑功能(网页浏览、文字处理等)。这些显然有些不足,因为纯文本操作实在是有些艰难。
### 在 Linux 终端里发邮件

要在终端里发邮件,选择有很多。很多人会推荐 mutt 和 notmuch,这两个软件都功能强大并且表现非凡,但是我却更喜欢 alpine。为何?不仅是因为它的高效性,还因为如果你习惯了像 Thunderbird 之类的 GUI 邮件客户端,你会发现 alpine 的界面与它们非常相似。
### 在 Linux 终端里浏览网页

我有一个词要告诉你:[w3m](https://en.wikipedia.org/wiki/W3m)。好吧,我承认这并不是一个真实的词。但 w3m 的确是我在 Linux 终端的 web 浏览器选择。它能够很好的呈现网页,并且它也足够强大,可以用来在像 Google+ 之类的网站上发布消息(尽管方法并不有趣)。 Lynx 可能是基于文本的 Web 浏览器的事实标准,但 w3m 还是我的最爱。
### 在 Linux 终端里编辑文本

对于编辑简单的文本文件,有一个应用是我最的最爱。不!不!不是 emacs,同样,也绝对不是 vim。对于编辑文本文件或者简要记下笔记,我喜欢使用 nano。对!就是 nano。它非常简单,易于学习并且使用方便。当然还有更多的软件具有更多功能,但 nano 的使用是最令人愉快的。
### 在 Linux 终端里处理文字

在一个只有文本的 shell 之中,“文本编辑器” 和 “文字处理程序” 实在没有什么大的区别。但是像我这样需要大量写作的,有一个专门用于长期写作的软件是非常必要的。而我最爱的就是 wordgrinder。它由足够的工具让我愉快工作——一个菜单驱动的界面(使用快捷键控制)并且支持 OpenDocument、HTML 或其他等多种文件格式。
### 在 Linux 终端里听音乐

当谈到在 shell 中播放音乐(比如 mp3,ogg 等),有一个软件绝对是卫冕之王:[cmus](https://en.wikipedia.org/wiki/Cmus)。它支持所有你想得到的文件格式。它的使用超级简单,运行速度超级快,并且只使用系统少量的资源。如此清洁,如此流畅。这才是一个好的音乐播放器的样子。
### 在 Linux 终端里发送即时消息

当我在想如果可以在终端里发送即时消息会是什么样子的时候,我的思绪瞬间爆发了。你可能知道 Pidgin——一个支持多种协议的 IM 客户端,它也有一个终端版,叫做“[finch](https://developer.pidgin.im/wiki/Using%20Finch)”,你可以使用它来同时链接多个网络、同时和几个人聊天。而且,它的界面也和 Pidgin 极为相似。多么令人惊叹啊!想要使用 Google 环聊(Google Hangouts)就试试 [hangups](https://github.com/tdryer/hangups)。它有一个非常漂亮的分页式界面,并且效果非常好。认真来说,除了一些可能需要的 emoji 表情和嵌入式图片外,在终端里发送即时消息真的是一个很好的体验。
### 在 Linux 终端里发布推文

这不是开玩笑!由于 [rainbowstream](http://www.rainbowstream.org/) 的存在,我们已经可以在终端里发布推文了。尽管我时不时遇到一些 bug,但整体上,它工作得很好。虽然没有网页版 Twitter 或官方移动客户端那么好用,但这是一个终端版的 Twitter,来试一试吧。尽管它的功能还未完善,但是用起来还是很酷,不是吗?
### 在 Linux 终端里看 Reddit 新闻

不管如何,在命令行中享受 Reddit 新闻时间真的感觉很棒。使用 rtv 真是一个相当愉快的体验。不管是阅读、评论,还是投票表决,它都可以。其体验和在网页版有一定相似。
### 在 Linux 终端里管理进程

可以使用 [htop](http://hisham.hm/htop/)。与 top 相似,但更好用、更美观。有时候,我打开 htop 之后就让它一直运行。没有原因,就是喜欢!从某方面说,它就像将音乐可视化——当然,这里显示的是 RAM 和 CPU 的使用情况。
### 在 Linux 终端里管理文件

在一个纯文本终端里并不意味着你不能享受生活之美好。比方说一个出色的文件浏览和管理器。这方面,[Midnight Commander](https://en.wikipedia.org/wiki/Midnight_Commander) 是很好用的。
### 在 Linux 终端里管理终端窗口

如果要在终端里工作很长时间,就需要一个多窗口终端了。它是这样一个软件 —— 可以将用户终端会话分割成一个自定义网格,从而可以同时使用和查看多个终端应用。对于 shell,它相当于一个平铺式窗口管理器。我最喜欢用的是 [tmux](https://tmux.github.io/)。不过 [GNU Screen](https://en.wikipedia.org/wiki/GNU_Screen) 也很好用。学习怎么使用它们可能要花点时间,但一旦会用,就会很方便。
### 在 Linux 终端里进行讲稿演示

这类软件有 LibreOffice、Google slides、gasp 或者 PowerPoint。我在讲稿演示软件花费很多时间,很高兴有一个终端版的软件。它称做“[文本演示程序(tpp)](http://www.ngolde.de/tpp.html)”。很显然,没有图片,只是一个使用简单标记语言将放在一起的幻灯片展示出来的简单程序。它不可能让你在其中插入猫的图片,但可以让你在终端里进行完整的演示。
---
via: <http://www.networkworld.com/article/3091139/linux/who-needs-a-gui-how-to-live-in-a-linux-terminal.html#slide1>
作者:[Bryan Lunduke](http://www.networkworld.com/author/Bryan-Lunduke/) 译者:[GHLandy](https://github.com/GHLandy) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,981 | 何时 NGINX 将取代 Apache? | http://www.zdnet.com/article/when-to-use-nginx-instead-of-apache/ | 2016-11-24T08:49:00 | [
"Nginx",
"Apache"
] | https://linux.cn/article-7981-1.html | 
>
> NGINX 和 Apache 两者都是主流的开源 web 服务器,但是据 NGINX 的首席执行官 Gus Robertson 所言,他们有不同的使用场景。此外还有微软,其 web 服务器 IIS 在活跃网站的份额在 20 年间首次跌破 10%。
>
>
>

*Apache 是最受欢迎的 web 服务器,不过 NGINX 正逐渐增长,而微软的 IIS 几十年来首次跌破 10%。*
[NGINX](https://www.nginx.com/) 已经成为第二大 web 服务器。它在很久以前就已经超越了[微软 IIS](https://www.iis.net/),并且一直在老大 [Apache](https://httpd.apache.org/) 的身后穷追不舍。但是,NGINX 的首席执行官Gus Roberston 在接受采访时表示,Apache 和 NGINX 的用户群体不一样。
“我认为 Apache 是很好的 web 服务器。NGINX 和它的使用场景不同,”Robertson 说。“我们没有把 Apache 当成竞争对手。我们的用户使用 NGINX 来取代硬件负载均衡器和构建微服务,这两个都不是 Apache 的长处。”
事实上,Robertson 发现许多用户同时使用了这两种开源的 web 服务。“用户会在 Apache 的上层使用 NGINX 来实现负载均衡。我们的架构差异很大,我们可以提供更好的并发 web 服务。”他还表示 NGINX 在云环境中表现更优秀。
他总结说,“我们是唯一一个仍然在持续增长的 web 服务器,其它的 web 服务器都在慢慢缩小份额。”
这不太准确。根据 [Netcraft 十月份的网络服务器调查](https://news.netcraft.com/archives/2016/10/21/october-2016-web-server-survey.html),Apache 当月的活跃网站增加得最多,获得了 180 万个新站点,而 NGINX 增加了 40 万个新站点,排在第二位。
这些增长,加上微软损失的 120 万个活跃站点,导致微软的活跃网站份额下降到 9.27%,这是他们第一次跌破 10%。Apache 的市场份额提高了 0.19%,并继续领跑市场,现在坐拥 46.3% 的活跃站点。尽管如此,多年来 Apache 一直在缓慢下降,而 NGINX 现在上升到了 19%。
NGINX 的开发者正在努力创造他们的核心开放(open-core )的商业 web 服务器 —— [NGINX Plus](https://www.nginx.com/products/),通过不断的改进使其变得更有竞争力。NGINX Plus 最新的版本是 [NGINX Plus 11 版(R11)](https://www.nginx.com/blog/nginx-plus-r11-released/),该服务器易于扩展和自定义,并支持更广泛的部署。
这次最大的补充是 [动态模块](https://www.nginx.com/blog/nginx-plus-r11-released/?utm_source=nginx-plus-r11-released&utm_medium=blog#r11-dynamic-modules) 的二进制兼容性。也就是说为 [开源 NGINX 软件](https://www.nginx.com/products/download-oss/) 编译的动态模块也可以加载到 NGINX Plus。
这意味着你可以利用大量的[第三方 NGINX 模块](https://www.nginx.com/resources/wiki/modules/index.html?utm_source=nginx-plus-r11-released&utm_medium=blog) 来扩展 NGINX Plus 的功能,借鉴一系列开源和商业化生产的模块。开发者可以基于支持 NGINX Plus 的内核创建自定义扩展、附加组件和新产品。
NGINX Plus R11 还增强了其它功能:
* [提升 TCP/UDP 负载均衡](https://www.nginx.com/blog/nginx-plus-r11-released/?utm_source=nginx-plus-r11-released&utm_medium=blog#r11-tcp-udp-lb) —— 新功能包括 SSL 服务器路由、新的日志功能、附加变量以及改进的代理协议支持。这些新功能增强了调试功能,使你能够支持更广泛的企业应用。
* [更好的 IP 定位](https://www.nginx.com/blog/nginx-plus-r11-released/?utm_source=nginx-plus-r11-released&utm_medium=blog#r11-geoip2) —— 第三方的 GeoIP2 模块现在已经通过认证,并提供给 NGINX Plus 用户。这个新版本提供比原来的 GeoIP 模块更精准和丰富的位置信息。
* [增强的 nginScript 模块](https://www.nginx.com/blog/nginx-plus-r11-released/?utm_source=nginx-plus-r11-released&utm_medium=blog#r11-nginScript) —— nginScript 是基于 JavaScript 的 NGINX Plus 的下一代配置语言。新功能可以让你在流(TCP/UDP)模块中即时修改请求和响应数据。
最终结果?NGINX 准备继续与 Apache 竞争顶级 web 服务器的宝座。至于微软的 IIS?它将逐渐淡出市场。
---
via: <http://www.zdnet.com/article/when-to-use-nginx-instead-of-apache/>
作者:[Steven J. Vaughan-Nichols](http://www.zdnet.com/meet-the-team/us/steven-j-vaughan-nichols/) 译者:[OneNewLife](https://github.com/OneNewLife) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,982 | aria2 (命令行下载器)实例 | http://www.2daygeek.com/aria2-command-line-download-utility-tool/ | 2016-11-24T10:18:00 | [
"wget",
"aria2"
] | https://linux.cn/article-7982-1.html | [aria2](https://aria2.github.io/) 是一个自由、开源、轻量级多协议和多源的命令行下载工具。它支持 HTTP/HTTPS、FTP、SFTP、 BitTorrent 和 Metalink 协议。aria2 可以通过内建的 JSON-RPC 和 XML-RPC 接口来操纵。aria2 下载文件的时候,自动验证数据块。它可以通过多个来源或者多个协议下载一个文件,并且会尝试利用你的最大下载带宽。默认情况下,所有的 Linux 发行版都包括 aria2,所以我们可以从官方库中很容易的安装。一些 GUI 下载管理器例如 [uget](http://www.2daygeek.com/install-uget-download-manager-on-ubuntu-centos-debian-fedora-mint-rhel-opensuse/) 使用 aria2 作为插件来提高下载速度。

### Aria2 特性
* 支持 HTTP/HTTPS GET
* 支持 HTTP 代理
* 支持 HTTP BASIC 认证
* 支持 HTTP 代理认证
* 支持 FTP (主动、被动模式)
* 通过 HTTP 代理的 FTP(GET 命令行或者隧道)
* 分段下载
* 支持 Cookie
* 可以作为守护进程运行。
* 支持使用 fast 扩展的 BitTorrent 协议
* 支持在多文件 torrent 中选择文件
* 支持 Metalink 3.0 版本(HTTP/FTP/BitTorrent)
* 限制下载、上传速度
### 1) Linux 下安装 aria2
我们可以很容易的在所有的 Linux 发行版上安装 aria2 命令行下载器,例如 Debian、 Ubuntu、 Mint、 RHEL、 CentOS、 Fedora、 suse、 openSUSE、 Arch Linux、 Manjaro、 Mageia 等等……只需要输入下面的命令安装即可。对于 CentOS、 RHEL 系统,我们需要开启 [uget](http://www.2daygeek.com/aria2-command-line-download-utility-tool/) 或者 [RPMForge](http://www.2daygeek.com/aria2-command-line-download-utility-tool/) 库的支持。
```
[对于 Debian、 Ubuntu 和 Mint]
$ sudo apt-get install aria2
[对于 CentOS、 RHEL、 Fedora 21 和更早些的操作系统]
# yum install aria2
[Fedora 22 和 之后的系统]
# dnf install aria2
[对于 suse 和 openSUSE]
# zypper install wget
[Mageia]
# urpmi aria2
[对于 Arch Linux]
$ sudo pacman -S aria2
```
### 2) 下载单个文件
下面的命令将会从指定的 URL 中下载一个文件,并且保存在当前目录,在下载文件的过程中,我们可以看到文件的(日期、时间、下载速度和下载进度)。
```
# aria2c https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
[#986c80 19MiB/21MiB(90%) CN:1 DL:3.0MiB]
03/22 09:49:13 [NOTICE] Download complete: /opt/owncloud-9.0.0.tar.bz2
Download Results:
gid |stat|avg speed |path/URI
======+====+===========+=======================================================
986c80|OK | 3.0MiB/s|/opt/owncloud-9.0.0.tar.bz2
Status Legend:
(OK):download completed.
```
### 3) 使用不同的名字保存文件
在初始化下载的时候,我们可以使用 `-o`(小写)选项在保存文件的时候使用不同的名字。这儿我们将要使用 owncloud.zip 文件名来保存文件。
```
# aria2c -o owncloud.zip https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
[#d31304 16MiB/21MiB(74%) CN:1 DL:6.2MiB]
03/22 09:51:02 [NOTICE] Download complete: /opt/owncloud.zip
Download Results:
gid |stat|avg speed |path/URI
======+====+===========+=======================================================
d31304|OK | 7.3MiB/s|/opt/owncloud.zip
Status Legend:
(OK):download completed.
```
### 4) 下载速度限制
默认情况下,aria2 会利用全部带宽来下载文件,在文件下载完成之前,我们在服务器就什么也做不了(这将会影响其他服务访问带宽)。所以在下载大文件时最好使用 `–max-download-limit` 选项来避免进一步的问题。
```
# aria2c --max-download-limit=500k https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
[#7f9fbf 21MiB/21MiB(99%) CN:1 DL:466KiB]
03/22 09:54:51 [NOTICE] Download complete: /opt/owncloud-9.0.0.tar.bz2
Download Results:
gid |stat|avg speed |path/URI
======+====+===========+=======================================================
7f9fbf|OK | 462KiB/s|/opt/owncloud-9.0.0.tar.bz2
Status Legend:
(OK):download completed.
```
### 5) 下载多个文件
下面的命令将会从指定位置下载超过一个的文件并保存到当前目录,在下载文件的过程中,我们可以看到文件的(日期、时间、下载速度和下载进度)。
```
# aria2c -Z https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2 ftp://ftp.gnu.org/gnu/wget/wget-1.17.tar.gz
[DL:1.7MiB][#53533c 272KiB/21MiB(1%)][#b52bb1 768KiB/3.6MiB(20%)]
03/22 10:25:54 [NOTICE] Download complete: /opt/wget-1.17.tar.gz
[#53533c 18MiB/21MiB(86%) CN:1 DL:3.2MiB]
03/22 10:25:59 [NOTICE] Download complete: /opt/owncloud-9.0.0.tar.bz2
Download Results:
gid |stat|avg speed |path/URI
======+====+===========+=======================================================
b52bb1|OK | 2.8MiB/s|/opt/wget-1.17.tar.gz
53533c|OK | 3.4MiB/s|/opt/owncloud-9.0.0.tar.bz2
Status Legend:
(OK):download completed.
```
### 6) 续传未完成的下载
当你遇到一些网络连接问题或者系统问题的时候,并将要下载一个大文件(例如: ISO 镜像文件),我建议你使用 `-c` 选项,它可以帮助我们从该状态续传未完成的下载,并且像往常一样完成。不然的话,当你再次下载,它将会初始化新的下载,并保存成一个不同的文件名(自动的在文件名后面添加 `.1` )。注意:如果出现了任何中断,aria2 使用 `.aria2` 后缀保存(未完成的)文件。
```
# aria2c -c https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
[#db0b08 8.2MiB/21MiB(38%) CN:1 DL:3.1MiB ETA:4s]^C
03/22 10:09:26 [NOTICE] Shutdown sequence commencing... Press Ctrl-C again for emergency shutdown.
03/22 10:09:26 [NOTICE] Download GID#db0b08bf55d5908d not complete: /opt/owncloud-9.0.0.tar.bz2
Download Results:
gid |stat|avg speed |path/URI
======+====+===========+=======================================================
db0b08|INPR| 3.3MiB/s|/opt/owncloud-9.0.0.tar.bz2
Status Legend:
(INPR):download in-progress.
如果重新启动传输,aria2 将会恢复下载。
# aria2c -c https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
[#873d08 21MiB/21MiB(98%) CN:1 DL:2.7MiB]
03/22 10:09:57 [NOTICE] Download complete: /opt/owncloud-9.0.0.tar.bz2
Download Results:
gid |stat|avg speed |path/URI
======+====+===========+=======================================================
873d08|OK | 1.9MiB/s|/opt/owncloud-9.0.0.tar.bz2
Status Legend:
(OK):download completed.
```
### 7) 从文件获取输入
就像 wget 可以从一个文件获取输入的 URL 列表来下载一样。我们需要创建一个文件,将每一个 URL 存储在单独的行中。ara2 命令行可以添加 `-i` 选项来执行此操作。
```
# aria2c -i test-aria2.txt
[DL:3.9MiB][#b97984 192KiB/21MiB(0%)][#673c8e 2.5MiB/3.6MiB(69%)]
03/22 10:14:22 [NOTICE] Download complete: /opt/wget-1.17.tar.gz
[#b97984 19MiB/21MiB(90%) CN:1 DL:2.5MiB]
03/22 10:14:30 [NOTICE] Download complete: /opt/owncloud-9.0.0.tar.bz2
Download Results:
gid |stat|avg speed |path/URI
======+====+===========+=======================================================
673c8e|OK | 4.3MiB/s|/opt/wget-1.17.tar.gz
b97984|OK | 2.5MiB/s|/opt/owncloud-9.0.0.tar.bz2
Status Legend:
(OK):download completed.
```
### 8) 每个主机使用两个连接来下载
默认情况,每次下载连接到一台服务器的最大数目,对于一条主机只能建立一条。我们可以通过 aria2 命令行添加 `-x2`(`2` 表示两个连接)来创建到每台主机的多个连接,以加快下载速度。
```
# aria2c -x2 https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
[#ddd4cd 18MiB/21MiB(83%) CN:1 DL:5.0MiB]
03/22 10:16:27 [NOTICE] Download complete: /opt/owncloud-9.0.0.tar.bz2
Download Results:
gid |stat|avg speed |path/URI
======+====+===========+=======================================================
ddd4cd|OK | 5.5MiB/s|/opt/owncloud-9.0.0.tar.bz2
Status Legend:
(OK):download completed.
```
### 9) 下载 BitTorrent 种子文件
我们可以使用 aria2 命令行直接下载一个 BitTorrent 种子文件:
```
# aria2c https://torcache.net/torrent/C86F4E743253E0EBF3090CCFFCC9B56FA38451A3.torrent?title=[kat.cr]irudhi.suttru.2015.official.teaser.full.hd.1080p.pathi.team.sr
[#388321 0B/0B CN:1 DL:0B]
03/22 20:06:14 [NOTICE] Download complete: /opt/[kat.cr]irudhi.suttru.2015.official.teaser.full.hd.1080p.pathi.team.sr.torrent
03/22 20:06:14 [ERROR] Exception caught
Exception: [BtPostDownloadHandler.cc:98] errorCode=25 Could not parse BitTorrent metainfo
Download Results:
gid |stat|avg speed |path/URI
======+====+===========+=======================================================
388321|OK | 11MiB/s|/opt/[kat.cr]irudhi.suttru.2015.official.teaser.full.hd.1080p.pathi.team.sr.torrent
Status Legend:
(OK):download completed.
```
### 10) 下载 BitTorrent 磁力链接
使用 aria2 我们也可以通过 BitTorrent 磁力链接直接下载一个种子文件:
```
# aria2c 'magnet:?xt=urn:btih:248D0A1CD08284299DE78D5C1ED359BB46717D8C'
```
### 11) 下载 BitTorrent Metalink 种子
我们也可以通过 aria2 命令行直接下载一个 Metalink 文件。
```
# aria2c https://curl.haxx.se/metalink.cgi?curl=tar.bz2
```
### 12) 从密码保护的网站下载一个文件
或者,我们也可以从一个密码保护网站下载一个文件。下面的命令行将会从一个密码保护网站中下载文件。
```
# aria2c --http-user=xxx --http-password=xxx https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
# aria2c --ftp-user=xxx --ftp-password=xxx ftp://ftp.gnu.org/gnu/wget/wget-1.17.tar.gz
```
### 13) 阅读更多关于 aria2
如果你希望了解了解更多选项 —— 它们同时适用于 wget,可以输入下面的命令行在你自己的终端获取详细信息:
```
# man aria2c
or
# aria2c --help
```
谢谢欣赏 …)
---
via: <http://www.2daygeek.com/aria2-command-line-download-utility-tool/>
作者:[MAGESH MARUTHAMUTHU](http://www.2daygeek.com/author/magesh/) 译者:[yangmingming](https://github.com/yangmingming) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,983 | Xfce 桌面新增‘免打扰’模式以及单一应用通知设置的新特性 | http://www.webupd8.org/2016/11/xfce-gets-do-not-disturb-mode-and-per.html | 2016-11-24T11:39:00 | [
"Xfce"
] | https://linux.cn/article-7983-1.html | Xfce 的开发者们正忙于把 Xfce 的应用和部件[转移](https://wiki.xfce.org/releng/4.14/roadmap)到 GTK3 上,在这个过程中,他们也增加了一些新的特性。

**“免打扰”**,一个常被要求增加的特性,[最近](http://simon.shimmerproject.org/2016/11/09/xfce4-notifyd-0-3-4-released-do-not-disturb-and-per-application-settings/)已登陆到了 xfce-notifyd 0.3.4 (Xfce 通知进程)上。
更近一步地,最新的 xfce-notifyd 包括了一个可以在单一应用基础上开启或关闭通知的选项。
当一个应用发出一个通知以后,这个应用就被加入到到了通知设置的列表里。从通知列表里,你可以控制哪些应用能够显示通知。
”免打扰“模式和应用特定的通知设置均可在“设置” > “通知” 中找到:

现在为止,还没有方法可以访问由于启用”免打扰“模式而错过的消息。然而,可以预期将来会发布**通知记录/维持的特性。**
最后, xfce-notifyd 0.3.4 的**另一个特性**是**选择在主监视器显示通知**(直到现在,通知都是显示在当前监视器)。这个特性目前在图形设置界面里是没有的,必须使用 `Xfconf`(设置编辑)在 xfce-notifyd 下增添一个叫做 `/primary-monitor`(没有引号)的布尔属性,并设置为 `True` 来启用该特性:

**xfce4-notifyd 0.3.4 目前在 PPA 上还没有,但是不久它可能被增添到 [Xfce GTK3 PPA](https://launchpad.net/%7Exubuntu-dev/+archive/ubuntu/xfce4-gtk3)中。**
**如果你想直接从源代码编译,从[这儿](http://archive.xfce.org/src/apps/xfce4-notifyd/0.3/)下载。**
---
via: <http://www.webupd8.org/2016/11/xfce-gets-do-not-disturb-mode-and-per.html>
作者:[Andrew](http://www.webupd8.org/p/about.html) 译者:[ucasFL](https://github.com/ucasFL) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | The Xfce developers are busy
[porting](https://wiki.xfce.org/releng/4.14/roadmap)Xfce applications and components to GTK3, and in the process, they are also adding new features.**"Do not disturb"**, a much requested feature, landed in
*xfce4-notifyd*0.3.4 (the Xfce notification daemon)
[recently](http://simon.shimmerproject.org/2016/11/09/xfce4-notifyd-0-3-4-released-do-not-disturb-and-per-application-settings/). Using this, you can suppress notification bubbles for a limited time-frame.
Furthermore,
**the latest**.*xfce4-notifyd*includes an option to enable or disable notifications on a per-application basisAfter an application sends a notification, the app is added to a list in the notification settings. From here, you can control which applications can show notifications.
Both the "Do not disturb" mode and the application-specific notification settings can be found in
*Settings > Notifications*:Right now there's no way of accessing notifications missed due to the "Do not disturb" mode being enabled. However,
**a notification logging / persistence feature is expected in a future release.**
And finally, yet
**another feature**in*xfce4-notifyd*0.3.4 is an**option display notifications on the primary monitor**(until now, notifications were displayed on the active monitor).This option is not available in the GUI for now, and it must be enabled using Xfconf (Settings Editor), by adding a Boolean property, called "/primary-monitor" (without the quotes), to
*xfce4-notifyd*and set it to "True":
*xfce4-notifyd*0.3.4 is not available in a PPA right now, but it will probably be added to the[Xfce GTK3 PPA](https://launchpad.net/~xubuntu-dev/+archive/ubuntu/xfce4-gtk3)soon.**If you want to build it from source, download it from**
[HERE](http://archive.xfce.org/src/apps/xfce4-notifyd/0.3/).*Looking for a "Do not disturb" mode for Unity? Check out* |
7,984 | 如何按最后修改时间对 ls 命令的输出进行排序 | http://www.tecmint.com/sort-ls-output-by-last-modified-date-and-time | 2016-11-25T07:45:00 | [
"ls",
"命令行"
] | https://linux.cn/article-7984-1.html | Linux 用户常常做的一个事情是,是在命令行[列出目录内容](http://www.tecmint.com/file-and-directory-management-in-linux/)。
我们已经知道,[ls](http://www.tecmint.com/15-basic-ls-command-examples-in-linux/) 和 [dir](http://www.tecmint.com/linux-dir-command-usage-with-examples/) 是两个可用在列出目录内容的 Linux 命令,前者是更受欢迎的,在大多数情况下,是用户的首选。
我们列出目录内容时,可以按照不同的标准进行排序,例如文件名、修改时间、添加时间、版本或者文件大小。可以通过指定一个特别的参数来使用这些文件的属性进行排序。

在这个简洁的 [ls 命令指导](http://www.tecmint.com/tag/linux-ls-command/)中,我们将看看如何通过上次修改时间(日期和时分秒)[排序 ls 命令的输出结果](http://www.tecmint.com/sort-command-linux/) 。
让我们由执行一些基本的 [ls 命令](http://www.tecmint.com/15-basic-ls-command-examples-in-linux/)开始。
### Linux 基本 ls 命令
1、 不带任何参数运行 ls 命令将列出当前工作目录的内容。
```
$ ls
```

*列出工作目录的内容*
2、要列出任何目录的内容,例如 /etc 目录使用如下命令:
```
$ ls /etc
```

*列出工作目录 /etc 的内容*
3、一个目录总是包含一些隐藏的文件(至少有两个),因此,要展示目录中的所有文件,使用`-a`或`-all`标志:
```
$ ls -a
```

*列出工作目录的隐藏文件*
4、你还可以打印输出的每一个文件的详细信息,例如文件权限、链接数、所有者名称和组所有者、文件大小、最后修改的时间和文件/目录名称。
这是由`-l`选项来设置,这意味着一个如下面的屏幕截图般的长长的列表格式。
```
$ ls -l
```

*长列表目录内容*
### 基于日期和基于时刻排序文件
5、要在目录中列出文件并[对最后修改日期和时间进行排序](http://www.tecmint.com/find-and-sort-files-modification-date-and-time-in-linux/),在下面的命令中使用`-t`选项:
```
$ ls -lt
```

*按日期和时间排序ls输出内容*
6、如果你想要一个基于日期和时间的逆向排序文件,你可以使用`-r`选项来工作,像这样:
```
$ ls -ltr
```

*按日期和时间排序的逆向输出*
我们将在这里结束,但是,[ls 命令](http://www.tecmint.com/tag/linux-ls-command/)还有更多的使用信息和选项,因此,应该特别注意它或看看其它指南,比如《[每一个用户应该知道 ls 的命令技巧](http://www.tecmint.com/linux-ls-command-tricks/)》或《[使用排序命令](http://www.tecmint.com/linux-sort-command-examples/)》。
最后但并非最不重要的,你可以通过以下反馈部分联系我们。
---
via: <http://www.tecmint.com/sort-ls-output-by-last-modified-date-and-time>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[zky001](https://github.com/zky001) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,985 | 在 Linux 上使用 Glyphr 设计自己的字体 | https://www.howtoforge.com/tutorial/how-to-design-and-add-your-own-font-on-linux-with-glyphr/ | 2016-11-25T09:15:00 | [
"字体",
"Glyphr"
] | https://linux.cn/article-7985-1.html | LibreOffice 提供了丰富的字体,并且用户可以自由选择和下载增加自己的字体。然而,就算是你想创造自己的字体,也可以非常容易地使用 Glyphr 来做到。Glyphr 是一个新开源的矢量字体设计器,通过直观而易用的图形界面和丰富的功能集可以完成字体设计的方方面面。虽然这个应用还在早期开发阶段,但是已经十分棒了。下面将会有一个简短的快速入门教你如何使用 Glyphr 创建字体并加入到 LibreOffice。

首先,从[官方 Git 库](https://github.com/glyphr-studio/Glyphr-Studio-Desktop)下载 Glyphr。它提供 32 位和 64 位版本的二进制格式。完成下载后,进入下载文件夹, 解压文件,进入解压后的文件夹,右键点击 Glyphr Studio,选择“Run”。

启动应用后会给你三个选项。一个是从头创建一个新的字体集;第二个是读取已经存在的项目,可以是 Glyphr Studio 项目文件,也可以是其他 OpenType 字体(otf)或 TrueType 字体(ttf),甚至是 SVG 字体。第三个是读取已有的两个示例之一,然后可以在示例上修改创建。我将会选择第一个选项,并教你一些简单的设计概念。

完成进入编辑界面后, 你可以从屏幕左边的面板中选择字母,然后在右边的绘制区域设计。我选择 A 字母的图标开始编辑它。

要在绘图板上设计一些东西,我们可以从该板的左上角选择矩形、椭圆形或者路径等同处的“形状”工具,也可以使用该工具的第二行的第一项的路径编辑工具。使用任意工具,开始在板上放<ruby> 路径点 <rp> ( </rp> <rt> path point </rt> <rp> ) </rp></ruby>来创建形状。添加的点数越多,接下来步骤的形状选项就越多。

将点移动到不同位置可以获得不同的路径,可以使用路径编辑工具右边的路径编辑,点击形状会出现可编辑点。然后可以把这些点拖到你喜欢的任意位置。

最后,形状编辑工具可以让你选择形状并将其拖动到其它位置、更改其尺寸以及旋转。

其它有用的设计动作集还有左侧面板提供的复制-粘贴、翻转-旋转操作。来看个例子,假设我现在正在创作 B 字母, 我要把已经创建好的上部分镜像到下半部分,保持设计的高度一致性。

现在,为了达到这个目的,选择形状编辑工具,选中欲镜像的部分,点击复制操作,然后在其上点击图形,拖放粘帖的形状到你需要的位置,根据你的需要进行水平翻转或者垂直翻转。

这款应用在太多地方可以讲述。如果有兴趣深入,可以深入了解数字化编辑、弯曲和引导等等,
然而,字体并不是仅仅是单个字体的设计,还需要学习字体设计的其他方面。通过应用左上角菜单栏上的“导航”还可以设置特殊字符对之间的字间距、增加连字符、部件、和设置常规字体设置等。

最棒的是你可以使用“测试驱动”来使用你的新字体,帮助你判断字体设计如何、间距对不对、尽量来优化你的字体。

完成设计和优化后,我们还可以导出 ttf 和 svg 格式的字体。

要将新的字体加入到系统中,打开字体浏览器并点击“安装”按钮。如果它不工作,可以在主目录下创建一个新的文件夹叫做`.fonts`,并将字体复制进去。也可以使用 root 用户打开文件管理器,进入 `/usr/share/fonts/opentype`, 创建一个新的文件夹并粘贴字体文件到里面。然后打开终端,输入命令重建字体缓存:`sudo fc-cache -f -v`。
在 LibreOffice 中已经可以看见新的字体咯,同样也可以使用你系统中的其它文本应用程序如 Gedit 来测试新字体。

---
via: <https://www.howtoforge.com/tutorial/how-to-design-and-add-your-own-font-on-linux-with-glyphr/>
作者:[Bill Toulas](https://twitter.com/howtoforgecom) 译者:[VicYu/Vic020](http://vicyu.net) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # How to design and add your own font on Linux with Glyphr
LibreOffice already offers a galore of fonts, and users can always download and add more. However, if you want to create your own custom font, you can do it easily by using Glyphr. Glyphr is a new open source vector font designer with an intuitive and easy to use graphical interface and a rich set of features that will take care every aspect of the font design. Although the application is still in early development, it is already pretty good. Here’s a quick guide showing how to design your own custom fonts on Glyphr, and how to add them on LibreOffice once you’re done.
First of all, we need to download Glyphr from the official git repository ([https://github.com/glyphr-studio/Glyphr-Studio-Desktop](https://github.com/glyphr-studio/Glyphr-Studio-Desktop)). It is available in binary form, in both 32 and 64 bits. Once the file is downloaded, navigate to the destination, unzip the file, enter the newly created folder, right click on the “Glyphr Studio” binary file and select “Run”.
This will launch the application giving you three options. One is to create a new font set from scratch. The second is to load an existing project that can be of a Glyphr Studio Project form, and Open or True Type font, or an SVG font. The third is to load one of the two example sets so that you can modify these instead of working on a new set from the ground up. I will select the first option to showcase a few basic design concepts.
Once you enter the editor screen, you may select the letter that you want to design from the panel on the left side of the screen, and then indulge in the design work on the drawing area that is on the right. I will start with the letter “A” by clicking on its icon.
To design something on the drawing board, we can select either the “shapes” tools from the top left of the board which are a rectangle, an oval, and a path share, or use the first item of the second row of the tools that is the path editing tool. Click on that and start putting points on the board to create shapes. The more points you add, the greater the shaping options that you’ll have on the next step.
To move the points and thus share the path differently, you will need to select the path edit tool that is to the right of the path editing tool and click on the shape to reveal the points. Then you may drag them into position as you like.
Finally, the shape edit tool lets you select a shape and drag it into position, change its dimension or even rotate it.
Another useful set of design actions are the copy-paste, flip-rotate options that are offered on the left panel after you enter the letter design phase. For example, let’s suppose that I am creating the “B” letter of my font set, and that I want to mirror the upper side of what I’ve done to the bottom so as to keep a good level of coherence in the design.
Now, to do this, I must choose the shape editing tool to select the part that I want to mirror, click on the copy action, then click on the past right above it, drag the pasted shape where I want it to be and then click on the flip horizontally or vertically depending on what I am trying to achieve.
There are tons of more things that I could showcase in the design aspect of the application, but there’s really no point in doing so. If you’re interested you can dive in and discover the numerical-based editing, the curving, the guiding, and many more.
Fonts however aren’t only about individual letters design, and you can discover other aspects of the font design by clicking on the “Navigate” menu on the top left of the application and adjust the kerning between specific pairs of characters, add ligatures, add components, and set general font settings.
You may even give your new font a “test drive” so that you can get the idea of how well your font settings and kerning works and what to do in order to optimize them.
After the design and optimization are done, you may export your new font set on either a true type font format, or an svg.
To add the font on your system, open it with the font viewer and click on the “Install” option. If that doesn’t work, create a new folder in your home directory named as “.fonts” and place the font file inside it. Alternatively, you may open the file manager as root, navigate to /usr/share/fonts/opentype, create a new folder there and paste the font file inside. Then open a terminal and run this command to clear the cache: “sudo fc-cache -f -v”
This should add the new font on LibreOffice, and also to any other text application in your system like Gedit for example. |
7,986 | 全新 Kali Linux 系统安装指南 | http://www.tecmint.com/kali-linux-installation-guide/ | 2016-11-26T12:34:00 | [
"Kali Linux",
"安全渗透"
] | https://linux.cn/article-7986-1.html | Kali Linux 系统可以说是在[安全测试方面最好](http://www.tecmint.com/best-security-centric-linux-distributions-of-2016/)的开箱即用的 Linux 发行版。Kali 下的很多工具软件都可以安装在大多数的 Linux 发行版中,Offensive Security 团队在 Kali 系统的开发过程中投入大量的时间精力来完善这个用于渗透测试和安全审计的 Linux 发行版。
Kali Linux 是基于 Debian 的面向安全的发行版本。该系统由于预安装了上百个知名的安全工具软件而出名。

Kali 甚至在信息安全领域还有一个含金量较高的认证叫做“<ruby> Kali 渗透测试 <rp> ( </rp> <rt> Pentesting with Kali </rt> <rp> ) </rp></ruby>”认证。该认证的申请者必须在艰难的 24 小时内成功入侵多台计算机,然后另外 24 小时内完成渗透测试报告并发送给 Offensive Security 的安全人员进行评审。成功通过考试的人将会获得 OSCP 认证证书。
本安装指南及以后的文章主要是为了帮助个人熟悉 Kali Linux 系统和其中一些工具软件的使用。
**请谨慎使用 Kali 下的工具,因为其中一些工具如果使用不当将会导致计算机系统损坏。请在合法的途径下使用所有 Kali 系列文章中所包含的信息。**
### 系统要求
Kali 系统对硬件有一些最基本的要求及建议。根据用户使用目的,你可以使有更高的配置。这篇文章中假设读者想要把 kali 安装为电脑上唯一的操作系统。
1. 至少 10GB 的磁盘空间;强烈建议分配更多的存储空间。
2. 至少 512MB 的内存;希望有更多的内存,尤其是在图形界面下。
3. 支持 USB 或 CD/DVD 启动方式。
4. Kali Linux 系统 ISO 镜像下载地址 <https://www.kali.org/downloads/>。
### 使用 dd 命令创建 USB 启动工具
该文章假设可使用 USB 设备来引导安装系统。注意尽可能的使用 4GB 或者 8GB 的 USB 设备,并且其上的所有数据将会被删除。
本文作者在使用更大容量的 USB 设备在安装的过程中遇到了问题,但是别的人应该还是可以的。不管怎么说,下面的安装步骤将会清除 USB 设备内的数据。
在开始之前请务必备份所有数据。用于安装 Kali Linux 系统的 USB 启动设备将在另外一台机器上创建完成。
第一步是获取 Kali Linux 系统 ISO 镜像文件。本指南将使用最新版的包含 Enlightenment 桌面环境的 Kali Linux 系统进行安装。
在终端下输入如下命令来获取这个版本的 ISO 镜像文件。
```
$ cd ~/Downloads
$ wget -c http://cdimage.kali.org/kali-2016.2/kali-linux-e17-2016.2-amd64.iso
```
上面两个命令将会把 Kali Linux 的 ISO 镜像文件下载到当前用户的 Downloads 目录。
下一步是把 ISO 镜像写入到 USB 设备中来启动安装程序。我们可以使用 Linux 系统中的 `dd` 命令来完成该操作。首先,该 USB 设备要在 `lsblk` 命令下可找到。
```
$ lsblk
```

*在 Linux 系统中确认 USB 设备名*
确定 USB 设备的名字为 `/dev/sdc`,可以使用 dd 工具将 Kali 系统镜像写入到 USB 设备中。
```
$ sudo dd if=~/Downloads/kali-linux-e17-2016.2-amd64.iso of=/dev/sdc
```
**注意:**以上命令需要 root 权限,因此使用 `sudo` 命令或使用 root 账号登录来执行该命令。这个命令会删除 USB 设备中的所有数据。确保已备份所需的数据。
一旦 ISO 镜像文件完全复制到 USB 设备,接下来可进行 Kali Linux 系统的安装。
### 安装 Kali Linux 系统
1、 首先,把 USB 设备插入到要安装 Kali 操作系统的电脑上,然后从 USB 设备引导系统启动。只要成功地从 USB 设备启动系统,你将会看到下面的图形界面,选择“Install”或者“Graphical Install”选项。
本指南将使用“Graphical Install”方式进行安装。

*Kali Linux 启动菜单*
2、 下面几个界面将会询问用户选择区域设置信息,比如语言、国家,以及键盘布局。
选择完成之后,系统将会提示用户输入主机名和域名信息。输入合适的环境信息后,点击继续安装。

*设置 Kali Linux 系统的主机名*

*设置 Kali Linux 系统的域名*
3、 主机名和域名设置完成后,需要设置 root 用户的密码。请勿忘记该密码。

*设置 Kali Linux 系统用户密码*
4、 密码设置完成之后,安装步骤会提示用户选择时区然后停留在硬盘分区界面。
如果 Kali Linux 是这个电脑上的唯一操作系统,最简单的选项就是使用“Guided – Use Entire Disk”,然后选择你需要安装 Kali 的存储设备。

*选择 Kali Linux 系统安装类型*

*选择 Kali Linux 安装磁盘*
5、 下一步将提示用户在存储设备上进行分区。大多数情况下,我们可以把整个系统安装在一个分区内。

*在分区上安装 Kali Linux 系统*
6、 最后一步是提示用户确认将所有的更改写入到主机硬盘。注意,点确认后将会**清空整个磁盘上的所有数据**。

*确认磁盘分区更改*
7、 一旦确认分区更改,安装包将会进行复制文件的安装过程。安装完成后,你需要设置一个网络镜像源来获取软件包和系统更新。如果你希望使用 Kali 的软件库,确保开启此功能。

*配置 Kali Linux 包管理器*
8、 选择网络镜像源后,系统将会询问你安装 Grub 引导程序。再次说明,本文假设你的电脑上仅安装唯一的 Kali Linux 操作系统。
在该屏幕上选择“Yes”,用户需要选择要写入引导程序信息的硬盘引导设备。

*安装 Grub 引导程序*

*选择安装 Grub 引导程序的分区*
9、 当 Grub 安装完成后,系统将会提醒用户重启机器以进入新安装的 Kali Linux 系统。

*Kali Linux 系统安装完成*
10、 因为本指南使用 Enlightenment 作为 Kali Linux 系统的桌面环境,因此默认情况下是启动进入到 shell 环境。
使用 root 账号及之前安装过程中设置的密码登录系统,以便运行 Enlightenment 桌面环境。
登录成功后输入命令`startx`进入 Enlightenment 桌面环境。
```
# startx
```

*Kali Linux 下进入 Enlightenment 桌面环境*
初次进入 Enlightenment 桌面环境时,它将会询问用户进行一些首选项配置,然后再运行桌面环境。
[](http://www.tecmint.com/wp-content/uploads/2016/10/Kali-Linux-Enlightenment-Desktop.png)
*Kali Linux Enlightenment 桌面*
此时,你已经成功地安装了 Kali Linux 系统,并可以使用了。后续的文章我们将探讨 Kali 系统中一些有用的工具以及如何使用这些工具来探测主机及网络方面的安全状况。
请随意发表任何评论或提出相关的问题。
---
via: <http://www.tecmint.com/kali-linux-installation-guide/>
作者:[Rob Turner](http://www.tecmint.com/author/robturner/) 译者:[rusking](https://github.com/rusking) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,987 | 写一个 JavaScript 框架:比 setTimeout 更棒的定时执行 | https://blog.risingstack.com/writing-a-javascript-framework-execution-timing-beyond-settimeout/ | 2016-11-26T13:41:30 | [
"JavaScript"
] | /article-7987-1.html | 这是 [JavaScript 框架系列](https://blog.risingstack.com/writing-a-javascript-framework-project-structuring/)的第二章。在这一章里,我打算讲一下在浏览器里的异步代码不同执行方式。你将了解定时器和事件循环之间的不同差异,比如 setTimeout 和 Promises。
这个系列是关于一个开源的客户端框架,叫做 NX。在这个系列里,我主要解释一下写该框架不得不克服的主要困难。如果你对 NX 感兴趣可以参观我们的 [主页](http://nx-framework.com/)。

这个系列包含以下几个章节:
1. [项目结构](https://blog.risingstack.com/writing-a-javascript-framework-project-structuring/)
2. 定时执行 (当前章节)
3. [沙箱代码评估](https://blog.risingstack.com/writing-a-javascript-framework-sandboxed-code-evaluation/)
4. [数据绑定介绍](https://blog.risingstack.com/writing-a-javascript-framework-data-binding-dirty-checking/)
5. [数据绑定与 ES6 代理](https://blog.risingstack.com/writing-a-javascript-framework-data-binding-es6-proxy/)
6. 自定义元素
7. 客户端路由
### 异步代码执行
你可能比较熟悉 `Promise`、`process.nextTick()`、`setTimeout()`,或许还有 `requestAnimationFrame()` 这些异步执行代码的方式。它们内部都使用了事件循环,但是它们在精确计时方面有一些不同。
在这一章里,我将解释它们之间的不同,然后给大家演示怎样在一个类似 NX 这样的先进框架里面实现一个定时系统。不用我们重新做一个,我们将使用原生的事件循环来达到我们的目的。
### 事件循环
事件循环甚至没有在 [ES6 规范](http://www.ecma-international.org/ecma-262/6.0/)里提到。JavaScript 自身只有任务(Job)和任务队列(job queue)。更加复杂的事件循环是在 NodeJS 和 HTML5 规范里分别定义的,因为这篇是针对前端的,我会在详细说明后者。
事件循环可以被看做某个条件的循环。它不停的寻找新的任务来运行。这个循环中的一次迭代叫做一个滴答(tick)。在一次滴答期间执行的代码称为一次任务(task)。
```
while (eventLoop.waitForTask()) {
eventLoop.processNextTask()
}
```
任务是同步代码,它可以在循环中调度其它任务。一个简单的调用新任务的方式是 `setTimeout(taskFn)`。不管怎样, 任务可能有很多来源,比如用户事件、网络或者 DOM 操作。

### 任务队列
更复杂一些的是,事件循环可以有多个任务队列。这里有两个约束条件,相同任务源的事件必须在相同的队列,以及任务必须按插入的顺序进行处理。除此之外,浏览器可以做任何它想做的事情。例如,它可以决定接下来处理哪个任务队列。
```
while (eventLoop.waitForTask()) {
const taskQueue = eventLoop.selectTaskQueue()
if (taskQueue.hasNextTask()) {
taskQueue.processNextTask()
}
}
```
用这个模型,我们不能精确的控制定时。如果用 `setTimeout()`浏览器可能决定先运行完其它几个队列才运行我们的队列。

### 微任务队列
幸运的是,事件循环还提供了一个叫做微任务(microtask)队列的单一队列。当前任务结束的时候,微任务队列会清空每个滴答里的任务。
```
while (eventLoop.waitForTask()) {
const taskQueue = eventLoop.selectTaskQueue()
if (taskQueue.hasNextTask()) {
taskQueue.processNextTask()
}
const microtaskQueue = eventLoop.microTaskQueue
while (microtaskQueue.hasNextMicrotask()) {
microtaskQueue.processNextMicrotask()
}
}
```
最简单的调用微任务的方法是 `Promise.resolve().then(microtaskFn)`。微任务按照插入顺序进行处理,并且由于仅存在一个微任务队列,浏览器不会把时间弄乱了。
此外,微任务可以调度新的微任务,它将插入到同一个队列,并在同一个滴答内处理。

### <ruby> 绘制 <rp> ( </rp> <rt> Rendering </rt> <rp> ) </rp></ruby>
最后是<ruby> 绘制 <rp> ( </rp> <rt> Rendering </rt> <rp> ) </rp></ruby>调度,不同于事件处理和分解,绘制并不是在单独的后台任务完成的。它是一个可以运行在每个循环滴答结束时的算法。
在这里浏览器又有了许多自由:它可能在每个任务以后绘制,但是它也可能在好几百个任务都执行了以后也不绘制。
幸运的是,我们有 `requestAnimationFrame()`,它在下一个绘制之前执行传递的函数。我们最终的事件模型像这样:
```
while (eventLoop.waitForTask()) {
const taskQueue = eventLoop.selectTaskQueue()
if (taskQueue.hasNextTask()) {
taskQueue.processNextTask()
}
const microtaskQueue = eventLoop.microTaskQueue
while (microtaskQueue.hasNextMicrotask()) {
microtaskQueue.processNextMicrotask()
}
if (shouldRender()) {
applyScrollResizeAndCSS()
runAnimationFrames()
render()
}
}
```
现在用我们所知道知识来创建定时系统!
### 利用事件循环
和大多数现代框架一样,[NX](http://nx-framework.com/) 也是基于 DOM 操作和数据绑定的。批量操作和异步执行以取得更好的性能表现。基于以上理由我们用 `Promises`、 `MutationObservers` 和 `requestAnimationFrame()`。
我们所期望的定时器是这样的:
1. 代码来自于开发者
2. 数据绑定和 DOM 操作由 NX 来执行
3. 开发者定义事件钩子
4. 浏览器进行绘制
#### 步骤 1
NX 寄存器对象基于 [ES6 代理](https://ponyfoo.com/articles/es6-proxies-in-depth) 以及 DOM 变动基于[MutationObserver](https://davidwalsh.name/mutationobserver-api) (变动观测器)同步运行(下一节详细介绍)。 它作为一个微任务延迟直到步骤 2 执行以后才做出反应。这个延迟已经在 `Promise.resolve().then(reaction)` 进行了对象转换,并且它将通过变动观测器自动运行。
#### 步骤 2
来自开发者的代码(任务)运行完成。微任务由 NX 开始执行所注册。 因为它们是微任务,所以按序执行。注意,我们仍然在同一个滴答循环中。
#### 步骤 3
开发者通过 `requestAnimationFrame(hook)` 通知 NX 运行钩子。这可能在滴答循环后发生。重要的是,钩子运行在下一次绘制之前和所有数据操作之后,并且 DOM 和 CSS 改变都已经完成。
#### 步骤 4
浏览器绘制下一个视图。这也有可能发生在滴答循环之后,但是绝对不会发生在一个滴答的步骤 3 之前。
### 牢记在心里的事情
我们在原生的事件循环之上实现了一个简单而有效的定时系统。理论上讲它运行的很好,但是还是很脆弱,一个轻微的错误可能会导致很严重的 BUG。
在一个复杂的系统当中,最重要的就是建立一定的规则并在以后保持它们。在 NX 中有以下规则:
1. 永远不用 `setTimeout(fn, 0)` 来进行内部操作
2. 用相同的方法来注册微任务
3. 微任务仅供内部操作
4. 不要干预开发者钩子运行时间
#### 规则 1 和 2
数据反射和 DOM 操作将按照操作顺序执行。这样只要不混合就可以很好的延迟它们的执行。混合执行会出现莫名其妙的问题。
`setTimeout(fn, 0)` 的行为完全不可预测。使用不同的方法注册微任务也会发生混乱。例如,下面的例子中 microtask2 不会正确地在 microtask1 之前运行。
```
Promise.resolve().then().then(microtask1)
Promise.resolve().then(microtask2)
```

#### 规则 3 和 4
分离开发者的代码执行和内部操作的时间窗口是非常重要的。混合这两种行为会导致不可预测的事情发生,并且它会需要开发者了解框架内部。我想很多前台开发者已经有过类似经历。
### 结论
如果你对 NX 框架感兴趣,可以参观我们的[主页](http://nx-framework.com/)。还可以在 GIT 上找到我们的[源代码](https://github.com/RisingStack/nx-framework)。
在下一节我们再见,我们将讨论 [沙盒化代码执行](https://blog.risingstack.com/writing-a-javascript-framework-sandboxed-code-evaluation/)!
你也可以给我们留言。
---
via: <https://blog.risingstack.com/writing-a-javascript-framework-execution-timing-beyond-settimeout/>
作者:[Bertalan Miklos](https://blog.risingstack.com/author/bertalan/) 译者:[kokialoves](https://github.com/kokialoves) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| null | ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) | null |
7,989 | 火狐是否在未经授权的情况下搜集您的数据? | https://iwf1.com/is-mozilla-firefox-collecting-your-data-without-your-consent/ | 2016-11-27T08:40:00 | [
"Firefox",
"隐私"
] | https://linux.cn/article-7989-1.html | 
打包在 Firefox Web 浏览器里面的地理位置服务即使浏览器关闭后也会在后台运行。
我们还没有从关于浏览器插件丑闻的消息中平复下来。插件原本目的是保卫隐私,[但现在却把信息卖给了第三方公司](https://iwf1.com/shock-this-popular-browser-add-on-sells-your-browsing-history/)。然而更令人愤怒的是其规模完全超出我们的预计。
**MLS**,即 Mozilla 位置服务,其可以让设备基于类似于 WIFI 接入点、无线电基站和蓝牙信标等基础设施确定其位置。
MLS 非常像是 Google 位置服务,后者是需要在 Android 设备上打开 GPS 并选择“高精度”模式时使用的服务。
那些曾经经历过 GPS 问题的人可能会知道这个模式是多么精确。
MLS 服务除了能够准确地确定您的位置以外,这个服务可以通过使用 WiFi 网络收集两种个人身份信息,包括**愿意贡献到数据库的用户**和**被扫描的 WiFi 设备的所有者**。
话虽这么说,Mozilla 也提到说你可以选择退出服务,但你真的可以退出吗?
### 当后台变成你隐私的展台
作为一个众包项目,为了维护和发展 MLS,Mozilla 事实上非常依赖于用户的贡献,因此他们开发了多种方法以便用户参与进来。
其中之一,就是被终端用户使用的一款名为 Stumbler 的 Android 应用程序:
>
> [Mozilla Stumbler](https://location.services.mozilla.com/apps) 是一个开源的无线网络扫描器,它为我们的众包位置数据库收集 GPS、蜂窝网络和无线网络元数据。
>
>
>
这样一来,Stumbler 不仅仅是一个独立的应用程序,同时也是 Firefox 在 Android 设备上提供的一种为 MLS“贡献数据和增强功能”的服务。
该服务的问题在于它在后台运行,而大多数用户都不知道它,**即使您可能已经禁用它**。
根据 Mozilla 提供的[信息](https://location.services.mozilla.com/apps),要启用该服务,您需要打开“设置”菜单(在 Firefox for Android 版本中) -> 打开“隐私”部分 -> 滚动到底部以查看“数据选择”,最后,勾选 Mozilla 位置服务框。

*Mozilla 定位服务尚未勾选,但 Stumbler 已开启*
实际上,你会发现 Stumbler 服务**运行在你的设备后台**,这意味着它几乎不可见,因为它没有接口,即使 MLS 框未被选中,即使“数据选择”复选框都未选中,甚至 Firefox 浏览器本身已被关闭。
显然,停止 stumbler 的唯一方法是直接结束它。然而,这样做你首先需要一种方法来检测它的运行和结束,最终,这只是一个设备重启前的临时解决方案。
### 如何保证安全
为了避免 MLS 收集您的数据,仍然有一些方法值得您尝试一下,希望这些方法不会像在 Firefox for Android 中的MLS 复选框一样被 Mozilla 忽视。
您可以将您的无线网络 SSID 隐藏或者在 SSID 结尾添加“\_nomap”,例如将您的 SSID 从“myWirelessNetwork”更名为“myWirelessNetwork\_nomap”。这在向 Mozilla 的应用程序暗示,您不希望参与他们的数据收集活动。
对于 Android 上的 Stumbler 服务,由于是一个服务(而不是进程),您可能无法在运行的进程/最近的应用程序列表中看到它。 因此,使用专用应用程序关闭它或启用“开发人员选项”,并转到“运行服务” -> 点击 Firefox,最后,停止“stumbler”。
---
via: <https://iwf1.com/is-mozilla-firefox-collecting-your-data-without-your-consent/>
作者:[Liron](https://iwf1.com/is-mozilla-firefox-collecting-your-data-without-your-consent/) 译者:[flankershen](https://github.com/flankershen) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,990 | 开源 vs. 闭源 | http://www.linuxandubuntu.com/home/open-source-vs-closed-source | 2016-11-28T09:18:00 | [
"开源",
"闭源"
] | https://linux.cn/article-7990-1.html | 
**开源操作系统**和**闭源操作系统**之间有诸多不同。这里我们仅寥书几笔。
### 开源是什么?自由!
这是用户需要知道的最重要的一点。无论我是否打算修改代码,其他人出于善意的修改都不应受到限制。且如果用户喜欢,他们可以分享这个软件。使用**开源**软件,这些都是可能的。
**闭源**操作系统的许可条款很是吓人。但真的所有人都会看吗?不,许多用户只是点了一下‘Accept’ 而已。
### 价格
几乎所有的开源操纵系统是免费的。仅有自愿性质的捐款。且只需有个一个 **CD/DVD 或 USB** 就能将系统安装到所有你想要安装的电脑上。
闭源操作系统相较于开源 OS 就贵了许多,如果你用它来构建 PC,每台 PC 得你花不少于 $100。
我们可以用花在闭源软件上的钱去买更好的东西。
### 选择
开源操作系统的发行版有很多。如果你不中意眼下的这个,你可以尝试其他的发行版,总能找到适合你的那一个。
诸如 Ubuntu studio、Bio Linux、Edubuntu、Kali Linux、Qubes、SteamOS 这些发行版,就是针对特定用户群产生的发行版。
闭源软件有“选择”这种说法吗?我觉得是没有的。
### 隐私
**开源操作系统**无需收集用户数据信息。不会根据用户的个性显示广告,也不会把你的信息卖给第三方机构。如果开发者需要资金,他们会要求捐助,或是在他们的网页上打广告。广告的内容也会与 Linux 相关,对我们有益无害。
你一定知道那个主流的闭源操作系统(名字就不写了,大家都知道的),据说因为收集用户信息这件事,导致多数用户关闭了他们的免费更新服务。多数该系统的用户为了避免升级,将更新功能关闭,他们宁可承担安全风险也不要免费更新。
### 安全
开源软件大多安全。究其缘由不仅有市场占有率低这个原因,其本身的构成方式就比较安全。例如, Qubes Os 是最安全的操作系统之一,它将运行的软件相互隔离。
闭源操作系统向易用性妥协,使其变得愈发脆弱。
### 硬件支持
我们中有大多数人,家里还放着那些不想丢的旧 PC,这时一个轻量级的发行版可能会让这些老家伙们重获新生。你可以试试在文章 [5 个适合旧电脑的轻量级 Linux](http://www.linuxandubuntu.com/home/5-lightweight-linux-for-old-computers) 中罗列的那些轻量级操作系统发行版。基于 Linux 的系统几乎包含所有设备的驱动,所以基本不需要你亲自寻找、安装驱动。
闭源操作系统时不时中止对旧硬件的支持,迫使用户去购买新的硬件。我们还不得不亲自寻找、安装驱动。
### 社区支持
几乎所有的**开源操作系统**都有用户论坛,你可以在那里提问题,并从别的用户那里得到答案。大家在那里分享技巧和窍门,互帮互助。有经验的 Linux 用户往往乐于帮助新手,为此他们常常不遗余力。
**闭源操作系统**社区和开源操作系统社区简直无法相提并论。提出的问题常常得不到回答。
### 商业化
在操作系统上挣钱是非常困难的。(开源)开发者一般通过用户的捐款和在网站上打广告来挣钱。捐款主要用于支付主机的开销和开发者的薪水。
许多闭源操作系统,不仅仅通过出售软件的使用许可这种方式来赚钱,还会推送广告大赚一票。
### 垃圾应用
我承认有些开源操作系统会提供一些我们可能一辈子都不会用到的应用,有些人认为他们是垃圾应用。但是也有发行版只提供最小安装,其中就不包含这些不想要的软件。所以,这不是真正的问题。
而所有的闭源操作系统中都包含厂商安装的垃圾应用,强制你安装,就像在安装一个干净系统一样。
开源软件更像是一门哲学。一种分享和学习的方式。甚至还有益于经济。
我们已经将我们知晓的罗列了出来。如果你觉得我们还漏了些什么,可以评论告诉我们。
---
via: <http://www.linuxandubuntu.com/home/open-source-vs-closed-source>
作者:[Mohd Sohail](https://www.linkedin.com/in/mohdsohail) 译者:[martin2011qi](https://github.com/martin2011qi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,991 | 安卓编年史(8):Android 1.5 Cupcake——虚拟键盘打开设备设计的大门 | http://arstechnica.com/gadgets/2016/10/building-android-a-40000-word-history-of-googles-mobile-os/8/ | 2016-11-27T12:24:00 | [
"Android",
"安卓编年史"
] | https://linux.cn/article-7991-1.html | 

*安卓 1.5 的虚拟键盘输入时的输入建议栏、大写状态键盘、数字与符号界面、更多符号弹窗。 [Ron Amadeo 供图]*
### Android 1.5 Cupcake——虚拟键盘打开设备设计的大门
在 2009 年 4 月,安卓 1.1 发布后将近三个月后,安卓 1.5 发布了。这是第一个拥有公开的、市场化代号的安卓版本:纸杯蛋糕(Cupcake)。从这个版本开始,每个版本的安卓将会拥有一个按字母表排序,以小吃为主题的代号。
纸杯蛋糕新增功能中最重要的明显当属虚拟键盘。这是 OEM 厂商第一次有可能抛开带有数不清的按键的实体键盘以及复杂的滑动结构,创造出平板风格的安卓设备。
安卓的按键标识可以在大小写之间切换,这取决于大写锁定是否开启。尽管默认情况下它是关闭的,显示在键盘顶部的建议栏有个选项可以打开它。在按键的弹框中带有省略号的,就像“u”,上面图那样的,可以在按住的情况下可以输入弹框中的[发音符号](http://en.wikipedia.org/wiki/Diacritic)。键盘可以切换到数字和符号,长按句号键可以打开更多符号。

*1.5 和 1.1 中的应用程序界面和通知面板的对比。 [Ron Amadeo 供图]*
给新的“摄像机”功能增加了新图标,Google Talk 从 IM 中分离出来成为了一个独立的应用。亚马逊 MP3 和浏览器的图标同样经过了重新设计。亚马逊 MP3 图标更改的主要原因是亚马逊即将计划推出其它的安卓应用,而“A”图标所指范围太泛了。浏览器图标无疑是安卓 1.1 中最糟糕的设计,所以它被重新设计了,并且不再像是一个桌面操作系统的对话框。应用抽屉的最后一个改变是“图片”,它被重新命名为了“相册”。
通知面板同样经过了重新设计。面板背景加上了布纹纹理,通知的渐变效果也被平滑化了。安卓 1.5 在系统核心部分有许多设计上的微小改变,这些改变影响到所有的应用。在“清除通知”按钮上,你可以看到全新的系统按钮风格,与旧版本的按钮相比有了渐变、更细的边框线以及更少的阴影。

*安卓 1.5 和 1.1 中的“添加到主屏幕”对话框。 [Ron Amadeo 供图]*
第三方小部件是纸杯蛋糕的另一个头等特性,它们现在仍然是安卓的本质特征之一。无论是用来控制应用还是显示应用的信息,开发者们都可以为他们的应用捆绑一个主屏幕小部件。谷歌同样展示了一些它们自己的新的小部件,分别来自日历和音乐这两个应用。

*左:日历小部件,音乐小部件以及一排实时文件夹的截图。中:文件夹列表。右:“带电话号码的联系人”实时文件夹的打开视图。 [Ron Amadeo 供图]*
在上方左边的截图里你可以看到新的日历和音乐图标。日历小部件只能显示当天的一个事件,点击它会打开日历。你不能够选择日历所显示的内容,小部件也不能够重新设置大小——它就是上面看起来的那个样子。音乐小部件是蓝色的——尽管音乐应用里没有一丁点的蓝色——它展示了歌曲名和歌手名,此外还有播放和下一曲按钮。
同样在左侧截图里,底部一排的头三个文件夹是一个叫做“[实时文件夹](http://android-developers.blogspot.com/2009/04/live-folders.html)”的新特性。它们可以在“添加到主屏幕”菜单中的新顶层选项“文件夹”中被找到,就像你在中间那张图看到的那样。实时文件夹可以展示一个应用的内容而不用打开这个应用。纸杯蛋糕带来的都是和联系人相关的实时文件夹,能够显示所有联系人,带有电话号码的联系人和加星标的联系人。
实时文件夹在主屏的弹窗使用了一个简单的列表视图,而不是图标。联系人只是实时文件夹的一个初级应用,它是给开发者使用的一个完整 API。谷歌用 Google Books 应用做了个图书文件夹的演示,它可以显示 RSS 订阅或是一个网站的热门故事。实时文件夹是安卓没有成功实现的想法之一,这个特性最终在蜂巢(3.x)中被取消。

*摄像机和相机界面,屏幕上有触摸快门。 [Ron Amadeo 供图]*
如果你不能认出新的“摄像机”图标,这不奇怪,视频录制是在安卓 1.5 中才被添加进来的。相机和摄像机两个图标其实是同一个应用,你可用过菜单中的“切换至相机”和“切换至摄像机”选项在它们之间切换。T-Mobile G1 上录制的视频质量并不高。一个“高”质量的测试视频输出一个 .3GP 格式的视频文件,其分辨率仅为 352 x 288,帧率只有 4FPS。
除了新的视频特性,相机应用中还可以看到一些急需的 UI 调整。上方左侧的快照展示了最近拍摄的那张照片,点击它会跳转到相册中的相机胶卷。各个界面上方右侧的圆形图标是触摸快门,这意味着,从 1.5 开始,安卓设备不再需要一个实体相机按钮。
这个界面相比于之后版本的相机应用实际上更加接近于安卓 4.2 的设计。尽管后续的设计会向相机加入愚蠢的皮革纹理和更多的控制设置,安卓最终还是回到了基本的设计,安卓 4.2 的重新设计和这里有很多共同之处。安卓 1.5 中的原始布局演变成了安卓 4.2 中的最小化的、全屏的取景器。

*Google Talk 运行在 Google Talk 中 vs 运行在 IM 应用中。 [Ron Amadeo 供图]*
安卓 1.0 的 IM 即时通讯应用功能上支持 Google Talk,但在安卓 1.5 中,Google Talk 从中分离出来成为独立应用。IM应用中对其的支持已经被移除。Google Talk(上图左侧)明显是基于 IM 应用(上图右侧)的,但随着独立应用在 1.5 中的发布,在 IM 应用的工作被放弃了。
新的 Google Talk 应用拥有重新设计过的状态栏、右侧状态指示灯、重新设计过的移动设备标识,是个灰色的安卓小绿人图案。聊天界面的蓝色的输入框变成了更加合理的灰色,消息的背景从淡绿和白色变成了淡绿和绿色。有了独立的应用,谷歌可以向其中添加 Gtalk 独有的特性,比如“不保存聊天记录”聊天,该特性可以阻止 Gmail 保存每个聊天记录。

*安卓 1.5 的日历更加明亮。 [Ron Amadeo 供图]*
日历抛弃了丑陋的黑色背景上白色方块的设计,转变为全浅色主题。所有东西的背景都变成了白色,顶部的星期日变成了蓝色。单独的约会方块从带有颜色的细条变成了拥有整个颜色背景,文字也变为白色。这将是很长一段时间内日历的最后一次改动。

*从左到右:新的浏览器控件,缩放视图,复制/粘贴文本高亮。 [Ron Amadeo 供图]*
安卓 1.5 从系统全局修改了缩放控件。缩放控件不再是两个大圆形,取而代之的是一个圆角的矩形从中间分开为左右两个按钮。这些新的控件被用在了浏览器、谷歌地图和相册之中。
浏览器在缩放功能上做了很多工作。在放大或缩小之后,点击“1x”按钮可以回到正常缩放状态。底部右侧的按钮会将缩放整个页面并在页面上显示一个放大矩形框,就像你能在上面中间截图看到的那样。按住矩形框并且释放会将页面的那一部分显示回“1x”视图。安卓并没有加速滚动,这使得最快的滚动速度也着实很慢——这就是谷歌对长网页页面导航的解决方案。
浏览器的另一个新增功能就是从网页上复制文本——之前你只能从输入框中复制文本。在菜单中选择“复制文本”会激活高亮模式,在网页文本上拖动你的手指使它们高亮。G1 的轨迹球对于这种精准的移动十分的方便,并且能够控制鼠标指针。这里并没有可以拖动的光标,当你的手指离开屏幕的时候,安卓就会复制文本并且移除高亮。所以你必须做到荒谬般的精确来使用复制功能。
安卓 1.5 中的浏览器很容易崩溃——比之前的版本经常多了。仅仅是以桌面模式浏览 Ars Technica 就会导致崩溃,许多其它的站点也是一样。

*Ron Amadeo供图*
默认的锁屏界面和图形锁屏都不再是空荡荡的黑色背景,而是和主屏幕一致的壁纸。
图形解锁界面的浅色背景显示出了谷歌在圆圈对齐工作上的草率和马虎。白色圆圈在黑圆圈里从来都不是在正中心的位置——像这样基本的对齐问题对于这一时期的安卓是个频繁出现的问题。

*Youtube 上传工具,内容快照,自动旋转设置,全新的音乐应用设计。 [Ron Amadeo 供图]*
安卓 1.5 给予了 YouTube 应用向其网站上传视频的能力。上传通过从相册中分享视频到 YouTube 应用来完成,或从 YouTube 应用中直接打开一个视频。这将会打开一个上传界面,用户在这里可以设置像视频标题、标签和权限这样的选项。照片可以以类似的方式上传到 Picasa,这是一个谷歌建立的图片网站。
整个系统的调整没有多少。常用联系人在联系人列表中可以显示图片(尽管常规联系人还是没有图片)。第三张截图展示了设置中全新的自动旋转选项——这个版本同样也是第一个支持基于从设备内部传感器读取的数据来自动切换方向的版本。

*HTC Magic,第二部安卓设备,第一个不带实体键盘的设备。 [HTC 供图]*
纸杯蛋糕在改进安卓上做了巨大的工作,特别是从硬件方面。虚拟键盘意味着不再需要实体键盘。自动旋转使得系统更加接近 iPhone,屏幕上的虚拟快门按键同样也意味着实体相机按键变成了可选选项。1.5 发布后不久,第二部安卓设备的出现将会展示出这个平台未来的方向:HTC Magic。Magic(上图)没有实体键盘或相机按钮。它是没有间隙、没有滑动结构的平板状设备,依赖于安卓的虚拟按键来完成任务。
安卓旗舰机开始可能有着最多按键——一个实体 qwerty 键盘——后来随着时间流逝开始慢慢减少按键数量。而 Magic 是重大的一步,去除了整个键盘和相机按钮,它仍然使用通话和挂断键、四个系统键以及轨迹球。
#### 谷歌地图是第一个登陆谷歌市场的内置应用
尽管这篇文章为了简单起见,(主要)以安卓版本顺序来组织应用更新,但还是有一些在这时间线之外的东西值得我们特别注意一下。2009 年 6 月 14 日,谷歌地图成为第一个通过谷歌市场更新的预置应用。尽管其它的所有应用更新还是要在一个完整的系统发布中进行更新,但是地图从系统中脱离了出来,只要新特性已经就绪就可以随时接收升级周期之外的更新。
将应用从核心系统分离发布到安卓市场上将成为谷歌前进的主要关注点。总的来说,OTA 更新是个重大的主动改进——这需要 OEM 厂商和运营商的合作,二者都是拖后腿的角色。更新同样没有做到到达每个设备。今天,谷歌市场给了谷歌一个与每个安卓手机之间的联系渠道,而没有了这样的外界干扰。
然而,这是后来才需要考虑的问题。在 2009 年,谷歌只有两种裸机需要支持,而且早期的安卓运营商似乎对谷歌的升级需要反应积极。这些早期的行动对谷歌这方面来说将被证明是非常积极的决定。一开始,公司只在最重要的应用——地图和 Gmail 上——走这条路线,但后来它将大部分预置应用导入安卓市场。后来的举措比如 Google Play 服务甚至将应用 API 从系统移除加入了谷歌商店。
至于这时的新地图应用,得到了一个新的路线界面,此外还有提供公共交通和步行方向的能力。现在,路线只有个朴素的黑色列表界面——逐步风格的导航很快就会登场。
2009 年 6 月同时还是苹果发布第三代 iPhone——3GS——以及第三版 iPhone OS 的时候。iPhone OS 3 的主要特性大多是追赶上来的项目,比如复制/粘贴和对彩信的支持。苹果的硬件依然是更好的,软件更流畅、更整合,还有更好的设计。尽管谷歌疯狂的开发步伐使得它不得不走上追赶的道路。iPhone OS 2 是在安卓 0.5 的 Milestone 5 版本之前发布的,在 iOS 一年的发布周期里安卓发布了五个版本。
---

[Ron Amadeo](http://arstechnica.com/author/ronamadeo) / Ron是Ars Technica的评论编缉,专注于安卓系统和谷歌产品。他总是在追寻新鲜事物,还喜欢拆解事物看看它们到底是怎么运作的。[@RonAmadeo](https://twitter.com/RonAmadeo)
---
via: <http://arstechnica.com/gadgets/2014/06/building-android-a-40000-word-history-of-googles-mobile-os/8/>
译者:[alim0x](https://github.com/alim0x) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,992 | 在 Linux 系统下从 ISO 镜像中提取和复制文件的 3 种方法 | http://www.tecmint.com/extract-files-from-iso-files-linux | 2016-11-27T14:44:00 | [
"ISO",
"7zip"
] | https://linux.cn/article-7992-1.html | 假设你的 Linux 服务器上有一个超大的 ISO 镜像文件,你想要打开它,然后提取或者复制其中的一个文件。你会怎么做呢?
其实在 Linux 系统里,有很多方法来实现这个要求。
比如说,你可以使用传统的 mount 命令以只读方式把 ISO 镜像文件加载为 loop 设备,然后再把文件复制到另一个目录。

### 在 Linux 系统下提取 ISO 镜像文件
为了完成该测试,你得有一个 ISO 镜像文件(我使用 ubuntu-16.10-server-amd64.iso 系统镜像文件)以及用于挂载和提取 ISO 镜像文件的目录。
首先,使用如下命令创建一个挂载目录来挂载 ISO 镜像文件:
```
$ sudo mkdir /mnt/iso
```
目录创建完成后,你就可以运行如下命令很容易地挂载 ubuntu-16.10-server-amd64.iso 系统镜像文件,并查看其中的内容。
```
$ sudo mount -o loop ubuntu-16.10-server-amd64.iso /mnt/iso
$ ls /mnt/iso/
```

*在 Linux 系统里挂载 ISO 镜像*
现在你就可以进入到挂载目录 /mnt/iso 里,查看文件或者使用 [cp 命令](http://www.tecmint.com/advanced-copy-command-shows-progress-bar-while-copying-files/)把文件复制到 /tmp 目录了。
```
$ cd /mnt/iso
$ sudo cp md5sum.txt /tmp/
$ sudo cp -r ubuntu /tmp/
```

*在 Linux 系统中复制 ISO 镜像里的文件*
注意:`-r` 选项用于递归复制目录里的内容。如有必要,你也可以[监控复制命令的完成进度](http://www.tecmint.com/monitor-copy-backup-tar-progress-in-linux-using-pv-command/)。
### 使用 7zip 命令提取 ISO 镜像里的内容
如果不想挂载 ISO 镜像,你可以简单地安装一个 7zip 工具,这是一个自由而开源的解压缩软件,用于压缩或解压不同类型格式的文件,包括 TAR、XZ、GZIP、ZIP、BZIP2 等等。
```
$ sudo apt-get install p7zip-full p7zip-rar [On Debian/Ubuntu systems]
$ sudo yum install p7zip p7zip-plugins [On CentOS/RHEL systems]
```
7zip 软件安装完成后,你就可以使用`7z` 命令提取 ISO 镜像文件里的内容了。
```
$ 7z x ubuntu-16.10-server-amd64.iso
```

*使用 7zip 工具在 Linux 系统下提取 ISO 镜像里的文件*
注意:跟 Linux 的 mount 命令相比起来,7zip 在压缩和解压缩任何格式的文件时速度更快,更智能。
### 使用 isoinfo 命令来提取 ISO 镜像文件内容
虽然 `isoinfo` 命令是用来以目录的形式列出 iso9660 镜像文件的内容,但是你也可以使用该程序来提取文件。
我说过,isoinfo 程序会显示目录列表,因此先列出 ISO 镜像文件的内容。
```
$ isoinfo -i ubuntu-16.10-server-amd64.iso -l
```

*Linux 里列出 ISO 文件的内容*
现在你可以按如下的方式从 ISO 镜像文件中提取单文件:
```
$ isoinfo -i ubuntu-16.10-server-amd64.iso -x MD5SUM.TXT > MD5SUM.TXT
```
注意:因为 `-x` 解压到标准输出,必须使用重定向来提取指定文件。

*从 ISO 镜像文件中提取单个文件*
就到这里吧,其实还有很多种方法来实现这个要求,如果你还知道其它有用的命令或工具来提取复制出 ISO 镜像文件中的文件,请在下面的评论中跟大家分享下。
---
via: <http://www.tecmint.com/extract-files-from-iso-files-linux>
作者:[Ravi Saive](http://www.tecmint.com/author/admin/) 译者:[rusking](https://github.com/rusking) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,994 | 在 Linux 系统里识别 USB 设备名字的 4 种方法 | http://www.tecmint.com/find-usb-device-name-in-linux | 2016-11-28T13:58:00 | [
"USB"
] | https://linux.cn/article-7994-1.html | 对于初学者来说,在 Linux 系统里你必须掌握的技术之一就是识别出插入系统里的各种设备。这也许是你的系统硬盘、外部的存储设备或者是可移动设备,比如 USB 设备或 SD 闪存卡等。

现如今,使用 USB 设备来传输文件是十分常见的事,对于那些喜欢使用命令行的新手来说,当你需要格式化 USB 设备时,学会使用不同的方法来识别 USB 设备名是非常重要的。
如果在系统中插入一个设备,尤其是在桌面环境下,比如 USB 设备,它会自动挂载到一个指定目录,一般是在 `/media/username/device-label` 目录下,之后你就可以进入到该目录下访问那些文件了。然而,在服务器上就不是这么回事了,你必须[手动挂载](http://www.tecmint.com/mount-filesystem-in-linux/)这个设备,并且指定一个挂载点。
Linux 系统使用 `/dev` 目录下特定的设备文件来标识插入的设备。你会发现该目录下的某些文件,包括 `/dev/sda` 或者 `/dev/hda` 表示你的第一个主设备,每个分区使用一个数字来表示,比如 `/dev/sda1` 或 `/dev/hda1` 表示主设备的第一个分区等等。
```
$ ls /dev/sda*
```

*列出 Linux 系统下所有的设备名*
现在让我们来使用下面一些特殊的命令行工具找出设备名:
### 使用 df 命令来找出插入的 USB 设备名
查看插入你系统里的每一个设备及对应的挂载点,你可以使用下图中的 `df` 命令检查 Linux 系统磁盘空间使用情况:
```
$ df -h
```

*使用 df 命令查找 USB 设备名*
### 使用 lsblk 命令查找 USB 设备名
你也可以使用下面的 `lsblk` 命令(列出块设备)来列出插入你系统里的所有块设备:
```
$ lsblk
```

*列出 Linux 系统里的块设备*
### 使用 fdisk 工具识别 USB 设备名
[fdisk 是一个功能强大的工具](http://www.tecmint.com/fdisk-commands-to-manage-linux-disk-partitions/),用于查看你系统中的所有分区表,包括所有的 USB 设备,使用 root 权限执行如下命令:
```
$ sudo fdisk -l
```

*列出块设备的分区表*
### 使用 dmesg 命令来识别出 USB 设备名
`dmesg` 是一个用于打印或者控制内核环形缓冲区(kernel ring buffer)的重要命令。环形缓冲区是一种数据结构,它[存放着内核操作数据的信息](http://www.tecmint.com/dmesg-commands/)。
运行如下命令来查看内核操作信息,它同时也会打印出 USB 设备的信息:
```
$ dmesg
```

*dmesg – 打印 USB 设备名*
以上就是这篇文章中提及到的所有命令,我们在命令行下使用不同的方法来找出 USB 设备名。你也可以跟大家分享下实现这个目的的其它方法,或者如果你对这篇文章有什么想法也可以在下面跟大家交流下。
---
via: <http://www.tecmint.com/find-usb-device-name-in-linux>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[rusking](https://github.com/rusking) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,996 | 安卓编年史(9):安卓 1.6 Donut——CDMA 支持将安卓带给了各个运营商 | http://arstechnica.com/gadgets/2016/10/building-android-a-40000-word-history-of-googles-mobile-os/9/ | 2016-11-29T09:23:00 | [
"Android",
"安卓编年史"
] | https://linux.cn/article-7996-1.html | 

*新版安卓市场——黑色比重减少,白色和绿色增多。 [Ron Amadeo 供图]*
### 安卓 1.6 Donut——CDMA 支持将安卓带给了各个运营商
安卓的第四个版本——1.6 甜甜圈——在 2009 年 9 月发布,这时是在纸杯蛋糕面世的 5 个月后。尽管有无数更新,谷歌仍然在给安卓添加基本的功能。甜甜圈带来了对不同屏幕尺寸和 CDMA 的支持,还有一个文本语音转换引擎。
安卓 1.6 是个很好的更新例子,要在今天的话,它将没什么理由作为一个独立更新存在。主要的改进基本上可以总结为新版安卓市场、相机以及 YouTube。从这一年起,像这样的应用已经从系统分离开来,并且谷歌任何时候都能升级它们。然而在完成所有的这些模块化功能工作之前,看起来甚至是一个微小的应用更新似乎都需要完整的系统更新。
另一个重大改进——CDMA 支持——也表明了除了版本号之外,谷歌仍然在忙于将基本功能带到安卓上来。
安卓市场被标注为版本“1.6”,并且得到了一个彻底的改进。原本的全黑设计被抛弃,转向带有绿色高亮的白色应用设计——安卓的设计师很明显使用了安卓吉祥物来获得灵感。
新的市场对谷歌来说一定是个新的应用设计风格。屏幕顶部的五分之一用于显示横幅 logo,表明了这个应用确实是“安卓市场”。在横幅之下是应用、游戏以及下载按钮,一个搜索按钮被安置在横幅的右侧。在导航键下面显示着特色应用的快照,可以在它们之间滑动。再下面是个垂直滚动列表,显示了更多的特色应用。

*新的市场设计,展示了:带有截图的应用页面、应用分类页面、应用排行榜、下载。 [Ron Amadeo 供图]*
市场的最大的新增内容是包含应用截图。安卓用户终于可以在安装之前看到应用长什么样子——之前他们只能看到简短的描述和用户评论。你的个人星级评价和评论被放在显著位置,随后是描述,最后是截图。查看截图常常需要一点点滚动来查看——如果你想要找个设计尚佳的应用,那可要费一番功夫了。
点击应用或游戏按钮会打开一个分类列表,就像你在上面第二张图看到的那样。选择一个类别之后,更多的导航显示在了屏幕顶部,用户可以看到“热门付费”、“热门免费”,或在分类里看到各自的“热门新品”应用。尽管这些看起来像是会加载出新页面的按钮,实际上它们仅仅是个笨拙的标签页。每个按钮边有个绿色小灯指示现在哪个标签处于活跃状态。这个界面最赞的地方是应用列表是无穷滚动的(滚动加载)——一旦你到达列表底部的时候,它将加载更多应用。这个特性使得查看应用列表变得轻松,但是你点开任意一个应用再返回的话将会丢失你在列表里的位置——你得从头开始查看。下载部分可以做一些连新的 Google Play 商店都做不到的事:不过是显示一个已购买应用列表而已。
尽管新的市场看起来无疑比旧的好多了,但应用间的一致性更糟糕了。看起来就像是每个应用都是由不同团队制作的,他们之间从没沟通过所有的安卓应用应该有的样子。

*相机取景窗,照片回看界面,菜单。 [Ron Amadeo 供图]*
举个例子,相机应用从全屏、精简设计变成一个盒状的边缘带控制的取景窗。在相机应用中,谷歌着手引入拟物化,将应用包装成一个大致复刻了皮革纹经典相机的样子。在相机和摄像机之间切换通过一个缺乏想象力的开关完成,下面是个触摸快门按钮。
点击最近照片快照不再会打开相册,而是一个内建在了相机应用内定制的照片查看器。当你查看照片的时候,皮革质感的控制区从相机操作键变成图片操作键,你可以在这里删除、共享照片,或者把照片设置成壁纸或联系人图像。这里图片之间依然没有滑动操作——切换照片还是要通过照片两侧的箭头按钮完成。
第二张截图展示的是设计师减少对菜单按钮依赖的例子之一,因为安卓团队慢慢开始意识到其在可发现性上的糟糕表现。许多的应用设计者(包括那些在谷歌的)使用菜单作为所有种类的控制和导航元素的集中之处。但大多数用户没想过点击菜单按钮,也从没看到这些指令。
未来版本的安卓的公共主题会将选项从菜单移到主要屏幕上,使得整个系统对用户更加友好。菜单按钮在安卓 4.0 中被完全移除,并且它只在老式应用中被支持。

*电池以及文本语音转换引擎设置。 [Ron Amadeo 供图]*
甜甜圈是第一个持续追踪电池使用量的安卓版本。在“关于手机”菜单里有个选项“电池使用”,它会以百分比的方式显示应用以及硬件功能的电池用量。点击其中一项会打开一个单独的相关状态页面。硬件项目有个按钮可以直接跳转到它们的设置界面,所以,举个例子,如果你觉得显示的电池用量太高你可以更改显示的屏幕超时。
安卓 1.6 同样是第一个支持文本语音转换引擎(TTS)的版本,这意味着系统以及应用能够用机器合成声音来回应你。“语音合成器”选项允许你设置语言,选择语速,以及从安卓市场安装语音数据(慎重)。今天,谷歌在安卓上部署它自己的 TTS 引擎,但是似乎甜甜圈是通过硬编码的方式使用了来自 SVOX 的 TTS 引擎。但 SVOX 的引擎并未部署在甜甜圈上,所以点击“安装语音数据”会链接到安卓市场的一个应用。(甜甜圈的全盛期几年后,这个应用已被撤下。看起来似乎安卓 1.6 再也不能说话了。)

*从左到右:新的小部件,搜索栏界面,新清除通知按钮,新相册控件。 [Ron Amadeo 供图]*
前端小部件部分花了更多的功夫。甜甜圈带来了全新的叫做“电量控制”小部件。它包含了常见耗电功能的开关:Wi-Fi、蓝牙、GPS、同步(同谷歌服务器之间),以及亮度。
搜索小部件同样经过了重新设计,变得更加纤细,并且内置了一个麦克风按钮用于语音搜索。它现在有了些实质界面并且够实时搜索,不仅仅是搜索互联网,还能搜索你的应用和历史。
“清除通知”按钮大幅缩水并且去掉了“通知”字样。在稍晚些的安卓后续版本总它还会缩减成仅仅是个方形按钮。相册继续遵循了把功能从菜单里拿出来的趋势,并且将它们放在用户面前——单张图片查看界面得到了“设置为”、“分享”以及“删除”按钮。
---

[Ron Amadeo](http://arstechnica.com/author/ronamadeo) / Ron 是 Ars Technica 的评论编缉,专注于安卓系统和谷歌产品。他总是在追寻新鲜事物,还喜欢拆解事物看看它们到底是怎么运作的。 [@RonAmadeo](https://twitter.com/RonAmadeo)
---
via: <http://arstechnica.com/gadgets/2016/10/building-android-a-40000-word-history-of-googles-mobile-os/9/>
译者:[alim0x](https://github.com/alim0x) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
7,997 | Git 系列(七):使用 Git 管理二进制大对象 | https://opensource.com/life/16/8/how-manage-binary-blobs-git-part-7 | 2016-11-29T09:36:00 | [
"Git",
"blob"
] | https://linux.cn/article-7997-1.html | 通过这系列的前六篇文章,我们已经学会使用 Git 来对文本文件进行版本控制的管理。我们不禁要问,还有二进制文件呢,也可进行进行版本控制吗?答案是肯定的,Git 已经有了可以处理像多媒体文件这样的二进制大对象块(blob)的扩展。因此,今天我们会学习使用 Git 来管理所谓的二进制资产。

似乎大家都认可的事就是 Git 对于大的二进制对象文件支持得不好。要记住,二进制大对象与大文本文件是不同的。虽然 Git 对大型的文本文件版本控制毫无问题,但是对于不透明的二进制文件起不了多大作用,只能把它当作一个大的实体黑盒来提交。
设想这样的场景,有一个另人兴奋的第一人称解密游戏,您正在为它制作复杂的 3D 建模,源文件是以二进制格式保存的,最后生成一个 1GB 大小的的文件。您提交过一次,在 Git 源仓库历史中有一个 1GB 大小的新增提交。随后,您修改了下模型人物的头发造型,然后提交更新,因为 Git 并不能把头发从头部及模型中其余的部分离开来,所以您只能又提交 1GB 的量。接着,您改变了模型的眼睛颜色,提交这部分更新:又是 GB 级的提交量。对一个模型的一些微小修改,就会导致三个 GB 级的提交量。对于想对一个游戏所有资源进行版本控制这样的规模,这是个严重的问题。
不同的是如 `.obj` 这种格式的文本文件,和其它类型文件一样,都是一个提交就存储所有更新修改状态,不同的是 `.obj` 文件是一系列描述模型的纯文本行。如果您修改了该模型并保存回 `.obj` 文件,Git 可以逐行读取这两个文件,然后创建一个差异版本,得到一个相当小的提交。模型越精细,提交就越小,这就是标准的 Git 用例。虽然文件本身很大,但 Git 使用覆盖或稀疏存储的方法来构建当前数据使用状态的完整描述。
然而,不是所有的都是纯文本的,但都要使用 Git,所以需要解决方案,并且已经出现几个了。
[OSTree](https://ostree.readthedocs.io/en/latest/) 开始是作为 GNOME 项目出现的,旨在管理操作系统的二进制文件。它不适用于这里,所以我直接跳过。
[Git 大文件存储](https://git-lfs.github.com/)(LFS) 是放在 GitHub 上的一个开源项目,是从 git-media 项目中分支出来的。[git-media](https://github.com/alebedev/git-media) 和 [git-annex](https://git-annex.branchable.com/walkthrough/) 是 Git 用于管理大文件的扩展。它们是对同一问题的两种不同的解决方案,各有优点。虽然它们都不是官方的项目,但在我看来,每个都有独到之处:
* git-media 是集中模式,有一个公共资产的存储库。你可以告诉 git-media 大文件需要存储的位置,是在硬盘、服务器还是在云存储服务器,项目中的每个用户都将该位置视为大型文件的中心主存储位置。
* git-annex 侧重于分布模式。用户各自创建存储库,每个存储库都有一个存储大文件的本地目录 `.git/annex`。这些 annex 会定期同步,只要有需要,每个用户都可以访问到所有的资源。除非通过 annex-cost 特别配置,否则 git-annex 优先使用本地存储,再使用外部存储。
对于这些,我已经在生产中使用了 git-media 和 git-annex,那么下面会向你们概述其工作原理。
### git-media
git-media 是使用 Ruby 语言开发的,所以首先要安装 gem(LCTT 译注:Gem 是基于 Ruby 的一些开发工具包)。安装说明在[其网站](https://github.com/alebedev/git-media)上。想使用 git-meida 的用户都需要安装它,因为 gem 是跨平台的工具,所以在各平台都适用。
安装完 git-media 后,你需要设置一些 Git 的配置选项。在每台机器上只需要配置一次。
```
$ git config filter.media.clean "git-media filter-clean"
$ git config filter.media.smudge "git-media filter-smudge"
```
在要使用 git-media 的每个存储库中,设置一个属性以将刚刚创建的过滤器结合到要您分类为“<ruby> 媒体 <rp> ( </rp> <rt> media </rt> <rp> ) </rp></ruby>”的文件类型里。别被这种术语混淆。一个更好的术语是“资产”,因为“媒体”通常的意思是音频、视频和照片,但您也可以很容易地将 3D 模型,烘焙和纹理等归类为媒体。
例如:
```
$ echo "*.mp4 filter=media -crlf" >> .gitattributes
$ echo "*.mkv filter=media -crlf" >> .gitattributes
$ echo "*.wav filter=media -crlf" >> .gitattributes
$ echo "*.flac filter=media -crlf" >> .gitattributes
$ echo "*.kra filter=media -crlf" >> .gitattributes
```
当您要<ruby> 暂存 <rp> ( </rp> <rt> stage </rt> <rp> ) </rp></ruby>这些类型的文件时,文件会被复制到 `.git/media` 目录。
假设在服务器已经有了一个 Git 源仓库,最后一步就告诉源仓库“母舰”所在的位置,也就是,当媒体文件被推送给所有用户共享时,媒体文件将会存储的位置。这在仓库的 `.git/config` 文件中设置,请替换成您的用户名、主机和路径:
```
[git-media]
transport = scp
autodownload = false #默认为 true,拉取资源
scpuser = seth
scphost = example.com
scppath = /opt/jupiter.git
```
如果您的服务器上 SSH 设置比较复杂,例如使用了非标准端口或非默认 SSH 密钥文件的路径,请使用 `.ssh/config` 为主机设置默认配置。
git-media 的使用和普通文件一样,可以把普通文件和 blob 文件一样对待,一样进行 commit 操作。操作流程中唯一的不同就是,在某些时候,您应该将您的资产(或称媒体)同步到共享存储库中。
当要为团队发布资产或自己备份资料时,请使用如下命令:
```
$ git media sync
```
要用一个变更后的版本替换 git-media 中的文件时(例如,一个已经美声过的音频文件,或者一个已经完成的遮罩绘画,或者一个已经被颜色分级的视频文件),您必须明确的告诉 Git 更新该媒体。这将覆盖 git-media 不会复制远程已经存在的文件的默认设置:
```
$ git update-index --really-refresh
```
当您团队的其他成员(或是您本人,在其它机器上)克隆本仓库时,如果没有在 `.git/config` 中把 `autodownload` 选项设置为 `true` 的话,默认是不会下载资源的。但 git-media 的一个同步命令 `git media sync` 可解决所有问题。
### git-annex
git-annex 的处理流程略微的有些不同,默认是使用本地仓库的,但基本的思想都一样。您可以从你的发行版的软件仓库中安装 git-annex,或者根据需要从该网站上下载安装。与 git-media 一样,任何使用 git-annex 的用户都必须在其机器上安装它。
其初始化设置比 git-media 都简单。运行如下命令,其中替换成您的路径,就可以在您的服务器上创建好裸存储库:
```
$ git init --bare --shared /opt/jupiter.git
```
然后克隆到本地计算机,把它标记为 git-annex 的初始路径:
```
$ git clone [email protected]:/opt/jupiter.clone
Cloning into 'jupiter.clone'...
warning: You appear to have clonedan empty repository.
Checking connectivity... done.
$ git annex init "seth workstation"
init seth workstation ok
```
不要使用过滤器来区分媒体资源或大文件,您可以使用 `git annex` 命令来配置归类大文件:
```
$ git annex add bigblobfile.flac
add bigblobfile.flac
(checksum) ok
(Recording state in Git...)
```
跟普通文件一样进行提交操作:
```
$ git commit -m 'added flac source for sound fx'
```
但是推送操作是不同的,因为 `git annex` 使用自己的分支来跟踪资产。您首次推送可能需要 `-u` 选项,具体取决于您如何管理您的存储库:
```
$ git push -u origin master git-annex
To [email protected]:/opt/jupiter.git
* [new branch] master -> master
* [new branch] git-annex -> git-annex
```
和 git-media 一样,普通的 `git push` 命令是不会拷贝资料到服务器的,仅仅只是发送了相关的消息,要真正共享文件,需要运行同步命令:
```
$ git annex sync --content
```
如果别人已经提交了共享资源,您需要拉取它们,`git annex sync` 命令将提示您要在本地检出你本机没有,但在服务器上存在的资源。
git-media 和 git-annex 都非常灵活,都可以使用本地存储库来代替服务器,所以它们也常用于管理私有的本地项目。
Git 是一个非常强大和扩展性非常强的系统应用软件,我们应该毫不犹豫的使用它。现在就开始试试吧!
---
via: <https://opensource.com/life/16/8/how-manage-binary-blobs-git-part-7>
作者:[Seth Kenlon](https://opensource.com/users/seth) 译者:[runningwater](https://github.com/runningwater) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | *Read:*
[Part 1: What is Git?](https://opensource.com/resources/what-is-git)*Part 2: Getting started with Git*[Part 3: Creating your first Git repository](https://opensource.com/life/16/7/creating-your-first-git-repository)*Part 4: How to restore older file versions in Git**Part 5: 3 graphical tools for Git**Part 6: How to build your own Git server**Part 7: How to manage binary blobs with Git*
In the previous six articles in this series we learned how to manage version control on text files with Git. But what about binary files? Git has extensions for handling binary blobs such as multimedia files, so today we will learn how to manage binary assets with Git.
One thing everyone seems to agree on is Git is not great for big binary blobs. Keep in mind that a binary blob is different from a large text file; you can use Git on large text files without a problem, but Git can't do much with an impervious binary file except treat it as one big solid black box and commit it as-is.
Say you have a complex 3D model for the exciting new first person puzzle game you're making, and you save it in a binary format, resulting in a 1 gigabyte file. You `git commit`
it once, adding a gigabyte to your repository's history. Later, you give the model a different hair style and commit your update; Git can't tell the hair apart from the head or the rest of the model, so you've just committed another gigabyte. Then you change the model's eye color and commit that small change: another gigabyte. That is three gigabytes for one model with a few minor changes made on a whim. Scale that across all the assets in a game, and you have a serious problem.
Contrast that to a text file like the `.obj`
format. One commit stores everything, just as with the other model, but an `.obj`
file is a series of lines of plain text describing the vertices of a model. If you modify the model and save it back out to `.obj`
, Git can read the two files line by line, create a diff of the changes, and process a fairly small commit. The more refined the model becomes, the smaller the commits get, and it's a standard Git use case. It is a big file, but it uses a kind of overlay or sparse storage method to build a complete picture of the current state of your data.
However, not everything works in plain text, and these days everyone wants to work with Git. A solution was required, and several have surfaced.
[Git Large File Storage](https://git-lfs.github.com) (LFS) is an open source project from GitHub that began life as a fork of git-media. Git-media and [git-annex](https://git-annex.branchable.com/walkthrough/) are extensions to Git meant to manage large files. They are two different approaches to the same problem, and they each have advantages. These aren't official statements from the projects themselves, but in my experience, the unique aspects of each are:
-
`Git-annex`
favors a distributed model; you and your users create repositories, and each repository gets a local`.git/annex`
directory where big files are stored. The annexes are synchronized regularly so that all assets are available to all users as needed. Unless configured otherwise with`annex-cost`
,`git-annex`
prefers local storage before off-site storage. -
`Git-portal`
is also distributed, and like Git-annex has the option to synchronize to a central location. It uses common utilities that you likely already have installed (specifally Bash, Git, rsync). -
`Git-LFS`
is a centralised model, a repository for common assets. You tell Git-LFS where your large files are stored, whether that's a hard drive, a server, or a cloud storage service, and each user on your project treats that location as the central master location for large assets.
## git-portal
Git-portal offers simplified blob management for Git using standard UNIX tools like Bash, Git itself, and optionally rsync. It copies big binary files to local or remote storage, replacing them with symlinks that you can commit along with the rest of your project files.
Git-portal is simple at the expense of being a little more manual sometimes (it doesn't have automated garbage collection, for instance). It's ideal for users who need to manage big files that aren't normally agreeable to Git management, but don't want to have to learn a whole new system. Git-portal mimics Git itself, so there's only a minimal learning curve.
You can install Git-portal from its project page on [Gitlab](https://gitlab.com/slackermedia/git-portal).
All Git-portal commands mirror Git itself. To use Git-portal in a project:
`$ git-portal init`
To add a file:
`$ git-portal add bigfile.png`
Once a file's been "sent through the portal" (in the project's terminology), your interactions with Git are exactly the same as usual. You add files as usual, relatively oblivious to the fact that some of them are secretly symlinks to the **_portal **directory.
Everything in the **_portal **directory, which is entirely ignored by Git, can be backed-up separately to any kind of storage you like, whether it's a USB drive or a remote server. Because Git-portal provides some Git hooks (automated scripts triggered by specific Git actions, like a push or a pull), you can even set up a special Git remote entry so your _portal directory is synchronized automatically with a remote location:
`$ git remote add _portal [email protected]:/home/alice/umbrella.git/_portal`
Git-portal has the advantage of being a simple and Linux-native system. With a fairly minimal stack of common utilities and only a few extra commands to remember, you can manage large project dependencies and even share them between collaborators. Git-portal has been used on media projects, indie video games, and a gaming blog to manage everything from minor splash images to big PDFs to even bigger 3d models.
## git-annex
`git-annex`
has a slightly different workflow, and defaults to local repositories, but the basic ideas are the same. You should be able to install `git-annex`
from your distribution's repository, or you can get it from the website as needed. As with `git-media`
, any user using `git-annex`
must install it on their machine.
The initial setup is simpler than `git-media`
. To create a bare repository on your server run this command, substituting your own path:
`$ git init --bare --shared /opt/jupiter.git`
Then clone it onto your local computer, and mark it as a `git-annex`
location:
```
$ git clone [email protected]:/opt/jupiter.clone
Cloning into 'jupiter.clone'... warning: You appear to have cloned
an empty repository. Checking connectivity... done.
$ git annex init "seth workstation" init seth workstation ok
```
Rather than using filters to identify media assets or large files, you configure what gets classified as a large file by using the `git annex`
command:
```
$ git annex add bigblobfile.flac
add bigblobfile.flac (checksum) ok
(Recording state in Git...)
```
Committing is done as usual:
`$ git commit -m 'added flac source for sound fx'`
But pushing is different, because `git annex`
uses its own branch to track assets. The first push you make may need the `-u`
option, depending on how you manage your repository:
```
$ git push -u origin master git-annex
To [email protected]:/opt/jupiter.git
* [new branch] master -> master
* [new branch] git-annex -> git-annex
```
As with `git-media`
, a normal `git push`
does *not* copy your assets to the server, it only sends information about the media. When you're ready to share your assets with the rest of the team, run the sync command:
`$ git annex sync --content`
If someone else has shared assets to the server and you need to pull them, `git annex sync`
will prompt your local checkout to pull assets that are not present on your machine, but that exist on the server.
Git annex is a finely-tuned solution, flexible and user-friendly. It's robust and well-tested.
## git-lfs
`git-lfs`
is written in Go, and you can install it from source code or as a downloadable binary. Instructions are on the [website](https://git-lfs.github.com). Each user who wants to use `git-lfs`
needs to install it, but it is cross-platform, so that generally doesn't pose a problem.
After installing `git-lfs`
, you can set what filetypes you want Git to ignore and Git-LFS to manage. For example, for Git-LFS to track all** .png** files:
`$ git lfs track "*.png"`
Any time you add a filetype for Git-LFS tracking, you must add and then commit the file **.gitattributes**:
```
$ git add .gitattributes
$ git commit -m "LFS track *.png"
```
When you stage a file of those types, the file is copied to `.git/lfs`
.
Git-LFS is a project by Github and it's heavily tied in to Github's infrastructure. If you want to run a Git server that allows for Git-LFS integration, you can study up on the [Git-LFS server specification](https://github.com/git-lfs/lfs-test-server) (also written in Go) and implement the API.
Both `git-portal`
and `git-annex`
are flexible and can use local repositories instead of a server, so they're just as useful for managing private local projects, too.
## Large files and Git
While Git is meant for text files, that doesn't mean you can't use it just because you have binary assets. There are very good solutions to help you manage large files. There really aren't many excuses for not using Git if you want to, so try it out today!
## 8 Comments |
7,998 | 微软呼吁所有的 Linux 开发者转到 Windows 10 平台 | http://news.softpedia.com/news/microsoft-wants-all-linux-developers-to-move-to-windows-10-510551.shtml | 2016-11-29T08:58:00 | [
"微软",
"WSL"
] | https://linux.cn/article-7998-1.html | 
微软终于承认了开源世界的潜力,尤其是对 Linux 而言,所以,微软正在尝试以各种方式来在开源领域开疆辟土。
最近,在微软的 [Channel 9](https://channel9.msdn.com/Events/Connect/2016/191) 上的一则名为“改进 Bash on Windows 和 Windows 控制台”的视频节目中,其高级程序经理 Rich Turner 呼吁 Linux 开发人员放弃 Linux ,转到 Windows 10 上来。
他解释说,“(Linux 开发者)可以启动 Windows 10 Insiders 实例,并在其中运行其代码和工具,把网站托管到 Apache 上,并用 Java 代码来访问其 MySQL 数据库。”
他继续补充说,Windows 中的 Linux 子系统将给开发者们提供所有他们在 Linux 开发中必要的工具,而不用丧失 Windows 10 的优势。
“就像在 Linux 中一样构建应用,无论它是用 Go 写的,还是用 Erlang、C,你可以在 Bash on Windows 中试试你要用的任何东西,有 bug 就丢给我们来解决。我们的目标就是构建一个大家都能用的、更高效的产品给大家。”
微软正在致力于改善 [Windows 10 上 Linux 子系统](/article-7177-1.html),最终目标是让当前 Linux 上的所有开发工具都能兼容地运行在 Windows 10 之中,让所有切换到他们的操作系统的开发者都能够用上。
最近,微软作为[白金会员加入了 Linux 基金会](/article-7966-1.html),许诺为开源世界的开发做出贡献。这个事情令很多人都很吃惊,特别是其前 CEO 巴尔默还曾经称 Linux 为“癌症”,但是随着新 CEO 萨提亚上任之后,微软的画风大变,这个软件巨人正在逐渐深入到开源生态之中。
| 301 | Moved Permanently | null |
7,999 | 安卓编年史(10):Android 2.0 Éclair——带动 GPS 产业 | http://arstechnica.com/gadgets/2016/10/building-android-a-40000-word-history-of-googles-mobile-os/10/ | 2016-11-29T14:31:00 | [
"android",
"安卓编年史"
] | https://linux.cn/article-7999-1.html | 
### Android 2.0 Éclair——带动 GPS 产业
41 天——这是从安卓 1.6 到安卓 2.0 所经历的时间。安卓的第一个大的版本号更迭发生在 2009 年 10 月的[摩托罗拉 Droid](http://arstechnica.com/gadgets/2009/12/review-of-the-motorola-droid/) 身上,它是第一部“第二代”安卓设备。相对于 G1 而言,Droid 进行了大幅的硬件升级,拥有巨大的 3.7 英寸(在当时而言),分辨率 854×480 的 LCD 屏幕。它同样带来了更强劲的性能:一个 600Mhz 的德州仪器 TI OMAP Cortex A8 处理器(还是单核),以及 256MB 的内存。

*摩托罗拉 Droid 凝视着你的灵魂。*
但 Droid 最重要的部分是围绕它的大型广告活动。Droid 是美国运营商威瑞森 Verizon 的旗舰设备,这个头衔给它从美国最大运营商那里带来了不少收入。威瑞森从卢卡斯影业那获得了单词“droid”的授权,并且开始了[“Droid Does”运动](http://www.youtube.com/watch?v=e52TSXwj774)——通过广告将设备定位成一个敢于发声、充满突破的(由此也延伸到安卓身上)强力 iPhone 替代品。媒体常常说 T-Mobile G1 想要成为一个“iPhone 杀手”,但是 Droid 走了出来,并拥有了这个称号。
就和 G1 一样,Droid 有个侧滑实体键盘。轨迹球已经不见了,但是还是强制性要求有类似十字方向键的东西,所以摩托罗拉把一个五键十字方向键放在了键盘右侧。Droid 正面按键从实体按键变成了电容式触摸按键,它们只是被印在了玻璃触摸屏上。安卓 2.0 同样最终取消了必须有“呼叫”和“结束”按钮的强制要求。所以连同十字方向键移到键盘那里的变动,正面的按键可以排成漂亮又整洁的一行。所有这些精简结果带来的是有史以来最好看的安卓设备。T-Mobile G1 看起来像是费雪牌的玩具,但摩托罗拉 Droid 看起来像个可以用来削人的工业工具。

*安卓 2.0 和 1.6 的锁屏和主屏幕。 [Ron Amadeo 供图]*
威瑞森的一些差劲的广告活动泄漏了这个软件,原本平静、水汪汪的远景默认壁纸变成了脏兮兮的混凝土。开机动画用了红色脉动的哈儿(HAL 9000)的眼球(LCTT 译注:哈儿是英国小说家亚瑟·克拉克所著《太空漫游》小说中出现的一部拥有强人工智能的超级电脑),每当你收到邮件的时候,默认通知铃声还会高喊“[DRRRRROOOOIIIIDDDD](http://www.youtube.com/watch?v=UBL47tHrvMA)”。Éclair 泡芙就像是安卓的忧郁少年阶段。
安卓 2.0 中最先呈现给用户的事情之一就是新的锁屏。滑动解锁是苹果的专利,因此谷歌就采用了来自旋转手机的灵感,使用了弧线解锁手势。把你的手指放在锁定图标上并且向右滑动可以解锁设备,从音量图标向左滑动可以让手机静音。手指的自然移动是圆弧状的,所以这手势感觉比按直线滑动更加自然。
默认主屏幕布局取消了多余的模拟时钟小部件,引入了现如今安卓的一个主要部分:主屏幕顶端的一个搜索栏。短信和安卓市场同样花了大功夫在新布局上。应用抽屉页同样被经过了明显的重新设计。

*应用抽屉和“添加到主屏幕”菜单截图。 [Ron Amadeo 供图]*
安卓在早期的阶段以极快的步伐开发前进,而安卓团队在考虑界面设计时也从来没有对未来的设备有过真正的规划。摩托罗拉 Droid——拥有 854×480 分辨率的 LCD 显示屏——相对于 320×480 分辨率的 G1 时代设备在分辨率上是个巨大的提升。几乎所有的东西都需要重绘。界面设计的“从头开始”就几乎成为了安卓 2.0 的主要课题。
谷歌借此机会几乎重新设计了安卓的所有图标,从带有等距轴线的卡通风格图标转变为风格更为正式直观的图标。唯一一套没有重绘的图标是状态栏图标,和经过修改的系统其它部分相比显得格格不入。这些图标会从安卓 0.9 一直使用到安卓 2.3。
应用阵容上同样也有一些改变。摄像机被合并到相机中,IM 应用被去除,并增加了两个新的谷歌应用:Car Home,这是一个被设计为在驾驶时使用的带有大按钮的启动器,还有企业日历,除了它支持 Exchange 而不是谷歌日历以外,它和常规的日历没什么不一样。奇怪的是,谷歌还预装了两个第三方应用程序:Facebook 和 Verizon 的 Visual VM 应用 (现在都不能用了)。第二组图片显示的是“添加到主屏幕”菜单,它同样经过了全新的设计。

*一个地点页面,显示“导航”选项,导航免责声明,实际的导航画面,以及交通信息。 [Ron Amadeo 供图]*
除了新的设计以外,安卓 2.0 最突出的亮点是谷歌地图导航。谷歌更新了地图,以支持免费的逐向导航,配有兴趣点搜索和文本到语音引擎,这使得它可以像一个独立的 GPS 设备一样大声读出街道名称。把 GPS 导航从一个单独的产品变成免费的智能手机功能,这几乎一夜之间[摧毁](http://techcrunch.com/2009/10/28/googles-new-mobile-app-cuts-gps-nav-companies-at-the-knees/)了独立 GPS 市场。TomTom 的股票在安卓 2.0 推出的一周内下跌了近 40%。
但一开始这个导航应用非常难以找到。你必须打开搜索框,键入一个地点或地址,并点击搜索结果。接下来,点击了“导航”按钮后,谷歌会显示一个警告,声明导航正处于 beta 测试阶段,不应该被信任。点击“接受”后,你可以跳上车,一个粗糙的合成语音会引导你到达目的地。菜单按钮背后隐藏着一个选项,可以查看整个路线上的交通状况和突发事件。导航的设计一直徘徊不前。甚至连谷歌地图主界面都在安卓 4.0 时更新了,安卓 2.0 风格的导航部分还是那么放着,这几乎持续到了安卓 4.3 才有所改观。
地图还会显示路线的概览,其中包含你的路线的交通数据。起初数据只是由常规的交通数据提供商授权,但后来,谷歌通过运行谷歌地图的安卓和 iOS 手机[收集原始交通数据](http://googleblog.blogspot.com/2009/08/bright-side-of-sitting-in-traffic.html)。这是在移动设备地图竞争中谷歌迈向霸主地位的第一步。毕竟,实时交通流量的监控确实仅仅取决于你有多少数据点来源。现在,伴随着数以亿计的 iOS 和安卓的谷歌地图的用户,谷歌已经成为世界上最好的交通数据提供商。
有了地图导航,安卓终于找到了自己的杀手级应用。谷歌公司那时提供了其他人提供不了的东西。“为什么我应该买这个而不是买个 iPhone?”问题终于有了个答案。谷歌地图也不需要像许多 GPS 设备一样通过 PC 更新。有了云,地图能够始终保持最新状态,所有这些更新都是免费的。唯一的缺点是,你需要一个互联网连接来使用谷歌地图。
精确的地图在[苹果地图的惨败](http://arstechnica.com/apple/2012/09/apple-ceo-tim-cook-apologizes-for-ios-6-maps-promises-improvements/)中被大大宣传,它已经成为了智能手机的最重要的功能之一,即使没有人真正在它们工作的时候赞赏它们。绘制世界真的只是借助了无数人的力量,今天,谷歌的“地球”部门是公司最大的部门,拥有超过[7000 名员工](http://www.businessinsider.com/apple-has-7000-fewer-people-working-on-maps-than-google-2012-9)。对于这里的大多数人来说,他们的工作就是驾驶着公司装满了相机的街景车驶过世界上的每一条道路。经过八年的数据收集,谷歌拥有超过[五百万英里](https://developers.google.com/events/io/sessions/383278298)的 360 度街景视图,谷歌地图成为了公司不可撼动的支柱之一。

*Car Home 主屏幕,并且因为有空间,加入了一个横版的导航。 [Ron Amadeo 供图]*
随着和谷歌地图导航一起到来的还有“Car Home”,一个大按钮设计的主屏幕,旨在帮助你在驾驶时使用手机。不能定制,每一个按钮只是一个独立应用的快捷方式。摩托罗拉 Droid 和其官方的[车载 dock 配件](http://www.amazon.com/Motorola-Generation-Vehicle-Charger-Packaging/dp/B002Y3BYQA)之间有特殊的磁铁,二者接触将自动触发 Car Home。在手机接入 dock 时,按压 Droid 的实体 home 键会打开 Car Home 主屏而不是正常的主屏幕,屏幕上的触摸 Home 键可以打开正常的主屏幕。
Car Home,虽然很有用,但并没有存在多久——它在安卓 3.0 中被去掉了,再也没有回来过。GPS 系统几乎全部用在汽车驾驶时,但它鼓励用户使用如“搜索”这样的功能,它会弹出一个键盘,谷歌的律师可能并不是很喜欢这种功能。随着[苹果的 CarPlay](http://arstechnica.com/apple/2014/03/ios-in-the-car-becomes-carplay-coming-to-select-dashboards-this-year/)和谷歌的[开放汽车联盟](http://arstechnica.com/information-technology/2014/01/open-automotive-alliance-aims-to-bring-android-inside-the-car/)的到来,车载电脑看到了复苏的希望。这一次,重点更多的是在安全上,政府机构(如美国国家公路交通安全管理局)也在协助着这一方面的发展。
---

[Ron Amadeo](http://arstechnica.com/author/ronamadeo) / Ron 是 Ars Technica 的评论编缉,专注于安卓系统和谷歌产品。他总是在追寻新鲜事物,还喜欢拆解事物看看它们到底是怎么运作的。 [@RonAmadeo](https://twitter.com/RonAmadeo)
---
via: <http://arstechnica.com/gadgets/2016/10/building-android-a-40000-word-history-of-googles-mobile-os/10/>
译者:[alim0x](https://github.com/alim0x) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,002 | 玩转 GitHub 的问题单(issue) | https://opensource.com/life/16/7/how-take-your-projects-github-issues-good-great | 2016-11-30T08:47:13 | [
"issue",
"github",
"问题跟踪"
] | https://linux.cn/article-8002-1.html | 
对于大多数开源项目来讲,<ruby> 问题追踪系统 <rp> ( </rp> <rt> Issue-tracking system </rt> <rp> ) </rp></ruby>是至关重要的。虽然有非常多的开源工具提供了这样的功能,但是大量项目还是选择了 GitHub 自带的<ruby> 问题追踪器 <rp> ( </rp> <rt> Issue Tracker </rt> <rp> ) </rp></ruby>。
它结构简单,可以让其他人可以非常轻松地参与进来,但这才仅仅是开始。
如果没有适当的处理,你的<ruby> 储存库 <rp> ( </rp> <rt> repository </rt> <rp> ) </rp></ruby>会变得很庞大,挤满重复的问题单、模糊不明的特性需求单、含混的 bug 报告单。项目维护者会被大量工作压得喘不过气来,新的贡献者也搞不清楚项目当前的工作重点是什么。
接下来,我们一起研究下,如何玩转 GitHub 的问题单。
### 问题单就是用户的故事
我的团队曾经和开源专家 [Jono Bacon](http://www.jonobacon.org/) 做过一次对话,他是<ruby> <a href="http://www.artofcommunityonline.org/"> 《社区艺术》 </a> <rp> ( </rp> <rt> The Art of Community </rt> <rp> ) </rp></ruby>一书的作者、一位战略顾问、前 GitHub 社区总监。他告诉我们,高质量的问题单是项目成功的关键。有些人把问题单仅仅看作是一堆你不得不去处理的问题列表,但是如果这些问题单管理完善,进行了分类并打上标签,会令人意想不到的提升我们对代码和社区的了解程度,也让我们更清楚问题的关键点在哪里。
“在提交问题单时,用户不太会有耐心或者有兴趣把问题的细节描述清楚。在这种情况下,你应当努力花最短的时间,尽量多的获取有用的信息。”,Jono Bacon 说。
统一的问题单模板可以大大减轻项目维护者的负担,尤其是开源项目的维护者。我们发现,让用户讲故事的方法总是可以把问题描述的非常清楚。用户讲故事时需要说明“是谁,做了什么,为什么而做”,也就是:我是【何种用户】,为了【达到何种目的】,我要【做何种操作】。
实际操作起来,大概是这样的:
>
> 我是一名**顾客**,我想**购买东西**,所以我想**创建个账户**。
>
>
>
我们建议,问题单的标题始终使用这样的用户故事形式。你可以设置[问题单模板](https://help.github.com/articles/creating-an-issue-template-for-your-repository/)来保证一致性。

*问题单模板让特性需求单保持统一的形式*
这个做法的核心点在于,问题单要清晰的呈现给它涉及的每一个人:它要尽量简单的指明受众(或者说用户),操作(或者说任务),和输出(或者说目标)。不过,不需要过分拘泥于这个模板,只要能把故事里的是什么事情或者是什么原因说清楚,就达到目的了。
### 高质量的问题单
问题单的质量是参差不齐的,这一点任何一个开源软件的贡献者或维护者都能证实。在[《The Agile Samurai》](https://www.amazon.ca/Agile-Samurai-Masters-Deliver-Software/dp/1934356581)中概述过一个良好的问题单所应具备的素质。
好的问题单尽量满足如下条件:
* 客户价值所在
* 避免使用术语或晦涩的文字,就算不是专家也能看懂
* 可以切分,也就是说我们可以逐步解决问题
* 尽量跟其他问题单没有瓜葛,依赖其它问题会降低处理的灵活性
* 可以协商,也就说我们有好几种办法达到目标
* 问题足够小,可以非常容易的评估出所需时间和资源
* 可衡量,我们可以对结果进行测试
### 不满足上述条件的问题单呢? 要有约束
如果一个问题单很难衡量,或者很难在短时间内完成,你也一样有办法搞定它。有些人把这种办法叫做“约束”(constraints)。
例如,“这个产品要快”,这种问题单不符合故事模板,而且是没办法协商的。多快才是快呢?这种模糊的需求没有达到“好问题单”的标准,但是如果你进一步定义一下,例如“每个页面都需要在 0.5 秒内加载完”,那我们就能更轻松地解决它了。我们可以把“约束”看作是成功的标尺,或者要实现的里程碑。每个团队都应该定期的对“约束”进行测试。
### 问题单里面有什么?
敏捷方法中,用户故事里通常要包含验收指标或者标准。在 GitHub 里,建议大家使用 markdown 格式的清单来概括解决这个问题单需要完成的任务。优先级越高的问题单应当包含更多的细节。
比如说,你打算提交一个关于新版网站主页的问题单。那这个问题单的子任务列表可能就是这样的:

*使用 markdown 的清单把复杂问题拆分成多个部分*
在必要的情况下,你还可以链接到其他问题单,以进一步明确任务。(GitHub 里做这个挺方便的)
将特性定义的越细化,越容易跟踪进度、测试,最终能更高效的发布有价值的代码。
以问题单的形式收到到问题所在后,还可以用 API 更深入的了解软件的健康度。
“在统计问题单的类型和趋势时,GitHub API 可以发挥巨大作用”,Bacon 告诉我们,“如果再做些数据挖掘工作,你就能发现代码里的问题点、社区里的活跃成员,或者其他有用的信息。”
有些问题单管理工具提供的 API 可以提高额外信息,比如预估时间或者历史进度。
### 团队协同一致
团队决定使用某种问题单模板后,如何让所有人都照做?存储库里的 ReadMe.md 其实也可以是你们项目的 “How-to” 文档。这个文档应描述清楚这个项目是做什么的(最好是用可以搜索的语言),以及其他贡献者应当如何参与进来(比如提交需求单、bug 报告、建议,或者直接贡献代码)。

*在 ReadMe 文件里增加清晰的说明,供新协作者参考*
ReadMe 文件是提供“问题单指引”的完美场所。如果希望特性需求单遵循“用户讲故事”的格式,那就把格式写在 ReadMe 里。如果使用某种跟踪工具来管理待办事项,那就标记在 ReadMe 里,这样别人也能看到。
“问题单模板、合理的标签、提交问题单的指导文档、确保问题单被分类并及时回应,这些对于开源项目都至关重要”,Bacon 说。
记住一点:这不是为了完成工作而做的工作。这是让其他人更轻松的发现、了解、融入你的社区而设立的规则。
"关注社区的成长,不仅要关注参与开发者的的数量增长,也要关注那些在问题单上帮助我们的人,他们让问题单更加明确、保持更新,这是活跃沟通和高效解决问题的力量源泉",Bacon 说。
---
via: <https://opensource.com/life/16/7/how-take-your-projects-github-issues-good-great>
作者:[Matt Butler](https://opensource.com/users/mattzenhub) 译者:[echoma](https://github.com/echoma) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Issue-tracking systems are important for many open source projects, and there are many open source tools that provide this functionality but many projects opt to use GitHub's built-in issue tracker.
Its simple structure makes it easy for others to weigh in, but issues are really only as good as you make them.
Without a process, your repository can become unwieldy, overflowing with duplicate issues, vague feature requests, or confusing bug reports. Project maintainers can become burdened by the organizational load, and it can become difficult for new contributors to understand where priorities lie.
In this article, I'll discuss how to take your GitHub issues from good to great.
## The issue as user story
My team spoke with open source expert [Jono Bacon](http://www.jonobacon.org/)—author of * The Art of Community,* a strategy consultant, and former Director of Community at GitHub—who said that high-quality issues are at the core of helping a projects succeed. He says that while some see issues as merely a big list of problems you have to tend to, well-managed, triaged, and labeled issues can provide incredible insight into your code, your community, and where the problem spots are.
"At the point of submission of an issue, the user likely has little patience or interest in providing expansive detail. As such, you should make it as easy as possible to get the most useful information from them in the shortest time possible," Jono Bacon said.
A consistent structure can take a lot of burden off project maintainers, particularly for open source projects. We've found that encouraging a user story approach helps make clarity a constant. The common structure for a user story addresses the "who, what, and why" of a feature: As a [user type], I want to [task] so that [goal].
Here's what that looks like in practice:
As a
customer, I want tocreate an accountso thatI can make purchases.
We suggest sticking that user story in the issue's title. You can also set up [issue templates](https://help.github.com/articles/creating-an-issue-template-for-your-repository/) to keep things consistent.

Issue templates bring consistency to feature requests.
The point is to make the issue well-defined for everyone involved: it identifies **the audience** (or user), **the action** (or task), and **the outcome** (or goal) as simply as possible. There's no need to obsess over this structure, though; as long as the *what* and *why* of a story are easy to spot, you're good.
## Qualities of a good issue
Not all issues are created equal—as any OSS contributor or maintainer can attest. A well-formed issue meets these qualities outlined in * The Agile Samurai*.
Ask yourself if it is...
- something of value to customers
- avoids jargon or mumbo jumbo; a non-expert should be able to understand it
- "slices the cake," which means it goes end-to-end to deliver something of value
- independent from other issues if possible; dependent issues reduce flexibility of scope
- negotiable, meaning there are usually several ways to get to the stated goal
- small and easily estimable in terms of time and resources required
- measurable; you can test for results
## What about everything else? Working with constraints
If an issue is difficult to measure or doesn't seem feasible to complete within a short time period, you can still work with it. Some people call these "constraints."
For example, "the product needs to be fast" doesn't fit the story template, but it is non-negotiable. But how fast is fast? Vague requirements don't meet the criteria of a "good issue", but if you further define these concepts—for example, "the product needs to be fast" can be "each page needs to load within 0.5 seconds"—you can work with it more easily. Constraints can be seen as internal metrics of success, or a landmark to shoot for. Your team should test for them periodically.
## What's inside your issue?
In agile, user stories typically include acceptance criteria or requirements. In GitHub, I suggest using markdown checklists to outline any tasks that make up an issue. Issues should get more detail as they move up in priority.
Say you're creating an issue around a new homepage for a website. The sub-tasks for that task might look something like this.

Use markdown checklists to split a complicated issue into several parts.
If necessary, link to other issues to further define a task. (GitHub makes this really easy.)
Defining features as granularly as possible makes it easier to track progress, test for success, and ultimately ship valuable code more frequently.
Once you've gathered some data points in the form of issues, you can use APIs to glean deeper insight into the health of your project.
"The GitHub API can be hugely helpful here in identifying patterns and trends in your issues," Bacon said. "With some creative data science, you can identify problem spots in your code, active members of your community, and other useful insights."
Some issue management tools provide APIs that add additional context, like time estimates or historical progress.
## Getting others on board
Once your team decides on an issue structure, how do you get others to buy in? Think of your repo's ReadMe.md file as your project's "how-to." It should clearly define what your project does (ideally using searchable language) and explain how others can contribute (by submitting requests, bug reports, suggestions, or by contributing code itself.)

Edit your ReadMe file with clear instructions for new collaborators.
This is the perfect spot to share your GitHub issue guidelines. If you want feature requests to follow the user story format, share that here. If you use a tracking tool to organize your product backlog, share the badge so others can gain visibility.
"Issue templates, sensible labels, documentation for how to file issues, and ensuring your issues get triaged and responded to quickly are all important" for your open source project, Bacon said.
Remember: It's not about adding process for the process' sake. It's about setting up a structure that makes it easy for others to discover, understand, and feel confident contributing to your community.
"Focus your community growth efforts not just on growing the number of programmers, but also [on] people interested in helping issues be accurate, up to date, and a source of active conversation and productive problem solving," Bacon said.
## Comments are closed. |
8,003 | Apache、Nginx 与 Node.js 之争 —— WordPress 与 Ghost 的性能大对决 | https://iwf1.com/apache-vs-nginx-vs-node-js-and-what-it-means-about-the-performance-of-wordpress-vs-ghost/ | 2016-11-30T11:36:00 | [
"Web服务器",
"性能"
] | https://linux.cn/article-8003-1.html | 
>
> 巨头之间的终极对决:崛起的新星 Node.js 能否战胜巨人 Apache 和 Nginx?
>
>
>
我和你一样,都阅读过大量散布在互联网各处的意见或事实,其中有一些我认为是可靠的,而其它的可能是谣传,让人难以置信。
我读过的许多信息是相当矛盾的,有人深信 StackOverflow(比如[这个](http://stackoverflow.com/questions/9967887/node-js-itself-or-nginx-frontend-for-serving-static-files)和[另一个](http://stackoverflow.com/questions/16770673/using-node-js-only-vs-using-node-js-with-apache-nginx)),而其他人展示了一个清晰的令人惊讶的[结果](http://centminmod.com/siegebenchmarks/2013/020313/index.html),这在推动我自己去做测试来验证结论的过程中扮演了重要的角色。
起初,我做了一些思想准备,我认为我可以避免自己进行实际测试来校验结论的麻烦——在我知道这一切之前我一直这样认为。
尽管如此,回顾之前,似乎我最初的想法是相当准确的,并且被我的测试再次印证。这个事实让我想起了当年我在学校学到的爱因斯坦和他的光电效应的实验,他面临着一个光的波粒二重性的问题,最初的结论是实验受到他的心理状态的影响,即当他期望结果是一个波的时候结果就会是一个波,反之亦然。
也就是说,我坚信我的结果不会在不久的将来被证明二重性,虽然我的心理状态可能在某种程度上对它们有影响。
### 关于比较
上面我读过一份材料具有一种革新的方式,在我看来,需要了解其自然而然的主观性和作者自身的偏见。
我决定采用这种方式,因此,提前声明以下内容:
开发者花了很多年来打磨他们的作品。那些取得了更高成就的人通常参考很多因素来做出自己的抉择,这是主观的做法;你需要推崇和捍卫你的技术决策。
也就是说,这个比较文章的着眼点不会成为另一篇“哥们,使用适合你的东西就好”的口水文章。我将会根据我的自身经验、需求和偏见提出建议。你可能会同意其中一些观点,反对另外一些;这很好——你的意见会帮助别人做出明智的选择。
感谢 [SitePoint](https://www.sitepoint.com/sitepoint-smackdown-php-vs-node-js/) 的 Craig Buckler ,重新启发了我对比较类文章的看法——尝试重新忘记自我,并试图让所有的读者心悦诚服。
### 关于测试
所有的测试都在本地运行:
* 英特尔酷睿 i7-2600k,四核八线程的机器
* [Gentoo Linux](http://iwf1.com/5-reasons-use-gentoo-linux/) 是用于测试的操作系统
用于基准测试的工具:ApacheBench,2.3 <$Revision: 1748469 $>
测试包括一系列基准,从 1000 到 10000 个请求以及从 100 到 1000 个的并发请求——结果相当令人惊讶。
此外,我还进行了在高负载下测量服务器功能的压力测试。
至于内容,主要是一个包含一些 Lorem Ipsum 的标题和一张图片静态文件。

*Lorem Ipsum 和 ApacheBenchmark*
我决定专注于静态文件的原因是因为它们去除了可能对测试产生影响的各种渲染因素,例如:编程语言解释器的速度、解释器与服务器的集成程度等等。
此外,基于我自身的经验,平均网页加载时间很大一部分通常花费在静态内容上,例如图片,因此关注哪个服务器可以节省我们加载静态内容的时间是比较现实的。
除此之外,我还想测试一个更加真实的案例,案例中我在运行不同 CMS 的动态页面(稍后将详细介绍)时对服务器进行基准测试。
#### 服务器
正如我用的是 Gentoo Linux,你就知道我的 HTTP 服务器在一开始就已经经过优化了,因为我在构建系统的时候只使用了我实际需要的东西。也就是说,当我运行我的测试的时候,不会在后台运行任何不必要的代码或加载没用的模块。

*Apache、Nginx 和 Node.js 的使用的配置对比*
#### Apache
```
$: curl -i http://localhost/index.html
HTTP/1.1 200 OK
Date: Sun, 30 Oct 2016 15:35:44 GMT
Server: Apache
Last-Modified: Sun, 30 Oct 2016 14:13:36 GMT
ETag: "2cf2-54015b280046d"
Accept-Ranges: bytes
Content-Length: 11506
Cache-Control: max-age=600
Expires: Sun, 30 Oct 2016 15:45:44 GMT
Vary: Accept-Encoding
Content-Type: text/html
```
Apache 配置了 “event mpm”。
#### Nginx
```
$: curl -i http://localhost/index.html
HTTP/1.1 200 OK
Server: nginx/1.10.1
Date: Sun, 30 Oct 2016 14:17:30 GMT
Content-Type: text/html
Content-Length: 11506
Last-Modified: Sun, 30 Oct 2016 14:13:36 GMT
Connection: keep-alive
Keep-Alive: timeout=20
ETag: "58160010-2cf2"
Accept-Ranges: bytes
```
Nginx 包括几个调整:`sendfile on`、`tcp_nopush on` 和 `tcp_nodelay on`。
#### Node.js
```
$: curl -i http://127.0.0.1:8080
HTTP/1.1 200 OK
Content-Length: 11506
Etag: 15
Last-Modified: Thu, 27 Oct 2016 14:09:58 GMT
Content-Type: text/html
Date: Sun, 30 Oct 2016 16:39:47 GMT
Connection: keep-alive
```
在静态测试中使用的 Node.js 服务器是从头定制的,这样可以让它尽可能更加的轻快——没有使用外部模块(Node 核心模块除外)。
### 测试结果
点击图片以放大:

*Apache、Nginx 与 Node 的对比:请求负载的性能(每 100 位并发用户)*

*Apache、Nginx 与 Node 的对比:用户负载能力(每 1000 个请求)*
### 压力测试

*Apache、Nginx 与 Node 的对比:完成 1000 位用户并发的 100000 个请求耗时*
### 我们可以从结果中得到什么?
从以上结果判断,似乎 Nginx 可以在最少的时间内完成最多请求,换句话来说,**Nginx** 是最快的 HTTP 服务器。
还有一个相当惊人的事实是,在特定的用户并发数和请求数下,Node.js 可以比 Nginx 和 Apache 更快。
但当请求的数量在并发测试中增加的时候,Nginx 将重回领先的位置,这个结果可以让那些陷入 Node.js 的遐想的人清醒一下。
和 Apache、Nginx 不同的是,Node.js 似乎对用户的并发数不太敏感,尤其是在集群节点。如图所示,集群节点在 0.1 秒左右保持一条直线,而 Apache 和 Nginx 都有大约 0.2 秒的波动。
基于上述统计可以得出的结论是:网站比较小,其使用的服务器就无所谓。然而,随着网站的受众越来越多,HTTP 服务器的影响变得愈加明显。
当涉及到每台服务器的原始速度的底线的时候,正如压力测试所描述的,我的感觉是,性能背后最关键的因素不是一些特定的算法,而实际上是运行的每台服务器所用的编程语言。
由于 Apache 和 Nginx 都使用了 C 语言—— AOT 语言(编译型语言),而 Node.js 使用了 JavaScript ——这是一种 JIT 语言(解释型语言)。这意味着 Node.js 在执行程序的过程中还有额外的工作负担。
这意味着我不能仅仅基于上面的结果来下结论,而要做进一步校验,正如你下面看到的结果,当我使用一台经过优化的 Node.js 服务器与流行的 Express 框架时,我得到几乎相同的性能结论。
### 全面考虑
逝者如斯夫,如果没有服务的内容,HTTP 服务器是没什么用的。因此,在比较 web 服务器的时候,我们必须考虑的一个重要的部分就是我们希望在上面运行的内容。
虽然也有其它的功能,但是 HTTP 服务器最广泛的使用就是运行网站。因此,为了看到每台服务器的性能的实际效果,我决定比较一下世界上使用最广泛的 CMS(内容管理系统)WordPress 和 Ghost —— 内核使用了 JavaScript 的一颗冉冉升起的明星。
基于 JavaScript 的 Ghost 网页能否胜过运行在 PHP 和 Apache / Nginx 上面的 WordPress 页面?
这是一个有趣的问题,因为 Ghost 具有操作工具单一且一致的优点——无需额外的封装,而 WordPress 需要依赖 Apache / Nginx 和 PHP 之间的集成,这可能会导致显著的性能缺陷。
除此之外,PHP 距 Node.js 之间还有一个显著的性能落差,后者更佳,我将在下面简要介绍一下,可能会出现一些与初衷大相径庭的结果。
#### PHP 与 Node.js 的对决
为了比较 WordPress 和 Ghost,我们必须首先考虑一个影响到两者的基本组件。
基本上,WordPress 是一个基于 PHP 的 CMS,而 Ghost 是基于 Node.js(JavaScript)的。与 PHP 不同,Node.js 有以下优点:
* 非阻塞的 I/O
* 事件驱动
* 更新颖、更少的残旧代码
由于有大量的测评文章解释和演示了 Node.js 的原始速度超过 PHP(包括 PHP 7),我不会再进一步阐述这个主题,请你自行用谷歌搜索相关内容。
因此,考虑到 Node.js 的性能优于 PHP,一个 Node.js 的网站的速度要比 Apache / Nginx 和 PHP 的网站快吗?
#### WordPress 和 Ghost 对决
当比较 WordPress 和 Ghost 时,有些人会说这就像比较苹果和橘子,大多数情况下我同意这个观点,因为 WordPress 是一个完全成熟的 CMS,而 Ghost 基本上只是一个博客平台。
然而,两者仍然有共同竞争的市场,这两者都可以用于向世界发布你的个人文章。
制定一个前提,我们怎么比较两个完全基于不同的代码来运行的平台,包括风格主题和核心功能。
事实上,一个科学的实验测试条件是很难设计的。然而,在这个测试中我对更接近生活的情景更感兴趣,所以 WordPress 和 Ghost 都将保留其主题。因此,这里的目标是使两个平台的网页大小尽可能相似,让 PHP 和 Node.js 在幕后斗智斗勇。
由于结果是根据不同的标准进行测量的,最重要的是尺度不一样,因此在图表中并排显示它们是不公平的。因此,我改为使用表:

*Node、Nginx、Apache 以及运行 WordPress 和 Ghost 的比较。前两行是 WordPress,底部的两行是 Ghost*
正如你所见,尽管事实上 Ghost(Node.js)正在加载一个更小的页面(你可能会惊讶 1kb 可以产生这么大的差异),它仍然比同时使用 Nginx 和 Apache 的 WordPress 要慢。
此外,使用 Nginx 代理作为负载均衡器来接管每个 Node 服务器的请求实际上会提升还是降低性能?
那么,根据上面的表格,如果说它产生什么效果的话,它造成了更慢的效果——这是一个合理的结果,因为额外封装一层理所当然会使其变得更慢。当然,上面的数字也表明这点差异可以忽略不计。
但是上表中最重要的一点是,即使 Node.js 比 PHP 快,HTTP 服务器的作用也可能超过某个 web 平台使用的编程语言的重要性。
当然,另一方面,如果加载的页面更多地依赖于服务器端的脚本处理,那么我怀疑结果可能会有点不同。
最后,如果一个 web 平台真的想在这场竞赛里击败 WordPress,从这个比较中得出的结论就是,要想性能占优,必须要定制一些像 PHP-FPM 的工具,它将直接与 JavaScript 通信(而不是作为服务器来运行),因此它可以完全发挥 JavaScript 的力量来达到更好的性能。
---
via: <https://iwf1.com/apache-vs-nginx-vs-node-js-and-what-it-means-about-the-performance-of-wordpress-vs-ghost/>
作者:[Liron](https://iwf1.com/tag/linux) 译者:[OneNewLife](https://github.com/OneNewLife) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
(题图来自:[deviantart.net](http://img11.deviantart.net/4258/i/2015/230/3/0/superman_vs_thanos_by_vinroc-d967zo6.jpg))
| 301 | Moved Permanently | null |
8,004 | Linux 下五个最佳的 FPS 游戏 | http://www.linuxandubuntu.com/home/5-best-fps-games-for-linux | 2016-12-01T08:14:00 | [
"游戏",
"FPS"
] | https://linux.cn/article-8004-1.html | 
开源用户久经游戏界的冷落与疏忽,他们给别的操作系统大量生产游戏,却没有几个在 Linux 上可以玩的。要在 Linux 上玩到画质好的 Linux 游戏大作,解决方案就是 [wine](https://www.winehq.org/),但 wine 在开箱即用方面做的并不好。大多数画质一般的小游戏的制作者通常并不考虑为 Linux 开发或移植游戏,因为 Linux 的用户群体太小了。
如今,Linux 的用户规模和范畴日益增多,而且你也看到了非开源的组织也[表达了他们对开源的支持](http://www.theverge.com/2016/9/15/12926288/microsoft-really-does-love-linux)。
我们应该对 Linux 游戏抱有期望吗?现在有能在 Linux 系统上运行的大作吗?可以在网上与其他操作系统的用户玩吗?这些问题的答案是响亮的 YES.
让我给你介绍一下 Linux 系统上的 5 个最好的 FPS 游戏(第一人称射击游戏)。想玩这些游戏并不太麻烦,你可以安装任何一种 Linux 系统。我们选择了五个最好的,你可以看看:
### **1、<ruby> <a href="http://store.steampowered.com/app/730/"> CS - 反恐精英:全球攻势 </a> <rp> ( </rp> <rt> Counter-Strike: Global Offensive </rt> <rp> ) </rp></ruby>**
这个多人的第一人称射击游戏是 Hidden Patch 与 Valve 公司开发的游戏,它发布于 2012 年 8 月 21 日,但到 2014 年 9 月份才为 Linux 用户推出 Linux 移植版。
这款游戏本来是为游戏<ruby> 半条命 <rp> ( </rp> <rt> Half-Life </rt> <rp> ) </rp></ruby>所开发的游戏 MOD。

这款跨平台游戏只支持 Windows、MacOS 和 Linux 用户,电视游戏机用户因为主机游戏更新速度太慢而不支持。这款 Linux 游戏包含四种游戏模式。
#### CS 游戏模式
**经典:竞技模式**
这是让 CS (反恐精英)出名的最有名的游戏模式,五对五,一场三十局。可以加入你同伴的队伍,也可以排队加入随机队伍的空位。

**经典:休闲模式**
如果玩家不想玩之前的 30 局 16 胜模式,可以选择休闲模式,找个对手按自己的节奏打。系统会自动给玩家穿上防弹衣,也提供防御炸弹用的工具包。成功射杀敌人还有额外奖励。
**爆破模式**
爆破模式是一个快节奏的游戏模式,游戏中玩家轮流保卫一个炸弹点,防御带有起始武器装备的攻击者。这个模式里,如果你在当前局成功射杀敌人,就会在下一局获得更强的武器,最终你会获得一把强大的狙击步枪。
**军备竞赛模式**
这个模式是一种武器升级模式,玩家通过击杀敌人来得到一把升级过的武器。当你取得武器列表中最先进的武器时,你将得到一把金匕首并赢得胜利。
#### CS 的配置要求
* **系统:** Ubuntu 12.04
* **处理器:** 64-bit 英特尔双核,或 AMD 2.8 GHz 处理器
* **内存:** 4 GB
* **显卡:** nVidia GeForce 8600/9600GT、ATI/AMD Radeon HD2600/3600 (Graphic Drivers: nVidia 310、AMD 12.11)、 OpenGL 2.1
* **硬盘:** 至少 15 GB 的空间
* **声卡:** OpenAL 兼容声卡
### **2、<ruby> <a href="http://store.steampowered.com/app/49520/"> 无主之地 2 </a> <rp> ( </rp> <rt> Borderlands 2 </rt> <rp> ) </rp></ruby>**

无主之地是综合了第一人称射击游戏和角色扮演游戏的角色扮演射击游戏,是 Gearbox(一个独立游戏开发组)制作的。
这个游戏中,四名玩家组成寻宝猎人队伍,做各种主线与支线任务找到潘多拉星球上的”传说宝库“。玩家可以在游戏里到网上与其他玩家组队。这个游戏于 2012 年 9 月 18 日正式出售。游戏采用虚幻引擎 3 和 PhysX Technology 开发。
#### 无主之地 2 游戏情节
这款游戏的游戏情节主要是完成主线任务和搜刮战利品(武器、盾、服饰等等)。游戏里有四种角色,每个角色有不同的技能和操作风格。
* **突击兵(Axton)** – 可以召唤“军刀炮塔“提供攻击性辅助角色;
* **魔女(Maya)** – 可以用一个能量球将敌人暂时固定在一处;
* **刺客(Zer0)** – 可以在短时间内进入隐身状态,并制造全息假象来迷惑敌人;
* **狂枪手(Salvador)** – 可以暂时手持两把武器,比如拿一对火箭筒指向敌人;
| 
*Axton “突击兵”*

*Zero “刺客”*

*Maya “魔女”*

*Salvador “狂枪手”*
这款游戏受到评论家的好评。根据游戏的趣味性、游戏世界的构造,还有 RPG 系统,IGN 给这个游戏的评分是 9/10。
#### 无主之地 2 配置要求
* **系统:** SteamOS、Ubuntu 14.04
* **处理器:** 英特尔双核、AMD Phenom II X4
* **处理器速度:** 2.4GHz
* **内存:** 4 GB
* **硬盘:** 13 GB
* **显卡 (NVidia):** Geforce 260
* **显卡 (VRam):** 1GB
无主之地 2 Linux 版目前不支持英特尔集成显卡芯片组和 ATI 芯片组。
### **3、<ruby> <a href="http://store.steampowered.com/app/440/"> 军团要塞 </a> <rp> ( </rp> <rt> Team Fortress </rt> <rp> ) </rp></ruby>**

这款游戏是有史以来最受欢迎,且评分最高的游戏之一,而且它是免费的。这是 [Valve 公司](http://www.valvesoftware.com/) 制作与发售的一款第一人称在线多玩家射击游戏。这款游戏经常更新,mod、地图,还有装备也常更新。游戏的玩家也可以参与游戏更新的内容设计。游戏于 2013 年 2 月 14 日移植到 Linux 系统。
游戏中,玩家可以加入不同队伍,选择不同角色参与各种游戏模式(包括情报战模式和山丘之王模式)。
#### 军团要塞 2 游戏情节
游戏的故事背景中,两个队伍由两方招的雇佣兵组成,目的是保护其中一方的资产,并销毁另一方的公司资产。两个队伍名字分别代表两方的公司 - RED(保证开挖爆破,即红队)和 BLU(建筑联合同盟,即蓝队)。你可以从九名各有优势和劣势的角色挑选自己喜欢的来玩。
#### 军团要塞 2 游戏模式
**情报战模式**
这个模式的目的是获取一个装有情报的公文包并回到你的大本营,而要防止敌人将公文包成功带回他们的大本营。拿着公文包的玩家可以随时丢掉公文包,或者在被杀的时候掉落。如果在两分钟之内没有别人捡起公文包,公文包就会回到起点。
时间到的时候,分数最高的队伍获胜。

**推车模式**
在这个游戏模式中,地图上只有一个公文包,所以双方需要强盗公文包运送到指定地点。只有同一个队伍的人可以拿公文包,直到成功运到指定地点,或者掉落倒计时结束时公文包回到起始点。

**山丘之王**
这个游戏模式的目的是控制地图中心点,并坚持保卫一段时间。
游戏开始时,玩家无法进入守卫点,直到某方达到了进入守卫点的分数,封锁才会被解除。占领控制点的时候,游戏会开始守卫倒计时,这时对方玩家需要夺得控制权,开始他们的守卫倒计时。当某方队伍的倒计时表达到 00:00 的时候,游戏结束,占领控制点的队伍获胜。

#### 军团要塞 2 配置要求
* **系统:** Ubuntu 12.04
* **处理器:** 英特尔双核或 AMD 2.8 GHz
* **内存:** 1 GB RAM **显卡:** nVidia GeForce 8600/9600GT、ATI/AMD Radeon HD2600/3600 (Graphic Drivers: nVidia 310、 AMD 12.11)、OpenGL 2.1
* **网络:** 互联网连接
* **硬盘:** 15 GB 可用空间
* **声卡:** OpenAL 兼容声卡
* **其他:** 鼠标,键盘
### **4、<ruby> <a href="http://store.steampowered.com/app/286690/"> 地铁 2033 重制版 </a> <rp> ( </rp> <rt> Metro 2033 redux </rt> <rp> ) </rp></ruby>**
地铁 2033 重制版由 4A 游戏工作室开发、THQ 发售。玩家以 Artyom 的角色在核战后莫斯科的废墟中生存,他需要打败一群被称为“DARKENS”的邪恶突变体。

有时游戏里的人类也是敌人,所以为了防止被抓住,游戏种玩家应该多用隐形术并悄无声息地干掉敌人。
地铁 2033 受到诸多评论家的好评,其中 IGN 给的评分是 6.9/10。
#### 地铁 2033 游戏情节
游戏主要发生在莫斯科地铁中,有个别任务设在在地面上的核辐射废墟中。游戏是单人游戏,玩家需要看游戏场景片得悉重要情节。
游戏里玩家可以使用传统武器(左轮手枪、猎枪)。玩家需要搜查废墟或尸体获得子弹。
敌人分两类,一类是人,另一类是突变体。人攻击玩家的时候会躲避玩家攻击,而突变体会正面攻击,企图咬伤玩家。
玩家大部分时间都待在黑暗的隧道里,需要手电筒照亮路线。在地面上的时候,玩家需要防毒面具,而这个防毒面具有可能在战斗种受到损害,这样玩家就不得不再去寻找一个新的防毒面具。
#### 地铁 2033 配置要求
**最低配置**
* **系统:** 64-bit Ubuntu 12.04 或 14.04 或 Steam OS
* **处理器:** 英特尔 i5 2.7 GHz (或同等的 AMD)
* **内存:** 4 GB RAM
* **显卡:** NVIDIA Geforce 460 / AMD 5850 加 2GB VRAM
* **硬盘:** 10 GB 可用空间
* **其他:** 因为用 OpenGL 4, 游戏不支持英特尔集成显卡
**推荐配置**
* **系统:** 64-bit Ubuntu 12.04 or 14.04 or Steam OS
* **处理器:** Intel Core i7 2.5 Ghz (or equivalent AMD)
* **内存:** 8 GB RAM
* **显卡:** NVIDIA Geforce 680 / AMD 7870 with 2GB VRAM+
* **硬盘:** 10 GB 可用空间
* **其他:** 因为用OpenGL 4, 游戏不支持英特尔集成显卡
### **5、<ruby> <a href="http://store.steampowered.com/app/550/"> 求生之路 2 </a> <rp> ( </rp> <rt> Left 4 Dead 2 </rt> <rp> ) </rp></ruby>**
这是 Valve 公司制作与发售的多人协作 FPS,于 2013 年 7 月发行 Linux 版本。

游戏有四名幸存者供玩家选择,需要打败僵尸,即感染者。这些感染者会因为严重的精神病而极具攻击性。游戏软件里的 AI 会按照玩家的水平而提升游戏难度,使游戏更有挑战性。
#### 求生之路 2 游戏情节
这个游戏里共有五个章节,其中每个章节分三到五个级别。每个章节在菜单里和加载屏幕中以电影形式出现,电影主人公是四名幸存者。

玩家可以看到队伍同伴的生命状况,同时也要注意射击或挥舞武器时不要误伤到同伴。
#### 游戏模式
求生之路 2 总共有 5 种游戏模式:
**战役模式**
四名玩家组成队伍,共同完成故事章节。游戏中遇到的其他幸存者都是 CPU 控制的 NPC。
**单人模式**
和战役模式相近,但队友都是 CPU 控制的 NPC。
**对抗模式**
四名操控幸存者的玩家对抗四名操控特殊感染者的玩家。每一局双方玩家都会调换角色,按幸存者局里面队伍所获得的分数计算积分。
**生存模式**
玩家会被封在某个章节地图中的一个区,游戏开始时画面会出一个计时器。玩家会按照地图里的生存时间得分,坚持的时间越长,得分越高。
**清道夫模式**
玩家分成两组,4 对 4,一组幸存者,一组感染者。幸存者需要收集大量的油桶,并装满一个发电机里,而感染者则要防止幸存者成功完成任务。
#### 求生之路 2 配置要求
* **系统:** Ubuntu 12.04
* **处理器:** 英特尔双核或 AMD 2.8 GHz
* **内存:** 2 GB RAM
* **显卡:** nVidia GeForce 8600/9600GT、ATI/AMD Radeon HD2600/3600 (显卡: nVidia 310、 AMD 12.11)、 OpenGL 2.1
* **硬盘:** 13 GB 可用空间
* **声卡:** OpenAL 兼容声卡
### 总结
这些年来,Linux 已经日益受到游戏厂家们的重视,在游戏界不像以前那么受到冷落。如今的 Linux 已不像昔日,以前,别的操作系统的用户笼统的概括说“Linux 只能供程序员编程“,但如今的 Linux 已经不同了。
现在,你已经不需要双系统来打游戏,虽然现在的选择暂时不多,但天天都会增加。在这五个游戏中,你最喜欢那一部?在下方的评论里告诉我们吧。
---
via: <http://www.linuxandubuntu.com/home/5-best-fps-games-for-linux>
作者:[Mohd Sohail](http://www.linuxandubuntu.com/contact-us.html) 译者:[jayjay823](https://github.com/jayjay823) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,005 | Livepatch —— 免重启给 Ubuntu Linux 内核打关键性安全补丁 | http://www.tecmint.com/livepatch-install-critical-security-patches-to-ubuntu-kernel | 2016-12-01T10:33:00 | [
"Ubuntu",
"补丁",
"实时补丁",
"Livepatch"
] | https://linux.cn/article-8005-1.html | 
如果你是一个在企业环境中维护关键性系统的系统管理员,你肯定对以下两件事深有感触:
1) 很难找个停机时间去给系统安装安全补丁以修复内核或者系统漏洞 。如果你工作的公司或者企业没有适当的安全策略,运营管理可能最终会优先保证系统的运行而不是解决系统漏洞。 此外,内部的官僚作风也可能延迟批准停机时间。我当时就是这样的。
2) 有时候你确实负担不起停机造成的损失,并且还要做好用别的什么方法减小恶意攻击带来的的风险的准备。
好消息是 Canonical 公司最近针对 Ubuntu 16.04 (64位版本 / 4.4.x 内核) 发布了 Livepatch 服务,它可以让你不用重启就能给内核打关键性安全补丁。 对,你没看错:使用 Livepatch 你不用重启就能使 Ubuntu 16.04 服务器系统的安全补丁生效。
### 注册 Ubuntu Livepatch 账号
要运行 Canonical Livepatch 服务你先要在这里注册一个账号 <https://auth.livepatch.canonical.com/>,并且表明你是一个普通用户还是企业用户(付费)。 通过使用令牌,所有的 Ubuntu 用户都能将最多 3 台不同的电脑连接到 Livepatch 服务:

*Canonical Livepatch 服务*
下一步系统会提示你输入你的 Ubuntu One 凭据,或者你也可以注册一个新账号。如果你选择后者,则需要你确认你的邮件地址才能完成注册:

*Ubuntu One 确认邮件*
一旦你点了上面的链接确认了你的邮件地址,你就会回到这个界面:<https://auth.livepatch.canonical.com/> 并获取你的 Livepatch 令牌。
### 获取并使用 Livepatch 令牌
首先把分配给你账号的这个唯一的令牌复制下来:

*Canonical Livepatch 令牌*
然后打开终端,输入:
```
$ sudo snap install canonical-livepatch
```
上面的命令会安装 livepatch 程序,下面的命令会为你的系统启用它。
```
$ sudo canonical-livepatch enable [YOUR TOKEN HERE]
```
如果后一条的命令提示找不到 `canonical-livepatch` ,检查一下 `/snap/bin` 是否已经添加到你的路径, 或者把你的工作目录切换到 `/snap/bin` 下执行也行。
```
$ sudo ./canonical-livepatch enable [YOUR TOKEN HERE]
```

*在 Ubuntu 中安装 Livepatch*
之后,你可能需要检查应用于内核的补丁的描述和状态。幸运的是,这很简单。
```
$ sudo ./canonical-livepatch status --verbose
```
如下图所示:

*检查补丁安装情况*
在你的 Ubuntu 服务器上启用了 Livepatch,你就可以在保证系统安全的同时把计划内的外的停机时间降到最低。希望 Canonical 的这个举措会在管理上给你带来便利,甚至更近一步带来提升。
如果你对这篇文章有什么疑问,欢迎在下面留言,我们会尽快回复。
---
via: <http://www.tecmint.com/livepatch-install-critical-security-patches-to-ubuntu-kernel>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[Yinux](https://github.com/Yinux) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,006 | 开源可以用来做设计吗? | https://freedompenguin.com/articles/opinion/open-source-design-thing/ | 2016-12-02T16:09:00 | [
"开源",
"设计"
] | https://linux.cn/article-8006-1.html | 开源的[超凡和强大](https://medium.com/dawn-capital/why-leverage-the-power-of-open-source-to-build-a-successful-software-business-8aba6f665bc4#.ggmn2ojxp)毋庸置疑。从服务器到个人电脑桌面、移动设备,甚至到所谓的“物联网”,开源在各个领域遍布全球。然而有一个行业,传统的专有闭源软件解决方案依然占据主导地位,并且通常特别昂贵,这就是设计产业。在这篇文章中,我们会大致描述一些自由及开源的替代软件来抛砖引玉,看是否能代替你现在所用的设计工具集。也许你是一个刚起步的设计师,需要节省开支。也许你的经验十分丰富,只是单纯的想换一个更加“开放”的工作方式。读下去,让我们看看[自由及开源软件](https://en.wikipedia.org/wiki/Free_and_open-source_software)世界到底带来了什么!

### 绘图
在开源世界,有几个可行且十分强大的工具,代替 Adobe 支持的主流产品。
#### GIMP
GIMP, 或者说 <ruby> <a href="https://www.gimp.org/"> GNU 图像处理程序 </a> <rt> GNU Image Manipulation Program </rt></ruby> 是一个非常强大的免费开源软件,可替代 Adobe 公司的 PhotoShop 。它由一个相当强大的核心团队开发和维护,为设计创造提供强大的图片编辑工具,比如滤镜、笔刷、修饰。如果你想使用 UX/UI 库设计模型,GIMP 甚至可以处理 .PSD 文件。最后,GIMP 还可以用来做数字艺术、logo 等类似的东西。GIMP 可以免费下载并在 Linux、MacOS 和 Windows 上运行。
#### Inkscape
[Inkscape](https://inkscape.org/en/) 有一个宣传语,代表着它的核心价值观 —— “Draw Freely”,它是一个开源而自由的产品,可以替代 Adobe 公司的另一产品 —— 强大、专有而且昂贵的矢量程序 Illustrator 。Inkscape 提供了大量的设计和画图工具,易用的颜色拾取导航栏,滤镜和渐变工具,还有很多很多。如果设计师下决心使用开源软件解决方案,你可以在博客和论坛帖子上找到非常好的在线文档。和 GIMP 一样,Inkscape 也可以免费下载并可在 Linux、MacOS 和 Windows 上运行。
想从经验丰富的图形和网页设计师那里学习更多关于这些开源工具的使用知识?请在 YouTube 网站上找一下这些人:
* [Nick Saporito](https://www.youtube.com/channel/UCEQXp_fcqwPcqrzNtWJ1w9w) (Nick 有很好的资源,介绍 Inkscape 的基本特性,涵盖了图标、网站或者图形设计师日常会使用的基本功能)。
* [Irfan Prastinato](https://www.youtube.com/user/desainew) (Irfan 的亮点是使用 Inkscape 专注于现代图标的创作)。
* [Cameron Bohnstedt](https://www.youtube.com/channel/UCOfXyFkINXf_e9XNosTJZDw) (Cameron 是一个数字艺术家,由于他很专业并且有丰富的经验,开源工具(GIMP、Inkscape、Blender)的力量被真正的展示了出来。很有感染力,值得一看)。
### 网页设计与开发
要设计功能丰富、响应快速的网页和原型时,这里有几个工具 —— 有些是开源的 —— 供设计师选择。这些工具最近几年一直在持续发展,在我看来,这应该是反映出了设计发展的趋势是响应式网站设计要和我们生产的设备变化得一样快。
#### Bootstrap
在我看来,[Bootstrap](http://getbootstrap.com/) 促进了响应式设计,甚至是“移动为先”的设计实现了跳跃式的突破。Boostrap 最初由 Twitter 开发人员 Mark Otto 和 Jacob Thornton 开发,是一个完全开源、完全可定制的开发框架,利用它你可以制作出满足你的客户需求的网页。有了 Bootstrap 就有了坚实的基础, Bootstrap 4.0 目前正在进行内部测试,在稳定的 3.0 版本的基础上做了大量的底层优化,包括 CSS 预处理器从 Less 换成 Sass,一个增强的网格系统,JavaScript 插件的重构等等。
#### Gravit
另一个自由开源的矢量程序 Gravit,它受到越来越多的关注。Gravit 可以在浏览器上运行,不仅是 Adobe Illustrator 在矢量方面的一个切实可行的替代品(尽管功能不是那么丰富),也有望成为一个成熟的设计环境。不论是 logo 设计,还是移动应用、网站,任何东西你都可以拿来会进行设计。自从 Gravit 成为我在浏览器上的可选工具后,我最近一些工作就是靠它完成的,除此之外它还很强大,简洁直观。
### 一些免费但不开源的解决方案……
#### Webflow
[Webflow](https://webflow.com/) 是一个强大的全能网页设计环境,可以在浏览器上运行。Webflow 的奇妙之处是设计网页基本不需要写代码,当你设计时,它会在后台自动生成代码。我发现 Webflow 的界面十分干净清爽,非常直观。诚然,Webflow 没有开源,但是免费版支持同时设计和开发两个网页项目。
#### Froont
另一个基于浏览器的网页设计程序是 [Froont](http://froont.com/)。和 Webflow 相似, Froont 设计非常直观简洁,而且强大。利用 Froont,在任何相关设备上,你都可以高效地设计一个全新、独一无二的响应式网站。和 Webflow 一样,Froont 还允许设计师在需要的时候导出代码。
Webflow 和 Froont 除了收费计划外均有免费版,很适于一次设计一个站点,还可以将你的工作成果发布到网上,如果你选择的话。
### 文本编辑器
有一些产品供想使用自由开源编辑器的设计师和开发者选择,作为自己平常编写代码工具的替代品。
#### Atom
Atom 号称为<ruby> “ <a href="https://atom.io/"> 面向 21 世纪的黑客级编辑器 </a> ” <rt> hackable editor for the 21st Century </rt></ruby>, 它是全功能的编辑器,看起来内置了完成工作所需的所有功能 —— 比如代码自动补全、多功能视图等。它的可玩性很高,用户可以以自己喜欢的方式对 Atom 进行自定义。Atom 有自己的包管理器, 用户可以下载成千上万的软件包进一步定制 Atom,添加独一无二的功能。
### 结论
当今时代,设计师不要被昂贵臃肿的专有软件所束缚。使用一些自由开源的工具,具有开源意识的设计师有足够多的选择,为他们的客户创造漂亮、实用的设计作品。如果喜欢这篇文章就分享吧,也可以在下面评论你最喜欢的开源的设计工具!
---
via: <https://freedompenguin.com/articles/opinion/open-source-design-thing/>
作者:[Sean LeRoy](https://freedompenguin.com/author/seanleroy/) 译者:[fuowang](https://github.com/fuowang) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,008 | Canonical 和 Docker 公司合作在 Ubuntu 上以 Snap 格式发布 Docker 引擎 | http://news.softpedia.com/news/canonical-and-docker-partner-to-distribute-docker-releases-as-snaps-on-ubuntu-510665.shtml | 2016-12-03T08:42:00 | [
"Docker",
"Ubuntu",
"Snap"
] | https://linux.cn/article-8008-1.html | 2016 年 11 月最后一天,Canonical 和 Docker 公司宣布了一个新的商务合作意向,承诺为 Ubuntu Linux 提供[商业版 Docker 引擎](https://www.docker.com/products/docker-engine)的企业级支持和 SLA。

这两家公司将在 Ubuntu 平台上集成商业版 Docker 引擎,这样 Canonical 就可以一体化为其客户提供商业版 Docker 引擎和 Ubuntu Linux 系统的支持。
“通过我们的合作,将商业版 Docker 引擎带到了庞大的 Ubuntu 社区, 在敏捷性、移植性和安全性方面为用户提供了更多选择。”Docker 的商业发展和技术联盟副总裁 Nick Stinemates 说。
### Ubuntu 的客户现在可以受益于 Docker 的官方支持
Docker 和 Canonical 之间的新合作将使 Ubuntu 客户得到 Docker 的官方支持,而目前其他的 Linux 发行版尚无此支持。因此, Docker 公司将会以 Snap 格式发布和维护新版本的商业版 Docker 引擎。
这些 Docker 维护的 Snap 软件包将由 Docker 公司推送回上游,Ubuntu 16.04 LTS 及其它支持 Snap 的 Linux 系统将可以直接访问由官方构建的 Docker 应用容器。
“在可伸缩容器运营方面,Ubuntu 和 Docker 的组合很流行,这次的合作意向将使我们的用户可以在商业版 Docker 引擎的 DevOps 产品化方面开辟一条更快、更容易的发展道路。”Canonical 的云联盟和商业发展副总裁 John Zannos 说。
据 Canonical 和 Docker 称,Ubuntu 在以容器为中心的 DevOps 平台环境中非常流行,所以在加快和保持维护 Docker 版本发布的需求方面日益增加。最新的 Snap 技术为 Ubuntu 上的新发布 Docker 软件提供了额外的安全保护。
| 301 | Moved Permanently | null |
8,009 | 起步的好选择:安装 Xubuntu 16.10 完全指南 | http://www.everydaylinuxuser.com/2016/10/an-everyday-linux-user-review-of_15.html | 2016-12-03T07:48:00 | [
"Xubuntu"
] | https://linux.cn/article-8009-1.html | ### 简介

Xubuntu 一直是我最喜欢的发行版之一。与其它的 Linux 发行版相比,它的外观看起来不那么迷人,它当然也不会把你需要的软件全部预装上。
Xubuntu 能够给你的就是一个良好的起点。
如果你是那种喜欢定制桌面和外观的人,那么 XFCE 绝对是适合于这种的最好的桌面环境。如果你的系统资源不足,或想让桌面漂亮舒服, XFCE 还是一个很棒的选择。
Xubuntu 之所以成领先于其它 Linux 发行版,就是因为它默认安装 XFCE 桌面。
毫无疑问,在硬件兼容性、易用性、稳定性、易于安装,以及拥有一个大型社区等方面,Ubuntu 是很难被超越的。Xubuntu 是 Ubuntu Linux 发行版的官方流派,因此你可以拥有所有 Ubuntu 的优点,除了用 XFCE 桌面代替 Unity 桌面。
你可以选择性的安装应用到你的发行版上,而不是像其它发行版那样预装了一堆你不需要的应用。Xubuntu 只附带了一些必须的应用,在这么小的核心之外的应用要靠你自己去找并安装。
对我来说,以上就是我为什么认为 Xubuntu 是最棒的发行版的原因。从简单的基本安装开始,然后按照你要的去定制就好了。
### 如何获得 Xubuntu
你可以访问 Xubuntu 的官网:<http://xubuntu.org/>。

你可以在这里 <http://xubuntu.org/getxubuntu/> 找到下载页。
它有两个版本,大多数人会选择长期支持版本(LTS),除非你希望每六个月更新一次系统。而另一个版本是我今天要讲的,它就是 16.10 版。
你既可以选择一个种子文件来下载 ISO,也可以访问它的镜像源下载。

如果你选择在镜像源中下载,你需要点击合适的 ISO 文件。比如 64 位的选择 amd-64.iso 文件,而 32 位的选择 i386.iso。
有很多教程,可以教你怎么创建一个 Linux 启动 U 盘:
* [这是一个如何在 Ubuntu 下创建的教程,同样适用于 Xubuntu](http://linux.about.com/od/howtos/ss/How-To-Create-A-UEFI-Bootable-Ubuntu-USB-Drive-Using-Windows.htm#step2)
* [你也可以试试这份针对 Xubuntu 的教程](http://linux.about.com/od/howtos/ss/How-To-Create-A-Persistent-Bootable-Xubuntu-Linux-USB-Drive.htm)
* [或者你也可以试试这个](http://www.everydaylinuxuser.com/2015/11/how-to-create-ubuntu-1510-usb-drive.html)
如果这些你都觉得太复杂,你可以 [从这买一个](https://www.osdisc.com/products/xubuntu?affiliate=everydaylinuxuser)。
### 安装

像 Ubuntu 其它版本一样,安装 Xubuntu 相当直白。如果你曾经装过一个版本,那么基本上你可以安装任何一个版本。
开始时选择你的安装语言。

你会被问到,是否需要同时安装更新,是否要安装第三方软件,包括播放音乐的软件和专有驱动。想要完成这些,你需要联网。
再次,这也很直白,我们会在之后再次涉及到这些。

如果你有一个备用的未分配的磁盘分区和并且安装了 Windows,您将看到可以选择在已有 Windows 的情况下安装 Xubuntu 并设置双启动。
您也可以选择安装 Xubuntu 作为唯一的操作系统,还可以选择别的任何你喜欢的分区来安装。

下一步是设置你所在的区域以确定你的时区。

接下来两步是选择语言和键盘设置,以确定键盘模式。

最后创建一个默认账户,输入你的名字、你计算机的名字、设置用户名和密码。
Xubuntu 将会被安装在你的电脑上了,你可以继续往下看了。
### 第一印象

Xubuntu 的初始界面只有一个面板位于蓝色桌面的顶部。通过桌面上的图标,你可以看到所有可用的驱动器。
画面的顶部是个简单的面板。
面板的左侧角落有一个单独的图标(老鼠的样子),点击它后会出现一个时尚而轻量,但功能全面的菜单,它被称为 Whisker(胡须)菜单。
在右上角有着通知、电源、蓝牙、网络、音量和时钟的图标。
### 连接互联网

你可以通过点击面板上的网络图标来连接互联网。一个无线网络的列表将会出现,你可以选择一个点击,并键入密码,就可以连接了。
我是在我的联想 Ideapad Y700 上安装 Xubuntu 的,这个本子很现代,其上运行的许多发行版在无线网络连接时会有些小问题,我不得不找些规避问题的方法。
但 Xubuntu 16.10 工作的很好,不需要做任何修改。
### 驱动

为你的电脑寻找可用的附加驱动是十分必要的。
虽然默认的开源驱动是基本够用的,但是如果你有着较好的显卡,并且想获得更好的图形体验,那就十分有必要去寻找专有驱动。
打开菜单,搜索附加驱动,你可以找到附加驱动设置界面。
如果看到你的显卡驱动,但是它不工作,那么我还是建议你用默认的显卡驱动。
### 打印

我有一个爱普生 WF-2630 无线打印机。 Xubuntu 能够直接找到这台打印机,并安装相关驱动。
我打印了测试页,发现它的输出非常合适。
### 网络存储

我有一个跨无线网络连接的 WD MyCloud 存储设备。
可以通过默认的文件管理器 Thunar 来访问这个设备。值得注意的是,我在网络设备中找到了 WD MyCloud 设备,但是点击它时显示错误。
但是我打开 Windows 网络文件夹时,WD MyCloud 也显示出来了,而且我也能正常访问该设备上的文件夹。
### 软件

我在文章开始时提到了,Xubuntu 配备了最少的应用集,不过它包含了你开始所需要的所有应用。
火狐浏览器是它的默认浏览器,Thunderbird 是默认的邮件客户端。

你也有一个全套的 LibreOffice 套件和 Parole 媒体播放器。
它也有一系列工具,比如图片查看器、计算器、光盘刻录工具,还有一个 BT 下载器。

我很高兴,现在在大多数发行版上,Abiword 和 Gnumeric 都被忽略掉了,因为它们实在无关紧要。大多数人们最终会安装 Libreoffice 的。
缺乏专门的音频播放器这点比较奇怪。另外我需要提到的是我通常最终会安装谷歌的 Chrome 浏览器,而不是使用Firefox。
本节的第一个图片说明了原因。这张图片里,我试图观看 Google Play 商店的 “Curb Your Enthusiam” 视频,可惜的是各种 DRM 和其它一些问题导致了视频无法播放。
从谷歌网站上一个简单的下载就可以解决问题。如下所示。

### 安装软件

在 Ubuntu 16.04 以后的发行版上普遍存在的一个主要问题是有些程序无法在图形安装软件中安装。
比如在软件管理器中找不到 Steam。

如果你使用命令行输入 `sudo apt-cache search steam` 你会发现有这个软件。

并不是只有 Steam 被遗漏了,其它软件比如 Skype 同样不能在图形软件管理工具中找到。
我真希望这个问题已经在所有 Ubuntu 发行版中解决了。
我最近还试用了 Kubuntu 16.04 ,发现它的叫做 Discover 的软件工具完全无用,搜索根本不工作。
幸运的是,Xubuntu 上的软件管理器可以安装大多数软件包,我利用它搜寻并装上了 Quod Libet 音乐播放器。


顺便说一下,如果你在安装 Xubuntu 时选择了同时安装解码器,那么 MP3 播放也不会出现任何问题。
如果没有安装,那么你需要打开终端模拟器,安装 Xubuntu Restricted Extras 包。
### 个性化 Xubuntu

在这方面你可以做很多事来定制 Xubuntu, [参见这里](http://linux.about.com/od/howtos/ss/Customise-The-XFCE-Desktop-Environment.htm)。
Xubuntu 提供一整套漂亮的壁纸,如上图所示,你要做的第一件事就是选一个好看的壁纸并添加一个 Dock 风格的面板,里面含所有你喜欢的软件的启动器。

Xubuntu 有一个相对较新的特性就是 XFDashboard 。它带来了与 Gnome 桌面类似的 Dash 面板。你可以在上面添加启动器和能够让应用快速启动的键盘快捷键。

此图展示了一个快速选择不同工作区和启动应用的好方法。
说老实话,当谈到个性化 Xubuntu 时,有一种世界尽在我掌中的感觉。

### 问题
我在使用 Xubuntu (包括所有基于 Ubuntu 的发行版)时感受到的最大问题就是应用商店里面找不到一些重要的应用。为啥没有 Steam ?
在 Xubuntu 安装时收到一个崩溃的错误,如下图所示。

我没有搞明白这个问题是怎么回事,因为它没有带来任何副作用。安装工作也没有出岔子。
### 总结
我不对 Xubuntu 点评更多,并不是因为我不喜欢它。事实上我是 Xubuntu 的大粉丝,并且我在另一个电脑上有一个它的深度定制版。
我使用电脑时,我希望了解发生了什么,没有比看到下面这种情况更让人恼火的了。

认真的说,为啥会有人认为 windows 适合工作?似乎每隔一就会看到消息 “正在安装(1/285)” ,于是当它自己更新时,你就失去了一个小时。而 Xubuntu(和其它发行版一样)更新不会打断你每天的工作。
事实是,Xubuntu 真的没有什么需要改变的,它可靠、稳定、不需要改变什么(除了软件管理器)。
我非常推荐 Xubuntu。
此外,我还得说去试一试 Peppermint OS、Linux Mint XFCE 或者 Manjaro XFCE 也是十分值得的。
---
via: <http://www.everydaylinuxuser.com/2016/10/an-everyday-linux-user-review-of_15.html>
作者:[Gary Newell](http://www.everydaylinuxuser.com/2016/10/an-everyday-linux-user-review-of_15.html) 译者:[chao-zhi](https://github.com/chao-zhi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,010 | 安卓编年史(11):The Nexus One——迎来 Google Phone | http://arstechnica.com/gadgets/2014/06/building-android-a-40000-word-history-of-googles-mobile-os/11/ | 2016-12-04T08:46:00 | [
"Android",
"安卓编年史"
] | https://linux.cn/article-8010-1.html | 

*重新设计的拨号和联系人页面。 [Ron Amadeo 供图]*
联系人/拨号应用程序的圆角标签拥有了更清晰、更成熟的外观设计。拨号器更名为“电话”,并且拨号按键从圆形改为了圆角矩形。语音邮件、拨号、以及删除按键被放置在底部。这个界面是安卓在 3.0 之前缺乏设计一致性的一个很好的例子。仅仅在这个界面上,标签用的是直角矩形,拨号按键使用圆角矩形,底部按键两侧合起来是个完整的圆。这里就像是个 UI 控件的摸奖袋,没有人尝试过让它们之间相互搭配。
安卓 2.0 的一个新特性是“快速拨号”,它将联系人以略缩图的形式添加到整个系统。从其它应用中点击它们可以打开一个联系这个人的快捷方式列表。这在联系人里并没有多大意义,但像在 Google Talk 中,能够通过点击某人的略缩图来给他拨号是十分方便的。

*[Ron Amadeo 供图]*
安卓 2.0 终于配备了接通和拒绝来电所需要的所有屏幕按键,而不再需要实体按钮,Droid 从中获益,从它的设计中除去了在现在看来是多余的按钮。安卓对于接通和拒绝来电的解决方案是这些左滑和右滑的标签。他们的工作方式就像是滑动解锁(后来被用到了滑动解锁中)——向右滑动绿色按钮接通来电,向左滑动红色按钮则是拒绝。一旦进入通话中,它看起来就很像安卓 1.6 了。所有选项还是隐藏在菜单按钮之中。
某人在设计拨号界面的时候一定在煲电话粥。他们只是去掉了“拨号盘”上字母的粗体,而不是从安卓 1.6 中重新绘制数字“5”的按键,然后就这么收工了。

*计算器和浏览器 [Ron Amadeo 供图]*
计算器从在安卓 0.9 中被引入以来第一次得到改进。黑色玻璃球按钮换成了蓝色和黑色过渡的按钮。旧版计算器按键的按下高亮的红色边框被改为了一个比较正常的白色轮廓。
浏览器的微型网站名称栏改进为一个完整的、功能更完善的地址栏,并且带有书签按钮。为了节省屏幕空间,地址栏被附加到网页上,所以地址栏会随着页面向上滚动,给你留下更多的网页阅读空间。安卓 1.6 独特的缩放控制和附加按钮被去除,被替换为一个更简单的双击缩放手势,并且浏览器可以再次打开 arstechnica.com 而不崩溃了。这里还是没有双指捏合缩放。

*打开设置的相机,闪光灯设置,以及查看照片界面的菜单。 [Ron Amadeo 供图]*
相机应用有个布满整个左侧的抽屉式菜单,打开它有许多设置。摩托罗拉 Droid 是率先带有 LED 闪光灯的安卓手机之一,所以设置里有个闪光灯控制,以及还有像场景模式、白平衡、效果、图片尺寸和存储位置(SD 卡或内置存储)的设置。
在照片查看界面,谷歌精简了菜单按钮。和屏幕上的选项相比,它们之间不再有重复的选项。这样精简后省下的空间,使得所有的选项能够在菜单里放得下了,而不再需要一个“更多”按钮。

*电子邮件应用的“帐户”页面,新的联合收件箱,系统设置的帐户与同步页面,自动亮度设置。 [Ron Amadeo 供图]*
电子邮件应用程序有了大的功能提升。最重要的是它终于支持了 Microsoft Exchange。安卓 2.0 版本的电子邮件中收件箱和文件夹视图终于分开了,而不是使用安卓 1.0 引入的凌乱的混合视图。电子邮件甚至有了一个统一的收件箱,可以将你不同账户的所有邮件显示到一起。
这个收件箱视图和 Gmail 一起,把普通的电子邮件应用打趴下了。联合收件箱甚至胜过了 Gmail 的功能,这是极其罕见的。尽管如此,相对于 Gmail 来说,电子邮件仍然感觉像个多余的继女。它使用了 Gmail 界面来查看邮件,这意味着收件箱和文件夹使用了黑色主题,查看邮件却奇怪地选择了亮色主题。
捆绑的 Facebook 应用程序有一个很棒的账户同步功能,它可以从社交网络上下载联系人的照片和信息,并无缝集成到联系人应用里。后来 Facebook 和谷歌分道扬镳,[谷歌取消了这一功能](http://techcrunch.com/2011/02/22/google-android-facebook-contacts/)。谷歌表示,在 Facebook 不向其共享信息的情况下,与 Facebook 分享信息并不是什么好想法,因此更好的用户体验败给了公司间的政治斗争。
(不幸的是,我们无法展示 Facebook 应用,因为它也是死在 OAuth 更新手中的客户端之一。现在不可能从像这么老旧的应用上登录了。)
最后一张图片显示了自动亮度控制,安卓 2.0 是第一个支持这一功能的版本。Droid 配备了光线传感器,点击该复选框,会使亮度滑块消失,并且允许设备自动控制屏幕亮度。
正如它的名字所暗示的那样,安卓 2.0 是谷歌有史以来最大的更新。摩托罗拉和威瑞森给安卓带来了一个外形酷炫的设备,并在广告上投入了数不清的资金。之后的一段时间里,“Droid”成为了一个家喻户晓的名字。
### The Nexus One——迎来 Google Phone

2010 年 1 月,第一款 Nexus 设备发布,称为“[Nexus One](http://arstechnica.com/gadgets/2010/01/nexus-one-review/)”。对谷歌来说,这部设备是个巨大的里程碑。这是第一部由谷歌设计并冠名的设备,而且谷歌计划直接向消费者出售设备。宏达电代工的 Nexus One 拥有 1GHz 的单核高通骁龙 S1 处理器、512MB 的内存、512MB 存储空间,以及一块 3.7 英寸的 AMOLED 显示屏。
Nexus One 代表着拥有纯净的安卓体验,没有运营商的定制和应用植入。谷歌直接控制安卓的更新。这使得谷歌能够在软件完成时直接向用户进行推送, 而不是再经过运营商的许可。运营商总是拖慢这一过程,因为他们对用户已经付过钱手机并不总是那么热切地想要改善它们。
谷歌[直接在网上](http://arstechnica.com/gadgets/2010/01/googles-big-news-today-was-not-a-phone-but-a-url/)销售 Nexus One,无锁、无合约、完整零售价 529.99 美元。尽管同样的 Nexus One 在 T-Mobile 商店的合约价仅为 179.99 美元,谷歌想通过它的在线商店改变美国手机行业的运作方式。谷歌当时的想法是先挑选手机,再选择运营商,以此打破美国无线寡头对硬件的控制。
但谷歌的零售革命并没有奏效,在在线手机商店开通半年后,谷歌关闭了该服务。谷歌指出首要问题是销量低。在 2010 年,网上购物并不像今天这样司空见惯,消费者也还没有准备好在他们不能先握在自己手中试用的设备上花费 530 美元。高昂的价格也是一个制约因素;智能手机消费者更习惯于为眼前的设备花费 200 美元,并签署一项为期两年的合同。还有摩托罗拉 Droid 的因素,相比之下这部三个月前发布的设备并没有显著的不足。还由于 Droid 的庞大的营销活动和“iPhone 杀手”的炒作,它已经夺取了大多数 Nexus One 所面向的安卓发烧友市场。
尽管 Nexus One 的网上销售尝试可以被认为是失败的,谷歌还是从中学到了很多。2012 年,谷歌以 Google Play 的“设备”板块[重新推出其网上商店](http://arstechnica.com/gadgets/2012/04/unlocked-samsung-galaxy-nexus-can-now-be-purchased-from-google/)。
---
[Ron Amadeo](http://arstechnica.com/author/ronamadeo) / Ron 是 Ars Technica 的评论编缉,专注于安卓系统和谷歌产品。他总是在追寻新鲜事物,还喜欢拆解事物看看它们到底是怎么运作的。[@RonAmadeo](https://twitter.com/RonAmadeo)
---
via: <http://arstechnica.com/gadgets/2014/06/building-android-a-40000-word-history-of-googles-mobile-os/11/>
译者:[alim0x](https://github.com/alim0x) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,011 | 容器和 Unikernel 能从树莓派和 Arduino 学到什么? | https://opensource.com/business/16/5/containers-unikernels-learn-arduino-raspberry-pi | 2016-12-04T10:03:00 | [
"容器",
"Unikernel"
] | https://linux.cn/article-8011-1.html | 
某一天,我和我的一个机械工程师朋友聊天的时候。 他最近在做一个给半挂卡车的电子辅助刹车系统,他提到他们公司的办公室里都是 [Arduinos](https://opensource.com/resources/what-arduino)。这主要是方便员工可以快速的对新的想法进行实验。他也提到了,Arduinos 其实比自己画电路板更加昂贵。对此,我感到非常震惊,因为我从软件行业得到的印象是 Arduinos 比定制电路板更加便宜。
我常常把 [Arduinos](https://opensource.com/life/16/4/arduino-day-3-projects) 和 [树莓派](https://opensource.com/resources/what-raspberry-pi) 看做是可以制作非常有趣设备的小型、Cool、特别的组件。我主要从事于软件行业,并且总是觉得运行在 x86 和 x86-64 设备上的 Linux 才算是“常规用途”。而事实是,Arduinos 并不是特殊用途。实际上,它们是很常规的用途。它们相当的小、便宜,而且非常的灵活。这就是为什么它们像野火一样流行起来的原因。它们有全品类的输入输出设备和扩展卡。它们能让创客们快速的构建非常 Cool 的设备。它们甚至可以让公司可以快速地开发产品。
一套 Arduino 的单价比批量生产的电路板高了很多,但是,看不见的时间成本却低了很多。当电路板大规模生产的时候,价格可以控制的很低,但是,之前的研发费用却高了很多。所以,总而言之,答案就是,使用 Arduino 划得来。
### Unikernel、Rump 内核和容器主机
Unikernel、Rump 内核和迷你 Linux 发行版,这些操作系统是为了特有用途而构建的。这些特有的操作系统,某种程度上就像定制电路板。它们需要前期的投入,还需要设计,但是,当大规模部署的时候,它可以提供强大的性能。
迷你操作系统,例如:红帽企业版 Atomic 或者 CoreOS 是为了运行容器而构建的。它们很小,快速,易于在启动时配置,并且很适合于运行容器。缺点就是它需要额外的工程量来添加第三方插件,比如监控客户端或者虚拟化的工具。副作用就是载入的工具也需要重新设计为超级权限的容器。 如果你正在构建一个巨大的容器环境,这些额外的工作量是划算的。但是,如果只是想尝试下容器,那可能就没必要了。
容器提供了运行标准化的工作流程(比如使用 [glibc](https://en.wikipedia.org/wiki/GNU_C_Library) 编译)的能力。一个好处就是你可以在你的电脑上构建和测试这个工作单元(Docker 镜像)并且在完全不同的硬件上或者云端非常顺利的部署,而保持着相同的特性。在生产环境中,容器的宿主机仍然由运维团队进行配置管理,但是应用被开发团队控制。这就是对双方来说最好的合作方式。
Unikernels 和 Rump 内核依旧是为了特定目标构建的,但是却更进一步。整个的操作系统在构建的时候就被开发或者架构师配置好了。这带来了好处,同时还有挑战。
一个好处就是,开发人员可以控制这个工作流程的运转。理论上说,一个开发者可以为了不同的特性,尝试 [不同的 TCP 协议栈](http://www.eetasia.com/ARTICLES/2001JUN/2001JUN18_NTEK_CT_AN5.PDF),并且选择最好的一个。在操作系统启动的时候,开发人也可以配置 IP 地址,而不是通过 DHCP。 开发人员也可以裁剪任何对于应用而言不需要的部分。这也是性能提升的保障,因为减少了[不必要的上下文切换](https://en.wikipedia.org/wiki/Context_switch)。
同时,Unikernel 也带来了挑战。目前,还缺失很多的工具。 现在,和画板子的世界类似,开发人员需要花费很多时间和精力在检查是否有完整的库文件存在,不然的话,他们必须改变他们应用的执行方式。在如何让这个“嵌入式”的操作系统在运行时配置的方面,也存在挑战。最后,每次操作系统的大改动,都需要[反馈到开发人员](http://developers.redhat.com/blog/2016/05/18/3-reasons-i-should-build-my-containerized-applications-on-rhel-and-openshift/)来进行修改。这并没有一个在开发和运维之间明确的界限,所以我能想象,为了接受了这个开发流程,一些组织或者公司必须要改变。
### 结论
在专门的容器主机比如 Rump 内核和 Unikernel 方面也有一些有趣的传闻,因为,它们会带来一个特定工作流程的潜在变革(嵌入式、云,等等)。在这个令人激动又快速发展的领域请保持你的关注,但是也要谨慎。
目前,Unikernel 看起来和定制电路板很像。它们都需要前期的研发投资,并且都是非常独特的,可以为确定的工作流程带来好处。同时,容器甚至在常规的工作流中都非常有趣,而且它不需要那么多的投入。一个简单的例子,运维团队能方便的在容器上部署一个应用,但是在 Unikernel 上部署一个应用则需要重新设计和编码,而且业界并不能完全保证,这个工作流程就可以被部署在 Unikernel 上。
容器,Rump 内核 和 Unikernel 有一个光明的未来!
---
via: <https://opensource.com/business/16/5/containers-unikernels-learn-arduino-raspberry-pi>
作者:[Scott McCarty](https://opensource.com/users/fatherlinux) 译者:[MikeCoder](https://github.com/MikeCoder) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Just the other day, I was speaking with a friend who is a mechanical engineer. He works on computer assisted braking systems for semi trucks and mentioned that his company has [Arduinos](https://opensource.com/resources/what-arduino) all over the office. The idea is to encourage people to quickly experiment with new ideas. He also mentioned that Arduinos are more expensive than printed circuits. I was surprised by his comment about price, because coming from the software side of things, my perceptions of Arduinos was that they cost less than designing a specialized circuit.
I had always viewed [Arduinos](https://opensource.com/life/16/4/arduino-day-3-projects) and [Raspberry Pi](https://opensource.com/resources/what-raspberry-pi) as these cool, little, specialized devices that can be used to make all kinds of fun gadgets. I came from the software side of the world and have always considered Linux on x86 and x86-64 "general purpose." The truth is, Arduinos are not specialized. In fact, they are very general purpose. They are fairly small, fairly cheap, and extremely flexible—that's why they caught on like wildfire. They have all kinds of I/O ports and expansion cards. They allow a maker to go out and build something cool really quickly. They even allow companies to build new products quickly.
The unit price for an Arduino is much higher than a printed circuit, but time to a minimum viable idea is much lower. With a printed circuit, the unit price can be driven much lower but the upfront capital investment is much higher. So, long story short, the answer is—it depends.
## Unikernels, rump kernels, and container hosts
Enter unikernels, rump kernels, and minimal Linux distributions—these operating systems are purpose-built for specific use cases. These specialized operating systems are kind of like printed circuits. They require some up-front investment in planning and design to utilize, but could provide a great performance increase when deploying a specific workload at scale.
Minimal operating systems such as Red Hat Enterprise Linux Atomic or CoreOS are purpose-built to run containers. They are small, quick, easily configured at boot time, and run containers quite well. The downside is that it requires extra engineering to add third-party extensions such as monitoring agents or tools for virtualization. Some side-loaded tooling needs redesigned as super-privileged containers. This extra engineering could be worth it if you are building a big enough container environment, but might not be necessary to just try out containers.
Containers provide the ability to run standard workloads (things built on [glibc](https://en.wikipedia.org/wiki/GNU_C_Library), etc.). The advantage is that the workload artifact (Docker image) can be built and tested on your desktop and deployed in production on completely different hardware or in the cloud with confidence that it will run with the same characteristics. In the production environment, container hosts are still configured by the operations teams, but the application is controlled by the developer. This is a sort of a best of both worlds.
Unikernels and rump kernels are also purpose-built, but go a step further. The entire operating system is configured at build time by the developer or architect. This has benefits and challenges.
One benefit is that the developer can control a lot about how the workload will run. Theoretically, a developer could try out [different TCP stacks](http://www.eetasia.com/ARTICLES/2001JUN/2001JUN18_NTEK_CT_AN5.PDF) for different performance characteristics and choose the best one. The developer can configure the IP address ahead of time or have the system configure itself at boot with DHCP. The developer can also cut out anything that is not necessary for their application. There is also the promise of increased performance because of less [context switching](https://en.wikipedia.org/wiki/Context_switch).
There are also challenges with unikernels. Currently, there is a lot of tooling missing. It's much like a printed circuit world right now. A developer has to invest a lot of time and energy discerning if all of the right libraries exist, or they have to change the way their application works. There may also be challenges with how the "embedded" operating system is configured at runtime. Finally, every time a major change is made to the OS, it requires [going back to the developer](http://developers.redhat.com/blog/2016/05/18/3-reasons-i-should-build-my-containerized-applications-on-rhel-and-openshift/) to change it. This is not a clean separation between development and operations, so I envision some organizational changes being necessary to truly adopt this model.
## Conclusion
There is a lot of interesting buzz around specialized container hosts, rump kernels, and unikernels because they hold the potential to revolutionize certain workloads (embedded, cloud, etc.). Keep your eye on this exciting, fast moving space, but cautiously.
Currently, unikernels seem quite similar to building printed circuits. They require a lot of upfront investment to utilize and are very specialized, providing benefits for certain workloads. In the meantime containers are quite interesting even for conventional workloads and don't require as much investment. Typically an operations team should be able to port an application to containers, whereas it takes real re-engineering to port an application to unikernels and the industry is still not quite sure what workloads can be ported to unikernels.
Here's to an exciting future of containers, rump kernels, and unikernels!
## 1 Comment |
8,012 | WattOS:一个稳如磐石、快如闪电、面向所有人的轻量级 Linux 发行版 | https://www.linux.com/learn/wattos-rock-solid-lightning-fast-lightweight-linux-distro-all | 2016-12-05T08:33:00 | [
"轻量级",
"WattOS"
] | https://linux.cn/article-8012-1.html | 
*Jack Wallen 将介绍一下是什么让 WattOS 这么特别。*
Linux 领域里的每个人不是听说过就是使用过某个轻量级的 Linux 发行版。大家都知道我们不断追求的是:占用内存少,配置资源要求低,包含一个轻量级的桌面环境(或者窗口管理器),并且提供和其他发行版相似的桌面布局,把赌注押在相同的需求之上。
这种发行版大多用来工作。有一个可以击垮很多轻量级 Linux 发行版的问题,它们没有真正含有一般用户完成工作需要的工具。结果就是,它们沦落为用来完成特殊任务(像数据恢复、做信息亭等)。
在某种程度上,WattOS 陷入了同样的困境(它唯一含有的生产力工具是 PDF 阅读器,而且它使用标准的“任务栏/开始菜单”象征桌面)。然而幸运的是,WattOS 通过难以置信的运行速度、稳定性以及内置新立得包管理器弥补了这些缺点;所以,WattOS 可以很容易的成为一个适合所有人的轻量级 Linux 发行版。
到底是什么让 WattOS 如此特别,让我们一起一探究竟。
### 内核
事实上当我发现 WattOS 基于 kernel 4.4 内核时我非常吃惊。升级系统之后,执行 `uname -r` 命令可以看到是 4.4.0-38-generic。鉴于这个发行版的目的是让老旧和运行卡顿的机器重获新生,它和我的 Elementary OS Loki 发行版内置相同版本的内核真是一个可爱的惊喜。这意味着 WattOS 在新旧硬件上都会有良好的工作表现。
真正的惊喜不止于此,当你去 WattOS 的网站,你会同时发现 32 位和 64 位版本的下载地址(现在大多数新的发行版都倾向于放弃 32 位发行版本)。所以,不仅系统内核对新式硬件提供支持,而且系统发行版本的多种架构也能让那些老式的 32 位机器重获新生。
### 运行速度
当安装上 WattOS 的时候,有那么一刻我对它有纯粹的羡慕。WattOS 的运行速度快的令人难以置信。甚至当它的桌面版作为客户机在 VirtualBox 虚拟机平台工作时,运行速度依然远远超过了我的 Elementary OS Loki 桌面发行版。后来我才了解到当时运行的宿主机是 [System76 Leopard](https://system76.com/desktops/leopard),配置有水冷装置的 i7 处理器和 16GB 的运行内存。分配给 WattOS 大约 2G 的内存,让它看起来没有什么任务可以拖慢它。WattOS 的运行速度壮观的令人难以诉说,它越来越成熟了。我从没见过火狐浏览器能打开的这么快。
接下来说说 LibreOffice 应用的启动。由于想测试 LibreOffice 的启动速度,所以我打开了新立得软件包管理器,计划安装这一开源办公软件套件的佼佼者。
无果。
安装 LibreOffice 的主要问题是缺少一个依赖软件包 python3-uno,而且无论怎么尝试都无法安装成功。然而,最后我在 [LibreOffice 官方网站](https://www.libreoffice.org/) 上下载了 deb 格式的软件包。把下载的文件解压之后,`cd` 到 LibreOffice*5.2.2.2*Linux*x86-64*deb/DEBS/ 目录下,最后通过执行 `sudo dpkg -i *.deb` 命令成功的安装好了 LibreOffice。
LibreOffice 运行的怎么样呢?速度快到要疯了。值得再提的是,我从没见过这个应用能像在 WattOS 上运行的这么快。点击 LibreOffice Writer 的图标,它花费的时间是在 Elementary OS Loki (已经很快了)主机上花费的一半。
### 桌面
我个人偏爱于桌面向更加现代化的趋势进行迭代。我是 Ubuntu 的 Unity 桌面,GNOME 3 桌面,以及(特别是) [Elementary OS](https://elementary.io/) 的粉丝。所以使用古老风格桌面的主意意味着对我几乎没有吸引力。即便如此,WattOS 在把现代设计风格融入老式设计时做的非常好。举例来说,默认的桌面主题(图 1)。WattOS 的 UI 设计者巧妙设计了桌面主题,所以它没有完全偏离 Windows XP 或者老式 Linux CDE 风格的窗口管理器的设计理念。

*图 1:WattOS 的文件管理器展示了有些现代化的主题 [使用许可](https://www.linux.com/licenses/category/used-permission)*
关于 WattOS 的桌面(基于 [LXDE](http://lxde.org/))的确有一些要说的但以前从来没说过,就是每个拥有像简洁、直接,有足够灵活度和自定义度这些特点的 Linux 桌面版,对每个使用过 Windows 95 的电脑使用者来说都会很熟悉。
### 惊喜之处,优点和缺点
正像每个新的 Linux 桌面版的体验那样,WattOS 有让人惊喜的地方,同时也有优点和缺点。首先,说说优点。
WattOS 除了绝对的速度(用一个简单的 “WOW” 来评论),还在桌面上固定了一些特别的惊喜(大多数都是预置的应用)。额外的软件中最好的是 [KeePassX](https://www.keepassx.org/)(一个极少被默认包含在桌面版的应用)。我认为密码管理器应该默认安装在每一个电脑桌面上,值得骄傲的是 WattOS 预装了这个杰出的工具。
下一个讨论的是预装火狐浏览器。许多轻量级的发行版会预装像 [Surf](http://surf.suckless.org/) 或者 [Midori](http://midori-browser.org/) 这样的浏览器。这两个浏览器都不错,但是它们的兼容性经常达不到像谷歌文档这样网站的要求。因为 WattOS 含有成熟的火狐浏览器,你会发现该系统的功能在火狐浏览器兼容的网站上表现的很完美。
最后,算不上好的意外。正如我已经提到的,在安装 LibreOffice 时马上就有了故障。然而安装像 GIMP 这样的软件就很顺利(所以我认为这是偶然问题)。除了这一个问题,我觉得默认桌面菜单有些混乱。例如,新立得软件包管理器放在个性化菜单里。我更愿在主菜单中突出显示项中看到它,并且加上类似“软件安装”(或任何其他新用户容易理解)的标签。从我的视角来说,个性化菜单项应该用于放置配置该平台各种风格的工具,而不是安装软件的工具。
除此之外,若想在 WattOS 主攻方向上的找茬的话,特别是你要找一个面对老旧硬件 Linux 发行版时,你会发现这非常困难。
### 结论
尽管 WattOS 主要为老旧硬件设计,但你完全可以把它运行在现代桌面电脑上,并且会运行的很好。根据零学习曲线,你很快就会熟悉 WattOS,并发现它运行极快而且稳定。试试这个小排量的 Linux 发行版吧,相信它会给你同样深刻的印象。如果你发现 WattOS 运行的不够快(发生了一些我没有预料到的事),你完全可以去使用 [Microwatt](http://planetwatt.com/new/index.php/2016/09/23/microwatt-r10-released/)(一个更轻的轻量级发行版)。
---
via: <https://www.linux.com/learn/wattos-rock-solid-lightning-fast-lightweight-linux-distro-all>
作者:[JACK WALLEN](https://www.linux.com/users/jlwallen) 译者:[fuowang](https://github.com/fuowang) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,013 | Neofetch :带发行版 Logo 图像的系统信息显示工具 | http://www.tecmint.com/neofetch-shows-linux-system-information-with-logo | 2016-12-04T14:57:00 | [
"系统信息",
"neofetch",
"ScreenFetch",
"Linux_Logo"
] | https://linux.cn/article-8013-1.html | Neofetch 是一个跨平台的易于使用的 [系统信息显示命令行脚本](http://www.tecmint.com/screenfetch-system-information-generator-for-linux/),它收集你的系统信息,并在终端中和图像一起显示出来,这个图像可能是你的发行版的 logo 也可能是你选择的一幅 ascii 艺术字。
Neofetch 和 [ScreenFetch](http://www.tecmint.com/screenfetch-system-information-generator-for-linux/) 或者 [Linux\_Logo](http://www.tecmint.com/linux_logo-tool-to-print-color-ansi-logos-of-linux/) 很像,但是它可以高度定制,并且还有一些额外的我们要在下面讨论的特点。
它的主要特点有:运行速度快,可以显示全色图像 —— 用 ASCII 字符显示的发行版 logo ,旁边显示系统信息,可以高度定制,可以随时随地显示系统信息,并且在脚本结束的时候还可以通过一个特殊的参数来启用桌面截图。

#### 系统要求:
1. Bash 3.0+ 带 ncurses 支持。
2. w3m-img (有时候会打包成 w3m) 或者 iTerm2 或者 Terminology,用于显示图像。
3. [imagemagick](http://www.tecmint.com/install-imagemagick-in-linux/),用于创建缩略图。
4. 支持 `[\033[14t` 的 [Linux 终端模拟器](http://www.tecmint.com/linux-terminal-emulators/) 或者 xdotool 或者 xwininfo + xprop 或者 xwininfo + xdpyinfo 。
5. Linux 系统中还需要 feh、nitrogen 或者 gsettings 来提供对墙纸的支持。
注意:你可以从 Neofetch 的 Github 页面了解更多关于可选依赖的信息,以检查你的 [Linux 终端模拟器](http://www.tecmint.com/linux-terminal-emulators/) 是不是真的支持 `\033[14t` 或者是否需要一些额外的依赖来使这个脚本在你的发行版上工作得更好。
### 怎样在 Linux 系统上安装 Neofetch
Neofetch 可以从几乎所有 Linux 发行版的第三方仓库轻松安装,请按照以下各自的安装说明进行安装。
#### Debian
```
$ echo "deb http://dl.bintray.com/dawidd6/neofetch jessie main" | sudo tee -a /etc/apt/sources.list
$ curl -L "https://bintray.com/user/downloadSubjectPublicKey?username=bintray" -o Release-neofetch.key && sudo apt-key add Release-neofetch.key && rm Release-neofetch.key
$ sudo apt-get update
$ sudo apt-get install neofetch
```
#### Ubuntu 和 Linux Mint
```
$ sudo add-apt-repository ppa:dawidd0811/neofetch
$ sudo apt-get update
$ sudo apt-get install neofetch
```
#### RHEL, CentOS 和 Fedora
你的系统里面要安装了 `dnf-plugins-core` ,或者用以下命令安装它:
```
$ sudo yum install dnf-plugins-core
```
启用 COPR 仓库然后安装 neofetch。
```
$ sudo dnf copr enable konimex/neofetch
$ sudo dnf install neofetch
```
#### Arch Linux
你可以用 packer 或 Yaourt 从 AUR 安装 neofetch 或 neofetch-git。
```
$ packer -S neofetch
$ packer -S neofetch-git
或
$ yaourt -S neofetch
$ yaourt -S neofetch-git
```
#### Gentoo
从 Gentoo/Funtoo 的官方源安装 app-misc/neofetch。如果你要安装这个程序的 git 版的话,你可以安装 app-misc/neofetch-9999。
### 怎么在 Linux 中使用 Neofetch
一旦你安装了 Neofetch ,使用它的一般语法是:
```
$ neofetch
```
注意: 要是你没有安装 w3m-img 或者 [imagemagick](http://www.tecmint.com/install-imagemagick-in-linux/) 的话,[screenfetch](http://www.tecmint.com/screenfetch-system-information-generator-for-linux/) 会默认被启用,neofetch 会如下图所示显示你的 [ASCII 艺术 logo]。
#### Linux Mint 系统信息

*Linux Mint 系统信息*
#### Ubuntu 系统信息

*Ubuntu 系统信息*
如果你想用图片显示你的发行版 logo,需要用下面的命令安装 w3m-img 或者 imagemagick 。
```
$ sudo apt-get install w3m-img [On Debian/Ubuntu/Mint]
$ sudo yum install w3m-img [On RHEL/CentOS/Fedora]
```
然后再次运行 neofetch,你就会看到如下图所示的用你系统的默认墙纸来显示图片。
```
$ neofetch
```

*Ubuntu 系统信息带 logo*
第一次运行 neofetch 后,它会在这里创建一个配置文件: `$HOME/.config/neofetch/config`。
这个配置文件可以让你通过 `printinfo ()` 函数来调整你想显示在终端的系统信息。你可以增加,修改,删除,也可以使用 bash 代码去调整你要显示的信息。
你可以如下图所示用你喜欢的编辑器打开这个配置文件:
```
$ vi ~/.config/neofetch/config
```
以下是我系统配置的片段 ,显示了 `printinfo ()` 函数。
Neofetch 配置
```
#!/usr/bin/env bash
# vim:fdm=marker
#
# Neofetch config file
# https://github.com/dylanaraps/neofetch
# Speed up script by not using unicode
export LC_ALL=C
export LANG=C
# Info Options {{{
# Info
# See this wiki page for more info:
# https://github.com/dylanaraps/neofetch/wiki/Customizing-Info
printinfo() {
info title
info underline
info "Model" model
info "OS" distro
info "Kernel" kernel
info "Uptime" uptime
info "Packages" packages
info "Shell" shell
info "Resolution" resolution
info "DE" de
info "WM" wm
info "WM Theme" wmtheme
info "Theme" theme
info "Icons" icons
info "Terminal" term
info "Terminal Font" termfont
info "CPU" cpu
info "GPU" gpu
info "Memory" memory
# info "CPU Usage" cpu_usage
# info "Disk" disk
# info "Battery" battery
# info "Font" font
# info "Song" song
# info "Local IP" localip
# info "Public IP" publicip
# info "Users" users
# info "Birthday" birthday
info linebreak
info cols
info linebreak
}
.....
```
下面的命令可以显示所有你能在 neofetch 脚本中用的参数和配置值:
```
$ neofetch --help
```
要启用所有的功能和参数来运行程序,你可以用 `--test` 参数:
```
$ neofetch --test
```
要再次显示 ASCII 艺术 logo ,你可以用 `--ascii` 参数 :
```
$ neofetch --ascii
```
这篇文章中,我们向你介绍了一个可以高度定制的、用来收集系统信息并将它显示在终端上的命令行脚本。
如果你有什么问题,或者对这个脚本有什么想法,请在下面留言。
最后但是同样重要的是,如果你知道有类似的脚本,请毫不犹豫地告诉我们,感谢反馈。
在此访问 [neofetch Github 仓库](https://github.com/dylanaraps/neofetch)。
---
via: <http://www.tecmint.com/neofetch-shows-linux-system-information-with-logo>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[Yinux](https://github.com/Yinux) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,014 | 在 Linux 下将 PNG 和 JPG 批量互转的四种方法 | http://www.tecmint.com/linux-image-conversion-tools/ | 2016-12-05T09:46:00 | [
"图片转换",
"convert",
"mogrify"
] | https://linux.cn/article-8014-1.html | 计算机术语中,批处理指的是用一个非交互式的程序来[执行一序列的任务](http://www.tecmint.com/using-shell-script-to-automate-linux-system-maintenance-tasks/)的方法。这篇教程里,我们会使用 Linux 命令行工具,并提供 4 种简单的处理方式来把一些 `.PNG` 格式的图像批量转换成 `.JPG` 格式的,以及转换回来。

虽然所有示例中我们使用的都是 `convert` 命令行工具,但是您也可以使用 `mogrify` 命令来达到同样的效果。
`convert` 命令的语法如下:
```
$ convert 输入选项 输入文件 输出选项 输出文件
```
而 `mogrify` 的为:
```
$ mogrify 选项 输入文件
```
注意:在使用 `mogrify` 命令时,默认情况下源图像文件会被转换后的新文件覆盖掉,您可以使用明确的操作选项来禁止覆盖,具体的选项可以在手册页中查询得到。
下面是把所有 `.PNG` 格式图像批量转换为 `.JPG` 格式的各种实现方式。如果想把 `.JPG` 转换为 `.PNG` 格式,也可使用这些命令,按需修改。
### 1、 使用 `ls` 和 `xargs` 命令来转换 PNG 和 JPG
[ls 命令](10) 可以列出所有的 png 图像文件, `xargs` 使得可以从标准输入构建和执行 `convert` 命令,从而将所有 `.png` 图像转换为 `.jpg` 图像。
```
----------- 从 PNG 转换到 JPG -----------
$ ls -1 *.png | xargs -n 1 bash -c 'convert "$0" "${0%.png}.jpg"'
----------- 从 JPG 转换到 PNG -----------
$ ls -1 *.jpg | xargs -n 1 bash -c 'convert "$0" "${0%.jpg}.png"'
```
关于上面命令选项的说明:
1. `-1` – 告诉 ls 每行列出一个图像名称的选项标识
2. `-n` – 指定最多参数个数,例子中为 1
3. `-c` – 指示 bash 运行给定的命令
4. `${0%.png}.jpg` – 设置新转换的图像文件的名字,`%` 符号用来删除源文件的扩展名
[](http://www.tecmint.com/wp-content/uploads/2016/11/Convert-PNG-to-JPG-in-Linux.png)
*Linux 中 PNG 格式转为 JPG 格式*
我使用 `ls -ltr` 命令按[修改的日期和时间列出所有文件](http://www.tecmint.com/sort-ls-output-by-last-modified-date-and-time/)。
类似的,也可以使用上面的命令要把 `.JPG` 图像转换为 `.PNG` 格式,只需稍微调整就行。
### 2、 使用 GNU 的 `parallel` 命令来转换 PNG 和 JPG
GNU 的 parallel 使用户能够从标准输入并行构建和执行 shell 命令。确保您的系统上安装了 GNU Parallel,否则请使用以下适当的命令进行安装:
```
$ sudo apt-get install parallel [在 Debian/Ubuntu 系统中]
$ sudo yum install parallel [在 RHEL/CentOS 和 Fedora 系统中]
```
安装好 `parallel` 工具后,您就可以运行下面的命令来把所有从标准输入的 `.PNG` 图像转换成 `.JPG` 格式的图像。
```
----------- 从 PNG 转换到 JPG -----------
$ parallel convert '{}' '{.}.jpg' ::: *.png
----------- 从 JPG 转换到 PNG -----------
$ parallel convert '{}' '{.}.png' ::: *.jpg
```
其中:
1. `{}` – 输入行替代符,代替了从输入源读取的完整行。
2. `{.}` – 去除扩展名的输入行。
3. `:::` – 指定输入源的符号,即上面示例的命令行,在这里 *png 或 jpg* 是命令参数。
[](http://www.tecmint.com/wp-content/uploads/2016/11/Convert-PNG-to-JPG-Using-Parallel-Command.png)
*Parallel 命令 – 把所有 PNG 图像转换为 JPG 格式*
或者,您也可以结合 [ls](http://www.tecmint.com/tag/linux-ls-command/) 和 `parallel` 命令来批量转换所有图像,如图所示:
```
----------- 从 PNG 转换到 JPG -----------
$ ls -1 *.png | parallel convert '{}' '{.}.jpg'
----------- 从 JPG 转换到 PNG -----------
$ ls -1 *.jpg | parallel convert '{}' '{.}.png'
```
### 3、 使用 `for` 循环命令来转换 PNG 和 JPG
为了避免编写 shell 脚本的繁琐,你可以从命令行执行 `for` 循环语句,如下所示:
```
----------- 从 PNG 转换到 JPG -----------
$ bash -c 'for image in *.png; do convert "$image" "${image%.png}.jpg"; echo “image $image converted to ${image%.png}.jpg ”; done'
----------- 从 JPG 转换到 PNG -----------
$ bash -c 'for image in *.jpg; do convert "$image" "${image%.jpg}.png"; echo “image $image converted to ${image%.jpg}.png ”; done'
```
对上面的命令所使用的选项参数的描述:
1. `-c` 允许执行包括在单引号中的循环语句。
2. `image` 变量是目录中的图像名的数量记数器。
3. 对于每个转换操作,在 `$image` 转换为 `${image%.png}.jpg` 这行中,[echo 命令](http://www.tecmint.com/echo-command-in-linux/)通知用户 png 图像已经转换为 jpg 格式,反之亦然。
4. `${image%.png}.jpg` 语句创建了转换后的图像名字,其中 `%` 表示去除源图像文件的扩展名。
[](http://www.tecmint.com/wp-content/uploads/2016/11/Convert-PNG-to-JPG-Using-for-loop-Command.png)
*for 循环语句 – 从 PNG 转换到 JPG 格式*
### 4、 使用 Shell 脚本来转换 PNG 和 JPG
如果你不想像前面的例子那样让你的命令行变得邋遢的话,可以写一个小脚本,如下所示:
注意:适当地交换 `.png` 和 `.jpg` 扩展名,如下面的例子所示,从一种格式转换到另一种格式:
```
#!/bin/bash
#convert
for image in *.png; do
convert "$image" "${image%.png}.jpg"
echo “image $image converted to ${image%.png}.jpg ”
done
exit 0
```
把上面的脚本保存为 `convert.sh` 文件,然后使此脚本文件可执行,接着从存有图像文件的目录下执行。
```
$ chmod +x convert.sh
$ ./convert.sh
```
[](http://www.tecmint.com/wp-content/uploads/2016/11/Batch-Image-Convert-Using-Shell-Script.png)
*使用 Shell 脚本来批量图像转换*
总之,我们介绍了一些重要的将 `.PNG` 图像批量转换为 `.JPG` 格式的方法,以及再转回来。如果还想对图像进行一些优化的话, 您可以移步到 [Linux 系统中如何压缩 png 和 jpg 图像](http://www.tecmint.com/optimize-and-compress-jpeg-or-png-batch-images-linux-commandline/)这篇指导文章。
您可以给我们分享一些包括 Linux 命令行工具在内的把图像从一种格式转成另一种格式的方式方法,或者在下面的评论部分畅所欲言。
---
via: <http://www.tecmint.com/linux-image-conversion-tools/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[runningwater](https://github.com/runningwater) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,015 | 在 CentOS 和 RHEL 系统上安装或自动更新安全补丁 | http://www.tecmint.com/auto-install-security-patches-updates-on-centos-rhel/ | 2016-12-06T11:21:00 | [
"更新",
"安全补丁"
] | https://linux.cn/article-8015-1.html | 在 Linux 系统上,其中一个最重要的需求就是保持定期更新最新的安全补丁,或者为相应的 Linux 版本更新可用的安全补丁。
在之前的文章中,我们分享了[如何在 Debian 和 Ubuntu 系统上自动安装安全更新](/article-8060-1.html),在这篇文章中,我们将分享如何在 CentOS/RHEL 7/6 版本中设置在需要时自动更新重要的安全补丁。

和它同一家族的其它 Linux 版本(Fedora 或 Scientific Linux)中可以用类似的方法进行配置。
### 在 CentOS/RHEL 系统上配置自动安全更新
在 CentOS/RHEL 7/6 系统上,你需要安装下面的安装包:
```
# yum update -y && yum install yum-cron -y
```
### 在 CentOS/RHEL 7 系统上启用自动安全更新
安装完成以后,打开 `/etc/yum/yum-cron.conf`,然后找到下面这些行内容,你必须确保它们的值和下面展示的一样
```
update_cmd = security
update_messages = yes
download_updates = yes
apply_updates = yes
```
第一行表明自动更新命令行应该像这样:
```
# yum --security upgrade
```
而其它的行保证了能够通知并自动下载、安装安全升级。
为了使来自 root@localhost 的通知能够通过邮件发送给同一账户(再次说明,你可以选择其他账户,如果你想这样的话),下面这些行也是必须的。
```
emit_via = email
email_from = root@localhost
email_to = root
```
### 在 CentOS/RHEL 6 上启用自动安全更新
默认情况下, cron 任务被配置成了立即下载并安装所有更新,但是我们可以通过在 `/etc/sysconfig/yum-cron` 配置文件中把下面两个参数改为 `yes`,从而改变这种行为。
```
# 不要安装,只做检查(有效值: yes|no)
CHECK_ONLY=yes
# 不要安装,只做检查和下载(有效值: yes|no)
# 要求 CHECK_ONLY=yes(先要检查后才可以知道要下载什么)
DOWNLOAD_ONLY=yes
```
为了启用关于安装包更新的邮件通知,你需要把 `MAILTO` 参数设置为一个有效的邮件地址。
```
# 默认情况下 MAILTO 是没有设置的,crond 会将输出发送邮件给自己
# (LCTT 译注:执行 cron 的用户,这里是 root)
# 例子: MAILTO=root
[email protected]
```
最后,打开并启用 `yum-cron` 服务:
```
------------- On CentOS/RHEL 7 -------------
systemctl start yum-cron
systemctl enable yum-cron
------------- On CentOS/RHEL 6 -------------
# service yum-cron start
# chkconfig --level 35 yum-cron on
```
恭喜你,你已经成功的在 CentOS/RHEL 7/6 系统上设置了自动升级。
### 总结
在这篇文章中,我们讨论了如何保持你的服务器定期更新或升级最新的安全补丁。另外,为了保证当新的补丁被应用时你自己能够知道,你也学习了如何配置邮件通知。
如果你有任何关于这篇文章的疑问,请在下面的评论区留下你的问题。我们期待收到你的回复。
---
via: <http://www.tecmint.com/auto-install-security-patches-updates-on-centos-rhel/>
作者:[Gabriel Cánepa](http://www.tecmint.com/author/gacanepa/) 译者:[ucasFL](https://github.com/ucasFL) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,016 | 如何在 Linux 中查找一个文件 | https://www.rosehosting.com/blog/linux-find-file/ | 2016-12-06T13:46:00 | [
"查找",
"文件"
] | https://linux.cn/article-8016-1.html | 
对于新手而言,在 Linux 中使用命令行可能会非常不方便。没有图形界面,很难在不同文件夹间浏览,找到需要的文件。本篇教程中,我会展示如何在 Linux 中查找特定的文件。
第一步要做的是**[通过 SSH 连接到你的 Linux](https://www.rosehosting.com/blog/connect-to-your-linux-vps-via-ssh/)**。在 Linux 中查找文件有两种方法。一种是使用 `find` 命令,另外一种是使用 `locate` 命令。我们先看第一种。
### find 命令
使用 **Linux find 命令**可以用不同的搜索标准如名字、类型、所属人、大小等来搜索目录树。基本语法如下:
```
# find path expression search-term
```
下面是使用 find 命令根据文件名来查找特定文件的一个例子:
```
# find -name test.file
```
命令会搜索整个目录树来查找名为 `test.file` 的文件,并且会提供其存放位置。你可以使用你 Linux 上一个存在的文件名来尝试一下。
find 命令有时会花费几分钟来查找整个目录树,尤其是如果系统中有很多文件和目录的话。要显著减少时间,你可以指定搜索的目录。比如,如果你知道 `/var` 中存在 `test.file`,那就没有必要搜索其它目录。这样,你可以使用下面的命令:
```
# find /var -name test.file
```
find 还可以根据时间、大小、所属人、权限等选项搜索文件。要了解更多关于这些选项的信息,你可以使用查看\*\* Linux find 命令\*\*的手册。
```
# man find
```
### locate 命令
要在Linux中使用`locate`命令,首先需要安装它。
如果你正在使用 Ubuntu,运行下面的命令来安装 locate:
```
# apt-get update
# apt-get install mlocate
```
如果你使用的是 CentOS ,运行下面的命令来安装 locate:
```
# yum install mlocate
```
locate 是一种比 find 更快的方式,因为它在数据库中查找文件。要更新搜索数据库,运行下面的命令:
```
# updatedb
```
使用 locate 查找文件的语法:
```
# locate test.file
```
就像 find 命令一样,locate 也有很多选项来过滤输出。要了解更多你可以查看**Linux Locate 命令**的手册。
```
# man locate
```
如果你喜欢这篇文件,请使用左边的按钮分享到社交网络上,或者在下面留言,谢谢。
---
via: <https://www.rosehosting.com/blog/linux-find-file/>
作者:[RoseHosting](https://www.rosehosting.com/blog/linux-find-file/) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Linux find file command explained. Finding files using the command line on a Linux machine could be very uncomfortable experience, especially for the beginners. Without a GUI it is very difficult to navigate through the directories and find the files you need. In this tutorial, we will show you how to find a specific file in Linux, using the command line.
The first thing your need to do is to [connect to your Linux VPS via SSH](https://www.rosehosting.com/blog/connect-to-your-linux-vps-via-ssh/). There are two common ways to search for a file under Linux. The one way is to use the `find`
command and the other way is to use the `locate`
command. Let’s start with the former.
## 1. Linux Find File Command
The **Linux find file command** allows you to search the directory tree using various search criteria such as name, type, ownership, size etc. This is the basic syntax:
# find path expression search-term
Here is a brief example on how to use the Linux find command to find a specific file by its name:
# find -name test.file
The command will search the entire directory tree for a file named `test.file`
and will provide you with the location. You can try using a name of a file that actually exists on your Linux VPS.
Sometimes it may take few minutes for the find command to search the entire directory tree, especially if there are many files and directories on your system. To save a significant amount of time you can specify the searching directory. For example, if you know that the `test.file`
is somewhere in the `/var`
directory, there is no need to search other directories. Therefore, you can use the command below:
# find /var -name test.file
There is also an option to search for a file by time, size, ownership, permissions etc. For more information about these options, you can check the **Linux find file command** man page.
# man find
## 2. Locate File command
In order to be able to use the Linux `locate`
command, you need to install it first.
If you are using an [Ubuntu VPS](https://www.rosehosting.com/ubuntu-hosting.html), run the following commands to install locate:
# apt-get update # apt-get install mlocate
If you are using a [CentOS VPS](https://www.rosehosting.com/centos-hosting.html), run the following command to install locate:
# yum install mlocate
Locate is a faster option to find a file since it searches for the files in a database. To update the search databases run the following command:
# updatedb
To find files in Linux with locate, use the following syntax:
# locate test.file
Just like with the find command, there are many options to filter the search output. To learn more about this you can check the **Linux locate command** man page.
# man locate
Of course, you don’t have to use the Linux find file, if you use one of our [Linux hosting services](https://www.rosehosting.com), in which case you can simply ask our expert Linux admins to look and find the files on Linux for you. They are available 24×7 and will take care of your request immediately. For more updates, you might want to consider reading [Find Large Files in Linux](https://www.rosehosting.com/blog/find-large-files-linux/).
PS. If you liked this post on how to use the Linux find file command, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks. |
8,017 | 安卓编年史(12):Android 2.1——动画的大发现(以及滥用)时代 | http://arstechnica.com/gadgets/2016/10/building-android-a-40000-word-history-of-googles-mobile-os/12/ | 2016-12-06T17:25:00 | [
"Android",
"安卓编年史"
] | https://linux.cn/article-8017-1.html | 
### Android 2.1——动画的大发现(以及滥用)时代
安卓 2.1 随着 Nexus One 的发布一同到来,这时距安卓 2.0 的发布仅仅过了三个月。新系统并不是一个大的更新升级,所以它仍然使用 Éclair(泡芙)这个名称。安卓的开发以一种闻所未闻的步伐急速进行,在过去的 15 个月中,谷歌平均每两个半月就发布一个新版本。
绝大部分得益于威瑞森在市场营销上的努力以及“Droid”产品线,安卓日益流行起来。即便如此,这个系统还是被人觉得丑,这时的安卓工程师看起来就几乎没有接受过正式的设计培训,在安卓 2.1 中,他们尝试着通过在所有能用上的地方大量使用动画效果,想让东西看起来更整齐一点。这么做的结果就是系统看起来拼命想要证明它可以实现动画效果。许多新增的部分感觉更像是技术的演示而不是为了用户体验的改善。

*安卓 2.1 和 2.0 中的锁屏和主屏幕。 [Ron Amadeo 供图]*
安卓 2.0 的旋转拨号式锁屏在仅仅在一个版本之后就被踢到路边去了,取而代之的是和来电界面使用的相同的拉动式标签式解锁。锁屏时钟尝试使用了一种独特的安卓字体,但是相比其它字体来说,它真是丑得可以。
安卓 2.1 最大的特色之一是“动态壁纸”——可互动的或是动态图片可以被设置为壁纸。默认的动态壁纸是个灰色正方形组成的大方阵,不断有蓝色,红色,黄色以及绿色的光点拖着尾巴穿越屏幕。点击屏幕会使光点以你点击的位置为中心向四个方向射出。尽管动态壁纸看起来很棒(并且相对 iPhone 而言是个独特的特性),但动画背景对电池和处理器而言可不是什么好事。它似乎让整个系统的运行都变得有点慢了。
在主屏幕上,默认的谷歌搜索小部件周围有了更多空间,并且现在它位于所在行的正中央。页面指示器现在出现在屏幕底部的左右角落,主屏幕的页数也从 3 页变成了 5 页。底部的应用抽屉标签被替换为一个正方形方阵组成的图标,这个(对应用列表的)暗喻直到今天谷歌也还在使用。

*图片展示了安卓 2.1 和 2.0 中的应用抽屉设计以及应用的选择。 [Ron Amadeo 供图]*
和新应用抽屉图标一同到来的还有全新的应用抽屉。应用抽屉不再是以前从屏幕底部上拉的带标签容器的样子,新界面显示为一个全屏界面。原先的碳纤维编织纹理被去掉了,变成了一个纯黑背景——这个改变会一直持续到 KitKat。
谷歌决定添加一个浮动的、半透明的 home 图标到应用抽屉的底部,好让人们方便地退出全屏的应用列表界面。这个可以看作是安卓 4.0 中引入的虚拟 home 键的前身。
应用抽屉同样有个俗气的图形效果。在滚动的时候,在应用列表顶部和底部的图标会向内弯曲并且看起来像是向手机深处移动一样,有点像星球大战开场的滚动字幕。
应用的图标也有不多的改变。“Amazon MP3”和“Alarm Clock”(闹钟)都去掉了前面那个单词,然后他们就从按字母排序的列表的前两个位置退了下来。出现了两个新的应用:新闻和天气,以及 Google Voice,这是谷歌的通信服务。由于 Nexus One 不是威瑞森的定制机,威瑞森的可视语音邮件被去掉了。

*修改后的时钟应用。 [Ron Amadeo 供图]*
不止是名称的更改,时钟应用还迎来了整体上的重制。点击时钟快捷方式不再会打开闹钟页面;取而代之的是去到“桌面时钟”界面(上方左图),它带有一个和壁纸一致的背景。时钟使用和锁屏一样的字体,并从新的新闻和天气应用中获取天气。
新的闹钟页面清除了许多旧版本中奇怪的设计。模拟时钟和可选择的时钟样式已经不见了。复选框已经被一个带绿色亮光的开关所取代,它比“灰色勾选/绿色勾选”更容易理解。尽管可能从快照很难看出来,旧的闹钟设计在时间旁同时显示 AM 和 PM。2.1 的设计里取消了这一项,只显示相关的 AM/PM 标记。底部放置了一个数字时钟,点击时钟图标会将你带回桌面时钟界面。

*安卓 2.1 和 2.0 中的相册和单独图片查看界面。 [Ron Amadeo 供图]*
谷歌想要改进安卓外观的欲望在 2.1 的相册中最为明显,这里几乎都是大量使用的动画效果和半透明。当应用打开的时候,单独的图片从屏幕顶部飞下并且打乱成小堆组成相册。当打开相册的时候,图片堆各自分离,照片滑开形成方阵的形式。所有你触摸的东西会弹开,压缩,以及拉伸,就像是果冻的弹簧片一样。
相册这里没有一个“标准”的背景。它会从屏幕上随机选择一张图片并深度模糊,然后作为背景图片使用。当这张图片滑出屏幕显示范围后,它会重新选择一张背景图片,所以背景色调总是会和你的图片相匹配。
屏幕的左上角放置了面包屑导航栏。它显示你当前的位置,以及你所在位置和主界面之间的任何文件夹——它可以被看作是在安卓 3.0 中即将推出的“向上”按钮的前身。在右上角是一个相机的链接,这还留着相同的在安卓 1.6 中登场的人造皮革设计——两个设计截然不同。
而相机是另一个奇怪的、一次性的设计,从来没有哪个安卓应用间的随意的 UI 设计差距能有和新的相册应用间这么明显。它并没有采用安卓的按钮、菜单、或任何现有的 UI 规范。它甚至在每个界面隐藏了状态栏——你几乎不能分辨出你正在盯着的是安卓。
在单张照片查看视图,你终于可以在图片之间滑动切换,从而去掉了短粗的左右箭头。出于某种原因,这个界面并没有颜色匹配的背景。它是应用中唯一一个背景为黑色的部分。缩放控制在右上方(仍然没有两指捏合缩放),可用命令沿着屏幕的底部排成一行。点击“菜单”按钮(虚拟或实体键)并不会像所有其他的应用一样出现一个 2×3 格的方阵——仅仅是底部的一行选项从两个变成了另外三个选项。

*充满动画效果的相册应用。 [Ron Amadeo 供图]*
上面第一张图片,显示了一个相册视图。大型相册的话你可以水平滚动,或使用在屏幕底部的快速滚动条。长按图片(虽然有点奇怪,或者可以按实体菜单按钮)会弹出一个“复选框”界面,这时你可以点击几张照片同时选中它们。你选中照片之后,你可以批量分享、删除或旋转照片。
这个界面和接下来的单张照片查看界面的菜单是半透明对话气泡式的,点击各个按钮时它们会跳出来。再重复一遍,这和你所看到的正常的安卓体验规范大相径庭。相册还是第一个拥有越界效果(overscroll)的应用之一。当你到达照片墙的底部时,整个界面会向滚动的方向扭曲。
2.1 的相册是第一个能同时显示您云存储的 Picasa 照片以及本地照片的客户端。这些照片缩略图的左下角有白色相机快门图标。这后来成为了 Google+ Photos。
之前或之后任何安卓应用程序看起来都不像这个相册。有很好的理由解释这是为什么——它不是谷歌做的!这个应用外包给了 Cooliris,他们看样子并没有打算花费精力遵循任何一条现有的安卓 UI 规范。尽管应用是可用的,所有的动画和效果使它看起来像是只注重风格而不注重实质的产物。

*“新闻和天气”应用展示了……新闻和天气。 [Ron Amadeo 供图]*
来比较下相册应用和另一个全新的安卓 2.1 应用:新闻和天气。相册是个充满透明动画效果的汇聚,而新闻和天气则全是深色渐变和对比色。这个应用提供了桌面时钟的天气显示,它甚至还带着一个主屏幕小部件。第一张图显示的是当前位置的天气和六天的预报。沿着屏幕顶部排列着一些标签,城市名称旁有个小小的“i”按钮,点击它会打开温度和降水图。你可以在图上滑动以得到指定时间的精确温度和降水信息。
这个应用里最大的创新在于可滑动标签,这个想法最终将成为一个标准的安卓 UI 规范。在天气之后是一些可由用户定制的新闻标签,除了点击标签切换之外,你还可以在屏幕上水平滑动,标签也会跟着切换。新闻标签都显示着一个新闻标题列表,它们几乎总是正好截断到你弄不明白这条新闻讲了什么的程度。当你从这个应用打开一个网页时,它并不会启动浏览器。相反,它会在应用内打开新闻,带着个奇怪的白色边框。

*谷歌地图的一些实验性功能,新的小部件设计,Google Voice 里我们能接触到的唯一一个界面,以及新的带标签的音乐界面设计。 [Ron Amadeo 供图]*
安卓 2.1 里的小部件全部经过了重新设计,几乎所有东西都带有黑色渐变,空间利用上也更加合理。时钟变回了一个圆,日历的顶部加上了蓝色,着让它和应用变得更加相似。Google Voice 可以启动,但是登录已经失效了——这是你现在能看到的所有东西了。
人们经常忽视的音乐应用有个小更新。四个按钮的主界面被完全去除,并且在屏幕顶部添加了每个音乐显示模式的标签。这意味着在打开应用的时候,你就能直接看到音乐列表,而不是一个导航页。不同于新闻和天气应用里的标签,这些新增的标签不能滑动切换。

### Android 2.1, update 1——无尽战争的开端
谷歌是第一代 iPhone 的主要合作伙伴——公司为苹果的移动操作系统提供了谷歌地图、搜索,以及 Youtube。在那时,谷歌 CEO 埃里克·施密特是苹果的董事会成员之一。实际上,在最初的苹果发布会上,施密特是在史蒂夫·乔布斯[之后第一个登台的人](http://www.youtube.com/watch?v=9hUIxyE2Ns8#t=3016),他还开玩笑说两家公司如此接近,都可以合并成“AppleGoo”了。
当谷歌开发安卓的时候,两家公司间的关系慢慢变得充满争吵。然而,谷歌很大程度上还是通过拒 iPhone 关键特性于安卓门外,如双指缩放,来取悦苹果。尽管如此,Nexus One 是第一部不带键盘的直板安卓旗舰机,设备被赋予了和 iPhone 相同的外观因素。Nexus One 结合了新软件和谷歌的品牌,这是压倒苹果的最后一根稻草。根据沃尔特·艾萨克森为史蒂夫·乔布斯写的传记,2010 年 1 月在看到了 Nexus One 之后,这位苹果的 CEO 震怒了,说道:“如果需要的话我会用尽最后一口气,以及花光苹果在银行里的 400 亿美元,来纠正这个错误……我要摧毁安卓,因为它完全是偷窃来的产品。我愿意为此发起核战争。”
所有的这些都在秘密地发生,仅在 Nexus One 发布后的几年后才公诸于众。公众们最早在安卓 2.1——推送给 Nexus One 的一个称作 “[2.1 update 1](http://arstechnica.com/gadgets/2010/02/googles-nexus-one-gets-multitouch/)” 的更新,发布后一个月左右捕捉到谷歌和苹果间愈演愈烈的分歧气息。这个更新添加了一个功能,正是 iOS 一直居于安卓之上的功能:双指缩放。
尽管安卓从 2.0 版本开始就支持多点触控 API 了,但系统的默认应用在乔布斯的命令下依然和这项实用的功能划清界限。在关于 Nexus One 的和解会议谈崩了之后,谷歌再也没有理由拒双指缩放于安卓门外了。谷歌给设备推送了更新,安卓终于补上了不足之处。
随着谷歌地图、浏览器以及相册中双指缩放的全面启用,谷歌和苹果的智能手机战争也就此拉开序幕。在接下来的几年中,两家公司会变成死敌。双指缩放功能更新的一个月后,苹果开始了它的征途,起诉了所有使用安卓的公司。HTC、摩托罗拉以及三星都被告上法庭,直到现在都还有一些诉讼还没解决。施密特也辞去了苹果董事会的职务。谷歌地图和 Youtube 被从 iPhone 中移除,苹果甚至开始打造自己的地图服务。今天,这两位选手几乎是 “AppleGoo” 竞赛的唯一选手,涉及领域十分广泛:智能手机、平板、笔记本、电影、TV 秀、音乐、书籍、应用、邮件、生产力工具、浏览器、个人助理、云存储、移动广告、即时通讯、地图以及机顶盒……以及不久它们将会在汽车智能、穿戴设备、移动支付,以及客厅娱乐等进行竞争。
---

[Ron Amadeo](http://arstechnica.com/author/ronamadeo) / Ron 是 Ars Technica 的评论编缉,专注于安卓系统和谷歌产品。他总是在追寻新鲜事物,还喜欢拆解事物看看它们到底是怎么运作的。 [@RonAmadeo](https://twitter.com/RonAmadeo)
---
via: <http://arstechnica.com/gadgets/2016/10/building-android-a-40000-word-history-of-googles-mobile-os/12/>
译者:[alim0x](https://github.com/alim0x) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,018 | Eclipse Che:下一代基于 Web 的 IDE | https://opensource.com/life/16/11/introduction-eclipse-che | 2016-12-07T07:37:00 | [
"Eclipse Che",
"IDE"
] | https://linux.cn/article-8018-1.html | 
即使对于熟练的开发人员,想要去为一个项目贡献代码,正确的安装和配置一个集成开发环境、<ruby> 工作区 <rp> ( </rp> <rt> workspace </rt> <rp> ) </rp></ruby>和构建工具,都是一个十分艰难和浪费时间的任务。[Codenvy](http://codenvy.com/) 的CEO,Tyler Jewell,也面临着这个问题。当他养好了一些小病,又处理了一些管理工作之后,试图建立一个简单的 Java 项目来找回他曾经的编程技能。经过多天的努力,Jewell 的项目依然无法工作,但这就是给予了他灵感。他想做个可以让“任何人,任何时候都可以为安装软件的项目做贡献”的东西。
正是这个想法引发了 [Eclipse Che](http://eclipse.org/che) 的发展。
Eclipse Che 是一个基于 Web 的集成开发环境(IDE)和工作区。Eclipse Che 将工作区与合适的运行时<ruby> 软件环境 <rp> ( </rp> <rt> stack </rt> <rp> ) </rp></ruby>捆绑在一起,全都紧密结合起来。在这些工作空间中的项目具有运行所需的一切工具,开发人员不用做什么事情,只需要创建工作空间时选择正确的软件环境。
Eclipse Che 已经就绪的捆绑软件环境支持绝大多数现代流行语言。现在已经支持 C++、Java、Go、PHP、 Python、 .NET、Node.js、 Ruby on Rails,和 Android 开发等。<ruby> 软件环境库 <rp> ( </rp> <rt> Stack Library </rt> <rp> ) </rp></ruby>提供了多种选择,如果这样还不够,还可以选择创建一个提供自定义的环境的定制软件环境。
Eclipse Che 是一个功能齐全的 IDE,而不是一个基于 Web 的简易文本编辑器。它构建于 Orion 和 JDT 之上。支持<ruby> 智能感知 <rp> ( </rp> <rt> Intellisense </rt> <rp> ) </rp></ruby>和调试,并集成了 Git 和 Subversion 版本控制软件。IDE 甚至可以由多个用户共享,进行结对编程。只需一个 Web 浏览器,开发人员就可以编写和调试他们的代码。但是,如果开发人员更喜欢使用基于桌面的 IDE,也可以使用 SSH 连接到工作空间。
Eclipse Che 底层所采用的主要技术之一是 [Linux 容器](https://opensource.com/resources/what-are-linux-containers) - Docker。工作空间是同样是使用 Docker 构建的,安装 Eclipse Che 的本地副本只需要 Docker 和一个小脚本文件。只需在第一次运行时,第一次运行 `che.sh start` 时,就会下载和运行必需的 Docker 容器。但是,如果你觉得设置 Docker 来安装 Eclipse Che 依然太麻烦,Codenvy 还提供在线托管的方法。甚至,他们为开源项目的每个贡献者都提供了 4GB 的工作区。使用 Codenvy 的托管选项或者其它的在线托管方式,只需要提供一个 URL 给潜在贡献者,就会自动创建一个包含项目代码的工作区,所有这些只需轻轻点击一下。
除了 Codenvy 之外,Eclipse Che 的贡献者还包括微软、红帽、IBM、三星和许多其它的人或组织。很多贡献者正在致力于开发 Eclipse Che 的定制版本以用于其特定用途。例如,三星的 [Artik IDE](http://eclipse.org/che/artik) 项目用于物联网领域。基于 Web 的 IDE 可能会让一些人失业,但 Eclipse Che 提供很多的机会,并且有很多业内的大公司需要,值得一试。
---
via: <https://opensource.com/life/16/11/introduction-eclipse-che>
作者:[Joshua Allen Holm](https://opensource.com/users/holmja) 译者:[Vic020](http://www.vicyu.net/) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | Correctly installing and configuring an integrated development environment, workspace, and build tools in order to contribute to a project can be a daunting or time consuming task, even for experienced developers. Tyler Jewell, CEO of [Codenvy](http://codenvy.com), faced this problem when he was attempting to set up a simple Java project when he was working on getting his coding skills back after dealing with some health issues and having spent time in managerial positions. After multiple days of struggling, Jewell could not get the project to work, but inspiration struck him. He wanted to make it so that "anyone, anytime can contribute to a project with installing software."
It is this idea that lead to the development of [Eclipse Che](http://eclipse.org/che).
Eclipse Che is a web-based integrated development environment (IDE) and workspace. Workspaces in Eclipse Che are bundled with an appropriate runtime stack and serve their own IDE, all in one tightly integrated bundle. A project in one of these workspaces has everything it needs to run without the developer having to do anything more than picking the correct stack when creating a workspace.
The ready-to-go bundled stacks included with Eclipse Che cover most of the modern popular languages. There are stacks for C++, Java, Go, PHP, Python, .NET, Node.js, Ruby on Rails, and Android development. A Stack Library provides even more options and if that is not enough, there is the option to create a custom stack that can provide specialized environments.
Eclipse Che is a full-featured IDE, not a simple web-based text editor. It is built on Orion and the JDT. Intellisense and debugging are both supported, and version control with both Git and Subversion is integrated. The IDE can even be shared by multiple users for paired programming. With just a web browser, a developer can write and debug their code. However, if a developer would prefer to use a desktop-based IDE, it is possible to connect to the workspace with a SSH connection.
One of the major technologies underlying Eclipse Che are [Linux containers](https://opensource.com/resources/what-are-linux-containers), using Docker. Workspaces are built using Docker and installing a local copy of Eclipse Che requires nothing but Docker and a small script file. The first time `che.sh start`
is run, the requisite Docker containers are downloaded and run. If setting up Docker to install Eclipse Che is too much work for you, Codenvy does offer online hosting options. They even provide 4GB workspaces for open source projects for any contributor to the project. Using Codenvy's hosting option or another online hosting method, it is possible to provide a url to potential contributors that will automatically create a workspace complete with a project's code, all with one click.
Beyond Codenvy, contributors to Eclipse Che include Microsoft, Red Hat, IBM, Samsung, and many others. Several of the contributors are working on customized versions of Eclipse Che for their own specific purposes. For example, Samsung's [Artik IDE](http://eclipse.org/che/artik) for IoT projects. A web-based IDE might turn some people off, but Eclipse Che has a lot to offer, and with so many big names in the industry involved, it is worth checking out.
If you are interested in learning more about Eclipse Che, [CheConf 2016](https://eclipse.org/che/checonf/) takes place on November 15. CheConf 2016 is an online conference and registration is free. Sessions start at 11:00 am Eastern time (4:00 pm UTC) and end at 5:30 pm Eastern time (10:30 pm UTC).
## Comments are closed. |
8,019 | 怎样在 Arch Linux 终端上更改 WiFi 密码 | https://www.ostechnix.com/update-wifi-network-password-terminal-arch-linux/ | 2016-12-06T22:04:00 | [
"WiFi",
"Arch"
] | https://linux.cn/article-8019-1.html | 
自从修改了我的路由器的 WiFi 网络密码后,我的 Arch Linux 测试机就不能连接到网络了。由于我的 Arch Linux 测试机没有图形化桌面环境,我不得不在终端上更改 WiFi 密码。在图形化操作界面中,更改 WiFi 密码是很容易的。我仅仅需要打开网络管理器,就能很快更改 WiFi 网络密码。但是,我从来没有在 Arch Linux 终端上用命令行来更改 WiFi 密码。我开始在 google 上搜索相关资料,并且在 Arch Linux 论坛找到了一个好的解决办法。如果你也面临同样的问题,读完这篇文章吧,这个方法并没有那么难。
### 在终端更改 WiFi 网络密码
修改了路由器的 WiFi 密码之后,我尝试运行 `wifi-menu` 命令来更新 WiFi 密码,但是它一直报如下错误。
```
sudo wifi-menu
```
它显示了可用的 WiFi 列表。

我的 WiFi 网络名为 Murugs9376。我选中了我的 WiFi 网络,然后在 OK 处按下回车。它没有让我输入新的 WiFi 密码(我以为它会先问我是否密码已经更改),却显示了下面的错误。
```
Interface 'wlp9s0' is controlled by netctl-auto
WPA association/authentication failed for interface 'wlp9s0'
```

在 Arch 发行版上,我没有太多的经验。因此我去了 Arch Linux 论坛希望能找到解决方法。感天谢地,之前有人发了同样问题的帖子并从一位 Arch 老司机那里得到了解决办法。
网络相关的配置文件都是存放在 `/etc/netctl/` 文件夹下。例如,下面是我的 Arch Linux 测试机上该文件夹下的内容:
```
ls /etc/netctl/
Sample Output:
examples ostechnix 'wlp9s0-Chendhan Cell Service' wlp9s0-Pratheesh
hooks wlp9s0 wlp9s0-Murugu9376
interfaces wlp9s0-AndroidAP wlp9s0-none
```

我如果想要更改密码,只需要删除我的 WiFi 网络配置文件 (这里是 `wlp9s0-Murugs9376`) 并且重新运行 `wifi-menu` 命令。
因此,用下面的命令来删除原来的 WiFi 配置文件:
```
sudo rm /etc/netctl/wlp9s0-Murugu9376
```
删除配置文件之后,运行 `wifi-menu` 命令来更新 WiFi 密码。
```
sudo wifi-menu
```
选择 WiFi 网络,并且按回车键。

为新配置文件输入一个新名字。

最后,输入 WiFi 新密码到配置文件中,并且按下回车键。

这样就完成了。现在,我们已经更新了我们的 WiFi 网络密码。像你所看到的一样,在 Arch Linux 终端里面更新 WiFi 密码并不是件很难的事情。任何人都能在几秒钟以内完成它。
如果您觉得这个教程很有帮助,希望您能分享到您的社交网络中来支持我们。
谢谢!
---
via: <https://www.ostechnix.com/update-wifi-network-password-terminal-arch-linux/>
作者:[SK](https://www.ostechnix.com/author/sk/) 译者:[chenzhijun](https://github.com/chenzhijun) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 403 | Forbidden | null |
8,021 | 在 Linux 中找出所有在线主机的 IP 地址 | http://www.tecmint.com/find-live-hosts-ip-addresses-on-linux-network/ | 2016-12-08T08:05:00 | [
"nmap"
] | https://linux.cn/article-8021-1.html | 
你可以在 Linux 的生态系统中找到很多[网络监控工具](https://linux.cn/topic-linux-system-performance-monitoring.html),它们可以为你生成出网络中所有设备的摘要,包括它们的 IP 地址等信息。
然而,实际上有时候你只需要一个简单的命令行工具,运行一个简单的命令就能提供同样的信息。
本篇教程会向你展示如何找出所有连接到给定网络的主机的 IP 地址。这里我们会使用 [Nmap 工具](http://www.tecmint.com/nmap-network-security-scanner-in-kali-linux/)来找出所有连接到相同网络的设备的IP地址。
[Nmap](/article-7960-1.html) (Network Mapper 的简称)是一款开源、强大并且多功能的探查网络的命令行工具,用来[执行安全扫描、网络审计](http://www.tecmint.com/audit-network-performance-security-and-troubleshooting-in-linux/)、[查找远程主机的开放端口](http://www.tecmint.com/find-open-ports-in-linux/)等等。
如果你的系统中还没有安装 Nmap,在你的发行版中运行合适的命令来安装:
```
$ sudo yum install nmap [在基于 RedHat 的系统中]
$ sudo dnf install nmap [在基于Fedora 22+ 的版本中]
$ sudo apt-get install nmap [在基于 Debian/Ubuntu 的系统中]
```
安装完成后,使用的语法是:
```
$ nmap [scan type...] options {target specification}
```
其中,**{target specification}**这个参数可以用**主机名、IP 地址、网络**等来替代。
所以要列出所有连接到指定网络的主机 IP 地址,首先要使用 [ifconfig 命令](http://www.tecmint.com/ifconfig-command-examples/)或者[ip 命令](http://www.tecmint.com/ip-command-examples/)来识别网络以及它的子网掩码:
```
$ ifconfig
或者
$ ip addr show
```

*在 Linux 中查找网络细节*
接下来,如下运行 Nmap 命令:
```
$ nmap -sn 10.42.0.0/24
```
[](http://www.tecmint.com/wp-content/uploads/2016/11/Find-All-Live-Hosts-on-Network.png)
*查找网络中所有活跃的主机*
上面的命令中:
* `-sn` - 是扫描的类型,这里是 ping 方式扫描。默认上,Nmap 使用端口扫描,但是这种扫描会禁用端口扫描。
* `10.42.0.0/24` - 是目标网络,用你实际的网络来替换。
要了解全面的信息,查看 Nmap 的手册:
```
$ man nmap
```
或者不带任何参数直接运行 Nmap 查看使用信息摘要:
```
$ nmap
```
此外,对于有兴趣学习 Linux 安全扫描技术的人,可以阅读 [Nmap in Kali Linux](http://www.tecmint.com/nmap-network-security-scanner-in-kali-linux/) 这篇实践指导。
好了,就是这样了,记得在下面的回复区给我们发送问题或者评论。你也可以跟我们分享其他列出指定网络已连接设备的 IP 地址的方法。
---
via: <http://www.tecmint.com/find-live-hosts-ip-addresses-on-linux-network/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[geekpi](https://github.com/geekpi) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,023 | Fedora 25 Workstation 安装指南 | http://www.tecmint.com/fedora-25-installation-guide/ | 2016-12-08T09:53:00 | [
"Fedora"
] | https://linux.cn/article-8023-1.html | 在这篇教程中,我们将会走完在电脑上安装 Fedora 25 workstation 的每一步。该指南包括整个安装过程中的每一步截图,因此,请认真跟着操作。

#### Fedora 25 Workstation 有哪些新特性?
正如大家所期待的那样,Fedora 的这个最新版本在基础组件上做了很多的改变以及修复大量的 bug,除此之外,它带来了很多新的功能强大的软件,如下所示:
* GNOME 3.22,可以重命名多个文件,重新设计的键盘布局工具以及一些用户界面上的改进。
* 使用 Wayland 代替 X11 系统,以满足现代图形硬件设备。
* 支持 MP3 格式解码。
* Docker 1.12。
* Node.js 6.9.1。
* 支持 Rust 系统编程语言。
* 支持多个版本的 Python 编程语言,包括 Python2.6、2.7、3.3、3.4 和 3.5。
* 不再检查 GNOME Shell 扩展与当前的 GNOME Shell 版本的兼容性等等。
注意:如果电脑上已安装了前一个版本 Fedora 24,或许你可以考虑使用更简单的几个步骤[将 Fedora 24 升级到 Fedora 25](http://www.tecmint.com/upgrade-fedora-24-to-fedora-25-workstation-server/) 以避免全新的安装过程。
### 安装 Fedora 25 Workstation 版本
从下面的链接下载 ISO 系统镜像开始,本安装教程将使用 64 位的镜像来安装。
* [下载 Fedora 25 Workstation 64 位版本](https://download.fedoraproject.org/pub/fedora/linux/releases/25/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-25-1.3.iso)
* [下载 Fedora 25 Workstation 32 位版本](https://download.fedoraproject.org/pub/fedora/linux/releases/25/Workstation/i386/iso/Fedora-Workstation-Live-i386-25-1.3.iso)
下载完 Fedora 25 的系统镜像后,第一步是创建一个可启动设备(DVD 或 USB 设备),使用 [Unetbootin 和 dd 命令](http://www.tecmint.com/install-linux-from-usb-device/)来制作 USB 启动工具,或使用其它你想用的方法也行。
1、 创建完成启动设备后,插入并从该设备(DVD/USB)启动,此时,你应该看到如下图所示的 Fedora Workstation Live 的启动界面。
选择 “Start Fedora-Workstation-Live 25” 选项,然后单点回车。

*Fedora 25 启动菜单*
2、 接下来,你会进入到登录界面,单击“Live System User”以 Live 用户身份进入系统。

*Fedora 25 Live 用户登录*
3、 登入系统后,几秒钟后桌面上会出现下面的欢迎界面,如果你想在安装前试用 Fedora 系统,单击 “Try Fedora”,否则单击 “Install to Hard Disk” 进入到全新安装过程。

*Fedora 25 欢迎界面*
4、 在下面的界面中,选择想要使用的安装语言,然后单击“<ruby> 继续 <rp> ( </rp> <rt> Continue </rt> <rp> ) </rp></ruby>”按钮进入到安装总结页面。

*选择安装语言类型*
5、 下图是安装总结界面,显示默认的区域及系统设置内容。你可以根据自己的位置和喜好来定制区域及系统设置。
从键盘设置开始。单击“<ruby> 键盘 <rp> ( </rp> <rt> KEYBOARD </rt> <rp> ) </rp></ruby>”进入到键盘布局自定义设置界面。

*Fedora 25 安装总结*
6、 在这个界面中,根据你电脑之前的设置使用`+`号来添加你需要的键盘布局,然后单击“<ruby> 完成 <rp> ( </rp> <rt> Done </rt> <rp> ) </rp></ruby>"返回到安装总结界面。

*设置键盘布局*
7、 下一步,单击“<ruby> 时间与日期 <rp> ( </rp> <rt> TIME & DATA </rt> <rp> ) </rp></ruby>”调整系统时间和日期。输入所在地区和城市来设置时区,或者从地图上快速选择。
注意你可以从右上角启用或者停用网络时间同步。设置完系统时间和日期后,单击“<ruby> 完成 <rp> ( </rp> <rt> Done </rt> <rp> ) </rp></ruby>”返回到安装总结界面。

*设置系统时区*
8、 返回到安装总结界面,单击“<ruby> 网络与主机名 <rp> ( </rp> <rt> NETWORK & HOSTNAME </rt> <rp> ) </rp></ruby>”设置网络和主机名。
主机名设置完成后,单击“<ruby> 应用 <rp> ( </rp> <rt> Apply </rt> <rp> ) </rp></ruby>”来检查主机名是否可用,如果可用,单击“<ruby> 完成 <rp> ( </rp> <rt> Done </rt> <rp> ) </rp></ruby>”。

*设置 Fedora 25 的主机名*
9、 此时,在安装总结界面,单击“<ruby> 安装目标 <rp> ( </rp> <rt> INSTALLATION DESTINATION </rt> <rp> ) </rp></ruby>”来为系统文件划分安装空间。
在“<ruby> 其它存储选项 <rp> ( </rp> <rt> Other Storage Options </rt> <rp> ) </rp></ruby>”上选择“<ruby> 我要配置分区 <rp> ( </rp> <rt> I will configure partitioning </rt> <rp> ) </rp></ruby>”来执行手动分区,然后单击 “<ruby> 完成 <rp> ( </rp> <rt> Done </rt> <rp> ) </rp></ruby>” 前进至手动分区界面。

*选择安装位置*
10、 下面是手动分区界面,选择“<ruby> 标准分区 <rp> ( </rp> <rt> Standard Partition </rt> <rp> ) </rp></ruby>”为新的分区模式来安装。

*手动配置分区*
11、 现在通过点`+`号增加一个挂载点来创建一个`/root`分区。
* 挂载点: /root
* 建议容量: 合适即可(比如 100 GB)
之后,单击“<ruby> 增加挂载点 <rp> ( </rp> <rt> Add mount point </rt> <rp> ) </rp></ruby>”添加刚刚创建的分区/挂载点。

*创建新的 Root 分区*
下图展示了 `/root` 分区设置。

*Root 分区设置*
12、 下一步,通过`+`号创建<ruby> 交换分区 <rp> ( </rp> <rt> swap </rt> <rp> ) </rp></ruby>
交换分区是硬盘上的一个虚拟的磁盘空间,用于临时存放那些当前 CPU 不使用的内存数据。
* 挂载点: swap
* 建议容量:合适即可(比如 4 GB)
单击“<ruby> 增加挂载点 <rp> ( </rp> <rt> Add mount point </rt> <rp> ) </rp></ruby>”添加交换分区。

*创建交换分区*

*交换分区设置*
13、 创建完 `root` 分区和 `swap` 分区后,单击“<ruby> 完成 <rp> ( </rp> <rt> Done </rt> <rp> ) </rp></ruby>”按钮来查看这些要对磁盘进行的更改。单击 “<ruby> 接受调整 <rp> ( </rp> <rt> Accept Changes </rt> <rp> ) </rp></ruby>” 允许执行所有的分区调整。

*接受分区调整*
14、 你最后的安装总结内容应该跟下图显示的差不多。单击“<ruby> 开始安装 <rp> ( </rp> <rt> Begin Installation </rt> <rp> ) </rp></ruby>”开始真正安装系统。

*最后的安装总结内容*
15、 系统文件安装开始后,你可以在下面的界面中,创建一个常用的系统用户,并为 root 账号设置密码。

*用户配置设置*
16、 之后,单击“<ruby> ROOT 密码 <rp> ( </rp> <rt> ROOT PASSWORD </rt> <rp> ) </rp></ruby>”来设置 root 账号密码。像之前一样,单击“<ruby> 完成 <rp> ( </rp> <rt> Done </rt> <rp> ) </rp></ruby>”返回到用户配置界面。

*设置 root 账号密码*
17、 之后,在用户配置界面单击“<ruby> 创建用户 <rp> ( </rp> <rt> USER CREATION </rt> <rp> ) </rp></ruby>”按钮来创建一个常用的系统用户。你也可以勾选“<ruby> 将该用户作为管理员 <rp> ( </rp> <rt> Make the user administrator </rt> <rp> ) </rp></ruby>”选项把该用户提升为系统管理员。
再次单击“<ruby> 完成 <rp> ( </rp> <rt> Done </rt> <rp> ) </rp></ruby>”按钮继续。

*创建系统用户账号*
18、 安装过程将会持续一段时间,你可以去休息会了。安装完成之后,单击“<ruby> 退出 <rp> ( </rp> <rt> Quit </rt> <rp> ) </rp></ruby>”重启系统,并弹出你使用的启动设备。终于,你可以登录进入新的 Fedora 25 Workstation 了。

*Fedora 25 登录界面*

*Fedora 25 Workstation 桌面*
就写到这里吧!请在下面提出相关的问题并发表评论。
---
via: <http://www.tecmint.com/fedora-25-installation-guide/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[rusking](https://github.com/rusking) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,024 | Linux 下清空或删除大文件内容的 5 种方法 | http://www.tecmint.com/empty-delete-file-content-linux/ | 2016-12-09T08:53:00 | [
"文件",
"清空"
] | https://linux.cn/article-8024-1.html | 在 Linux 终端下处理文件时,有时我们想直接清空文件的内容但又不必使用任何 [**Linux 命令行编辑器**](http://www.tecmint.com/linux-command-line-editors/) 去打开这些文件。那怎样才能达到这个目的呢?在这篇文章中,我们将介绍几种借助一些实用的命令来清空文件内容的方法。

**注意:**在我们进一步深入了解这些方法之前,请记住: 由于[**在 Linux 中一切皆文件**](http://www.tecmint.com/explanation-of-everything-is-a-file-and-types-of-files-in-linux/),你需要时刻注意,确保你将要清空的文件不是重要的用户文件或者系统文件。清空重要的系统文件或者配置文件可能会引发严重的应用失败或者系统错误。
前面已经说道,下面的这些方法都是从命令行中达到清空文件的目的。
**提示:**在下面的示例中,我们将使用名为 `access.log` 的文件来作为示例样本。
### 1. 通过重定向到 Null 来清空文件内容
清空或者让一个文件成为空白的最简单方式,是像下面那样,通过 shell 重定向 `null` (不存在的事物)到该文件:
```
# > access.log
```

*在 Linux 下使用 Null 重定向来清空大文件*
### 2. 使用 ‘true’ 命令重定向来清空文件
下面我们将使用 `:` 符号,它是 shell 的一个内置命令,等同于 `true` 命令,它可被用来作为一个 no-op(即不进行任何操作)。
另一种清空文件的方法是将 `:` 或者 `true` 内置命令的输出重定向到文件中,具体如下:
```
# : > access.log
或
# true > access.log
```

*使用 Linux 命令清空大文件*
### 3. 使用 cat/cp/dd 实用工具及 /dev/null 设备来清空文件
在 Linux 中, `null` 设备基本上被用来丢弃某个进程不再需要的输出流,或者作为某个输入流的空白文件,这些通常可以利用重定向机制来达到。
所以 `/dev/null` 设备文件是一个特殊的文件,它将清空送到它这里来的所有输入,而它的输出则可被视为一个空文件。
另外,你可以通过使用 [**cat 命令**](http://www.tecmint.com/13-basic-cat-command-examples-in-linux/) 显示 `/dev/null` 的内容然后重定向输出到某个文件,以此来达到清空该文件的目的。
```
# cat /dev/null > access.log
```

*使用 cat 命令来清空文件*
下面,我们将使用 [**cp 命令**](http://www.tecmint.com/progress-monitor-check-progress-of-linux-commands/) 复制 `/dev/null` 的内容到某个文件来达到清空该文件的目的,具体如下所示:
```
# cp /dev/null access.log
```

*使用 cp 命令来清空文件*
而下面的命令中, `if` 代表输入文件,`of` 代表输出文件。
```
# dd if=/dev/null of=access.log
```

*使用 dd 命令来清空文件内容*
### 4. 使用 echo 命令清空文件
在这里,你可以使用 [**echo 命令**](http://www.tecmint.com/echo-command-in-linux/) 将空字符串的内容重定向到文件中,具体如下:
```
# echo "" > access.log
或者
# echo > access.log
```

*使用 echo 命令来清空文件*
**注意:**你应该记住空字符串并不等同于 `null` 。字符串表明它是一个具体的事物,只不过它的内容可能是空的,但 `null` 则意味着某个事物并不存在。
基于这个原因,当你将 [echo 命令](http://www.tecmint.com/echo-command-in-linux/) 的输出作为输入重定向到文件后,使用 [cat 命令](http://www.tecmint.com/13-basic-cat-command-examples-in-linux/) 来查看该文件的内容时,你将看到一个空白行(即一个空字符串)。
要将 null 做为输出输入到文件中,你应该使用 `-n` 选项,这个选项将告诉 echo 不再像上面的那个命令那样输出结尾的那个新行。
```
# echo -n "" > access.log
```

*使用 Null 重定向来清空文件*
### 5. 使用 truncate 命令来清空文件内容
`truncate` 可被用来[**将一个文件缩小或者扩展到某个给定的大小**](http://www.tecmint.com/parted-command-to-create-resize-rescue-linux-disk-partitions/)。
你可以利用它和 `-s` 参数来特别指定文件的大小。要清空文件的内容,则在下面的命令中将文件的大小设定为 0:
```
# truncate -s 0 access.log
```

*在 Linux 中截断文件内容*
我要介绍的就是这么多了。在本文中,我们介绍了几种通过使用一些简单的命令行工具和 shell 重定向机制来清除或清空文件内容的方法。
上面介绍的这些可能并不是达到清空文件内容这个目的的所有可行的实践方法,所以你也可以通过下面的评论栏告诉我们本文中尚未提及的其他方法。
---
via: <http://www.tecmint.com/empty-delete-file-content-linux/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[FSSlc](https://github.com/FSSlc) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,025 | 不常见但是很有用的 gcc 命令行选项(一) | https://www.howtoforge.com/tutorial/uncommon-but-useful-gcc-command-line-options/ | 2016-12-09T09:51:00 | [
"调试",
"编译",
"gcc"
] | https://linux.cn/article-8025-1.html | 软件工具通常情况下会提供多个功能以供选择,但是如你所知的,不是所有的功能都能被每个人用到的。公正地讲,这并不是设计上的错误,因为每个用户都会有自己的需求,他们只在他们的领域内使用该工具。然而,深入了解你所使用的工具也是很有益处的,因为你永远不知道它的某个功能会在什么时候派上用场,从而节省下你宝贵的时间。

举一个例子:编译器。一个优秀的编程语言编译器总是会提供极多的选项,但是用户一般只知道和使用其中很有限的一部分功能。更具体点来说,比如你是 C 语言开发人员,并将 Linux 作为你的开发平台,那么你很有可能会用到 gcc 编译器,这个编译器提供了 (几乎) 数不清的命令行选项列表。
你知道,你可以让 gcc 保存每个编译阶段的输出吗?你知道用于生成警告的 `-Wall` 选项,它并不会包含一些特殊的警告吗?gcc 的很多命令行选项都不会经常用到,但是它们在某些特定的情况下会变得非常有用,例如,当你在调试代码的时候。
所以在本文中,我们会介绍这样的几个选项,提供所有必要的细节,并通过简单易懂的例子来解释它们。
但是在开始前,请注意本文中所有的例子所使用的环境:基于 Ubuntu 16.04 LTS 操作系统,gcc 版本为 5.4.0。
### 在每个编译阶段查看中间代码的输出
你知道在通过 gcc 编译 c 语言代码的时候大体上共分为四个阶段吗?分别为预处理 -> 编译 -> 汇编 -> 链接。在每个阶段之后,gcc 都会产生一个将移交给下一个阶段的临时输出文件。但是生成的都是临时文件,因此我们并不能看到它们——我们所看到的只是我们发起编译命令,然后它生成的我们可以直接运行的二进制文件或可执行文件。
但是比如说在预处理阶段,如果调试时需要查看代码是如何进行处理的,你要怎么做呢?好消息是 gcc 编译器提供了相应的命令行选项,你可以在标准编译命令中使用这些选项获得原本被编译器删除的中间文件。我们所说的选项就是`-save-temps`。
以下是 [gcc 手册](https://linux.die.net/man/1/gcc)中对该选项的介绍:
>
> 永久存储临时的中间文件,将它们放在当前的文件夹下并根据源文件名称为其命名。因此,用 `-c -save-temps` 命令编译 foo.c 文件时会生成 foo.i foo.s 和 foo.o 文件。即使现在编译器大多使用的是集成的预处理器,这命令也会生成预处理输出文件 foo.i。
>
>
> 当与 `-x` 命令行选项结合使用时,`-save-temps` 命令会避免覆写与中间文件有着相同扩展名的输入源文件。相应的中间文件可以通过在使用 `-save-temps` 命令之前重命名源文件获得。
>
>
>
以下是怎样使用这个选项的例子:
```
gcc -Wall -save-temps test.c -o test-exec
```
下图为该命令的执行结果,验证其确实产生了中间文件:

因此,在截图中你所看到的 test.i、test.s、 test.o 文件都是由 `-save-temps` 选项产生的。这些文件分别对应于预处理、编译和链接阶段。
### 让你的代码可调试和可分析
你可以使用专有的工具调试和分析代码。如 [gdb](https://www.gnu.org/software/gdb/) 就是专用于调试的工具,而 [gprof](https://sourceware.org/binutils/docs/gprof/) 则是热门的分析工具。但你知道 gcc 特定的命令行选项也可以让你的代码可调试和可分析吗?
让我们开始调试之路吧!为了能在代码调试中使用 gdb,你需要在编译代码的时候使用 gcc 编译器提供的 `-g` 选项。这个选项让 gcc 生成 gdb 需要的调试信息从而能成功地调试程序。
如果你想要使用此选项,建议您详细阅读 [gcc 手册](https://linux.die.net/man/1/gcc)提供的有关此选项的详细信息——在某些情况下,其中的一些内容可能是至关重要的。 例如,以下是从手册页中摘录的内容:
>
> GCC 允许在使用 `-g` 选项的时候配合使用 `-O` 选项。优化代码采用的便捷方式有时可能会产生意想不到的结果:某些你声明的变量可能不复存在;控制流可能会突然跳转到你未曾预期的位置;一些语句也许不会执行,因为它们已经把常量结果计算了或值已经被保存;一些语句可能会在不同地方执行,因为它们已经被移出循环。
>
>
> 然而优化的输出也是可以调试的。这就使得让优化器可以合理地优化或许有 bug 的代码。
>
>
>
不只是 gdb,使用 `-g` 选项编译代码,还可以开启使用 Valgrind 内存检测工具,从而完全发挥出该选项的潜力。或许还有一些人不知道,mencheck 工具被程序员们用来检测代码中是否存在内存泄露。你可以在[这里](http://valgrind.org/docs/manual/mc-manual.html)参见这个工具的用法。
继续往下,为了能够在代码分析中使用 gprof 工具,你需要使用 `-pg` 命令行选项来编译代码。这会让 gcc 生成额外的代码来写入分析信息,gprof 工具需要这些信息来进行代码分析。[gcc 手册](https://linux.die.net/man/1/gcc) 中提到:当编译你需要数据的源文件时,你必须使用这个选项,当然链接时也需要使用它。为了能了解 gprof 分析代码时具体是如何工作的,你可以转到我们的网站[专用教程](https://www.howtoforge.com/tutorial/how-to-install-and-use-profiling-tool-gprof/)进行了解。
**注意**:`-g` 和 `-pg` 选项的用法类似于上一节中使用 `-save-temps` 选项的方式。
### 结论
我相信除了 gcc 的专业人士,都可以在这篇文章中得到了一些启发。尝试一下这些选项,然后观察它们是如何工作的。同时,请期待本教程系列的[下一部分](https://www.howtoforge.com/tutorial/uncommon-but-useful-gcc-command-line-options-2/),我们将会讨论更多有趣和有用的 gcc 命令行选项。
---
via: <https://www.howtoforge.com/tutorial/uncommon-but-useful-gcc-command-line-options/>
作者:[Ansh](https://twitter.com/howtoforgecom) 译者:[dongdongmian](https://github.com/dongdongmian) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # Uncommon but useful GCC command line options
Software tools usually offer multiple features, but - as most of you will agree - not all their features are used by everyone. Generally speaking, there's nothing wrong in that, as each user has their own requirement and they use the tools within that sphere only. However, it's always good to keep exploring the tools you use as you never know when one of their features might come in handy, saving you some of your precious time in the process.
Case in point: compilers. A good programming language compiler always offers plethora of options, but users generally know and use a limited set only. Specifically, if you are C language developer and use Linux as your development platform, it's highly likely that you'd using the gcc compiler, which offers an endless list of command line options.
Do you know that if you want, you can ask gcc to save the output at each stage of the compilation process? Do you know the *-Wall* option that you use for generating warnings doesn't cover some specific warnings? There are many command line gcc options that are not commonly used, but can be extremely useful in certain scenarios, for example, while debugging the code.
So, in this article, we will cover a couple of such options, offering all the required details, and explaining them through easy to understand examples wherever necessary.
*But before we move ahead, please keep in mind that all the examples, command, and instructions mentioned in this tutorial have been tested on Ubuntu 16.04 LTS, and the gcc version that we've used is 5.4.0.*
* *
## See intermediate output during each compilation stage
Do you know there are, broadly, a total of four stages that your C code goes through when you compile it using the gcc compiler? These are preprocessing, compilation, assembly, and linking. After each stage, gcc produces a temporary output file which is handed over to the next stage. Now, these are all temporary files that are produced, and hence we don't get to see them - all we see is that we've issued the compilation command and it produces the binary/executable that we can run.
But suppose, if while debugging, there's a requirement to see how the code looked after, say, the preprocessing stage. Then, what would you do? Well, the good thing is that the gcc compiler offers a command line option that you can use in your standard compilation command and you'll get those intermediate files that are deleted by the compiler otherwise. The option we're talking about is *-save-temps*.
Here's what the [gcc man page](https://linux.die.net/man/1/gcc) says about this option:
Store the usual "temporary" intermediate files permanently; place
them in the current directory and name them based on the source
file. Thus, compiling foo.c with -c -save-temps produces files
foo.i and foo.s, as well as foo.o. This creates a preprocessed
foo.i output file even though the compiler now normally uses an
integrated preprocessor.
When used in combination with the -x command-line option,
-save-temps is sensible enough to avoid over writing an input
source file with the same extension as an intermediate file. The
corresponding intermediate file may be obtained by renaming the
source file before using -save-temps.
Following is an example command that'll give you an idea on how you can use this option:
gcc -Wall-save-tempstest.c -o test-exec
And this is how I verified that all the intermediate files were indeed produced after the above mentioned command was executed:
So as you can see in the screenshot above, the *test.i*, *test.s*, and *test.o* files were produced by the *-save-temps* option. These files correspond to the preprocessing, compiling, and linking stages, respectively.
## Make your code debugging and profiling ready
There are dedicated tools that let you debug and profile your source code. For example, [gdb](https://www.gnu.org/software/gdb/) is used for debugging purposes, while [gprof](https://sourceware.org/binutils/docs/gprof/) is a popular tool for profiling purposes. But do you know there are specific command line options that gcc offers in order to make your code debugging as well profiling ready?
Let us start with debugging. To be able to use gdb for code debugging, you'll have to compile your code using the *-g* command line option provided the gcc compiler. This option basically allows gcc to produce debugging information that's required by gdb to successfully debug your program.
In case you plan to use this option, you are advised to go through the details the [gcc man page](https://linux.die.net/man/1/gcc) offers on this option - some of that can prove to be vital in some cases. For example, following is an excerpt taken from the man page:
GCC allows you to use -g with -O. The shortcuts taken by optimized
code may occasionally produce surprising results: some variables
you declared may not exist at all; flow of control may briefly move
where you did not expect it; some statements may not be executed
because they compute constant results or their values are already
at hand; some statements may execute in different places because
they have been moved out of loops.
Nevertheless it proves possible to debug optimized output. This
makes it reasonable to use the optimizer for programs that might
have bugs.
Not only gdb, compiling your code using the *-g* option also opens up the possibility of using Valgrind's memcheck tool to its complete potential. For those who aren't aware, memcheck is used by programmers to check for memory leaks (if any) in their code. You can learn more about this tool [here](http://valgrind.org/docs/manual/mc-manual.html).
Moving on, to be able to use gprof for code profiling, you have to compile your code using the *-pg* command line option. It allows gcc to generate extra code to write profiling information, which is required by gprof for code analysis. "You must use this option when compiling the source files you want data about, and you must also use it when linking," the [gcc man page](https://linux.die.net/man/1/gcc) says. To learn more about how to perform code profiling using gprof, head to this [dedicated tutorial](https://www.howtoforge.com/tutorial/how-to-install-and-use-profiling-tool-gprof/) on our website.
**Note**: Usage of both *-g* and *-pg* options is similar to the way the *-save-temps* option was used in the previous section.
## Conclusion
Unless you are a gcc pro, I am sure you learned something new with this article. Do give these options a try, and see how they work. Meanwhile, wait for the [next part](https://www.howtoforge.com/tutorial/uncommon-but-useful-gcc-command-line-options-2/) in this tutorial series where-in we'll discuss more such interesting and useful gcc command line options. |
8,026 | Linux 的实用性 VS 行动主义 | http://www.datamation.com/open-source/linux-practicality-vs-activism.html | 2016-12-10T09:49:00 | [
"自由软件",
"开源软件"
] | https://linux.cn/article-8026-1.html | *我们使用 Linux 是因为它比其他操作系统更实用,还是其他更高级的理由呢?*

运行 Linux 的最吸引人的事情之一就是它所提供的自由。 Linux 社区之间的分野在于我们如何看待这种自由。
对一些人来说,使用 Linux 可以享受到不受供应商限制或避免高昂的软件成本的自由。大多数人会称这个是一个实用性的考虑。而其它用户会告诉你,他们享受的是自由软件的自由。那就意味着拥护支持<ruby> <a href="https://en.wikipedia.org/wiki/Free_software_movement"> 自由软件运动 </a> <rt> Free Software Movement </rt></ruby>的 Linux 发行版,完全避免专有软件和所有相关的东西。
在这篇文章中,我将带你比较这两种自由的区别,以及它们如何影响 Linux 的使用。
### 专有的问题
大多数 Linux 用户有一个共同点,就是他们尽量避免使用专有软件。对像我这样的实用主义的爱好者来说,这意味着我能够控制我的软件支出,以及避免过度依赖特定供应商。当然,我不是一个程序员……所以我对安装软件的调整是十分微小的。但也有一些个别情况,对应用程序的小调整就意味着它要么能工作,要么不能。
还有一些 Linux 爱好者,倾向于避开专有软件,因为他们觉得使用它们是不道德的。通常这里主要的问题是使用专有软件会剥夺或者干脆阻碍你的个人自由。像这些用户更喜欢使用 Linux 发行版和软件来支持 [自由软件理念](https://www.gnu.org/philosophy/free-sw.en.html) 。虽然它与开源的概念相似并经常直接与之混淆,[但它们之间还是有些差异的](https://www.gnu.org/philosophy/free-software-for-freedom.en.html) 。
因此,问题就在这里:像我这样的用户往往将便利性置于纯粹的软件自由的理念之上。不要误会我的意思,像我这样的人喜欢使用符合自由软件理念的软件,但我们也更有可能做出让步(使用专有软件),以完成特定的任务。
这两种类型的 Linux 爱好者都喜欢使用非专有软件的解决方案。但是,自由软件倡导者根本不会去使用专有软件,而实用主义用户会选择具有最佳性能的工具。这意味着,在有些情况下,这些用户会在他们的非专有操作系统上运行专有应用或代码。
最终,这两种类型的用户都喜欢使用 Linux 所提供的非专有解决方案。但是,我们这样做的原因往往会有所不同。有人认为那些不支持自由软件的人是无知的。我不同意这种看法,我认为它是实用方便性的问题。那些喜欢实用方便性的用户根本不关心他们软件的政治问题。
### 实用方便性
当你问起绝大多数的人为什么使用他们现在的操作系统,回答通常都集中于实用方便性。方便性可能体现在“它是我一直使用的系统”,乃至于“它运行了我需要的软件”。 其他人可能进一步解释说,软件对他们使用操作系统的偏好影响不大,而是对操作系统的熟悉程度的问题,最后,还有一些特殊的“商业考虑”或硬件兼容性等问题也导致我们使用这个操作系统而不是另一个。
这可能会让你们中许多人很惊讶,不过如今我运行桌面 Linux 最大的一个原因是由于我熟悉它。即使我能为别人提供 Windows 和 OS X 的支持,实际上我使用这些操作系统时感觉相当沮丧,因为它们根本就不是我习惯的用法。也因此我对那些 Linux 新手表示同情,因为我太懂得踏入陌生的领域是怎样的让人恼火了。我的观点是这样的 —— 熟悉具有价值,而且熟悉加强了实用方便性。
现在,如果我们把它和一个自由软件倡导者的需求来比较,你会发现这种人都愿意学习新的甚至更具挑战性的东西,以避免使用非自由软件。对这种用户,我最赞赏的地方,就是他们坚定的采取少数人选择的道路来坚持他们的原则,在我看来,这是十分值得赞赏的。
### 自由的价值
我不羡慕那些自由软件倡导者的一个地方,就是根据<ruby> <a href="https://en.wikipedia.org/wiki/Free_Software_Foundation"> 自由软件基金会 </a> <rt> Free Software Foundation </rt></ruby>规定的标准,为实现其自由,他们要始终使用 Linux 发行版和硬件而付出的额外工作。这意味着 Linux 内核需要摆脱专有的驱动支持,而且硬件不需要任何专有代码。当然不是不可能的,但确实很难。
一个自由软件倡导者可以达到的最好的情况是硬件是“自由兼容”的。有些供应商,可以满足这一需求,但大多提供的硬件依赖于 Linux 兼容的专有固件。实用主义用户对自由软件倡导者来说是个搅局者。
那么这一切意味着的是,倡导者必须比实用主义的 Linux 爱好者,更加警惕。这本身并不一定是坏事,但如果是打算跳入自由软件的阵营那就要考虑下了。比较而言,实用主义的用户可以不假思索地使用与 Linux 兼容的任何软件或硬件。我不知道你是怎么想的,但在我眼中这样更轻松一点。
### 定义自由软件
这一部分可能会让一部分人不高兴,因为我不相信自由软件只有一种。从我的立场,我认为真正的自由是能够在一个特定情况下在所有可用的数据里,用最适合这个人生活方式的方法来解决。
对我来说,我更喜欢使用能满足我所有需求的 Linux 桌面,这包括使用非专有软件和专有软件。尽管有人认为专有软件限制了我的个人自由,但我必须反驳这一点,因为我有优先使用它的自由,即选择的自由。
或许,这也就是为什么我更认同<ruby> 开源软件 <rt> Open Source Software </rt></ruby>的理想,而不是坚持<ruby> 自由软件运动 <rt> Free Software movement </rt></ruby>的理念。我更愿意和这样的人群在一起,他们不会花时间告诉我,我使用对我最适合的方式却是错误的。根据我的经验,这些开源的人群仅仅是感兴趣去分享自由软件的优点,不带有自由软件的理想主义的激情。
我觉得自由软件的概念很棒。而且对那些需要活跃在软件政治,并向大众指出使用专有软件的缺陷的人来说,我认为 Linux ( [GNU/Linux](https://en.wikipedia.org/wiki/GNU/Linux_naming_controversy) ) 行动是一个不错的选择。而像我这样的实用主义用户可能从自由软件的支持者转向,如本文中所说。
当我介绍 Linux 的桌面时,我富有激情地分享它的实际优点。如果我成功地让他们享受这一经历,我鼓励用户自己去发现自由软件的观点。但我发现大多数人使用 Linux 并不是因为他们想拥抱自由软件,而仅仅是他们想要最好的用户体验。也许只有我是这样的观点,很难说。
你怎么认为呢?你是一个自由软件倡导者吗?也许你倾向于在桌面 Linux 发行版中使用专有软件/代码?那么评论和分享您的 Linux 桌面体验吧!
---
via: <http://www.datamation.com/open-source/linux-practicality-vs-activism.html>
作者:[Matt Hartley](http://www.datamation.com/author/Matt-Hartley-3080.html) 译者:[joVoV](https://github.com/joVoV) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,027 | 如何在 Linux 和 Windows 之间共享 Steam 的游戏文件 | https://itsfoss.com/share-steam-files-linux-windows/ | 2016-12-10T10:21:00 | [
"游戏",
"Steam"
] | https://linux.cn/article-8027-1.html | 
*简介:这篇详细的指南将向你展示如何在 Linux 和 Windows 之间共享 Steam 的游戏文件以节省下载的总用时和下载的数据量。我们将展示给你它是怎样为我们节约了 83% 的数据下载量。*
假如你决心成为一名 Linux 平台上的玩家,并且在 [Steam](http://store.steampowered.com/) 上拥有同时支持 Linux 和 Windows 平台的游戏,或者基于同样的原因,拥有双重启动的系统,则你可以考虑看看这篇文章。
我们中的许多玩家都拥有双重启动的 Linux 和 Windows。有些人只拥有 Linux 系统,但同时拥有当前还没有被 Linux 平台上的 Steam 支持的游戏。所以我们同时保留这两个系统以便我们可以在忽略平台的前提下玩我们喜爱的游戏。
幸运的是 [Linux 游戏](https://itsfoss.com/linux-gaming-guide/)社区应运而生,越来越多在 Windows 平台上受欢迎的 Steam 游戏也发布在 Linux 平台上的 Steam 中。
我们中的许多人喜欢备份我们的 Steam 游戏,使得我们不再苦苦等待游戏下载完成。这些游戏很大程度上是 Windows 平台下的 Steam 游戏。
现在,很多游戏也已经登陆了 [Linux 平台上的 Steam](https://itsfoss.com/install-steam-ubuntu-linux/),例如<ruby> 奇异人生 <rp> ( </rp> <rt> Life is Strange </rt> <rp> ) </rp></ruby>、<ruby> 古墓丽影 2013 <rp> ( </rp> <rt> Tomb Raider 2013 </rt> <rp> ) </rp></ruby>、<ruby> 中土世界:魔多阴影 <rp> ( </rp> <rt> Shadow of Mordor </rt> <rp> ) </rp></ruby>、<ruby> 幽浮:未知敌人 <rp> ( </rp> <rt> XCOM: Enemy Unknown </rt> <rp> ) </rp></ruby>、幽浮 2、<ruby> 与日赛跑 <rp> ( </rp> <rt> Race The Sun </rt> <rp> ) </rp></ruby>、<ruby> 公路救赎 <rp> ( </rp> <rt> Road Redemption </rt> <rp> ) </rp></ruby>、<ruby> 燥热 <rp> ( </rp> <rt> SUPERHOT </rt> <rp> ) </rp></ruby>等等,并且[这份名单一直在增长](https://itsfoss.com/best-linux-games/)。甚至还有<ruby> <a href="https://itsfoss.com/deus-ex-mankind-divided-linux/"> 杀出重围:人类分裂 </a> <rp> ( </rp> <rt> Deus Ex: Mankind Divided </rt> <rp> ) </rp></ruby>和<ruby> <a href="http://www.kotaku.com.au/2016/10/avalanche-studios-mad-max-arrives-on-linux-and-mac-os/"> 疯狂的麦克斯 </a> <rp> ( </rp> <rt> Mad Max </rt> <rp> ) </rp></ruby>!!!在一些游戏的 Windows 版发布之后,现在我们不必再等候多年,而只需等待几月左右,便可以听到类似的消息了,这可是大新闻啊!
下面的实验性方法将向你展示如何使用你现存的任何平台上游戏文件来在 Steam 上恢复游戏的大部分数据。对于某些游戏,它们在两个平台下有很多相似的文件,利用下面例子中的方法,将减少你在享受这些游戏之前的漫长的等待时间。
在下面的方法中,我们将一步一步地尝试利用 Steam 自身的备份与恢复功能或者以手工的方式来达到我们的目的。当涉及到这些方法的时候,我们也将向你展示这两个平台上游戏文件的相同和不同之处,以便你也可以探索并做出你自己的调整。
下面的方法中,我们将使用 Ubuntu 14.04 LTS 和 Windows 10 来执行备份与恢复 Steam 的测试。
### 1、Steam 自身的备份与恢复
当我们尝试使用 Windows 平台上 Steam 中《<ruby> 燥热 <rp> ( </rp> <rt> SUPERHOT </rt> <rp> ) </rp></ruby>》这个游戏的备份(这些加密文件是 .csd 格式)时,Linux 平台上的 Steam 不能识别这些文件,并重新开始下载整个游戏了!甚至在做了验证性检验后,仍然有很大一部分文件不能被 Steam 识别出来。我们在 Windows 上也做了类似的操作,但结果是一样的!


现在到了我们用某些手工的方法来共享 Windows 和 Linux 上的 Steam 游戏的时刻了!
### 2、手工方法
首先,让我们先看看 Linux 下这些游戏文件所处的位置(用户目录在 /home 中):
这是 Linux 平台上 Steam 游戏的默认安装位置。 `.local` 和 `.steam` 目录默认情况下是不可见的,你必须将它们显现出来。我们将推荐使用一个自定义的 Steam 安装位置以便更容易地处理这些文件。这里 `SUPERHOT.x86_64` 是 Linux 下原生的可执行文件,与 Windows 中的 `.exe` 文件类似。

下图展示的位置包含我们需要的大部分文件(在 Windows 和 Linux 平台上相同):

下面我们来看看这些 `.acf` 格式的文件。`appmanifest_322500.acf` 便是那个我们需要的文件。编辑并调整这个文件有助于 Steam 识别在 `common` 这个目录下现存的非加密的原始文件备份:

为了确认这个文件是一样的,用编辑器打开这个文件并检查它。我们越多地了解这个文件越好。这个[链接是来自 Steam 论坛上的一个帖子](https://steamcommunity.com/app/292030/discussions/0/357286663676318082/),它展示了这个文件的主要意义。它类似于下面这样:
```
“AppState”
{
“appid” “322500”
“Universe” “1”
“name” “SUPERHOT”
“StateFlags” “4”
“installdir” “SUPERHOT”
“LastUpdated” “1474466631”
“UpdateResult” “0”
“SizeOnDisk” “4156100762”
“buildid” “1234395”
“LastOwner” “<SteamID>”
“BytesToDownload” “909578688”
“BytesDownloaded” “909578688”
“AutoUpdateBehavior” “0”
“UserConfig”
{
“Language” “english”
}
“MountedDepots”
{
“322503” “1943012315434556837”
}
}
```
在 Linux 平台上卸载游戏后我们再进行测试。现在让我们看看在 Windows 10 上相同的游戏安装目录里包含哪些内容:

我们复制了 `SUPERHOT` 目录和 `.acf` 格式的清单文件(这个文件在 Windows 的 Steam 上格式是一样的)。在复制 `.acf` 文件和游戏目录到 Linux 中 Steam 它们对应的位置时,我们需要确保 Steam 没有在后台运行。
在转移完成之后,我们运行 Steam 并看到了这个:

所以下图显示只需要有 235.5 MB 的文件需要下载,而不是整个 867.4 MB,这意味着超过 70% 的文件已经被 Steam 识别了:) !相对来说,节省了一笔大量的时间开销。当然不同的游戏可能有所不同,但对于那些网速居于平均水平或以下的玩家来说,这种方法绝对值得一试,尤其是考虑到当前那些 40-50 GB 大小的重量级游戏。
我们还进行了其他几种尝试:
* 我们尝试使用 Linux 下原有的清单文件(`.acf`)和来自 Windows 的手工备份文件,但结果是 Steam 重新开始下载游戏。
* 我们看到当我们将 `SUPERHOT_Data` 这个目录中的 `SH_Data` 更换为 Windows 中的对应目录时,同上面的一样,也重新开始下载整个游戏。
### 理解清单目录的一个尝试
清单目录绝对可以被进一步地被编辑和修改以此来改善上面的结果,使得 Steam 检测出尽可能多的文件。
在 Github 上有一个[项目](https://github.com/dotfloat/steam-appmanifest),包含一个可以生成这些清单文件的 python 脚本。任何 Steam 游戏的 AppID 可以从[SteamDB](https://steamdb.info/) 上获取到。知晓了游戏的 ID 号后,你便可以用你喜爱的编辑器以下面的格式创建你自己的清单文件 `appmanifest_<AppID>.acf`。在上面手工方法中,我们可以看到 SUPERHOT 这个游戏的 AppID 是 322500,所以对应的清单文件名应该是 `appmanifest_322500.acf`。
下面以我们知晓的信息来尝试对该文件进行一些解释:
```
“AppState” // 应用(游戏)的状态
“appid” “322500” // 游戏的 AppID
“Universe” “1”
“name” “SUPERHOT” // 游戏的名称
“StateFlags” “4”
“installdir” “SUPERHOT” // 安装目录的名称
“LastUpdated” “1474466631”
“UpdateResult” “0”
“SizeOnDisk” “4156100762”
“buildid” “1234395”
“LastOwner” “<SteamID>” // 唯一的帐号拥有者的 <SteamID>
“BytesToDownload” “909578688” // 将这个数字除以 1073741824(1024 x 1024 x 1024) 便可以计算出还需要下载的数据大小,以 GB 记。
“BytesDownloaded” “909578688” // 已下载数据的大小, 以 Bytes 记。
“AutoUpdateBehavior” “0” // 当这个设为 0 时,该游戏将自动升级。
“UserConfig” // 用户的配置信息
{
“Language” “english”
}
“MountedDepots” // 这个部分大多与游戏的 DLC 相关。
{
“322503” “1943012315434556837”
}
}
```
通过计算下载的数据的大小,你可以将它与 Steam 展现的信息进行比较并进行更多的调整。
假如你知道更多关于清单文件或者手工方式中另外可以改进的方法,请在评论中分享给大家。我们打算去发现更多的关于这些文件格式的信息,当前在官方的 [Valve 开发者社区](https://developer.valvesoftware.com/wiki/Main_Page) 或者 [Steam 论坛](http://steamcommunity.com/discussions/) 上我们还没有发现完整的文档。
至少现在为止,这些便是我们知道的在 Linux 和 Windows 之间分享 Steam 游戏的最好方法了。
---
via: <https://itsfoss.com/share-steam-files-linux-windows/>
作者:[Avimanyu Bandyopadhyay](https://itsfoss.com/author/avimanyu/) 译者:[FSSlc](https://github.com/FSSlc) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | *Brief: This detailed guide shows you how to share Steam game files between Linux and Windows to save download time and data. We will also show you how it saved over 83% of download data for us.*
If you are or want to be a committed Linux gamer and have games on [Steam](http://store.steampowered.com/) that are supported both on Linux and Windows, or have dual booting OSs for the same reason, you might want to consider reading this.
There are many of us gamers who [dual boot Linux with Windows](https://itsfoss.com/guide-install-elementary-os-luna/). Some of us would have had only Linux had it not been for those games which have not yet arrived on Steam for Linux. Hence we keep both of the OSs so that we can play all of our favourite games regardless of the platforms they arrive on.
Thankfully, the [Linux gaming](https://itsfoss.com/linux-gaming-guide/) community is emerging gracefully and we are having more and more popular Steam for Windows games being launched on Steam for Linux.
Many of us like to backup our Steam games so we won’t have to wait for downloads to complete. These collections are a majority of Steam for Windows games.
Now there are so many of these games that have arrived on [Steam for Linux](https://itsfoss.com/install-steam-ubuntu-linux/) as well, such as Life is Strange, Tomb Raider 2013, Shadow of Mordor, XCOM: Enemy Unknown, XCOM 2, Race The Sun, Road Redemption, SUPERHOT,…and the [list grows on](https://itsfoss.com/best-linux-games/)! We also have the [upcoming Deus Ex: Mankind Divided](https://itsfoss.com/deus-ex-mankind-divided-linux/) and [Mad Max](http://www.kotaku.com.au/2016/10/avalanche-studios-mad-max-arrives-on-linux-and-mac-os/)!!! Instead of years, nowadays we only have to wait for months for such titles after Windows releases and this is big news!
This experimental method shows you how to use your existing game files on either platform to restore the majority of the game data files on Steam. This results in having much lesser waiting times for you to enjoy the game as the files are pretty much common between the two OSs as we are going to see in the following example.
In the following method, we show you step by step procedures to attempt both Steam’s own backup and restore feature and the manual way. While we’re at it, we will also show you the similarities and differences in the game file structures between both platforms so that you too can explore and come up with your own tweaks.
In this method, we’ve used Ubuntu 14.04 LTS and Windows 10 to perform the backup and restore Steam tests.
## #1 : Steam’s own backup and restore
When we tried to use a Windows Steam Backup of SUPERHOT on Linux(encrypted files in .csd format), Steam for Linux failed to recognise any of the files and started downloading the entire game from 0 MB! Even on doing a validation check, a vast majority of the files could not be identified by Steam. We also did a similar test on Windows, but the result was the same!
Time for some manual tweaks to share Steam games between Windows and Linux!
## #2 : Manual Method
First, we took a look at the locations(user directory in home) where the game’s files were present on Linux:
This is the default installation location for Steam for Linux. “.local” and “.steam” directories are hidden by default and you would have to unhide them. We would recommend having a custom Steam installation location for easier handling of files. Here “SUPERHOT.x86_64” is the native Linux “executable” unlike a “.exe” file in Windows:
This is the location which contains the majority of the files that we need(common between Windows and Linux):
Here below we see .acf files. “appmanifest_322500.acf” is the one we need. Editing and tweaking this file helps a lot to make Steam recognise existing unencrypted raw file backups present in the “common” directory:
To confirm the same, just open the file with an editor and check. The more we understand this file, the better. Here is [a post on the Steam forums](https://steamcommunity.com/app/292030/discussions/0/357286663676318082/) that shows its major significance. It looks something like this:
It looks something like this:
“AppState”
{
“appid” “322500”
“Universe” “1”
“name” “SUPERHOT”
“StateFlags” “4”
“installdir” “SUPERHOT”
“LastUpdated” “1474466631”
“UpdateResult” “0”
“SizeOnDisk” “4156100762”
“buildid” “1234395”
“LastOwner” “<SteamID>”
“BytesToDownload” “909578688”
“BytesDownloaded” “909578688”
“AutoUpdateBehavior” “0”
“UserConfig”
{
“Language” “english”
}
“MountedDepots”
{
“322503” “1943012315434556837”
}
}
After uninstalling the game on Linux to try the test, we now have a look at the contents of the same game on Windows 10:
We copied the “SUPERHOT” folder and also the manifest(.acf) file(it is created in the same format in Steam for Windows). While copying the .acf file and the directory to their respective locations on Steam for Linux, we made sure Steam wasn’t running in the background.
After the transfer was complete, we ran Steam and saw this:
So instead of the entire 867.4 MB, it now shows 235.5 MB of files to download and that means more than 70% of the files have been identified by Steam :) ! So this is a massive time gain, relatively speaking. While this might vary for different games, of course, this is definitely worth a try for gamers who have below-average/average internet connections especially when the “heavy duty” games are considered that are mostly sized at around 40-50 GB these days.
Other tweaks that we tried:
- We tried using a backup version of the original manifest file for Linux along with the Windows manual backup. But that resulted in Steam downloading the game for the beginning.
- We can see that the data files are in a folder named “SH_Data” on Windows instead of the directory, “SUPERHOT_Data” as on Linux. Changing it did not make any difference in the above result.
## An Attempt to Understand The Manifest File
The manifest file can certainly be edited and tweaked for improving these results to make Steam detect as many files as it can.
There is a [project on Github](https://github.com/dotfloat/steam-appmanifest) which is a python script to generate these manifest files. AppIDs for any Steam game can be obtained from [SteamDB](https://steamdb.info/). By knowing the App ID, you can create your own manifest file with your favourite editor by using the following format: “appmanifest_<AppID>.acf” . In the above manual method, we can see that the AppID for SUPERHOT is 322500. Hence the filename would be appmanifest_322500.acf .
Let’s try to document it within the file according to our best interpretations:
“AppState” // The State of the Application(Game)
{
“appid” “322500” // The Steam Application ID of the Game
“Universe” “1”
“name” “SUPERHOT” // Game Name
“StateFlags” “4”
“installdir” “SUPERHOT” // Installation Directory Name
“LastUpdated” “1474466631”
“UpdateResult” “0”
“SizeOnDisk” “4156100762”
“buildid” “1234395”
“LastOwner” “<SteamID>” // Unique <SteamID> for account owner in numerical format
“BytesToDownload” “909578688” // Divide this number by 1073741824(1024 x 1024 x 1024) to calculate data remaining to download in GB.
“BytesDownloaded” “909578688” // Bytes downloaded
“AutoUpdateBehavior” “0” // The game will update automatically when this is set to 0.“UserConfig” // User Configuration
{
“Language” “english”
}
“MountedDepots” // This section is mostly related to Game DLCs
{
“322503” “1943012315434556837”
}
}
By calculating the data download size in GB/MB, you can compare it with what Steam shows and try more tweaks.
## It saved over 83% of download data
So, I used the method I mentioned here and guess what, it saved me 19.8 GB of data.
I tried it on XCOM 2 game which is of 23.6 GB in size but using this method, I had to download only 3.8 GB.
That’s a little over 83%. Amazing isn’t it?
Please share with us in the comments if you know about more such tips and tricks/suggestions about the manifest file or other improvements/ways for manual workarounds. We are yet to discover a complete documentation for these file formats as it not yet available officially in the [Valve Developer Community](https://developer.valvesoftware.com/wiki/Main_Page) or in [the forums](http://steamcommunity.com/discussions/).
But for now, these are the best ways to share Steam games between Linux and Windows. |
8,028 | 如何在 Linux 中启用 Shell 脚本的调试模式 | http://www.tecmint.com/enable-shell-debug-mode-linux/ | 2016-12-11T12:37:17 | [
"脚本",
"调试"
] | https://linux.cn/article-8028-1.html | 脚本是存储在一个文件的一系列命令。在终端上输入一个个命令,按顺序执行的方法太弱了,使用脚本,系统中的用户可以在一个文件中存储所有命令,反复调用该文件多次重新执行命令。
在学习脚本或写脚本的初期阶段,我们通常从写小脚本或者几行命令的短脚本开始,调试这样的脚本时我们通常无非就是通过观察它们的输出来确保其正常工作。
然而,当我们开始写非常长或上千行命令的高级脚本,例如改变系统设置的脚本,[在网络上执行关键备份](/article-5694-1.html) 等等,我们会意识到仅仅看脚本输出是不足以在脚本中找到 Bug 的!
因此,在 Linux 系列中这篇介绍 Shell 脚本调试, 我们将看看如何启用 Shell 脚本调试,然后在之后的系列中解释不同的 Shell 脚本调试模式以及如何使用它们。

### 如何开始写一个脚本
一个脚本与其它文件的区别是它的首行,它包含 `#!` (She-Bang - [释伴](/article-3664-1.html):定义文件类型)和路径名(解释器路径),通知系统该文件是一个命令集合,将被指定程序(解释器)解释。
下面是不同类型脚本 `首行` 示例:
```
#!/bin/sh [sh 脚本]
#!/bin/bash [bash 脚本]
#!/usr/bin/perl [perl 程序]
#!/bin/awk -f [awk 脚本]
```
注意:如果脚本仅包含一组标准系统命令,没有任何内部 Shell 指令,首行或 `#!` 可以去掉。
### 如何在 Linux 操作系统执行 Shell 脚本
调用一个脚本脚本的常规语法是:
```
$ 脚本名 参数1 ... 参数N
```
另一种可能的形式是明确指定将执行这个脚本的 Shell,如下:
```
$ shell 脚本名 参数1 ... 参数N
```
示例:
```
$ /bin/bash 参数1 ... 参数N [bash 脚本]
$ /bin/ksh 参数1 ... 参数N [ksh 脚本]
$ /bin/sh 参数1 ... 参数N [sh 脚本]
```
对于没有 `#!` 作为首行,仅包含基础系统命令的脚本,示例如下:
```
### 脚本仅包含标准系统命令
cd /home/$USER
mkdir tmp
echo "tmp directory created under /home/$USER"
```
使它可执行并运行,如下:
```
$ chmod +x 脚本名
$ ./脚本名
```
### 启用 Shell 脚本调试模式的方法
下面是主要的 Shell 脚本调试选项:
* `-v` (verbose 的简称) - 告诉 Shell 读取脚本时显示所有行,激活详细模式。
* `-n` (noexec 或 no ecxecution 简称) - 指示 Shell 读取所有命令然而不执行它们,这个选项激活语法检查模式。
* `-x` (xtrace 或 execution trace 简称) - 告诉 Shell 在终端显示所有执行的命令和它们的参数。 这个选项是启用 Shell 跟踪模式。
#### 1、 改变 Shell 脚本首行
第一个机制是改变 Shell 脚本首行,如下,这会启动脚本调试。
```
#!/bin/sh 选项
```
其中, 选项可以是上面提到的一个或多个调试选项。
#### 2、 调用 Shell 调试选项
第二个是使用如下调试选项启动 Shell,这个方法也会打开整个脚本调试。
```
$ shell 选项 参数1 ... 参数N
```
示例:
```
$ /bin/bash 选项 参数1 ... 参数N
```
#### 3、 使用 Shell 内置命令 set
第三个方法是使用内置命令 `set` 去调试一个给定的 Shell 脚本部分,如一个函数。这个机制是重要的,因为它让我们可以去调试任何一段 Shell 脚本。
我们可以如下使用 `set` 命令打开调试模式,其中选项是之前提到的所有调试选项。
```
$ set 选项
```
启用调试模式:
```
$ set -选项
```
禁用调试模式:
```
$ set +选项
```
此外,如果我们在 Shell 脚本不同部分启用了几个调试模式,我们可以一次禁用所有调试模式,如下:
```
$ set -
```
关于启用 Shell 脚本调试模式,先讲这些。正如我们看到的,我们可以调试一整个 Shell 脚本或者特定部分脚本。
在此系列下面的两篇文章中,我们会举例介绍如何使用 Shell 脚本调试选项,进一步了解 <ruby> 详细 <rp> ( </rp> <rt> verbose </rt> <rp> ) </rp></ruby>、<ruby> 语法检查 <rp> ( </rp> <rt> syntax checking </rt> <rp> ) </rp></ruby>、 <ruby> 跟踪 <rp> ( </rp> <rt> tracing </rt> <rp> ) </rp></ruby>调试模式。
更重要的是,关于这个指南,欢迎通过下面评论提出任何问题或反馈。
---
via: <http://www.tecmint.com/enable-shell-debug-mode-linux/>
作者:[Aaron Kili](http://www.tecmint.com/author/aaronkili/) 译者:[imxieke](https://github.com/imxieke) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 组织编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,029 | Arch Linux:DIY 用户的终极圣地,纯粹主义者的最后避难所 | http://www.theregister.co.uk/2016/11/02/arch_linux_taster/ | 2016-12-12T09:23:00 | [
"Arch"
] | https://linux.cn/article-8029-1.html | 让我们翻过一页页 Linux 的新闻报道,你会发现其中对一些冷门的 Linux 发行版的报道数量却出乎预料的多。像 Elementary OS 和 Solus 这样的新发行版因其华丽的界面而被大家所关注,而搭载 MATE 桌面环境的那些系统则因其简洁性而被广泛报道。
感谢像《黑客军团》这样的电视节目,我完全可以预料到关于 Kali Linux 系统的报道很快就会增加。
尽管有很多关于 Linux 系统的报道,然而有一个被广泛使用的 Linux 发行版几乎被大家完全遗忘了:Arch Linux 系统!
关于 Arch 的新闻报道很少的原因有很多,不仅仅是因为它很难安装,而且你还得能在命令行下娴熟地完成各种配置以使其正常运行。更糟糕的是,以大多数的用户的观点来看,其困难是设计之初就没有考虑过其复杂的安装过程会令无数的菜鸟们望而却步。
这的确很遗憾,在我看来,实际上一旦安装完成后,Arch 比我用过的其它 Linux 发行版易用得多。
确实如此,Arch 的安装过程很让人蛋疼。有些发行版的安装过程只需要点击“安装”后就可以放手地去干其它事了。Arch 相对来说要花费更多的时间和精力去完成手动分区、手动挂载、生成 fstab 文件等。但是从 Arch 的安装过程中,我们学到很多。它掀开帷幕,让我们弄明白很多背后的东西。事实上,这层掩盖底层细节的帷幕已经彻底消失了,在 Arch 的世界里,你就是帷幕背后的主宰。
除了大家所熟知的难于安装外,Arch 甚至没有自己默认的桌面环境,虽然这有些让人难以理解,但是 Arch 也因其可定制化而被广泛推崇。你可以自行决定在 Arch 的基础软件包上安装的任何东西。

虽然你可以视之为无限可定制性,但也可以说它完全没有定制化。比如,不像 Ubuntu 系统那样,Arch 中几乎没有修改过或是定制开发过的软件包。Arch 的开发者从始至终都使用的是上游开发者提供的软件包。对于部分用户来说,这种情况非常棒。比如,你可以使用“纯粹”的 GNOME 桌面环境。但是,在某些情况下,定制的补丁可以解决一些上游开发者没有处理的很多的缺陷。
由于 Arch 缺乏一些默认的应用程序和桌面系统,以至于很难形成一致的看法——或者根本不会有什么真正的看法,因为我安装的毫无疑问和你安装的不会一样。我可能选择安装最小化安装配置 Openbox、tint2 和 dmenu,你可能却是使用了最新版的 GNOME 桌面系统。我们都在使用 Arch,但我们的体验却是大相径庭。对于任何发行版来说也有这种情况,但是其它大多数的 Linux 系统都至少有个默认的桌面环境。
然而对 Arch 的看法还是由很多共性的元素的。比如说,我使用 Arch 系统的主要原因是因为它是一个滚动更新的发行版。这意味着两件事情。首先,Arch 会尽可能的使用最新的内核,只要它们可用,被认为稳定就行。这就意味着我可以在 Arch 系统里测试一些在其它 Linux 发行版中难于测试的东西。滚动版另外一个最大的好处就是所有软件更新就绪就会被即时发布出来。这不仅意味着软件包更新速度更快,而且意味着不会出现破坏掉系统的大规模更新。
很多用户因为 Arch 是一个滚动发行版认为它不太稳定。但是在我使用了 9 个多月之后,我并不赞同这种观点。
然而,我从未因为一次升级系统而搞坏过任何东西。我确实有过回滚,因为系统启动分区 /boot 没有挂载,但是后来我发现那完全是自己操作上的失误,我更新后而忘记写入改变。一些暴露出来的缺陷(比如我关于戴尔 XPS 笔记本触摸板又出现以前解决过的问题)很快被修复,并且更新速度要比其它非滚动发行版快得多。总的来说,我认为 Arch 滚动更新的发布模式比其它我在用的发行版要稳定得多。唯一一点我要强调的是查阅维基上的资料,多关注你要更新的内容。
我怀疑 Arch 之所以没那么受欢迎,主要原因就是你必须要随时小心你的操作。盲目的更新 Arch 系统是极其危险的。但是任何一个发行版的更新都有风险,你只是认为它没有风险而已——因为你别无选择。
[Arch 的哲学理念](https://wiki.archlinux.org/index.php/Arch_Linux)是我支持它的另外一个最主要的原因。我认为 Arch 最吸引用户的一点就是:“(Arch)面向的是专业的 Linux 用户,或者是有 DIY 精神,愿意查资料并解决问题的人”。
随着 Linux 进一步纳入主流,开发者们更需要顺利地渡过每一个艰难的技术领域。那些晦涩难懂的专有软件方面的经验恰恰能反映出用户高深的技术能力。
尽管在这个时代听起来有些怪怪的,但是事实上我们很多人更愿意自己动手装配一些东西。在这种情形下,Arch 将会是Linux DIY 用户的终极圣地。
---
via: <http://www.theregister.co.uk/2016/11/02/arch_linux_taster/>
作者:[Scott Gilbertson](http://www.theregister.co.uk/Author/1785) 译者:[rusking](https://github.com/rusking) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 301 | Moved Permanently | null |
8,031 | Linux 内核 4.9 正式发布,这才是有史以来最大的版本 | http://news.softpedia.com/news/linux-kernel-4-9-officially-released-with-support-for-amd-radeon-si-gcn-1-0-gpus-510879.shtml | 2016-12-12T11:05:00 | [
"Linux",
"内核"
] | https://linux.cn/article-8031-1.html | 按照预期计划,Linus Torvalds 在 2016 年 12 月 11 日发布了 Linux 内核 4.9 的正式版本,这次主要带来了一些新的功能和一些驱动更新,当然,还有一些底层的改进。

Linux 内核 4.9 的开发始于 10 月中旬,这次缩短了合并窗口的截止期,以避免出现 4.8 时发生的在最后一刻提交的 PR 导致的内核错误。Linux 内核 4.9 是最新的主线内核,一些滚动发行版,比如 Arch Linux、Solus、openSUSE Tumbleweed 等都会很快将这个内核推送到它们的用户手中。
Linus [称](http://lkml.iu.edu/hypermail/linux/kernel/1612.1/01831.html),“我估计这是我们开发的最大的发布版本,至少从提交数上来说是这样的。从变更的行数看,之前有过更大的版本,但是那些是因为一些特殊的原因(比如说,4.2 因 AMD GPU 寄存器定义文件而增加了大量变更行数。之前也因为一些代码重组而导致了大量变更行数: 3.2 是因为 staging 太大,3.7 是因为解离了自动 uapi 头文件,等等情况 )。以差异来说,4.9 才是最大的。”
### Linux 内核 4.9 的主要变化
Linux 内核 4.9 中带来了许多新的功能,不过最激动人心的可能是对较老的 AMD Radeon 显卡的试验性支持。此外,这个版本也改进了对新的 AMD Radeon GPU 的支持,比如虚拟显示支持和更好的重置支持。对于 Intel GPU,也有对 DMA-BUF 方面的改进。
在这个版本中,对硬件和文件系统方面的改进也很多,涉及到 Btrfs、XFS、F2FS、OverlayFS 的 UBIFS 支持、FUSE 支持 POSIX ACL、OverlayFS SELinux 等方面。
### 相关情况
随着 4.9 内核的正式发布,4.10 (不是 5.x)内核的合并窗口也同时打开了。
此外,前几天发布了 4.8.13 之后仅仅两天,又发布了 4.8.14;而长期支持版本 4.4.38 LTS 也是在前一个版本发布两天后同期发布的。
| 301 | Moved Permanently | null |
8,032 | 不常见但是很有用的 GCC 命令行选项(二) | https://www.howtoforge.com/tutorial/uncommon-but-useful-gcc-command-line-options-2/ | 2016-12-13T08:43:34 | [
"gcc",
"调试",
"编译"
] | https://linux.cn/article-8032-1.html | gcc 编译器提供了几乎数不清的命令行选项列表。当然,没有人会使用过或者精通它所有的命令行选项,但是有一些命令行选项是每一个 gcc 用户都应该知道的 - 即使不是必须知道。它们中有一些很常用,其他一些不太常用,但不常用并不意味着它们的用处没前者大。

在这个系列的文章中,我们集中于一些不常用但是很有用的 gcc 命令行选项,在[第一节](/article-8025-1.html)已经讲到几个这样的命令行选项。
不知道你是否能够回想起,在这个系列教程的第一部分的开始,我简要的提到了开发者们通常用来生成警告的 `-Wall` 选项,并不包括一些特殊的警告。如果你不了解这些特殊警告,并且不知道如何生成它们,不用担心,我将在这篇文章中详细讲解关于它们所有的细节。
除此以外,这篇文章也将涉及与浮点值相关的 gcc 警告选项,以及在 gcc 命令行选项列表变得很大的时候如何更好的管理它们。
在继续之前,请记住,这个教程中的所有例子、命令和指令都已在 Ubuntu 16.04 LTS 操作系统和 gcc 5.4.0 上测试过。
### 生成 -Wall 选项不包括的警告
尽管 gcc 编译器的 `-Wall` 选项涵盖了绝大多数警告标记,依然有一些警告不能生成。为了生成它们,请使用 `-Wextra` 选项。
比如,下面的代码:
```
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=0;
/* ...
some code here
...
*/
if(i);
return 1;
return 0;
}
```
我不小心在 `if` 条件后面多打了一个分号。现在,如果使用下面的 gcc 命令来进行编译,不会生成任何警告。
```
gcc -Wall test.c -o test
```
但是如果同时使用 `-Wextra` 选项来进行编译:
```
gcc -Wall -Wextra test.c -o test
```
会生成下面这样一个警告:
```
test.c: In function ‘main’:
test.c:10:8: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]
if(i);
```
从上面的警告清楚的看到, `-Wextra` 选项从内部启用了 `-Wempty-body` 选项,从而可以检测可疑代码并生成警告。下面是这个选项启用的全部警告标记。
* `-Wclobbered`
* `-Wempty-body`
* `-Wignored-qualifiers`
* `-Wmissing-field-initializers`
* `-Wmissing-parameter-type` (仅针对 C 语言)
* `-Wold-style-declaration` (仅针对 C 语言)
* `-Woverride-init`
* `-Wsign-compare`
* `-Wtype-limits`
* `-Wuninitialized`
* `-Wunused-parameter` (只有和 `-Wunused` 或 `-Wall` 选项使用时才会启用)
* `-Wunused-but-set-parameter (只有和`-Wunused`或`-Wall` 选项使用时才会生成)
如果想对上面所提到的标记有更进一步的了解,请查看 [gcc 手册](https://linux.die.net/man/1/gcc)。
此外,遇到下面这些情况, `-Wextra` 选项也会生成警告:
* 一个指针和整数 `0` 进行 `<`, `<=`, `>`, 或 `>=` 比较
* (仅 C++)一个枚举类型和一个非枚举类型同时出现在一个条件表达式中
* (仅 C++)有歧义的虚拟基底
* (仅 C++)寄存器类型的数组加下标
* (仅 C++)对寄存器类型的变量进行取址
* (仅 C++)基类没有在派生类的复制构建函数中进行初始化
### 浮点值的等值比较时生成警告
你可能已经知道,浮点值不能进行确切的相等比较(如果不知道,请阅读与浮点值比较相关的 [FAQ](https://isocpp.org/wiki/faq/newbie))。但是如果你不小心这样做了, gcc 编译器是否会报出错误或警告?让我们来测试一下:
下面是一段使用 `==` 运算符进行浮点值比较的代码:
```
#include<stdio.h>
void compare(float x, float y)
{
if(x == y)
{
printf("\n EQUAL \n");
}
}
int main(void)
{
compare(1.234, 1.56789);
return 0;
}
```
使用下面的 gcc 命令(包含 `-Wall` 和 `-Wextra` 选项)来编译这段代码:
```
gcc -Wall -Wextra test.c -o test
```
遗憾的是,上面的命令没有生成任何与浮点值比较相关的警告。快速看一下 gcc 手册,在这种情形下可以使用一个专用的 `-Wfloat-equal` 选项。
下面是包含这个选项的命令:
```
gcc -Wall -Wextra -Wfloat-equal test.c -o test
```
下面是这条命令产生的输出:
```
test.c: In function ‘compare’:
test.c:5:10: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
if(x == y)
```
正如上面你所看到的输出那样, `-Wfloat-equal` 选项会强制 gcc 编译器生成一个与浮点值比较相关的警告。
这儿是[gcc 手册](https://linux.die.net/man/1/gcc)关于这一选项的说明:
>
> 这背后的想法是,有时,对程序员来说,把浮点值考虑成近似无限精确的实数是方便的。如果你这样做,那么你需要通过分析代码,或者其他方式,算出这种计算方式引入的最大或可能的最大误差,然后进行比较时(以及产生输出时,不过这是一个不同的问题)允许这个误差。特别要指出,不应该检查是否相等,而应该检查两个值是否可能出现范围重叠;这是用关系运算符来做的,所以等值比较可能是搞错了。
>
>
>
### 如何更好的管理 gcc 命令行选项
如果在你使用的 gcc 命令中,命令行选项列表变得很大而且很难管理,那么你可以把它放在一个文本文件中,然后把文件名作为 gcc 命令的一个参数。之后,你必须使用 `@file` 命令行选项。
比如,下面这行是你的 gcc 命令:
```
gcc -Wall -Wextra -Wfloat-equal test.c -o test
```
然后你可以把这三个和警告相关的选项放到一个文件里,文件名叫做 `gcc-options`:
```
$ cat gcc-options
-Wall -Wextra -Wfloat-equal
```
这样,你的 gcc 命令会变得更加简洁并且易于管理:
```
gcc @gcc-options test.c -o test
```
下面是 gcc 手册关于 `@file` 的说明:
>
> 从文件中读取命令行选项。读取到的选项随之被插入到原始 `@file` 选项所在的位置。如果文件不存在或者无法读取,那么这个选项就会被当成文字处理,而不会被删除。
>
>
> 文件中的选项以空格分隔。选项中包含空白字符的话,可以用一个由单引号或双引号包围完整选项。任何字符(包括反斜杠: '\')均可能通过一个 '\' 前缀而包含在一个选项中。如果该文件本身包含额外的 `@file` 选项,那么它将会被递归处理。
>
>
>
### 结论
在这个系列的教程中,我们一共讲解了 5 个不常见但是很有用的 gcc 命令行选项: `-Save-temps`、`-g`、 `-Wextra`、`-Wfloat-equal` 以及 `@file`。记得花时间练习使用每一个选项,同时不要忘了浏览 gcc 手册上面所提供的关于它们的全部细节。
你是否知道或使用其他像这样有用的 gcc 命令行选项,并希望把它们在全世界范围内分享?请在下面的评论区留下所有的细节。
---
via: <https://www.howtoforge.com/tutorial/uncommon-but-useful-gcc-command-line-options-2/>
作者:[Ansh](https://twitter.com/howtoforgecom) 译者:[ucasFL](https://github.com/ucasFL) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | # Uncommon but useful GCC command line options - part 2
The gcc compiler offers a seemingly never-ending list of command line options. Of course, no body uses or has expertise on all of them, but there are a select bunch that every gcc user should - if not must - know. While some of them are commonly used, others are a bit uncommon but no less useful.
In this article series, we are focusing on some of those uncommon but useful gcc command line options, and have already covered a couple of them in the [part 1](https://www.howtoforge.com/tutorial/uncommon-but-useful-gcc-command-line-options/).
If you recall, in the beginning of the first part of this tutorial series, I briefly mentioned that the *-Wall* option that developers generally use for generating warnings doesn't cover some specific warnings. If you aren't aware of these warnings and have no idea on how to enable them, worry not, as we'll be explaining all that in detail in this article.
Aside from this, we'll also be covering a gcc warning option related to floating point variables, as well as how to better manage the gcc command line options if the list grows large.
*But before we move ahead, please keep in mind that all the examples, command, and instructions mentioned in this tutorial have been tested on Ubuntu 16.04 LTS, and the gcc version that we've used is 5.4.0.*
## Enable warnings that aren't covered by -Wall
While the *-Wall* option of the gcc compiler covers most of the warning flags, there are some that remain disabled. To enable them, use the ** -Wextra** option.
For example, take a look at the following code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=0;
/* ...
some code here
...
*/
if(i);
return 1;
return 0;
}
I accidentally put a semicolon after the 'if' condition. Now, when the code was compiled using the following gcc command, no warning was produced.
gcc -Wall test.c -o test
But when the -Wextra option was used:
gcc -Wall -Wextra test.c -o test
A warning was produced:
test.c: In function ‘main’:
test.c:10:8: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]
if(i);
As clear from the warning shown above, the *-Wextra* option internally enabled the *-Wempty-body* flag, which in turned detected the suspicious code and issued the warning. Here is the complete list of warning flags enabled by this option:
-Wclobbered, -Wempty-body, -Wignored-qualifiers, -Wmissing-field-initializers, -Wmissing-parameter-type (C only), -Wold-style-declaration (C only), -Woverride-init, -Wsign-compare, -Wtype-limits, -Wuninitialized, -Wunused-parameter (only with -Wunused or -Wall), and -Wunused-but-set-parameter (only with -Wunused or -Wall).
If you want to learn what the above mentioned flags do, head to [gcc's man page](https://linux.die.net/man/1/gcc).
Moving on, the -Wextra option also issues warnings in the following cases:
- A pointer is compared against integer zero with <, <=, >, or >=
- (C++ only) An enumerator and a non-enumerator both appear in a
conditional expression. - (C++ only) Ambiguous virtual bases.
- (C++ only) Subscripting an array that has been declared
register. - (C++ only) Taking the address of a variable that has been
declared register. - (C++ only) A base class is not initialized in a derived class's
copy constructor.
## Enable warning for floating point values in equity comparisons
As you might already know, one should never test for the exact equality of floating-point values (didn't know this - read the floating-point comparison-related FAQ [here](https://isocpp.org/wiki/faq/newbie)). But even if you accidentally do this, does the gcc compiler throw any warning or error? Let's check out:
Here's a code that compares floating point variables using == operator:
`#include<stdio.h>`
void compare(float x, float y)
{
if(x == y)
{
printf("\n EQUAL \n");
}
}
int main(void)
{
compare(1.234, 1.56789);
return 0;
}
And here's the gcc command (containing both -Wall and -Wextra options) used to compile this code:
gcc -Wall -Wextra test.c -o test
Sadly, the above command doesn't produce any warning related to floating point comparison. A quick look at GCC's man page reveals that there exists a dedicated option ** -Wfloat-equal** that should be used in these scenarios.
Here's the command containing this option:
gcc -Wall -Wextra -Wfloat-equal test.c -o test
And following is the output it produced:
test.c: In function ‘compare’:
test.c:5:10: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
if(x == y)
So as you can see in the output above, the -Wfloat-equal option forced gcc to produce warning related to floating comparison.
Here is what [the gcc man page](https://linux.die.net/man/1/gcc) says about this option:
The idea behind this is that sometimes it is convenient (for the programmer) to consider floating-point values as approximations to infinitely precise real numbers. If you are doing this, then you
need to compute (by analyzing the code, or in some other way) the maximum or likely maximum error that the computation introduces, and allow for it when performing comparisons (and when producing
output, but that's a different problem). In particular, instead of testing for equality, you shouldcheck to see whether the two values have ranges that overlap; and this is done with the relational operators, so equality comparisons are probably mistaken.
## How to better manage gcc command line options
If the list of command line options that you are using in your gcc command is becoming larger and difficult to manage, then you can put it in a text file, and pass that file's name as an argument to the gcc command. For this, you'll have to use the ** @file** command line option.
For example, if following is your gcc command:
`gcc -Wall -Wextra -Wfloat-equal test.c -o test`
Then you can put the three warnings-related options in a file named, say 'gcc-options' :
$ cat gcc-options
-Wall -Wextra -Wfloat-equal
And your gcc command becomes less cluttered and easy to manage:
gcc @gcc-options test.c -o test
Here's what the gcc man page says about @file:
Read command-line options from file. The options read are inserted in place of the original @file option. If file does not exist, or cannot be read, then the option will be treated literally, and not removed.
Options in file are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes. Any character (including a backslash) may be included by prefixing the character to be included with a backslash. The file may itself contain additional @file options; any such options will be processed recursively.
## Conclusion
So we covered a total of 5 uncommon but useful gcc command line options in this tutorial series: -save-temps, -g, -Wextra, -Wfloat-equal, and @file. Do spend time practicing each of them and don't forget to go through all the details that the gcc man page offers about them.
Do you know or use other such useful gcc command line options, and want to share them with the world? Leave all the details in comments below. |
8,033 | 我们大学机房使用的 Fedora 系统 | https://fedoramagazine.org/fedora-computer-lab-university/ | 2016-12-13T18:03:08 | [
"Fedora",
"机房",
"大学"
] | https://linux.cn/article-8033-1.html | 
在[塞尔维亚共和国诺维萨德大学的自然科学系和数学与信息学系](http://www.dmi.rs/),我们教学生很多东西。从编程语言的入门到机器学习,所有开设的课程最终目的是让我们的学生能够像专业的开发者和软件工程师一样思考。课程时间紧凑而且学生众多,所以我们必须对现有可利用的资源进行合理调整以满足正常的教学。最终我们决定将机房计算机系统换为 Fedora。
### 以前的设置
我们过去的解决方案是在 Ubuntu 系统上面安装 Windows [虚拟机](https://en.wikipedia.org/wiki/Virtual_machine)并在虚拟机下安装好教学所需的开发软件。这在当时看起来是一个很不错的主意。然而,这种方法有很多弊端。首先,运行虚拟机导致了严重的计算机性能的浪费,因此导致操作系统性能和运行速度降低。此外,虚拟机有时候会在另一个用户会话里面同时运行。这会导致计算机工作严重缓慢。我们不得不在启动电脑和启动虚拟机上花费宝贵的时间。最后,我们意识到我们的大部分教学所需软件都有对应的 Linux 版本。虚拟机不是必需的。我们需要寻找一个更好的解决办法。
### 进入 Fedora!

*默认运行 Fedora 工作站版本的一个机房的照片*
我们考虑使用一种简洁的安装替代以前的 Windows 虚拟机方案。我们最终决定使用 Fedora,这有很多原因。
#### 发展的前沿
在我们所教授的课程中,我们会用到很多各种各样的开发工具。因此,能够及时获取可用的最新、最好的开发工具很重要。在 Fedora 下,我们发现我们用到的开发工具有 95% 都能够在官方的软件仓库中找到!只有少量的一些工具,我们才需要手动安装。这在 Fedora 下很简单,因为你能获取到几乎所有的现成的开发工具。
在这个过程中我们意识到我们使用了大量自由、开源的软件和工具。保证这些软件总是能够及时更新通常需要做大量的工作,然而 Fedora 没有这个问题。
#### 硬件兼容性
我们机房选择 Fedora 的第二个原因是硬件兼容性。机房现在的电脑还是比较崭新的。过去比较低的内核版本总有些问题。在 Fedora 下,我们总能获得最新的内核版本。正如我们预期的那样,一切运行良好,没有任何问题。
我们决定使用带有 [GNOME 桌面环境](https://www.gnome.org/)的 Fedora [工作站版本](https://getfedora.org/workstation/)。学生们发现它很容易、直观,可以快速上手。对我们来说,学生有一个简单的环境很重要,这样他们会更多的关注自己的任务和课程本身,而不是一个复杂的或者运行缓慢的用户界面。
#### 自主的技术支持
最后一个原因,我们院系高度赞赏自由、开放源代码的软件。使用这些软件,学生们即便在毕业后和工作的时候,仍然能够继续自由地使用它们。在这个过程中,他们通常也对 Fedora 和自由、开源的软件有了一定了解。
### 转换机房
我们找来其中的一台电脑,完全手动安装好。包括准备所有必要的脚本和软件,设置远程控制权限和一些其他的重要组成部分。我们也为每一门课程单独设置一个用户账号以方便学生存储他们的文件。
一台电脑安装配置好后,我们使用一个强大的、免费的、开源的叫做 [CloneZilla](http://clonezilla.org/) 的工具。 CloneZilla 能够制作硬盘镜像以做恢复用。镜像大小约为 11 G。我们用一些带有高速 USB 3.0 接口的闪存来还原磁盘镜像到其余的电脑。我们仅仅利用若干个闪存设备花费了 75 分钟设置好其余的 24 台电脑。
### 将来的工作
我们机房现在所有的电脑都完全使用 Fedora (没有虚拟机)。剩下的工作是设置一些管理脚本方便远程安装软件,电脑的开关等等。
我们由衷地感谢所有 Fedora 的维护人员、软件包管理人员和其他贡献者。我们希望我们的工作能够鼓励其他的学校和大学像我们一样将机房电脑的操作系统转向 Fedora。我们很高兴地确认 Fedora 完全适合我们,同时我们也保证 Fedora 同样会适合您!
---
via: <https://fedoramagazine.org/fedora-computer-lab-university/>
作者:[Nemanja Milošević](https://fedoramagazine.org/author/nmilosev/) 译者:[WangYueScream](https://github.com/WangYueScream),[LemonDemo](https://github.com/LemonDemo) 校对:[jasminepeng](https://github.com/jasminepeng)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
| 200 | OK | At the [University of Novi Sad in Serbia, Faculty of Sciences, Department of Mathematics and Informatics](http://www.dmi.rs), we teach our students a lot of things. From an introduction to programming to machine learning, all the courses make them think like great developers and software engineers. The pace is fast and there are many students, so we must have a setup on which we can rely on. We decided to switch our computer lab to Fedora.
## Previous setup
Our previous solution was keeping our development software in Windows [virtual machines](https://en.wikipedia.org/wiki/Virtual_machine) installed on Ubuntu Linux. This seemed like a good idea at the time. However, there were a couple of drawbacks. Firstly, there were serious performance losses because of running virtual machines. Performance and speed of the operating system was impacted because of this. Also, sometimes virtual machines ran concurrently in another user’s session. This led to serious slowdowns. We were losing precious time on booting the machines and then booting the virtual machines. Lastly, we realized that most of our software was Linux-compatible. Virtual machines weren’t necessary. We had to find a better solution.
## Enter Fedora!

Picture of a computer lab running Fedora Workstation by default
We thought about replacing the virtual machines with a “bare bones” installation for a while. We decided to go for Fedora for several reasons.
#### Cutting edge of development
In our courses, we use many different development tools. Therefore, it is crucial that we always use the latest and greatest development tools available. In Fedora, we found 95% of the tools we needed in the official software repositories! For a few tools, we had to do a manual installation. This was easy in Fedora because you have almost all development tools available out of the box.
What we realized in this process was that we used a lot of free and open source software and tools. Having all that software always up to date was always going to be a lot of work – but not with Fedora.
#### Hardware compatibility
The second reason for choosing Fedora in our computer lab was hardware compatibility. The computers in the lab are new. In the past, there were some problems with older kernel versions. In Fedora, we knew that we would always have a recent kernel. As we expected, everything worked out of the box without any issues.
We decided that we would go for the [Workstation edition](https://getfedora.org/workstation/) of Fedora with [GNOME desktop environment](https://www.gnome.org/). Students found it easy, intuitive, and fast to navigate through the operating system. It was important for us that students have an easy environment where they could focus on the tasks at hand and the course itself rather than a complicated or slow user interface.
#### Powered by freedom
Lastly, in our department, we value free and open source software greatly. By utilizing such software, students are able to use it freely even when they graduate and start working. In the process, they also learn about Fedora and free and open source software in general.
## Switching the computer lab
We took one of the computers and fully set it up manually. That included preparing all the needed scripts and software, setting up remote access, and other important components. We also made one user account per course so students could easily store their files.
After that one computer was ready, we used a great, free and open source tool called [CloneZilla](http://clonezilla.org/). CloneZilla let us make a hard drive image for restoration. The image size was around 11GB. We used some fast USB 3.0 flash drives to restore the disk image to the remaining computers. We managed to fully provision and setup twenty-four computers in one hour and fifteen minutes, with just a couple of flash drives.
## Future work
All the computers in our computer lab are now exclusively using Fedora (with no virtual machines). The remaining work is to set up some administration scripts for remotely installing software, turning computers on and off, and so forth.
We would like to thank all Fedora maintainers, packagers, and other contributors. We hope our work encourages other schools and universities to make a switch similar to ours. We happily confirm that Fedora works great for us, and we can also vouch that it would work great for you!
## Rodd Clarkson
I’ve been using Fedora on the desktop in the computer lab I run at my school for about 4 years now.
I’ve got a simple shell script that runs the same command on multiple machines, allowing me to maintain the machines remotely.
It uses ssh connections, authenticated using ssh-copy-id, to run a wide range of commands, including poweroff and dnf.
I’d be happy to share it with you if you’re interested.
## chris
Is there a reason you are using a shellscript instead of something like ansible? Seems a little bit dangerous and overcomplicated.
## James
Chris, Ansible ad-hoc is also what came to mind as I read. The Ansible docs use almost this exact scenario
“For instance, if you wanted to power off all of your lab for Christmas vacation, you could execute a quick one-liner in Ansible without writing a playbook.”
Nemanja, it’s worth checking out for ease of use and configuration management. http://docs.ansible.com/ansible/intro_adhoc.html
## Nemanja Milošević
We will definitely look into Ansible but I’m not sure if it is worth it for our use case. 🙂
I wrote some Python scripts for management over SSH, and it is a closed network, so we will stick with that for now.
Thanks for your comments! 🙂
## Adam Williamson
Ansible basically
is‘python scripts for management over ssh’, only with a dedicated development team so you don’t have to develop it, and a whole bunch of awesome features and modules for managing different things, and more being added all the time by a big user community. It’s also very easy to get started with. Really do look into it! you want it!This is a great story, btw, really happy to see Fedora is working out for you!
## Nemanja Milošević
Well, if my personal Fedora hero adamw is suggesting it, I will definitely try to learn more about Ansible and how we can use it. 🙂
Thanks!
## Cornel Panceac
“We managed to fully provision and setup twenty-four computers in one hour and fifteen minutes, with just a couple of flash drives.”
You can also do it over the network but again, the machines must be booted . PXE can be at help here. You setup a Clonezilla server on the first configured machine, then boot the clients with PXE from the Clonezilla server, and just do the cloning.
## Nemanja Milošević
We considered this, and actually tried to do it over network, however our network gear is limited to 100Mbps and it took around 30 minutes to deploy that single machine. Compare that to around 6-7 minutes restore time from a fast USB3 drive. 🙂
We actually had just one drive with CloneZilla (boot to RAM, then take it) and three USB flash drives with the image. All in all it would take I think around 12-13h to do it over network, especially if we tried to do it all at once, so this was just faster for us.
Thanks for your comment! 🙂
## Nemanja Milošević
We tried doing it over network (w/o PXE just using scp to get the image) but it was really slow. Partly because our network gear is a bit older (100 Mbps) and partly because the machines were fighting for resources. In the end the solution with flash drives worked better for us, especially because you can boot CloneZilla to RAM and just yank the drive out. 🙂
Thanks for the suggestion, though!
## BOb
How do you handle updates? You’ve made an image , that’s out of date pretty much as soon as you’ve finished making it. Do you have a process by which updates are applied as soon as Clonezilla has written the image? How did you handle Dirty COW?
Did you consider using Kickstart and if so, what made you chose creating an image instead?
“We also made one user account per course so students could easily store their files.”
So users are per-course rather than per, well, user. Where are students storing their files? Are those files being backed up? What prevents a student accessing or modifying another student’s files?
## Nemanja Milošević
We will be trying to update machines frequently over SSH (with an automation script). The image was used just as a base. 🙂
We considered using a kickstart, however, some of the software needed compilation and additional setting up. Also this seemed faster at the time – but maybe not as ‘pure’ Fedora way. 🙂
About user files, students usually use the same computers, because they tend to sit at the same place during the semester. They store their files inside home directory – optionally they can make a folder with their name. Nothing prevents students from accessing files from other students (in one course) but this is not the concern because tests are handled differently.
Thanks for your comment! 🙂
## Honigmelone
The computer lab I work in (as a student) also uses fedora machines. However the fast update cycles of fedora make it hard for the staff to keep up with fedora development. Testing if an upgrade breaks anything is a substantial effort, thus Fedora 22 is still running and I don’t know of any upgrade plan.
## chris
I feel like the right way to do this is to have ansible configured for multiple batches (e.g. updated, a week old, last fedora version). Then show a message with the hint that if something is broken on this machines they should shoot an email to IT, which machines still have the old configuration and a list of known problems (to avoid multiple reports or the feeling of ‘it surely has been reported’) on the login-screen. (this can easily be updated via ansible as well).
I feel like this is way saver then running an eol-version and keeps the amount of testwork in place.
## Florian H
How do you guys realize screen sharing the instructor’s screen?
## Nemanja Milošević
Not sure what you mean, we have one “teacher” workstation which is connected via HDMI to the projector. You can actually see it in the first picture on the wall. 🙂
## chris
I think he means something like having a vnc server running on the students PCs, so the teacher can connect if he has the feeling a student is struggeling.
Can be pretty usefull
## Wallyk
Nemanja, It would be illuminating if you described what sort of use students are making of Fedora. Is it surfing the web or writing webservers? Writing email or weather modeling? Etc.
## Nemanja Milošević
Uh, hard to sum it all up. Our faculty offers BSc, MSc, and PhD studies in Computer Science. So there is actually everything between really low level assembly programming and high-level software engineering. Of course, that’w what we are trying to teach, but occasionally they are just reading emails and surfing the web just like you said. 🙂
## Smalltownnetadmin
Nemanja, first of all, congratulations on successfully overhauling your lab! I am curious whether Ubuntu was not keeping up with the development tools as well or there were more packages to install manually? I have been running Fedora since 2007 and haven’t felt the need to “shop around much”.
I’d also like to mention another clone/imaging utility here though there are quite a few. Since Cornel mentioned a Clonezilla server, another analogue to that is FOG (Free Opensource Ghost). It has been developed as a mixed environment, network imaging solution. From the features section of their wiki:
Imaging of Windows (XP, Vista, 7, 8/8.1, 10), Linux and Mac OS X
Partitions, full disk, multiple disks, resizable, raw
There is much more to this project. In my office we run Windows
ahemmore often than not and FOG has fairly heavily developed management for Windows clients:Printer management
Change hostname and join domain
Track user access on computers, automatic log off and shutdown on idle timeouts
Anti-Virus
Disk wiping
Restore deleted files
Bad blocks scan
Sadly, I can’t say how much attention has been given to Mac and Linux in these areas as I haven’t had time or clients to explore this with.
A few things are worth mentioning at this point for newer Administrators supporting Microsoft clients. First, make sure you have imaging rights (should be common for volume licensing) for the licenses you are using. Second, if you are not familiar with the process, research Sysprepping before creating your image, Generalizing your image can easily save you numerous headaches down the road. Third, do not activate the image you are sysprepping. Either find a Microsoft supported dummy “license” key to insert into the sysprep process or skip the license key entirely until deployment. At this point enter your
Actuallicense key to the deployed image for your activation to register itself properly with MS.I hate to end on a sour note for FOG but it should be noted that (at least with regards to PXE. Does this affect Clonezilla as well?) there may be some work involved finding which of their kernels will boot the majority of your equipment. The packaged kernel handles a reasonably broad set of equipment but, as with any package, it is not impossible to say find a graphics card that is not supported in that kernel.
## Edward O'Callaghan
Hi,
You guys may find it very useful to integrate FreeIPA into your stack so you can manage user accounts without so much fuss.
Cheers,
Edward.
## Nemanja Milošević
Thanks for the suggestion, I will definitely look it up it looks very interesting!
Thanks!
## Glenn L. Jenkins
We’re running Fedora 24 in our Linux lab (which dual boots Window 7). I’ve been using Ansible to mange the lab for the last year or so and there are significant advantages. For example mid way though the year I need to install some libraries for OpenAL for one of my modules, I added these to the Ansible playbook containing the list of software for the lab I used to setup the original machine and ran it against the lab. Contrast this with our technician going from machine to machine installing software for Windows.
Some other useful software, we use Ganglia to monitor the machines in the labs, ganglia-gmond in the Linux lab and on the servers and host sflow in the Windows 7 labs reporting back to ganglia-gmond collectors for each room. Essentially our dashboard shows each room as a cluster within a grid and we have another grid for servers (active directory, various web and database servers used by the students etc.)
To setup the dual boot lab we create one image using Clonezilla then cast this to the other machines using clonzilla server (which uses DRBL and PXE boot).
This year we’re using connecting the machines to active director for login, we have in the past run a separate IPA server but a single sign on suits the students better. Future work on this setup will hopefully include a auto mounted share so they can store their Linux work on a central server.
## P.D.Sandaruwan
we are also with fedora in our computer lab Computer science Dept. university of Ruhuna Sri Lanka. its nice. really… |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.