mirror of
https://github.com/LCTT/TranslateProject.git
synced 2026-09-01 04:27:55 +08:00
@@ -1,43 +1,43 @@
|
||||
# dpkg commands to manage packages on Debian Based Systems
|
||||
用 dpkg 命令在 Debian 系的 Linux 系统中管理软件包
|
||||
==================
|
||||
|
||||
[dpkg][7] stands for Debian package manager (dpkg). dpkg is a command-line tool to install, build, remove and manage Debian packages. dpkg uses Aptitude (primary and more user-friendly) as a front-end to perform all the actions.
|
||||
[dpkg][7] 意即 Debian 包管理器(Debian PacKaGe manager)。dpkg 是一个可以安装、构建、删除及管理 Debian 软件包的命令行工具。dpkg 将 Aptitude(首选而更用户友好)作为执行所有操作的前端界面。
|
||||
|
||||
Other utility such as dpkg-deb and dpkg-query uses dpkg as a front-end to perform some action.
|
||||
其它的一些工具如 dpkg-deb 和 dpkg-query 等也使用 dpkg 作为执行某些操作的前端。
|
||||
|
||||
Now a days most of the administrator using Apt, [Apt-Get][6] & Aptitude to manage packages easily without headache and its robust management too.
|
||||
现在大多数系统管理员使用 Apt、[Apt-Get][6] 及 Aptitude 等工具,不用费心就可以轻松地管理软件。
|
||||
|
||||
Even though still we need to use dpkg to perform some software installation where it’s necessary. Some other package manger utilities which are being used widely in Linux are [yum][5], [dnf][4], [apt-get][3], dpkg, [rpm][2], [Zypper][1], pacman, urpmi, etc.,
|
||||
尽管如此,必要的时候还是需要用 dpkg 来安装某些软件。其它的一些在 Linux 系统上广泛使用的包管理工具还有 [yum][5]、[dnf][4]、[apt-get][3]、dpkg、[rpm][2]、[Zypper][1]、pacman、urpmi 等等。
|
||||
|
||||
Now, i’m going to play on our Ubuntu 15.10 box to explain and cover mostly used dpkg commands with examples.
|
||||
现在,我要在装有 Ubuntu 15.10 的机器上用一些实例讲解最常用的 dpkg 命令。
|
||||
|
||||
#### 1) Common syntax/file location for dpkg
|
||||
### 1) dpkg 常见命令的语法及 dpkg 文件位置
|
||||
|
||||
See below for common syntax/ file location of dpkg which will help you if you want to check more about it.
|
||||
下面是 dpkg 常见命令的语法及 dpkg 相关文件的位置,如果想深入了解,这些对你肯定大有益处。
|
||||
|
||||
<iframe marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="90" width="728" id="_mN_gpt_827143833" style="border-width: 0px; border-style: initial; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline;"></iframe>
|
||||
```
|
||||
[General syntax for dpkg]
|
||||
### dpkg 命令的语法
|
||||
$ dpkg -[command] [.deb package name]
|
||||
|
||||
$ dpkg -[command] [package name]
|
||||
|
||||
[dpkg releated files location]
|
||||
### dpkg 相关文件的位置
|
||||
$ /var/lib/dpkg
|
||||
|
||||
[This file contain modified package info by dpkg command like (install, remove, etc..,)]
|
||||
### 这个文件包含了被 dpkg 命令(install、remove 等)所修改的包的信息
|
||||
$ /var/lib/dpkg/status
|
||||
|
||||
[This file contain available package list]
|
||||
### 这个文件包含了可用包的列表
|
||||
$ /var/lib/dpkg/status
|
||||
|
||||
```
|
||||
|
||||
#### 2) Install/Upgrade the package
|
||||
### 2) 安装/升级软件
|
||||
|
||||
Use the below command to install/upgrade .deb packge on Debian based systems such as Debian, Mint, Ubuntu & elementryOS, etc..,. Here i’m going to install Atom through atom-amd64.deb file. It will upgrade if it’s installed other wise install a fresh one.
|
||||
在基于 Debian 的系统里,比如 Debian、Mint、Ubuntu 和 elementryOS,用以下命令来安装/升级 .deb 软件包。这里我要用 `atom-amd64.deb` 文件安装 Atom。要是已经安装了 Atom,就会升级它。要么就会安装一个新的 Atom。
|
||||
|
||||
```
|
||||
[Install/Upgrade dpkg packages]
|
||||
### 安装或升级 dpkg 软件包
|
||||
$ sudo dpkg -i atom-amd64.deb
|
||||
Selecting previously unselected package atom.
|
||||
(Reading database ... 426102 files and directories currently installed.)
|
||||
@@ -52,9 +52,9 @@ Processing triggers for mime-support (3.58ubuntu1) ...
|
||||
|
||||
```
|
||||
|
||||
#### 3) Install a package from folder
|
||||
### 3) 从文件夹里安装软件
|
||||
|
||||
Use the below command to install the packages recursively from directory on Debian based systems such as Debian, Mint, Ubuntu & elementryOS, etc,. This will install all the *.deb packages under the /opt/software directory.
|
||||
在基于 Debian 的系统里,用下列命令从目录中逐个安装软件。这会安装 `/opt/software` 目录下的所有以 .deb 为后缀的软件。
|
||||
|
||||
```
|
||||
$ sudo dpkg -iR /opt/software
|
||||
@@ -70,9 +70,9 @@ Processing triggers for desktop-file-utils (0.22-1ubuntu3) ...
|
||||
Processing triggers for mime-support (3.58ubuntu1) ...
|
||||
```
|
||||
|
||||
#### 4) Print the Installed packages list
|
||||
### 4) 显示已安装软件列表
|
||||
|
||||
Use the below command to List all installed packages, along with package version and description on Debian based systems such as Debian, Mint, Ubuntu & elementryOS, etc..,.
|
||||
以下命令可以列出 Debian 系的系统中所有已安装的软件,同时会显示软件版本和描述信息。
|
||||
|
||||
```
|
||||
$ dpkg -l
|
||||
@@ -92,11 +92,10 @@ ii account-plugin-salut 3.12.10-0ubuntu2 amd64
|
||||
|
||||
```
|
||||
|
||||
#### 5) Check particular Installed package
|
||||
### 5) 查看指定的已安装软件
|
||||
|
||||
Use the below command to List individual installed package, along with package version and description on Debian based systems such as Debian, Mint, Ubuntu & elementryOS, etc..,.
|
||||
用以下命令列出指定的一个已安装软件,同时会显示软件版本和描述信息。
|
||||
|
||||
<iframe marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="90" width="728" id="_mN_gpt_827143833" style="border-width: 0px; border-style: initial; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline;"></iframe>
|
||||
```
|
||||
$ dpkg -l atom
|
||||
Desired=Unknown/Install/Remove/Purge/Hold
|
||||
@@ -108,9 +107,9 @@ ii atom 1.5.3 amd64 A hackable text editor for the 21st
|
||||
|
||||
```
|
||||
|
||||
#### 6) Check package Installed Location
|
||||
### 6) 查看软件安装目录
|
||||
|
||||
Use the below command to Check package Installed Location on Debian based systems such as Debian, Mint, Ubuntu & elementryOS, etc..,.
|
||||
以下命令可以在基于 Debian 的系统上查看软件的安装路径。
|
||||
|
||||
```
|
||||
$ dpkg -L atom
|
||||
@@ -128,9 +127,9 @@ $ dpkg -L atom
|
||||
|
||||
```
|
||||
|
||||
#### 7) View deb package content
|
||||
### 7) 查看 deb 包内容
|
||||
|
||||
Use the below command to View deb package content, It will show list of files on inside .deb package.
|
||||
下列命令可以查看 deb 包内容。它会显示 .deb 包中的一系列文件。
|
||||
|
||||
```
|
||||
$ dpkg -c atom-amd64.deb
|
||||
@@ -149,9 +148,9 @@ drwxr-xr-x root/root 0 2016-02-13 02:13 ./usr/share/doc/
|
||||
.
|
||||
```
|
||||
|
||||
#### 8) Display details about package
|
||||
### 8) 显示软件的详细信息
|
||||
|
||||
Use the below command to Display detailed information about package, package group, version, maintainer, Architecture, display depends packages, description, etc.,.
|
||||
以下命令可以显示软件的详细信息,如软件名、软件类别、版本、维护者、软件架构、依赖的软件、软件描述等等。
|
||||
|
||||
```
|
||||
$ dpkg -s atom
|
||||
@@ -169,9 +168,9 @@ 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.</atom@github.com>
|
||||
```
|
||||
|
||||
#### 9) Find what package owns the file
|
||||
### 9) 查看文件属于哪个软件
|
||||
|
||||
Use the below command to find out what package does file belong.
|
||||
用以下命令来查看文件属于哪个软件。
|
||||
|
||||
```
|
||||
$ dpkg -S /usr/bin/atom
|
||||
@@ -179,11 +178,11 @@ atom: /usr/bin/atom
|
||||
|
||||
```
|
||||
|
||||
#### 10) Remove/Delete package
|
||||
### 10) 移除/删除软件
|
||||
|
||||
以下命令可以用来移除/删除一个已经安装的软件,但不删除配置文件。
|
||||
|
||||
Use the below command to Remove/Delete an installed package except configuration files.
|
||||
|
||||
<iframe marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="90" width="728" id="_mN_gpt_827143833" style="border-width: 0px; border-style: initial; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline;"></iframe>
|
||||
```
|
||||
$ sudo dpkg -r atom
|
||||
(Reading database ... 426404 files and directories currently installed.)
|
||||
@@ -196,9 +195,9 @@ Processing triggers for mime-support (3.58ubuntu1) ...
|
||||
|
||||
```
|
||||
|
||||
#### 11) Purge package
|
||||
### 11) 清除软件
|
||||
|
||||
Use the below command to Remove/Delete everything including configuration files.
|
||||
以下命令可以用来移除/删除包括配置文件在内的所有文件。
|
||||
|
||||
```
|
||||
$ sudo dpkg -P atom
|
||||
@@ -212,28 +211,26 @@ Processing triggers for mime-support (3.58ubuntu1) ...
|
||||
|
||||
```
|
||||
|
||||
#### 12) Read more about dpkg
|
||||
### 12) 了解更多
|
||||
|
||||
Use the below commands to read more about dpkg command information.
|
||||
用以下命令来查看更多关于 dpkg 的信息。
|
||||
|
||||
```
|
||||
$ dpkg -help
|
||||
or
|
||||
或
|
||||
$ man dpkg
|
||||
|
||||
```
|
||||
|
||||
Enjoy….)
|
||||
开始体验 dpkg 吧。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.2daygeek.com/dpkg-command-examples/
|
||||
|
||||
作者:[MAGESH MARUTHAMUTHU ][a]
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
作者:[MAGESH MARUTHAMUTHU][a]
|
||||
译者:[GitFuture](https://github.com/GitFuture)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
轻轻几个点击,在 AWS 和 Azure 上搭建 Docker 数据中心
|
||||
===================================================
|
||||
|
||||
通过几个点击即可在 “AWS 快速起步”和“Azure 市场”上高效搭建产品级 Docker 数据中心。
|
||||
|
||||
通过 AWS 快速起步的 CloudFormation 模板和在 Azure 市场上的预编译模板来部署 Docker 数据中心使得比以往在公有云基础设施下的部署企业级的 CaaS Docker 环境更加容易。
|
||||
|
||||
Docker 数据中心 CaaS 平台为各种规模的企业的敏捷应用部署提供了容器和集群的编排和管理,使之更简单、安全和可伸缩。使用新为 Docker 数据中心预编译的云模板,开发者和 IT 运维人员可以无缝的把容器化的应用迁移到亚马逊 EC2 或者微软的 Azure 环境而无需修改任何代码。现在,企业可以快速实现更高的计算和运营效率,可以通过短短几步操作实现支持 Docker 的容器管理和编排。
|
||||
|
||||
### 什么是 Docker 数据中心?
|
||||
|
||||
Docker 数据中心包括了 Docker 通用控制面板(Docker Universal Control Plane)(UCP),Docker 可信注册库( Docker Trusted Registry)(UTR)和商用版 Docker 引擎(CS Docker Engine),并带有与客户的应用服务等级协议相匹配的商业支持服务。
|
||||
|
||||
- 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][1] 获取 [30 天免费试用][2]或者[联系销售][4]
|
||||
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 天试用][5]许可或者[联系销售][6]
|
||||
2. [跳转到微软 Azure 市场的 Docker 数据中心][7]
|
||||
3. [查看部署文档][8]
|
||||
|
||||
|
||||
---
|
||||
|
||||
通过注册获取 Docker 数据中心许可证开始,然后你就能够通过 AWS 或者 Azure 模板搭建自己的数据中心。
|
||||
|
||||
- [获取 30 天试用许可证][9]
|
||||
- [通过视频理解 Docker 数据中心架构][10]
|
||||
- [观看演示视频][11]
|
||||
- [获取 AWS 提供的部署 Docker 数据中心的 75 美元红包奖励][12]
|
||||
|
||||
了解有关 Docker 的更多信息:
|
||||
|
||||
- 初识 Docker? 尝试一下 10 分钟[在线学习课程][20]
|
||||
- 分享镜像,自动构建,或用一个[免费的 Docker Hub 账号][21]尝试更多
|
||||
- 阅读 [Docker 1.12 发行说明][22]
|
||||
- 订阅 [Docker Weekly][23]
|
||||
- 报名参加即将到来的 [Docker Online Meetups][24]
|
||||
- 参加即将发生的 [Docker Meetups][25]
|
||||
- 观看 [DockerCon EU2015][26]视频
|
||||
- 开始为 [Docker][27] 贡献力量
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://blog.docker.com/2016/06/docker-datacenter-aws-azure-cloud/
|
||||
|
||||
作者:[Trisha McCanna][a]
|
||||
译者:[firstadream](https://github.com/firstadream)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://blog.docker.com/author/trisha/
|
||||
[1]: https://store.docker.com/login?next=%2Fbundles%2Fdocker-datacenter%2Fpurchase?plan=free-trial
|
||||
[2]: https://store.docker.com/login?next=%2Fbundles%2Fdocker-datacenter%2Fpurchase?plan=free-trial
|
||||
[4]: https://goto.docker.com/contact-us.html
|
||||
[5]: https://store.docker.com/login?next=%2Fbundles%2Fdocker-datacenter%2Fpurchase?plan=free-trial
|
||||
[6]: https://goto.docker.com/contact-us.html
|
||||
[7]: https://azure.microsoft.com/en-us/marketplace/partners/docker/dockerdatacenterdocker-datacenter/
|
||||
[8]: https://success.docker.com/Datacenter/Apply/Docker_Datacenter_on_Azure
|
||||
[9]: http://www.docker.com/trial
|
||||
[10]: https://www.youtube.com/playlist?list=PLkA60AVN3hh8tFH7xzI5Y-vP48wUiuXfH
|
||||
[11]: https://www.youtube.com/playlist?list=PLkA60AVN3hh8a8JaIOA5Q757KiqEjPKWr
|
||||
[12]: https://aws.amazon.com/quickstart/promo/
|
||||
[20]: https://docs.docker.com/engine/understanding-docker/
|
||||
[21]: https://hub.docker.com/
|
||||
[22]: https://docs.docker.com/release-notes/
|
||||
[23]: https://www.docker.com/subscribe_newsletter/
|
||||
[24]: http://www.meetup.com/Docker-Online-Meetup/
|
||||
[25]: https://www.docker.com/community/meetup-groups
|
||||
[26]: https://www.youtube.com/playlist?list=PLkA60AVN3hh87OoVra6MHf2L4UR9xwJkv
|
||||
[27]: https://docs.docker.com/contributing/contributing/
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
2016 年 Linux 下五个最佳视频编辑软件
|
||||
=====================================================
|
||||
|
||||

|
||||
|
||||
概要: 在这篇文章中,Tiwo 讨论了 Linux 下最佳视频编辑器的优缺点和在基于 Ubuntu 的发行版中的安装方法。
|
||||
|
||||
在过去,我们已经在类似的文章中讨论了 [Linux 下最佳图像管理应用软件][1],[Linux 上四个最佳的现代开源代码编辑器][2]。今天,我们来看看 Linux 下的最佳视频编辑软件。
|
||||
|
||||
当谈及免费的视频编辑软件,Windows Movie Maker 和 iMovie 是大多数人经常推荐的。
|
||||
|
||||
不幸的是,它们在 GNU/Linux 下都是不可用的。但是你不必担心这个,因为我们已经为你收集了一系列最佳的视频编辑器。
|
||||
|
||||
### Linux下最佳的视频编辑应用程序
|
||||
|
||||
接下来,让我们来看看 Linux 下排名前五的最佳视频编辑软件:
|
||||
|
||||
#### 1. Kdenlive
|
||||
|
||||

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

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

|
||||
|
||||
如果你要寻找一个有更多功能的视频编辑软件,这会是答案。 [Lightworks][7] 是一个跨平台的专业的视频编辑器,在 Linux、Mac OS X 和 Windows 系统下都可用。
|
||||
|
||||
它是一个获奖的专业的[非线性编辑][8](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 下载页面][9]下载安装包。这个安装包大约 79.5MB。*请注意:这里没有32 位 Linux 的支持。*
|
||||
- 第2步 – 一旦下载,你可以使用 [Gdebi 软件包安装器][10]来安装。Gdebi 会自动下载依赖关系 :
|
||||

|
||||
- 第3步 – 现在你可以从 Ubuntu 仪表板或您的 Linux 发行版菜单中打开它。
|
||||
- 第4步 – 当你第一次使用它时,需要一个账号。点击 “Not Registerd?” 按钮来注册。别担心,它是免费的。
|
||||
- 第5步 – 在你的账号通过验证后,就可以登录了。
|
||||
|
||||
现在,Lightworks 可以使用了。
|
||||
|
||||
需要 Lightworks 的视频教程? 在 [Lightworks 视频教程页][11]得到它们。
|
||||
|
||||
#### 5. Blender
|
||||
|
||||

|
||||
|
||||
|
||||
Blender 是一个专业的,工业级的开源、跨平台的视频编辑器。在 3D 作品的制作中,是非常受欢迎的。 Blender 已被用于几部好莱坞电影的制作,包括蜘蛛侠系列。
|
||||
|
||||
虽然最初是设计用于制作 3D 模型,但它也可以用于各种格式的视频编辑和输入能力。 该视频编辑器包括:
|
||||
|
||||
- 实时预览、亮度波形、色度矢量示波器和直方图显示
|
||||
- 音频混合、同步、擦除和波形可视化
|
||||
- 多达 32 个插槽用于添加视频、图像、音频、场景、面具和效果
|
||||
- 速度控制、调整图层、过渡、关键帧、过滤器等
|
||||
|
||||
最新的版本可以从 [Blender 下载页][12]下载.
|
||||
|
||||
### 哪一个是最好的视频编辑软件?
|
||||
|
||||
如果你需要一个简单的视频编辑器,OpenShot、Kdenlive 和 Flowblade 是一个不错的选择。这些软件是适合初学者的,并且带有标准规范的系统。
|
||||
|
||||
如果你有一个高性能的计算机,并且需要高级功能,你可以使用 Lightworks。如果你正在寻找更高级的功能, Blender 可以帮助你。
|
||||
|
||||
这就是我写的 5 个最佳的视频编辑软件,它们可以在 Ubuntu、Linux Mint、Elementary 和其他 Linux 发行版下使用。 请与我们分享您最喜欢的视频编辑器。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/best-video-editing-software-linux/
|
||||
|
||||
作者:[Tiwo Satriatama][a]
|
||||
译者:[DockerChen](https://github.com/DockerChen)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/tiwo/
|
||||
[1]: https://linux.cn/article-7462-1.html
|
||||
[2]: https://linux.cn/article-7468-1.html
|
||||
[3]: https://kdenlive.org/
|
||||
[4]: https://itsfoss.com/tag/open-source/
|
||||
[5]: http://www.openshot.org/
|
||||
[6]: http://jliljebl.github.io/flowblade/
|
||||
[7]: https://www.lwks.com/
|
||||
[8]: https://en.wikipedia.org/wiki/Non-linear_editing_system
|
||||
[9]: https://www.lwks.com/index.php?option=com_lwks&view=download&Itemid=206
|
||||
[10]: https://itsfoss.com/gdebi-default-ubuntu-software-center/
|
||||
[11]: https://www.lwks.com/videotutorials
|
||||
[12]: https://www.blender.org/download/
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
拥有开源项目部门的公司可以从四个方面获益
|
||||
====
|
||||
|
||||

|
||||
|
||||
在我的第一篇关于开源项目部门(program office)的系列文章中,我深入剖析了[什么是开源项目部门,为什么你的公司需要一个开源项目部门][1]。接着我又说到了[谷歌是如何创建一种新的开源项目部门的][2]。而这篇文章,我将阐述拥有一个开源项目部门的好处。
|
||||
|
||||
乍一看,非软件开发公司会更加热情的去拥抱开源项目部门的一个重要原因是他们并没有什么损失。毕竟,他们并不需要依靠这些软件产品来获得收益。比如,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][a]
|
||||
译者:[chao-zhi](https://github.com/chao-zhi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/johnmark
|
||||
[1]: https://opensource.com/business/16/5/whats-open-source-program-office
|
||||
[2]: https://opensource.com/business/16/8/google-open-source-program-office
|
||||
@@ -0,0 +1,113 @@
|
||||
在 Linux 下使用 TCP 封装器来加强网络服务安全
|
||||
===========
|
||||
|
||||
在这篇文章中,我们将会讲述什么是 TCP 封装器(TCP wrappers)以及如何在一台 Linux 服务器上配置他们来[限制网络服务的权限][7]。在开始之前,我们必须澄清 TCP 封装器并不能消除对于正确[配置防火墙][6]的需要。
|
||||
|
||||
就这一点而言,你可以把这个工具看作是一个[基于主机的访问控制列表][5],而且并不能作为你的系统的[终极安全措施][4]。通过使用一个防火墙和 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` 作为例子,输出如下所示。
|
||||
|
||||
[][3]
|
||||
|
||||
*查找 TCP 过滤器支持的服务*
|
||||
|
||||
### 如何使用 TCP 过滤器来限制服务的权限
|
||||
|
||||
当你编辑 `/etc/hosts.allow` 和 `/etc/hosts.deny` 的时候,确保你在最后一个非空行后面通过回车键来添加一个新的行。
|
||||
|
||||
为了使得 [SSH 和 FTP][2] 服务只允许 `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` 不可用。在我们添加了通配符以后,服务又变得可用了。
|
||||
|
||||
[][1]
|
||||
|
||||
*确认 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][a]
|
||||
译者:[LinuxBars](https://LinuxBar.org)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/gacanepa/
|
||||
[1]:http://www.tecmint.com/wp-content/uploads/2016/10/Verify-FTP-Access.png
|
||||
[2]:http://www.tecmint.com/block-ssh-and-ftp-access-to-specific-ip-and-network-range/
|
||||
[3]:http://www.tecmint.com/wp-content/uploads/2016/10/Find-Supported-Services-in-TCP-Wrapper.png
|
||||
[4]:http://www.tecmint.com/linux-server-hardening-security-tips/
|
||||
[5]:https://linux.cn/article-3966-1.html
|
||||
[6]:https://linux.cn/article-4425-1.html
|
||||
[7]:https://linux.cn/article-7719-1.html
|
||||
@@ -0,0 +1,166 @@
|
||||
删除一个目录下部分类型之外的所有文件的三种方法
|
||||
=========
|
||||
|
||||
有的时候,你可能会遇到这种情况,你需要删除一个目录下的所有文件,或者只是简单的通过删除除了一些指定类型(以指定扩展名结尾)之外的文件来清理一个目录。
|
||||
|
||||
在这篇文章,我们将会向你展现如何通过 `rm`、 `find` 和 `globignore` 命令删除一个目录下除了指定文件扩展名或者类型的之外的文件。
|
||||
|
||||
在我们进一步深入之前,让我们开始简要的了解一下 Linux 中的一个重要的概念 —— 文件名模式匹配,它可以让我们解决眼前的问题。
|
||||
|
||||
在 Linux 下,一个 shell 模式是一个包含以下特殊字符的字符串,称为通配符或者元字符:
|
||||
|
||||
1. `*` – 匹配 0 个或者多个字符
|
||||
2. `?` – 匹配任意单个字符
|
||||
3. `[序列]` – 匹配序列中的任意一个字符
|
||||
4. `[!序列]` – 匹配任意一个不在序列中的字符
|
||||
|
||||
我们将在这儿探索三种可能的办法,包括:
|
||||
|
||||
### 使用扩展模式匹配操作符删除文件
|
||||
|
||||
下来列出了不同的扩展模式匹配操作符,这些模式列表是一个用 `|` 分割包含一个或者多个文件名的列表:
|
||||
|
||||
1. `*(模式列表)` – 匹配 0 个或者多个出现的指定模式
|
||||
2. `?(模式列表)` – 匹配 0 个或者 1 个出现的指定模式
|
||||
4. `@(模式列表)` – 匹配 1 个或者多个出现的指定模式
|
||||
5. `!(模式列表)` – 匹配除了一个指定模式之外的任何内容
|
||||
|
||||
为了使用它们,需要像下面一样打开 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 命令][5]的适当的选项或者采用管道配合 `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` 变量存储了一个路径名展开(pathname expansion)功能的忽略模式(或文件名)列表,以冒号分隔。
|
||||
|
||||
为了使用这种方法,切换到要删除文件的目录,像下面这样设置 `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][a]
|
||||
译者:[yangmingming](https://github.com/yangmingming)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: http://www.tecmint.com/author/aaronkili/
|
||||
[1]:http://www.tecmint.com/wp-content/uploads/2016/10/Delete-Files-Using-Bash-GlobIgnore.png
|
||||
[2]:http://www.tecmint.com/wp-content/uploads/2016/10/Remove-All-Files-Except-File-Extensions.png
|
||||
[3]:http://www.tecmint.com/wp-content/uploads/2016/10/Remove-Files-Using-Find-and-Xargs-Command.png
|
||||
[4]:http://www.tecmint.com/wp-content/uploads/2016/10/Remove-All-Files-Except-gz-Files.png
|
||||
[5]:http://www.tecmint.com/35-practical-examples-of-linux-find-command/
|
||||
[6]:http://www.tecmint.com/wp-content/uploads/2016/10/Delete-All-Files-Except-Certain-File-Extensions.png
|
||||
[7]:http://www.tecmint.com/wp-content/uploads/2016/10/Delete-All-Files-Except-Zip-Files-in-Linux.png
|
||||
[8]:http://www.tecmint.com/wp-content/uploads/2016/10/Delete-All-Files-Except-Few-Files-in-Linux.png
|
||||
[9]:http://www.tecmint.com/wp-content/uploads/2016/10/DeleteAll-Files-Except-One-File-in-Linux.png
|
||||
@@ -0,0 +1,27 @@
|
||||
98% 的开发者在工作中使用了开源软件
|
||||
==================
|
||||
|
||||

|
||||
|
||||
开源每天都会达到新的高度。但是一个新的研究表明超过 98% 的开发者在工作中使用开源工具。
|
||||
|
||||
Git 仓库管理软件 [GitLab][1] 进行了一项调查披露了一些关于开源接受度的有趣事实。针对开发人员群体的调查表明 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][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: http://opensourceforu.com/author/jagmeet-singh/
|
||||
[1]:https://about.gitlab.com/2016/11/02/global-developer-survey-2016/
|
||||
@@ -1,148 +0,0 @@
|
||||
TOP 5 BEST VIDEO EDITING SOFTWARE FOR LINUX IN 2016
|
||||
=====================================================
|
||||
|
||||

|
||||
|
||||
Brief: Tiwo discusses the best video editors for Linux, their pros and cons and the installation method for Ubuntu-based distros in this article.
|
||||
|
||||
We have discussed [best photo management applications for Linux][1], [best code editors for Linux][2] in similar articles in the past. Today we shall see the best video editing software for Linux.
|
||||
|
||||
When asked about free video editing software, Windows Movie Maker and iMovie is what most people often suggest.
|
||||
|
||||
Unfortunately, both of them are not available for GNU/Linux. But you don’t need to worry about it, we have pooled together a list of best free video editors for you.
|
||||
|
||||
### BEST VIDEO EDITOR APPS FOR LINUX
|
||||
|
||||
Let’s have a look at the top 5 best free video editing software for Linux below :
|
||||
|
||||
#### 1. KDENLIVE
|
||||
|
||||

|
||||
|
||||
[Kdenlive][3] is a free and [open source][4] video editing software from KDE that provides dual video monitors, a multi-track timeline, clip list, customizable layout support, basic effects, and basic transitions.
|
||||
It supports wide variety of file formats and a wide range of camcorders and cameras including Low resolution camcorder (Raw and AVI DV editing), Mpeg2, mpeg4 and h264 AVCHD (small cameras and camcorders), High resolution camcorder files, including HDV and AVCHD camcorders, Professional camcorders, including XDCAM-HD™ streams, IMX™ (D10) streams, DVCAM (D10) , DVCAM, DVCPRO™, DVCPRO50™ streams and DNxHD™ streams.
|
||||
|
||||
You can install it from terminal by running the following command :
|
||||
|
||||
```
|
||||
sudo apt-get install kdenlive
|
||||
```
|
||||
|
||||
Or, open Ubuntu Software Center then search Kdenlive.
|
||||
|
||||
#### 2. OPENSHOT
|
||||
|
||||

|
||||
|
||||
[OpenShot][5] is the second choice in our list of Linux video editing software. OpenShot can help you create the film that supports for transitions, effects, adjusting audio levels, and of course, it support of most formats and codecs.
|
||||
|
||||
You can also export your film to DVD, upload to YouTube, Vimeo, Xbox 360, and many other common formats. OpenShot is simpler than kdenlive. So if you need a video editor with a simple UI OpenShot is a good choice.
|
||||
|
||||
The latest version is 2.0.7. You can install OpenShot video editor by run the following command from terminal window :
|
||||
|
||||
```
|
||||
sudo apt-get install openshot
|
||||
```
|
||||
|
||||
It needs to download 25 MB, and 70 MB disk space after installed.
|
||||
|
||||
#### 3. FLOWBLADE MOVIE EDITOR
|
||||
|
||||

|
||||
|
||||
[Flowblade Movie Editor][6] is a multitrack non-linear video editor for Linux. It is free and open source. It comes with a stylish and modern user interface.
|
||||
|
||||
Written in Python, it is designed to provide a fast, and precise. Flowblade has focused on providing the best possible experience on Linux and other free platforms. So there’s no Windows and OS X version for now.
|
||||
|
||||
To install Flowblade in Ubuntu and other Ubuntu based systems, use the command below:
|
||||
|
||||
```
|
||||
sudo apt-get install flowblade
|
||||
```
|
||||
|
||||
#### 4. LIGHTWORKS
|
||||
|
||||

|
||||
|
||||
If you looking for a video editor software that has more feature, this is the answer. [Lightworks][7] is a cross-platform professional video editor, available for Linux, Mac OS X and Windows.
|
||||
|
||||
It is an award winning professional [non-linear editing][8] (NLE) software that supports resolutions up to 4K as well as video in SD and HD formats.
|
||||
|
||||
This application has two versions: Lightworks Free and Lightworks Pro. While free version doesn’t support Vimeo (H.264 / MPEG-4) and YouTube (H.264 / MPEG-4)- Up to 2160p (4K UHD), Blu-ray, and H.264/MP4 export option with configurable bitrate setting, then pro version is.
|
||||
|
||||
- Lightworks Free
|
||||
- Lightworks Pro
|
||||
|
||||
Pro version has more features such as higher resolution support, 4K and Blue Ray support etc.
|
||||
|
||||
##### HOW TO INSTALL LIGHTWORKS?
|
||||
|
||||
Unlike the other video editors, installing Lightwork is not as straight forward as running a single command. Don’t worry, it’s not that complicated either.
|
||||
|
||||
- Step 1 – You can get the package from [Lightworks Downloads Page][9]. The package’s size about 79,5 MB.
|
||||
|
||||
>Please note: There’s no Linux 32-bit support.
|
||||
|
||||
- Step 2 – Once downloaded, you can install it using [Gdebi package installer][10]. Gdebi automatically downloads the dependency :
|
||||
|
||||

|
||||
|
||||
- Step 3 – Now you can open it from Ubuntu dashboard, or your Linux distro’s menu.
|
||||
|
||||
- Step 4 – It needs an account when you use it for first time. Click at Not Registerd? button to register. Don’t worry, it’s free!
|
||||
|
||||
- Step 5 – After your account has been verified, now login.
|
||||
|
||||
Now the Lightworks is ready to use.
|
||||
|
||||
Need Lightworks video tutorial? Get them at [Lightworks video tutorials Page][11].
|
||||
|
||||
#### 5. BLENDER
|
||||
|
||||

|
||||
|
||||
Blender 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 Spider Man series.
|
||||
|
||||
Although originally designed for produce 3D modeling, but it can also be used for video editing and input capabilities with a variety of formats. The Video Editor includes:
|
||||
|
||||
- Live preview, luma waveform, chroma vectorscope and histogram displays
|
||||
- Audio mixing, syncing, scrubbing and waveform visualization
|
||||
- Up to 32 slots for adding video, images, audio, scenes, masks and effects
|
||||
- Speed control, adjustment layers, transitions, keyframes, filters and more.
|
||||
|
||||
The latest version can be downloaded from [Blender Download Page][12].
|
||||
|
||||
### WHICH IS THE BEST VIDEO EDITING SOFTWARE?
|
||||
|
||||
If you need a simple video editor, OpenShot, Kdenlive or Flowblade is a good choice. These are suitable for beginners and a system with standard specification.
|
||||
|
||||
Then if you have a high-end computer, and need advanced features you can go out with Lightworks. If you are looking for more advanced features, Blender has got your back.
|
||||
|
||||
So that’s all I can write about 5 best video editing software for Linux such as Ubuntu, Linux Mint, Elementary, and other Linux distributions. Share with us which video editor you like the most.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/best-video-editing-software-linux/
|
||||
|
||||
作者:[Tiwo Satriatama][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/tiwo/
|
||||
[1]: https://itsfoss.com/linux-photo-management-software/
|
||||
[2]: https://itsfoss.com/best-modern-open-source-code-editors-for-linux/
|
||||
[3]: https://kdenlive.org/
|
||||
[4]: https://itsfoss.com/tag/open-source/
|
||||
[5]: http://www.openshot.org/
|
||||
[6]: http://jliljebl.github.io/flowblade/
|
||||
[7]: https://www.lwks.com/
|
||||
[8]: https://en.wikipedia.org/wiki/Non-linear_editing_system
|
||||
[9]: https://www.lwks.com/index.php?option=com_lwks&view=download&Itemid=206
|
||||
[10]: https://itsfoss.com/gdebi-default-ubuntu-software-center/
|
||||
[11]: https://www.lwks.com/videotutorials
|
||||
[12]: https://www.blender.org/download/
|
||||
|
||||
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
LinuxBars翻译中
|
||||
How to Secure Network Services Using TCP Wrappers in Linux
|
||||
===========
|
||||
|
||||
|
||||
In this article we will explain what TCP wrappers are and how to configure them to [restrict access to network services][7] running on a Linux server. Before we start, however, we must clarify that the use of TCP wrappers does not eliminate the need for a properly [configured firewall][6].
|
||||
|
||||
In this regard, you can think of this tool as a [host-based access control list][5], and not as the [ultimate security measure][4] for your system. By using a firewall and TCP wrappers, instead of favoring one over the other, you will make sure that your server is not left with a single point of failure.
|
||||
|
||||
### Understanding hosts.allow and hosts.deny
|
||||
|
||||
When a network request reaches your server, TCP wrappers uses `hosts.allow` and `hosts.deny` (in that order) to determine if the client should be allowed to use a given service.
|
||||
|
||||
By default, these files are empty, all commented out, or do not exist. Thus, everything is allowed through the TCP wrappers layer and your system is left to rely on the firewall for full protection. Since this is not desired, due to the reason we stated in the introduction, make sure both files exist:
|
||||
|
||||
```
|
||||
# ls -l /etc/hosts.allow /etc/hosts.deny
|
||||
|
||||
```
|
||||
|
||||
The syntax of both files is the same:
|
||||
|
||||
```
|
||||
<services> : <clients> [: <option1> : <option2> : ...]
|
||||
|
||||
```
|
||||
|
||||
where,
|
||||
|
||||
1. services is a comma-separated list of services the current rule should be applied to.
|
||||
2. clients represent the list of comma-separated hostnames or IP addresses affected by the rule. The following wildcards are accepted:
|
||||
1. ALL matches everything. Applies both to clients and services.
|
||||
2. LOCAL matches hosts without a period in their FQDN, such as localhost.
|
||||
3. KNOWN indicate a situation where the hostname, host address, or user are known.
|
||||
4. UNKNOWN is the opposite of KNOWN.
|
||||
5. PARANOID causes a connection to be dropped if reverse DNS lookups (first on IP address to determine host name, then on host name to obtain the IP addresses) return a different address in each case.
|
||||
3. Finally, an optional list of colon-separated actions indicate what should happen when a given rule is triggered.
|
||||
|
||||
You may want to keep in mind that a rule allowing access to a given service in `/etc/hosts.allow` takes precedence over a rule in `/etc/hosts.deny` prohibiting it. Additionally, if two rules apply to the same service, only the first one will be taken into account.
|
||||
|
||||
Unfortunately, not all network services support the use of TCP wrappers. To determine if a given service supports them, do:
|
||||
|
||||
```
|
||||
# ldd /path/to/binary | grep libwrap
|
||||
|
||||
```
|
||||
|
||||
If the above command returns output, it can be TCP-wrapped. An example of this are sshd and vsftpd, as shown here:
|
||||
|
||||
[][3]
|
||||
|
||||
Find Supported Services in TCP Wrapper
|
||||
|
||||
### How to Use TCP Wrappers to Restrict Access to Services
|
||||
|
||||
As you edit `/etc/hosts.allow` and `/etc/hosts.deny`, make sure you add a newline by pressing Enter after the last non-empty line.
|
||||
|
||||
To [allow SSH and FTP access][2] only to 192.168.0.102 and localhost and deny all others, add these two lines in `/etc/hosts.deny`:
|
||||
|
||||
```
|
||||
sshd,vsftpd : ALL
|
||||
ALL : ALL
|
||||
|
||||
```
|
||||
|
||||
and the following line in `/etc/hosts.allow`:
|
||||
|
||||
```
|
||||
sshd,vsftpd : 192.168.0.102,LOCAL
|
||||
|
||||
```
|
||||
|
||||
TCP Wrappers – hosts.deny File
|
||||
```
|
||||
#
|
||||
# hosts.deny This file contains access rules which are used to
|
||||
# deny connections to network services that either use
|
||||
# the tcp_wrappers library or that have been
|
||||
# started through a tcp_wrappers-enabled xinetd.
|
||||
#
|
||||
# The rules in this file can also be set up in
|
||||
# /etc/hosts.allow with a 'deny' option instead.
|
||||
#
|
||||
# See 'man 5 hosts_options' and 'man 5 hosts_access'
|
||||
# for information on rule syntax.
|
||||
# See 'man tcpd' for information on tcp_wrappers
|
||||
#
|
||||
sshd,vsftpd : ALL
|
||||
ALL : ALL
|
||||
|
||||
```
|
||||
|
||||
TCP Wrappers – hosts.allow File
|
||||
```
|
||||
#
|
||||
# hosts.allow This file contains access rules which are used to
|
||||
# allow or deny connections to network services that
|
||||
# either use the tcp_wrappers library or that have been
|
||||
# started through a tcp_wrappers-enabled xinetd.
|
||||
#
|
||||
# See 'man 5 hosts_options' and 'man 5 hosts_access'
|
||||
# for information on rule syntax.
|
||||
# See 'man tcpd' for information on tcp_wrappers
|
||||
#
|
||||
sshd,vsftpd : 192.168.0.102,LOCAL
|
||||
|
||||
```
|
||||
|
||||
These changes take place immediately without the need for a restart.
|
||||
|
||||
In the following image you can see the effect of removing the word `LOCAL` from the last line: the FTP server will become unavailable for localhost. After we add the wildcard back, the service becomes available again.
|
||||
|
||||
[][1]
|
||||
>Verify FTP Access
|
||||
|
||||
To allow all services to hosts where the name contains `example.com`, add this line in `hosts.allow`:
|
||||
|
||||
```
|
||||
ALL : .example.com
|
||||
|
||||
```
|
||||
|
||||
and to deny access to vsftpd to machines on 10.0.1.0/24, add this line in `hosts.deny`:
|
||||
|
||||
```
|
||||
vsftpd : 10.0.1.
|
||||
|
||||
```
|
||||
|
||||
On the last two examples, notice the dot at the beginning and the end of the client list. It is used to indicate “ALL hosts and / or clients where the name or the IP contains that string”.
|
||||
|
||||
Was this article helpful to you? Do you have any questions or comments? Feel free to drop us a note using the comment form below.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/secure-linux-tcp-wrappers-hosts-allow-deny-restrict-access/
|
||||
|
||||
作者:[Gabriel Cánepa][a]
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/gacanepa/
|
||||
[1]:http://www.tecmint.com/wp-content/uploads/2016/10/Verify-FTP-Access.png
|
||||
[2]:http://www.tecmint.com/block-ssh-and-ftp-access-to-specific-ip-and-network-range/
|
||||
[3]:http://www.tecmint.com/wp-content/uploads/2016/10/Find-Supported-Services-in-TCP-Wrapper.png
|
||||
[4]:http://www.tecmint.com/linux-server-hardening-security-tips/
|
||||
[5]:http://www.tecmint.com/secure-files-using-acls-in-linux/
|
||||
[6]:http://www.tecmint.com/configure-firewalld-in-centos-7/
|
||||
[7]:http://www.tecmint.com/mandatory-access-control-with-selinux-or-apparmor-linux/
|
||||
@@ -1,552 +0,0 @@
|
||||
OneNewLife translating
|
||||
|
||||
# Getting Started with Webpack 2
|
||||
|
||||

|
||||
|
||||
Webpack 2 will be out of beta [once the documentation has been finished][26]. But that doesn’t mean you can’t start using version 2 now if you know how to configure it.
|
||||
|
||||
### What is Webpack?
|
||||
|
||||
At its simplest, Webpack is a module bundler for your JavaScript. However, since its release it’s evolved into a manager of all your front-end code (either intentionally or by the community’s will).
|
||||
|
||||

|
||||
|
||||
|
||||
A task runner such as _Gulp _can handle many different preprocessers and transpilers, but in all cases, it will take a source _input_ and crunch it into a compiled _output. _However, it does this on a case-by-case basis with no concern for the system at large. That is the burden of the developer: to pick up where the task runner left off and find the proper way for all these moving parts to mesh together in production.
|
||||
|
||||
Webpack attempts to lighten the developer load a bit by asking a bold question: _what if there were a part of the development process that handled dependencies on its own? What if we could simply write code in such a way that the build process managed itself, based on only what was necessary in the end?_
|
||||
|
||||

|
||||
|
||||
If you’ve been a part of the web community for the past few years, you already know the preferred method of solving a problem: _build this with JavaScript._And so Webpack attempts to make the build process easier by passing dependencies through JavaScript. But the true power of its design isn’t simply the code _management_ part; it’s that this management layer is 100% valid JavaScript (with Node features). Webpack gives you the ability to write valid JavaScript that has a better sense of the system at large.
|
||||
|
||||
In other words: _you don’t write code for Webpack. You write code for your projec_t. And Webpack keeps up (with some config, of course).
|
||||
|
||||
In a nutshell, if you’ve ever struggled with any of the following:
|
||||
|
||||
* Accidentally including stylesheets and JS libraries you don’t need into production, bloating the size
|
||||
* Encountering scoping issues—both from CSS and JavaScript
|
||||
* Finding a good system for using Node/Bower modules in your JavaScript, or relying on a crazy backend configuration to properly utilize those modules
|
||||
* Needing to optimize asset delivery better but fearing you’ll break something
|
||||
|
||||
…then you could benefit from Webpack. It handles all the above effortlessly by letting JavaScript worry about your dependencies and load order instead of your developer brain. The best part? Webpack can even run purely on the server side, meaning you can still build [progressively-enhanced][25] websites using Webpack.
|
||||
|
||||
### First Steps
|
||||
|
||||
We’ll use [Yarn][24] (`brew install yarn`) in this tutorial instead of `npm`, but it’s totally up to you; they do the same thing. From our project folder, we’ll run the following in a terminal window to add Webpack 2 to both our global packages and our local project:
|
||||
|
||||
```
|
||||
yarn global add webpack@2.1.0-beta.25 webpack-dev-server@2.1.0-beta.9
|
||||
yarn add --dev webpack@2.1.0-beta.25 webpack-dev-server@2.1.0-beta.9
|
||||
```
|
||||
|
||||
We’ll then declare a webpack configuration with a `webpack.config.js` file in the root of our project directory:
|
||||
|
||||
```
|
||||
`'use strict';
|
||||
|
||||
const webpack = require("webpack");
|
||||
|
||||
module.exports = {
|
||||
context: __dirname + "/src",
|
||||
entry: {
|
||||
app: "./app.js",
|
||||
},
|
||||
output: {
|
||||
path: __dirname + "/dist",
|
||||
filename: "[name].bundle.js",
|
||||
},
|
||||
};`
|
||||
```
|
||||
|
||||
_Note: _`___dirname_`_ refers to the root of your project._
|
||||
|
||||
Remember that Webpack “knows” what’s going in your project? It _knows_ by reading your code (don’t worry; it signed an NDA). Webpack basically does the following:
|
||||
|
||||
1. Starting from the `context` folder, …
|
||||
2. … it looks for `entry` filenames …
|
||||
3. … and reads the content. Every `import` ([ES6][7]) or `require()` (Node) dependency it finds as it parses the code, it bundles for the final build. It then searches _those_ dependencies, and those dependencies’ dependencies, until it reaches the very end of the “tree”—only bundling what it needed to, and nothing else.
|
||||
4. From there, Webpack bundles everything to the `output.path` folder, naming it using the `output.filename` naming template (`[name]` gets replaced with the object key from `entry`)
|
||||
|
||||
So if our `src/app.js` file looked something like this (assuming we ran `yarn add --dev moment` beforehand):
|
||||
|
||||
```
|
||||
'use strict';
|
||||
```
|
||||
|
||||
```
|
||||
import moment from 'moment';
|
||||
var rightNow = moment().format('MMMM Do YYYY, h:mm:ss a');
|
||||
console.log( rightNow );
|
||||
```
|
||||
|
||||
```
|
||||
// "October 23rd 2016, 9:30:24 pm"
|
||||
```
|
||||
|
||||
We’d run
|
||||
|
||||
```
|
||||
webpack -p
|
||||
```
|
||||
|
||||
_Note: The _`_p_`_ flag is “production” mode and uglifies/minifies output._
|
||||
|
||||
And it would output a `dist/app.bundle.js` that logged the current date & time to the console. Note that Webpack automatically knew what `'moment'`referred to (although if you had a `moment.js` file in your directory, by default Webpack would have prioritized this over your `moment` Node module).
|
||||
|
||||
### Working with Multiple Files
|
||||
|
||||
You can specify any number of entry/output points you wish by modifying only the `entry` object.
|
||||
|
||||
#### Multiple files, bundled together
|
||||
|
||||
```
|
||||
`'use strict';
|
||||
|
||||
const webpack = require("webpack");
|
||||
|
||||
module.exports = {
|
||||
context: __dirname + "/src",
|
||||
entry: {
|
||||
app: ["./home.js", "./events.js", "./vendor.js"],
|
||||
},
|
||||
output: {
|
||||
path: __dirname + "/dist",
|
||||
filename: "[name].bundle.js",
|
||||
},
|
||||
};`
|
||||
```
|
||||
|
||||
Will all be bundled together as one `dist/app.bundle.js` file, in array order.
|
||||
|
||||
#### Multiple files, multiple outputs
|
||||
|
||||
```
|
||||
`const webpack = require("webpack");
|
||||
|
||||
module.exports = {
|
||||
context: __dirname + "/src",
|
||||
entry: {
|
||||
home: "./home.js",
|
||||
events: "./events.js",
|
||||
contact: "./contact.js",
|
||||
},
|
||||
output: {
|
||||
path: __dirname + "/dist",
|
||||
filename: "[name].bundle.js",
|
||||
},
|
||||
};`
|
||||
```
|
||||
|
||||
Alternately, you may choose to bundle multiple JS files to break up parts of your app. This will be bundled as 3 files: `dist/home.bundle.js`, `dist/events.bundle.js`, and `dist/contact.bundle.js`.
|
||||
|
||||
#### Advanced auto-bundling
|
||||
|
||||
If you’re breaking up your application into multiple `output` bundles (useful if one part of your app has a ton of JS you don’t need to load up front), there’s a likelihood you may be duplicating code across those files, because it will resolve each dependency separately from one another. Fortunately, Webpack has a built-in _CommonsChunk_ plugin to handle this:
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
// …
|
||||
```
|
||||
|
||||
```
|
||||
plugins: [
|
||||
new webpack.optimize.CommonsChunkPlugin({
|
||||
name: "commons",
|
||||
filename: "commons.js",
|
||||
minChunks: 2,
|
||||
}),
|
||||
],
|
||||
```
|
||||
|
||||
```
|
||||
// …
|
||||
};
|
||||
```
|
||||
|
||||
Now, across your `output` files, if you have any modules that get loaded `2` or more times (set by `minChunks`), it will bundle that into a `commons.js` file which you can then cache on the client side. This will result in an additional header request, sure, but you prevent the client from downloading the same libraries more than once. So there are many scenarios where this is a net gain for speed.
|
||||
|
||||
### Developing
|
||||
|
||||
Webpack actually has its own development server, so whether you’re developing a static site or are just prototyping your front-end, it’s perfect for either. To get that running, just add a `devServer` object to `webpack.config.js`:
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
context: __dirname + "/src",
|
||||
entry: {
|
||||
app: "./app.js",
|
||||
},
|
||||
output: {
|
||||
filename: "[name].bundle.js",
|
||||
path: __dirname + "/dist/assets",
|
||||
publicPath: "/assets", // New
|
||||
},
|
||||
devServer: {
|
||||
contentBase: __dirname + "/src", // New
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
Now make a `src/index.html` file that has:
|
||||
|
||||
```
|
||||
<script src="/assets/app.bundle.js"></script>
|
||||
```
|
||||
|
||||
… and from your terminal, run:
|
||||
|
||||
```
|
||||
webpack-dev-server
|
||||
```
|
||||
|
||||
Your server is now running at `localhost:8080`. _Note how _`_/assets_`_ in the script tag matches _`_output.publicPath_`_—you can name this whatever you want (useful if you need a CDN)._
|
||||
|
||||
Webpack will hotload any JavaScript changes as you make them without the need to refresh your browser. However, any changes to the`webpack.config.js` file will require a server restart to take effect.
|
||||
|
||||
### Globally-accessible methods
|
||||
|
||||
Need to use some of your functions from a global namespace? Simply set `output.library` within `webpack.config.js`:
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
output: {
|
||||
library: 'myClassName',
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
… and it will attach your bundle to a `window.myClassName` instance. So using that name scope, you could call methods available to that entry point (you can read more about this setting [on the documentation][23]).
|
||||
|
||||
### Loaders
|
||||
|
||||
Up until now, we’ve only covered working with JavaScript. It’s important to start with JavaScript because _that’s the only language Webpack speaks_. We can work with virtually any file type, as long as we pass it into JavaScript. We do that with _Loaders_.
|
||||
|
||||
A loader can refer to a preprocessor such as Sass, or a transpiler such as Babel. On NPM, they’re usually named `*-loader` such as `sass-loader` or `babel-loader`.
|
||||
|
||||
#### Babel + ES6
|
||||
|
||||
If we wanted to use ES6 via [Babel][22] in our project, we’d first install the appropriate loaders locally:
|
||||
|
||||
```
|
||||
yarn add --dev babel-loader babel-core babel-preset-es2015
|
||||
```
|
||||
|
||||
… and then add it to `webpack.config.js` so Webpack knows where to use it.
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
// …
|
||||
```
|
||||
|
||||
```
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
use: [{
|
||||
loader: "babel-loader",
|
||||
options: { presets: ["es2015"] }
|
||||
}],
|
||||
},
|
||||
|
||||
// Loaders for other file types can go here
|
||||
```
|
||||
|
||||
```
|
||||
],
|
||||
},
|
||||
```
|
||||
|
||||
```
|
||||
// …
|
||||
};
|
||||
```
|
||||
|
||||
_A note for Webpack 1 users: the core concept for Loaders remains the same, but the syntax has improved. Until they finish the docs this may/may not be the exact preferred syntax._
|
||||
|
||||
This looks for the `/\.js$/` RegEx search for any files that end in `.js` to be loaded via Babel. Webpack relies on RegEx tests to give you complete control—it doesn’t limit you to file extensions or assume your code must be organized in a certain way. For example: maybe your `/my_legacy_code/` folder isn’t written in ES6\. So you could modify the `test` above to be `/^((?!my_legacy_folder).)*\.js$/` which would exclude that specific folder, but process the rest with Babel.
|
||||
|
||||
#### CSS + Style Loader
|
||||
|
||||
If we wanted to only load CSS as our application needed, we could do that as well. Let’s say we have an `index.js` file. We’ll import it from there:
|
||||
|
||||
```
|
||||
import styles from './assets/stylesheets/application.css';
|
||||
```
|
||||
|
||||
We’ll get the following error: `You may need an appropriate loader to handle this file type`. Remember that Webpack can only understand JavaScript, so we’ll have to install the appropriate loader:
|
||||
|
||||
```
|
||||
yarn add --dev css-loader style-loader
|
||||
```
|
||||
|
||||
… and then add a rule to `webpack.config.js`:
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
// …
|
||||
```
|
||||
|
||||
```
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: ["style-loader", "css-loader"],
|
||||
},
|
||||
```
|
||||
|
||||
```
|
||||
// …
|
||||
],
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
_Loaders are processed in __reverse array order__. That means _`_css-loader_`_ will run before _`_style-loader_`_._
|
||||
|
||||
You may notice that even in production builds, this actually bundles your CSS in with your bundled JavaScript, and `style-loader` manually writes your styles to the `<head>`. At first glance it may seem a little kooky, but slowly starts to make more sense the more you think about it. You’ve saved a header request—saving valuable time on some connections—and if you’re loading your DOM with JavaScript anyway, this essentially eliminates [FOUC][21] on its own.
|
||||
|
||||
You’ll also notice that—out of the box—Webpack has automatically resolved all of your `@import` queries by packaging those files together as one (rather than relying on CSS’s default import which can result in gratuitious header requests and slow-loading assets).
|
||||
|
||||
Loading CSS from your JS is pretty amazing, because you now can modularize your CSS in powerful new ways. Say you loaded `button.css`only through `button.js`. This would mean if `button.js` is never actually used_, _its CSS wouldn’t bloat out our production build. If you adhere to component-oriented CSS practices such as SMACSS or BEM, you see the value in pairing your CSS more closely with your markup + JavaScript.
|
||||
|
||||
#### CSS + Node modules
|
||||
|
||||
We can use Webpack to take advantage of importing Node modules using Node’s `~` prefix. If we ran `yarn add normalize.css`, we could use:
|
||||
|
||||
```
|
||||
@import "~normalize.css";
|
||||
```
|
||||
|
||||
… and take full advantage of NPM managing our third party styles for us—versioning and all—without any copy + pasting on our part. Further, getting Webpack to bundle CSS for us has obvious advantages over using CSS’s default import, saving the client from gratuitous header requests and slow load times.
|
||||
|
||||
_Update: this and the following section have been updated for accuracy, no longer confusing using CSS Modules to simply import Node modules. Thanks to _[_Albert Fernández_][20]_ for the help!_
|
||||
|
||||
#### CSS Modules
|
||||
|
||||
You may have heard of [CSS Modules][19], which takes the _C_ out of _CSS_. It typically works best only if you’re building the DOM with JavaScript, but in essence, it magically scopes your CSS classes to the JavaScript file that loaded it ([learn more about it here][18]). If you plan on using it, CSS Modules comes packaged with `css-loader` (`yarn add --dev css-loader`):
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
// …
|
||||
```
|
||||
|
||||
```
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
"style-loader",
|
||||
{ loader: "css-loader", options: { modules: true } }
|
||||
],
|
||||
},
|
||||
```
|
||||
|
||||
```
|
||||
// …
|
||||
],
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
_Note: for _`_css-loader_`_ we’re now using the __expanded object syntax__ to pass an option to it. You can use a string instead as shorthand to use the default options, as we’re still doing with _`_style-loader_`_._
|
||||
|
||||
* * *
|
||||
|
||||
It’s worth noting that you can actually drop the `~` when importing Node Modules with CSS Modules enabled (e.g.: `@import "normalize.css";`). However, you may encounter build errors now when you `@import` your own CSS. If you’re getting “can’t find ___” errors, try adding a `resolve` object to `webpack.config.js` to give Webpack a better understanding of your intended module order.
|
||||
|
||||
```
|
||||
const path = require("path");
|
||||
```
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
//…
|
||||
```
|
||||
|
||||
```
|
||||
resolve: {
|
||||
modules: [path.resolve(__dirname, "src"), "node_modules"]
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
We specified our source directory first, and then `node_modules`. So Webpack will handle resolution a little better, first looking through our source directory and then the installed Node modules, in that order (replace `"src"` and `"node_modules"` with your source and Node module directories, respectively).
|
||||
|
||||
#### Sass
|
||||
|
||||
Need to use Sass? No problem. Install:
|
||||
|
||||
```
|
||||
yarn add --dev sass-loader node-sass
|
||||
```
|
||||
|
||||
And add another rule:
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
// …
|
||||
```
|
||||
|
||||
```
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.(sass|scss)$/,
|
||||
use: [
|
||||
"style-loader",
|
||||
"css-loader",
|
||||
"sass-loader",
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
// …
|
||||
],
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
Then when your Javascript calls for an `import` on a `.scss` or `.sass` file, Webpack will do its thing.
|
||||
|
||||
#### CSS bundled separately
|
||||
|
||||
Maybe you’re dealing with progressive enhancement; maybe you need a separate CSS file for some other reason. We can do that easily by swapping out `style-loader` with `extract-text-webpack-plugin` in our config without having to change any code. Take our example `app.js` file:
|
||||
|
||||
```
|
||||
import styles from './assets/stylesheets/application.css';
|
||||
```
|
||||
|
||||
Let’s install the plugin locally (we need the beta version for this as of Oct 2016)…
|
||||
|
||||
```
|
||||
yarn add --dev extract-text-webpack-plugin@2.0.0-beta.4
|
||||
```
|
||||
|
||||
… and add to `webpack.config.js`:
|
||||
|
||||
```
|
||||
const ExtractTextPlugin = require("extract-text-webpack-plugin");
|
||||
```
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
// …
|
||||
```
|
||||
|
||||
```
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
ExtractTextPlugin.extract("css"),
|
||||
{ loader: "css-loader", options: { modules: true } },
|
||||
],
|
||||
},
|
||||
|
||||
// …
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new ExtractTextPlugin({
|
||||
filename: "[name].bundle.css",
|
||||
allChunks: true,
|
||||
}),
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
Now when running `webpack -p` you’ll also notice an `app.bundle.css` file in your `output` directory. Simply add a `<link>` tag to that file in your HTML as you would normally.
|
||||
|
||||
#### HTML
|
||||
|
||||
As you might have guessed, there’s also an `[html-loader][6]`[ plugin][17] for Webpack. However, when we get to loading HTML with JavaScript, this is about the point where we branch off into a myriad of differing approaches, and I can’t think of one single example that would set you up for whatever you’re planning on doing next. Typically, you’d load HTML for the purpose of using JavaScript-flavored markup such as [JSX][16] or [Mustache][15] or [Handlebars][14] to be used within a larger system such as [React][13], [Angular][12], [Vue][11], or [Ember][10].
|
||||
|
||||
So I’ll end the tutorial here: you _can_ load markup with Webpack, but by this point you’ll be making your own decisions about your architecture that neither I nor Webpack can make for you. But using the above examples for reference and searching for the right loaders on NPM should be enough to get you going.
|
||||
|
||||
### Thinking in Modules
|
||||
|
||||
In order to get the most out of Webpack, you’ll have to think in modules—small, reusable, self-contained processes that do one thing and one thing well. That means taking something like this:
|
||||
|
||||
```
|
||||
└── js/
|
||||
└── application.js // 300KB of spaghetti code
|
||||
```
|
||||
|
||||
… and turning it into this:
|
||||
|
||||
```
|
||||
└── js/
|
||||
├── components/
|
||||
│ ├── button.js
|
||||
│ ├── calendar.js
|
||||
│ ├── comment.js
|
||||
│ ├── modal.js
|
||||
│ ├── tab.js
|
||||
│ ├── timer.js
|
||||
│ ├── video.js
|
||||
│ └── wysiwyg.js
|
||||
│
|
||||
└── application.js // ~ 1KB of code; imports from ./components/
|
||||
```
|
||||
|
||||
The result is clean, reusable code. Each individual component depends on `import`-ing its own dependencies, and `export`-ing what it wants to make public to other modules. Pair this with Babel + ES6, and you can utilize [JavaScript Classes][9] for great modularity, and _don’t-think-about-it _scoping that just works.
|
||||
|
||||
For more on modules, see [this excellent article by Preethi Kasreddy][8].
|
||||
|
||||
* * *
|
||||
|
||||
### Further Reading
|
||||
|
||||
* [What’s New in Webpack 2][5]
|
||||
* [Webpack Config docs][4]
|
||||
* [Webpack Examples][3]
|
||||
* [React + Webpack Starter Kit][2]
|
||||
* [Webpack How-to][1]
|
||||
|
||||
</section>
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://blog.madewithenvy.com/getting-started-with-webpack-2-ed2b86c68783#.oozfpppao
|
||||
|
||||
作者:[Drew Powers][a]
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://blog.madewithenvy.com/@an_ennui
|
||||
[1]:https://github.com/petehunt/webpack-howto
|
||||
[2]:https://github.com/kriasoft/react-starter-kit
|
||||
[3]:https://github.com/webpack/webpack/tree/master/examples
|
||||
[4]:https://webpack.js.org/configuration/
|
||||
[5]:https://gist.github.com/sokra/27b24881210b56bbaff7
|
||||
[6]:https://github.com/webpack/html-loader
|
||||
[7]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
|
||||
[8]:https://medium.freecodecamp.com/javascript-modules-a-beginner-s-guide-783f7d7a5fcc
|
||||
[9]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
|
||||
[10]:http://emberjs.com/
|
||||
[11]:http://vuejs.org/
|
||||
[12]:https://angularjs.org/
|
||||
[13]:https://facebook.github.io/react/
|
||||
[14]:http://handlebarsjs.com/
|
||||
[15]:https://github.com/janl/mustache.js/
|
||||
[16]:https://jsx.github.io/
|
||||
[17]:https://github.com/webpack/html-loader
|
||||
[18]:https://github.com/css-modules/css-modules
|
||||
[19]:https://github.com/css-modules/css-modules
|
||||
[20]:https://medium.com/u/901a038e32e5
|
||||
[21]:https://en.wikipedia.org/wiki/Flash_of_unstyled_content
|
||||
[22]:https://babeljs.io/
|
||||
[23]:https://webpack.js.org/concepts/output/#output-library
|
||||
[24]:https://yarnpkg.com/
|
||||
[25]:https://www.smashingmagazine.com/2009/04/progressive-enhancement-what-it-is-and-how-to-use-it/
|
||||
[26]:https://github.com/webpack/webpack/issues/1545#issuecomment-255446425
|
||||
@@ -1,121 +0,0 @@
|
||||
alim0x translating
|
||||
|
||||
How to Check Bad Sectors or Bad Blocks on Hard Disk in Linux
|
||||
===
|
||||
|
||||
Let us start by defining a bad sector/block, it’s a section on a disk drive or flash memory that can not be read from or written to anymore, as a result of a fixed [physical damage on the disk][7] surface or failed flash memory transistors.
|
||||
|
||||
As bad sectors continue to accumulate, they can undesirably or destructively affect your disk drive or flash memory capacity or even lead to a possible hardware failure.
|
||||
|
||||
It is also important to note that the presence of bad blocks should alert you to start thinking of getting a new disk drive or simply mark the bad blocks as unusable.
|
||||
|
||||
Therefore, in this article, we will go through the necessary steps that can enable you determine the presence or absence of bad sectors on your Linux disk drive or flash memory using certain [disk scanning utilities][6].
|
||||
|
||||
That said, below are the methods:
|
||||
|
||||
### Check Bad Sectors in Linux Disks Using badblocks Tool
|
||||
|
||||
A badblocks program enables users to scan a device for bad sectors or blocks. The device can be a hard disk or an external disk drive, represented by a file such as /dev/sdc.
|
||||
|
||||
Firstly, use the [fdisk command][5] with superuser privileges to display information about all your disk drives or flash memory plus their partitions:
|
||||
|
||||
```
|
||||
$ sudo fdisk -l
|
||||
|
||||
```
|
||||
|
||||
[][4]
|
||||
|
||||
List Linux Filesystem Partitions
|
||||
|
||||
Then scan your Linux disk drive to check for bad sectors/blocks by typing:
|
||||
|
||||
```
|
||||
$ sudo badblocks -v /dev/sda10 > badsectors.txt
|
||||
|
||||
```
|
||||
|
||||
[][3]
|
||||
|
||||
Scan Hard Disk Bad Sectors in Linux
|
||||
|
||||
In the command above, badblocks is scanning device /dev/sda10 (remember to specify your actual device) with the `-v` enabling it to display details of the operation. In addition, the results of the operation are stored in the file badsectors.txt by means of output redirection.
|
||||
|
||||
In case you discover any bad sectors on your disk drive, unmount the disk and instruct the operating system not to write to the reported sectors as follows.
|
||||
|
||||
You will need to employ e2fsck (for ext2/ext3/ext4 file systems) or fsck command with the badsectors.txt file and the device file as in the command below.
|
||||
|
||||
The `-l` option tells the command to add the block numbers listed in the file specified by filename (badsectors.txt) to the list of bad blocks.
|
||||
|
||||
```
|
||||
------------ Specifically for ext2/ext3/ext4 file-systems ------------
|
||||
$ sudo e2fsck -l badsectors.txt /dev/sda10
|
||||
|
||||
OR
|
||||
|
||||
------------ For other file-systems ------------
|
||||
$ sudo fsck -l badsectors.txt /dev/sda10
|
||||
|
||||
```
|
||||
|
||||
### Scan Bad Sectors on Linux Disk Using Smartmontools
|
||||
|
||||
This method is more reliable and efficient for modern disks (ATA/SATA and SCSI/SAS hard drives and solid-state drives) which ship in with a S.M.A.R.T (Self-Monitoring, Analysis and Reporting Technology) system that helps detect, report and possibly log their health status, so that you can figure out any impending hardware failures.
|
||||
|
||||
You can install smartmontools by running the command below:
|
||||
|
||||
```
|
||||
------------ On Debian/Ubuntu based systems ------------
|
||||
$ sudo apt-get install smartmontools
|
||||
|
||||
------------ On RHEL/CentOS based systems ------------
|
||||
$ sudo yum install smartmontools
|
||||
|
||||
```
|
||||
|
||||
Once the installation is complete, use smartctl which controls the S.M.A.R.T system integrated into a disk. You can look through its man page or help page as follows:
|
||||
|
||||
```
|
||||
$ man smartctl
|
||||
$ smartctl -h
|
||||
|
||||
```
|
||||
|
||||
Now execute the smartctrl command and name your specific device as an argument as in the following command, the flag `-H` or `--health` is included to display the SMART overall health self-assessment test result.
|
||||
|
||||
```
|
||||
$ sudo smartctl -H /dev/sda10
|
||||
|
||||
```
|
||||
|
||||
[][2]
|
||||
|
||||
Check Linux Hard Disk Health
|
||||
|
||||
The result above indicates that your hard disk is healthy, and may not experience hardware failures any soon.
|
||||
|
||||
For an overview of disk information, use the `-a` or `--all` option to print out all SMART information concerning a disk and `-x` or `--xall` which displays all SMART and non-SMART information about a disk.
|
||||
|
||||
In this tutorial, we covered a very important topic concerning [disk drive health diagnostics][1], you can reach us via the feedback section below to share your thoughts or ask any questions and remember to always stay connected to Tecmint.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/check-linux-hard-disk-bad-sectors-bad-blocks/
|
||||
|
||||
|
||||
作者:[Aaron Kili][a]
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: http://www.tecmint.com/author/aaronkili/
|
||||
[1]:http://www.tecmint.com/defragment-linux-system-partitions-and-directories/
|
||||
[2]:http://www.tecmint.com/wp-content/uploads/2016/10/Check-Linux-Hard-Disk-Health.png
|
||||
[3]:http://www.tecmint.com/wp-content/uploads/2016/10/Scan-Hard-Disk-Bad-Sectors-in-Linux.png
|
||||
[4]:http://www.tecmint.com/wp-content/uploads/2016/10/List-Linux-Filesystem-Partitions.png
|
||||
[5]:http://www.tecmint.com/fdisk-commands-to-manage-linux-disk-partitions/
|
||||
[6]:http://www.tecmint.com/ncdu-a-ncurses-based-disk-usage-analyzer-and-tracker/
|
||||
[7]:http://www.tecmint.com/defragment-linux-system-partitions-and-directories/
|
||||
@@ -1,3 +1,5 @@
|
||||
translating by chenzhijun
|
||||
|
||||
HOW TO CREATE AN EBOOK WITH CALIBRE IN LINUX [COMPLETE GUIDE]
|
||||
====
|
||||
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
# How to Convert Files to UTF-8 Encoding in Linux
|
||||
|
||||
In this guide, we will describe what character encoding and cover a few examples of converting files from one character encoding to another using a command line tool. Then finally, we will look at how to convert several files from any character set (charset) to UTF-8 encoding in Linux.
|
||||
|
||||
As you may probably have in mind already, a computer does not understand or store letters, numbers or anything else that we as humans can perceive except bits. A bit has only two possible values, that is either a `0` or `1`, `true` or `false`, `yes` or `no`. Every other thing such as letters, numbers, images must be represented in bits for a computer to process.
|
||||
|
||||
In simple terms, character encoding is a way of informing a computer how to interpret raw zeroes and ones into actual characters, where a character is represented by set of numbers. When we type text in a file, the words and sentences we form are cooked-up from different characters, and characters are organized into a charset.
|
||||
|
||||
There are various encoding schemes out there such as ASCII, ANSI, Unicode among others. Below is an example of ASCII encoding.
|
||||
|
||||
```
|
||||
Character bits
|
||||
A 01000001
|
||||
B 01000010
|
||||
|
||||
```
|
||||
|
||||
In Linux, the iconv command line tool is used to convert text from one form of encoding to another.
|
||||
|
||||
You can check the encoding of a file using the file command, by using the `-i` or `--mime` flag which enables printing of mime type string as in the examples below:
|
||||
|
||||
```
|
||||
$ file -i Car.java
|
||||
$ file -i CarDriver.java
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][3]
|
||||
|
||||
Check File Encoding in Linux
|
||||
|
||||
The syntax for using iconv is as follows:
|
||||
|
||||
```
|
||||
$ iconv option
|
||||
$ iconv options -f from-encoding -t to-encoding inputfile(s) -o outputfile
|
||||
|
||||
```
|
||||
|
||||
Where `-f` or `--from-code` means input encoding and `-t` or `--to-encoding` specifies output encoding.
|
||||
|
||||
To list all known coded character sets, run the command below:
|
||||
|
||||
```
|
||||
$ iconv -l
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][2]
|
||||
|
||||
List Coded Charsets in Linux
|
||||
|
||||
### Convert Files from UTF-8 to ASCII Encoding
|
||||
|
||||
Next, we will learn how to convert from one encoding scheme to another. The command below converts from ISO-8859-1 to UTF-8 encoding.
|
||||
|
||||
Consider a file named `input.file` which contains the characters:
|
||||
|
||||
```
|
||||
<EFBFBD> <20> <20> <20>
|
||||
|
||||
```
|
||||
|
||||
Let us start by checking the encoding of the characters in the file and then view the file contents. Closely, we can convert all the characters to ASCII encoding.
|
||||
|
||||
After running the iconv command, we then check the contents of the output file and the new encoding of the characters as below.
|
||||
|
||||
```
|
||||
$ 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
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][1]
|
||||
|
||||
Convert UTF-8 to ASCII in Linux
|
||||
|
||||
Note: In case the string `//IGNORE` is added to to-encoding, characters that can’t be converted and an error is displayed after conversion.
|
||||
|
||||
Again, supposing the string `//TRANSLIT` is added to to-encoding as in the example above (ASCII//TRANSLIT), characters being converted are transliterated as needed and if possible. Which implies in the event that a character can’t be represented in the target character set, it can be approximated through one or more similar looking characters.
|
||||
|
||||
Consequently, any character that can’t be transliterated and is not in target character set is replaced with a question mark `(?)` in the output.
|
||||
|
||||
### Convert Multiple Files to UTF-8 Encoding
|
||||
|
||||
Coming back to our main topic, to convert multiple or all files in a directory to UTF-8 encoding, you can write a small shell script called encoding.sh as follows:
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
#enter input encoding here
|
||||
FROM_ENCODING="value_here"
|
||||
#output encoding(UTF-8)
|
||||
TO_ENCODING="UTF-8"
|
||||
#convert
|
||||
CONVERT=" iconv -f $FROM_ENCODING -t $TO_ENCODING"
|
||||
#loop to convert multiple files
|
||||
for file in *.txt; do
|
||||
$CONVERT "$file" -o "${file%.txt}.utf8.converted"
|
||||
done
|
||||
exit 0
|
||||
|
||||
```
|
||||
|
||||
Save the file, then make the script executable. Run it from the directory where your files (`*.txt`) are located.
|
||||
|
||||
```
|
||||
$ chmod +x encoding.sh
|
||||
$ ./encoding.sh
|
||||
|
||||
```
|
||||
|
||||
Important: You can as well use this script for general conversion of multiple files from one given encoding to another, simply play around with the values of the `FROM_ENCODING` and `TO_ENCODING`variable, not forgetting the output file name `"${file%.txt}.utf8.converted"`.
|
||||
|
||||
For more information, look through the iconv man page.
|
||||
|
||||
```
|
||||
$ man iconv
|
||||
|
||||
```
|
||||
|
||||
To sum up this guide, understanding encoding and how to convert from one character encoding scheme to another is necessary knowledge for every computer user more so for programmers when it comes to dealing with text.
|
||||
|
||||
Lastly, you can get in touch with us by using the comment section below for any questions or feedback.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/convert-files-to-utf-8-encoding-in-linux/#
|
||||
|
||||
作者:[Aaron Kili][a]
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/aaronkili/
|
||||
[1]:http://www.tecmint.com/wp-content/uploads/2016/10/Converts-UTF8-to-ASCII-in-Linux.png
|
||||
[2]:http://www.tecmint.com/wp-content/uploads/2016/10/List-Coded-Charsets-in-Linux.png
|
||||
[3]:http://www.tecmint.com/wp-content/uploads/2016/10/Check-File-Encoding-in-Linux.png
|
||||
@@ -1,30 +0,0 @@
|
||||
translating------geekpi
|
||||
|
||||
# 98 percent of developers use open source at work
|
||||
|
||||

|
||||
|
||||
Open source is already reaching new heights each day. But a new study surfaced online that claims over 98 percent of developers use open source tools at work.
|
||||
|
||||
Git repository manager [GitLab][1] has conducted a survey that revealed some interesting facts about open source adoption. The survey, conducted with a developer group, claimed that of the 98 percent developers who prefer open source usage at work, 91 percent opt for the same development tools for work and personal projects. Moreover, 92 percent of the total group consider distributed version control systems (Git repositories) are crucial for their everyday work.
|
||||
|
||||
Among all the preferred programming languages, JavaScript comes on top with 51 percent of respondents. It is followed by Python, PHP, Java, Swift and Objective-C. Furthermore, 86 percent of developers considers security as a prime factor for judging the code.
|
||||
|
||||
“While process-driven development techniques have been successful in the past, developers are searching for a more natural evolution of software development that fosters collaboration and information sharing across the lifecycle of a project,” said Sid Sijbrandij, CEO and co-founder of GitLab, in a statement.
|
||||
|
||||
GitLab surveyed 362 startup and enterprise CTOs, developers and DevOps professionals who used its repository platform between July 6 and 27.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://opensourceforu.com/2016/11/98-percent-developers-use-open-source-at-work/
|
||||
|
||||
作者:[JAGMEET SINGH ][a]
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: http://opensourceforu.com/author/jagmeet-singh/
|
||||
[1]:https://about.gitlab.com/2016/11/02/global-developer-survey-2016/
|
||||
@@ -1,283 +0,0 @@
|
||||
# 4 Easy Ways To Generate A Strong Password In Linux
|
||||
|
||||

|
||||
Image Courtesy: Google.
|
||||
|
||||
Yesterday, We have covered how to [force users to use a strong password in DEB based systems][8]such as Debian, Ubuntu, Linux Mint, Elementary OS etc. You might wonder how a strong password looks like, and how could I create one? No worries! Here is the 4 easy ways to generate a strong password in Linux. Of course, there are many free tools and ways to accomplish this task, however I consider these methods are simple, and straightforward. Let us get started.
|
||||
|
||||
Download – [Free EBook: “Getting started with Ubuntu 16.04”][7]
|
||||
|
||||
### 1\. Generate a strong password in Linux using OpenSSL
|
||||
|
||||
OpenSSL is available for all Unix-like distributions, Solaris, Mac OS X, and Windows.
|
||||
|
||||
To generate a random password with OpenSSL, fire up your Terminal and run the following command:
|
||||
|
||||
```
|
||||
openssl rand 14 -base64
|
||||
```
|
||||
|
||||
Here, ‘-base64’ string will make sure the password can be typed on a keyboard.
|
||||
|
||||
Sample output:
|
||||
|
||||
```
|
||||
wXCHXlxuhrFrFMQLqik=
|
||||
```
|
||||
|
||||
[
|
||||

|
||||
][6]
|
||||
|
||||
The above command will generate a random and strong password with length of 14 characters. Remember It is always recommend to generate 14 characters password. Of course you can generate any length of characters using openssl.
|
||||
|
||||
For more details, refer the man pages.
|
||||
|
||||
```
|
||||
man openssl
|
||||
```
|
||||
|
||||
### 2\. Generate a strong password in Linux using Pwgen
|
||||
|
||||
pwgen is simple, yet useful command line utility to generate a random and strong password in seconds. It designs secure passwords that can be easily memorized by humans. It is available in the most Unix-like operating systems.
|
||||
|
||||
To install pwgen in DEB based systems, run:
|
||||
|
||||
```
|
||||
sudo apt-get install pwgen
|
||||
```
|
||||
|
||||
In RPM based systems:
|
||||
|
||||
```
|
||||
sudo yum install pwgen
|
||||
```
|
||||
|
||||
In Arch based systems:
|
||||
|
||||
```
|
||||
sudo pacman -S pwgen
|
||||
```
|
||||
|
||||
Once pwgen installed, generate a random and strong password with length of 14 letters using command:
|
||||
|
||||
```
|
||||
pwgen 14 1
|
||||
```
|
||||
|
||||
Sample output:
|
||||
|
||||
```
|
||||
Choo4aicozai3a
|
||||
```
|
||||
|
||||
[
|
||||

|
||||
][5]
|
||||
|
||||
The above command will create only one password with length of 14 characters. To create 2 different passwords with length of 14 characters, run:
|
||||
|
||||
```
|
||||
pwgen 14 2
|
||||
```
|
||||
|
||||
Sample output:
|
||||
|
||||
```
|
||||
xee7seerez6Kau Aeshu0geveeji8
|
||||
```
|
||||
|
||||
To crate 100 different passwords (Not necessary though) with length of 14 characters, run:
|
||||
|
||||
```
|
||||
pwgen 14
|
||||
```
|
||||
|
||||
Sample output:
|
||||
|
||||
```
|
||||
kaeNg3EiVei4ei Oo0iehiJaix5Ae aenuv2eree2Quo iaT7zahH1eN2Aj Bie2owaiFahsie
|
||||
gaan9zu5Xeh5ah ahGeeth8ea5ooh Ir0ueda5poogh5 uo0ohqu2ufaiX2 Mei0pee6Og3zae
|
||||
Oofeiceer8Aipu sheew3aeReidir Dee4Heib2eim2o eig6jar8giPhae Zahde9nae1Niew
|
||||
quatol5Oi3Bah2 quue4eebaiNgaa oGoahieSh5oL4m aequeeQue2piti laige5seePhugo
|
||||
iiGo9Uthee4ros WievaiQu2xech6 shaeve0maaK3ae ool8Pai2eighis EPheiRiet1ohci
|
||||
ZieX9outhoht8N Uh1UoPhah2Thee reaGhohZae5idi oiG4ooshiyi5in keePh1ohshei8y
|
||||
aim5Eevah2thah Xaej8tha5eisho IeGie1Anaalaev gaoY3ohthooh3x chaebeesahTh8e
|
||||
soh7oosieY5eiD ahmoh6Ihii6que Shoowoo5dahbah ieW0aiChubee7I Caet6aikai6aex
|
||||
coo1du2Re9aika Ohnei5Egoh7leV aiyie6Ahdeipho EiV0aeToeth1da iNgaesu4eeyu0S
|
||||
Eeb1suoV3naera railai2Vaina8u xu3OhVee1reeyu Og0eavae3oohoh audahneihaeK8a
|
||||
foo6iechi5Eira oXeixoh6EwuboD we1eiDahNgoh9s ko1Eeju1iedu1z aeP7achiisohr7
|
||||
phang5caeGei5j ait4Shuo5Aitai no4eis9Tohd8oh Quiet6oTaaQuei Dei2pu2NaefeCa
|
||||
Shiim9quiuy0ku yiewooph3thieL thu8Aphai1ieDa Phahnahch1Aam1 oocex7Yaith8oo
|
||||
eraiGaech5ahNg neixa3malif5Ya Eux7chah8ahXix eex1lahXae4Mei uGhahzonu6airu
|
||||
yah8uWahn3jeiW Yi4ye4Choongie io1Vo3aiQuahpi rie4Rucheet6ae Dohbieyaeleis5
|
||||
xi1Zaushohbei7 jeeb9EiSiech0u eewo0Oow7ielie aiquooZamah5th kouj7Jaivohx9o
|
||||
biyeeshesaDi9e she9ooj3zuw6Ah Eit7dei1Yei5la xohN0aeSheipaa Eeg9Phob6neema
|
||||
eengoneo4saeL4 aeghi4feephu6W eiWash2Vie1mee chieceish5ioPe ool4Hongo7ef1o
|
||||
jahBe1pui9thou eeV2choohoa4ee Ohmae0eef4ic8I Eet0deiyohdiew Ke9ue5thohzei3
|
||||
aiyoxeiva8Maih gieRahgh8anahM ve2ath9Eyi5iet quohg6ok3Ahgee theingaech5Nef
|
||||
```
|
||||
|
||||
[
|
||||

|
||||
][4]
|
||||
|
||||
To include at least 1 number in the password run:
|
||||
|
||||
```
|
||||
pwgen 14 1 -n 1
|
||||
```
|
||||
|
||||
Sample output:
|
||||
|
||||
```
|
||||
xoiFush3ceiPhe
|
||||
```
|
||||
|
||||
There are also some useful options available to use with pwgen command.
|
||||
|
||||
```
|
||||
-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)
|
||||
```
|
||||
|
||||
For more details, check the man pages.
|
||||
|
||||
```
|
||||
man pwgen
|
||||
```
|
||||
|
||||
### 3\. Generate a strong password in Linux using GPG
|
||||
|
||||
GPG (GnuPG or GNU Privacy Guard), is free command-line program and replacement of Symantec’s PGP cryptographic software. It is available for Unix-like operating systems, Microsoft Windows and Android versions.
|
||||
|
||||
To generate a random and strong password with length of 14 characters using GPG, run the following command from the Terminal:
|
||||
|
||||
```
|
||||
gpg --gen-random --armor 1 14
|
||||
```
|
||||
|
||||
Sample output:
|
||||
|
||||
```
|
||||
DkmsrUy3klzzbIbavx8=
|
||||
```
|
||||
|
||||
[
|
||||

|
||||
][3]
|
||||
|
||||
The above command will generate a secure, random, strong and base64 encoded password.
|
||||
|
||||
### 4\. Generate a strong password in Linux using Perl
|
||||
|
||||
Perl is available in the most Linux distribution’s default repositories. Install it using the package manager.
|
||||
|
||||
For example, to install Perl on DEB based systems run:
|
||||
|
||||
```
|
||||
sudo apt-get install perl
|
||||
```
|
||||
|
||||
To install Perl on RPM based systems, run:
|
||||
|
||||
```
|
||||
sudo yum install perl
|
||||
```
|
||||
|
||||
On Arch based systems:
|
||||
|
||||
```
|
||||
sudo pacman -S perl
|
||||
```
|
||||
|
||||
Once Perl installed, create a file:
|
||||
|
||||
```
|
||||
vi password.pl
|
||||
```
|
||||
|
||||
Add the following contents in it.
|
||||
|
||||
```
|
||||
#!/usr/bin/perl
|
||||
|
||||
my @alphanumeric = ('a'..'z', 'A'..'Z', 0..9);
|
||||
my $randpassword = join '', map $alphanumeric[rand @alphanumeric], 0..8;
|
||||
print "$randpassword\n"
|
||||
```
|
||||
|
||||
[
|
||||

|
||||
][2]
|
||||
|
||||
Save and close the file.
|
||||
|
||||
Now, go to the location where you saved the file, and run the following command:
|
||||
|
||||
```
|
||||
perl password.pl
|
||||
```
|
||||
|
||||
Replace password.pl with your own filename.
|
||||
|
||||
Sample output:
|
||||
|
||||
```
|
||||
3V4CJJnYd
|
||||
```
|
||||
|
||||
[
|
||||

|
||||
][1]
|
||||
|
||||
Note: I couldn’t find the original author of this script. If anyone know the author’s name, please let me know in the comment section below. I will add the author name in this guide.
|
||||
|
||||
Please note that you must memorize or keep the passwords you have generated in a safe place in your computer. I recommend you to memorize the password and delete it from your system. It is much better in case your system is compromised by any hackers.
|
||||
|
||||
That’s all for today folks. I will here with another interesting article soon. Until then, stay tuned with OSTechNix.
|
||||
|
||||
Happy Weekend!
|
||||
|
||||
Cheers!!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/4-easy-ways-to-generate-a-strong-password-in-linux/
|
||||
|
||||
作者:[ SK ][a]
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.ostechnix.com/author/sk/
|
||||
[1]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@sk_002.png
|
||||
[2]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@sk_001.png
|
||||
[3]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@sk_006.png
|
||||
[4]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@sk_005.png
|
||||
[5]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@sk_004.png
|
||||
[6]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@sk_003.png
|
||||
[7]:http://ostechnix.tradepub.com/free/w_ubun08/prgm.cgi?a=1
|
||||
[8]:https://www.ostechnix.com/force-users-use-strong-passwords-debian-ubuntu/
|
||||
221
sources/tech/20161107 Kali Linux – Fresh Installation Guide.md
Normal file
221
sources/tech/20161107 Kali Linux – Fresh Installation Guide.md
Normal file
@@ -0,0 +1,221 @@
|
||||
# Kali Linux – Fresh Installation Guide
|
||||
|
||||
Kali Linux is arguably one of the best out of the box [Linux distributions available for security testing][18]. While many of the tools in Kali can be installed in most Linux distributions, the Offensive Security team developing Kali has put countless hours into perfecting their ready to boot security distribution.
|
||||
|
||||
Kali Linux is a Debian based, security distribution. The distribution comes pre-loaded with hundreds of well known security tools and has gained quite a name for itself.
|
||||
|
||||
Kali even has an industry respected certification available called “Pentesting with Kali”. The certification is a rigorous 24 hour challenge in which applicants must successfully compromise a number of computers with another 24 hours to write up a professional penetration test report that is sent to and graded by the personnel at Offensive Security. Successfully passing this exam will allow the test taker to obtain the OSCP credential.
|
||||
|
||||
The focus of this guide and future articles is to help individuals become more familiar with Kali Linux and several of the tools available within the distribution.
|
||||
|
||||
Please be sure to use extreme caution with the tools included with Kali as many of them can accidentally be used in a manner that will break computer systems. The information contained within all of these Kali articles is intended for legal usages.
|
||||
|
||||
#### System Requirements
|
||||
|
||||
Kali has some minimum suggested specifications for hardware. Depending upon the intended use, more may be desired. This guide will be assuming that the reader will want to install Kali as the only operating system on the computer.
|
||||
|
||||
1. At least 10GB of disk space; strongly encouraged to have more
|
||||
2. At least 512MB of ram; more is encouraged especially for graphical environments
|
||||
3. USB or CD/DVD boot support
|
||||
4. Kali Linux ISO available from [https://www.kali.org/downloads/][1]
|
||||
|
||||
#### Create a Bootable USB Using dd Command
|
||||
|
||||
This guide will be assuming that a USB drive is available to use as the installation media. Take note that the USB drive should be as close to 4/8GB as possible and ALL DATA WILL BE REMOVED!
|
||||
|
||||
The author has had issues with larger USB drives but some may still work. Regardless, following the next few steps WILL RESULT IN DATA LOSS ON THE USB DRIVE.
|
||||
|
||||
Please be sure to backup all data before proceeding. This bootable Kali Linux USB drive is going to be created from another Linux machine.
|
||||
|
||||
Step 1 is to obtain the Kali Linux ISO. This guide is going to use the current newest version of Kali with the Enlightenment [Linu desktop environment][17].
|
||||
|
||||
To obtain this version, type the following into a terminal.
|
||||
|
||||
```
|
||||
$ cd ~/Downloads
|
||||
$ wget -c http://cdimage.kali.org/kali-2016.2/kali-linux-e17-2016.2-amd64.iso
|
||||
|
||||
```
|
||||
|
||||
The two commands above will download the Kali Linux ISO into the current user’s ‘Downloads’ folder.
|
||||
|
||||
The next process is to write the ISO to a USB drive to boot the installer. To accomplish this we can use the ‘dd’tool within Linux. First, the disk name needs to be located with lsblk command though.
|
||||
|
||||
```
|
||||
$ lsblk
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][16]
|
||||
|
||||
Find Out USB Device Name in Linux
|
||||
|
||||
With the name of the USB drive determined as `/dev/sdc`, the Kali ISO can be written to the drive with the ‘dd’tool.
|
||||
|
||||
```
|
||||
$ sudo dd if=~/Downloads/kali-linux-e17-2016.2-amd64.iso of=/dev/sdc
|
||||
|
||||
```
|
||||
|
||||
Important: The above command requires root privileges so utilize sudo or login as the root user to run the command. Also this command will REMOVE EVERYTHING on the USB drive. Be sure to backup needed data.
|
||||
|
||||
Once the ISO is copied over to the USB drive, proceed further to install Kali Linux.
|
||||
|
||||
### Installation of Kali Linux Distribution
|
||||
|
||||
1. First, plug the USB drive into the respective computer that Kali should be installed upon and proceed to boot to the USB drive. Upon successful booting to the USB drive, the user will be presented with the following screen and should proceed with the ‘Install’ or ‘Graphical Install’ options.
|
||||
|
||||
This guide will be using the ‘Graphical Install’ method.
|
||||
|
||||
[
|
||||

|
||||
][15]
|
||||
|
||||
Kali Linux Boot Menu
|
||||
|
||||
2. The next couple of screens will ask the user to select locale information such as language, country, and keyboard layout.
|
||||
|
||||
Once through the locale information, the installer will prompt for a hostname and domain for this install. Provide the appropriate information for the environment and continue installing.
|
||||
|
||||
[
|
||||

|
||||
][14]
|
||||
|
||||
Set Hostname for Kali Linux
|
||||
|
||||
[
|
||||

|
||||
][13]
|
||||
|
||||
Set Domain for Kali Linux
|
||||
|
||||
3. After setting up the hostname and domain name, the root user’s password needs to be set. DO NOT FORGET THIS PASSWORD.
|
||||
|
||||
[
|
||||

|
||||
][12]
|
||||
|
||||
Set Root User Password for Kali Linux
|
||||
|
||||
4. After setting the password is set, the installer will prompt for time zone data and then pause at the disk partitioning.
|
||||
|
||||
If Kali will be the only operating on the machine, the easiest option is to use ‘Guided – Use Entire Disk’ and then select the storage device you wish to install Kali.
|
||||
|
||||
[
|
||||

|
||||
][11]
|
||||
|
||||
Select Kali Linux Installation Type
|
||||
|
||||
[
|
||||

|
||||
][10]
|
||||
|
||||
Select Kali Linux Installation Disk
|
||||
|
||||
5. The next question will prompt the user to determine the partitioning on the storage device. Most installs can simply put all data on one partition though.
|
||||
|
||||
[
|
||||

|
||||
][9]
|
||||
|
||||
Install Kali Linux Files in Partition
|
||||
|
||||
6. The final step with ask the user to confirm all changes to be made to the disk on the host machine. Be aware that continuing will ERASE DATA ON THE DISK.
|
||||
|
||||
[
|
||||

|
||||
][8]
|
||||
|
||||
Confirm Disk Partition Write Changes
|
||||
|
||||
7. Once confirming the partition changes, the installer will run through the process of installing the files. Once it is completed, the system will want to setup a network mirror to obtain future pieces of software and updates. Be sure to enable this functionality if you wish to use the Kali repositories.
|
||||
|
||||
[
|
||||

|
||||
][7]
|
||||
|
||||
Configure Kali Linux Package Manager
|
||||
|
||||
8. After selecting a network mirror, the system will ask to install grub. Again this guide is assuming that Kali is to be the only operating system on this computer.
|
||||
|
||||
Selecting ‘Yes’ on this screen will allow the user to pick the device to write the necessary boot loader information to the hard drive to boot Kali.
|
||||
|
||||
[
|
||||

|
||||
][6]
|
||||
|
||||
Install GRUB Boot Loader
|
||||
|
||||
[
|
||||

|
||||
][5]
|
||||
|
||||
Select Partition to Install GRUB Boot Loader
|
||||
|
||||
9. Once the installer finishes installing GRUB to the disk, it will alert the user to reboot the machine to boot into the newly installed Kali machine.
|
||||
|
||||
[
|
||||

|
||||
][4]
|
||||
|
||||
Kali Linux Installation Completed
|
||||
|
||||
10. Since this guide installed Enlightenment as the Kali desktop environment, it will likely default boot into a shell.
|
||||
|
||||
In order to launch Enlightenment, log in as the user ‘root‘ with the password created earlier in the installation process.
|
||||
|
||||
Once logged in all that needs to be issued to start Enlightenment is the command ‘startx‘.
|
||||
|
||||
```
|
||||
# startx
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][3]
|
||||
|
||||
Start Enlightenment Desktop in Kali Linux
|
||||
|
||||
The first time that Enlightenment is run, it will ask the user for some configuration preferences and then launch the Desktop Environment.
|
||||
|
||||
[
|
||||

|
||||
][2]
|
||||
|
||||
Kali Linux Enlightenment Desktop
|
||||
|
||||
At this point, Kali is successfully installed and ready to be used! Upcoming articles will walk through the tools available within Kali and how the can be utilized to test the security posture of hosts and networks. Please feel free to post any comments or questions below.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/kali-linux-installation-guide/
|
||||
|
||||
作者:[Rob Turner][a]
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/robturner/
|
||||
[1]:https://www.kali.org/downloads/
|
||||
[2]:http://www.tecmint.com/wp-content/uploads/2016/10/Kali-Linux-Enlightenment-Desktop.png
|
||||
[3]:http://www.tecmint.com/wp-content/uploads/2016/10/Start-Enlightenment-Desktop-in-Kali-Linux.png
|
||||
[4]:http://www.tecmint.com/wp-content/uploads/2016/10/Kali-Linux-Installation-Completed.png
|
||||
[5]:http://www.tecmint.com/wp-content/uploads/2016/10/Select-Partition-to-Install-GRUB-Boot-Loader.png
|
||||
[6]:http://www.tecmint.com/wp-content/uploads/2016/10/Install-GRUB-Boot-Loader.png
|
||||
[7]:http://www.tecmint.com/wp-content/uploads/2016/10/Configure-Kali-Linux-Package-Manager.png
|
||||
[8]:http://www.tecmint.com/wp-content/uploads/2016/10/Confirm-Disk-Partition-Write-Changes.png
|
||||
[9]:http://www.tecmint.com/wp-content/uploads/2016/10/Install-Kali-Linux-Files-in-Partition.png
|
||||
[10]:http://www.tecmint.com/wp-content/uploads/2016/10/Select-Kali-Linux-Installation-Disk.png
|
||||
[11]:http://www.tecmint.com/wp-content/uploads/2016/10/Select-Kali-Linux-Installation-Type.png
|
||||
[12]:http://www.tecmint.com/wp-content/uploads/2016/10/Set-Root-User-Password-for-Kali-Linux.png
|
||||
[13]:http://www.tecmint.com/wp-content/uploads/2016/10/Set-Domain-for-Kali-Linux.png
|
||||
[14]:http://www.tecmint.com/wp-content/uploads/2016/10/Set-Hostname-for-Kali-Linux.png
|
||||
[15]:http://www.tecmint.com/wp-content/uploads/2016/10/Kali-Linux-Boot-Menu.png
|
||||
[16]:http://www.tecmint.com/wp-content/uploads/2016/10/Find-USB-Device-Name-in-Linux.png
|
||||
[17]:http://www.tecmint.com/best-linux-desktop-environments/
|
||||
[18]:http://www.tecmint.com/best-security-centric-linux-distributions-of-2016/
|
||||
@@ -0,0 +1,249 @@
|
||||
DockerChen翻译中
|
||||
|
||||
# A Practical Guide to Nmap (Network Security Scanner) in Kali Linux
|
||||
|
||||
In the second Kali Linux article, the network tool known as ‘[nmap][30]‘ will be discussed. While nmap isn’t a Kali only tool, it is one of the most [useful network mapping tools][29] in Kali.
|
||||
|
||||
1. [Kali Linux Installation Guide for Beginners – Part 1][4]
|
||||
|
||||
Nmap, short for Network Mapper, is maintained by Gordon Lyon (more about Mr. Lyon here: [http://insecure.org/fyodor/][28]) and is used by many security professionals all over the world.
|
||||
|
||||
The utility works in both Linux and Windows and is command line (CLI) driven. However for those a little more timid of the command line, there is a wonderful graphical frontend for nmap called zenmap.
|
||||
|
||||
It is strongly recommended that individuals learn the CLI version of nmap as it provides much more flexibility when compared to the zenmap graphical edition.
|
||||
|
||||
What purpose does nmap server? Great question. Nmap allows for an administrator to quickly and thoroughly learn about the systems on a network, hence the name, Network MAPper or nmap.
|
||||
|
||||
Nmap has the ability to quickly locate live hosts as well as services associated with that host. Nmap’s functionality can be extended even further with the Nmap Scripting Engine, often abbreviated as NSE.
|
||||
|
||||
This scripting engine allows administrators to quickly create a script that can be used to determine if a newly discovered vulnerability exists on their network. Many scripts have been developed and included with most nmap installs.
|
||||
|
||||
A word of caution – nmap is a commonly used by people with both good and bad intentions. Extreme caution should be taken to ensure that you aren’t using nmap against systems that permission has not be explicitlyprovided in a written/legal agreement. Please use caution when using the nmap tool.
|
||||
|
||||
#### System Requirements
|
||||
|
||||
1. [Kali Linux][3] (nmap is available in other operating systems and functions similar to this guide).
|
||||
2. Another computer and permission to scan that computer with nmap – This is often easily done with software such as [VirtualBox][2] and the creation of a virtual machine.
|
||||
1. For a good machine to practice with, please read about Metasploitable 2
|
||||
2. Download for MS2 [Metasploitable2][1]
|
||||
3. A valid working connection to a network or if using virtual machines, a valid internal network connection for the two machines.
|
||||
|
||||
### Kali Linux – Working with Nmap
|
||||
|
||||
The first step to working with nmap is to log into the Kali Linux machine and if desired, start a graphical session (This first article in this series installed [Kali Linux with the Enlightenment Desktop Environment][27]).
|
||||
|
||||
During the installation, the installer would have prompted the user for a ‘root‘ user password which will be needed to login. Once logged in to the Kali Linux machine, using the command ‘startx‘ the Enlightenment Desktop Environment can be started – it is worth noting that nmap doesn’t require a desktop environment to run.
|
||||
|
||||
```
|
||||
# startx
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][26]
|
||||
|
||||
Start Desktop Environment in Kali Linux
|
||||
|
||||
Once logged into Enlightenment, a terminal window will need to be opened. By clicking on the desktop background, a menu will appear. Navigating to a terminal can be done as follows: Applications -> System ->‘Xterm‘ or ‘UXterm‘ or ‘Root Terminal‘.
|
||||
|
||||
The author is a fan of the shell program called ‘[Terminator][25]‘ but this may not show up in a default install of Kali Linux. All shell programs listed will work for the purposes of nmap.
|
||||
|
||||
[
|
||||

|
||||
][24]
|
||||
|
||||
Launch Terminal in Kali Linux
|
||||
|
||||
Once a terminal has been launched, the nmap fun can begin. For this particular tutorial, a private network with a Kali machine and a Metasploitable machine was created.
|
||||
|
||||
This made things easier and safer since the private network range would ensure that scans remained on safe machines and prevents the vulnerable Metasploitable machine from being compromised by someone else.
|
||||
|
||||
In this example, both of the machines are on a private 192.168.56.0 /24 network. The Kali machine has an IP address of 192.168.56.101 and the Metasploitable machine to be scanned has an IP address of 192.168.56.102.
|
||||
|
||||
Let’s say though that the IP address information was unavailable. A quick nmap scan can help to determine what is live on a particular network. This scan is known as a ‘Simple List’ scan hence the `-sL` arguments passed to the nmap command.
|
||||
|
||||
```
|
||||
# nmap -sL 192.168.56.0/24
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][23]
|
||||
|
||||
Nmap – Scan Network for Live Hosts
|
||||
|
||||
Sadly, this initial scan didn’t return any live hosts. Sometimes this is a factor of the way certain Operating Systems handle [port scan network traffic][22].
|
||||
|
||||
Not to worry though, there are some tricks that nmap has available to try to find these machines. This next trick will tell nmap to simply try to ping all the addresses in the 192.168.56.0/24 network.
|
||||
|
||||
```
|
||||
# nmap -sn 192.168.56.0/24
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][21]
|
||||
|
||||
Nmap – Ping All Connected Live Network Hosts
|
||||
|
||||
This time nmap returns some prospective hosts for scanning! In this command, the `-sn` disables nmap’s default behavior of attempting to port scan a host and simply has nmap try to ping the host.
|
||||
|
||||
Let’s try letting nmap port scan these specific hosts and see what turns up.
|
||||
|
||||
```
|
||||
# nmap 192.168.56.1,100-102
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][20]
|
||||
|
||||
Nmap – Network Ports Scan on Host
|
||||
|
||||
Wow! This time nmap hit a gold mine. This particular host has quite a bit of [open network ports][19].
|
||||
|
||||
These ports all indicate some sort of listening service on this particular machine. Recalling from earlier, the 192.168.56.102 IP address is assigned to the metasploitable vulnerable machine hence why there are so many [open ports on this host][18].
|
||||
|
||||
Having this many ports open on most machines is highly abnormal so it may be a wise idea to investigate this machine a little closer. Administrators could track down the physical machine on the network and look at the machine locally but that wouldn’t be much fun especially when nmap could do it for us much quicker!
|
||||
|
||||
This next scan is a service scan and is often used to try to determine what [service may be listening on a particular port][17] on a machine.
|
||||
|
||||
Nmap will probe all of the open ports and attempt to banner grab information from the services running on each port.
|
||||
|
||||
```
|
||||
# nmap -sV 192.168.56.102
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][16]
|
||||
|
||||
Nmap – Scan Network Services Listening of Ports
|
||||
|
||||
Notice this time nmap provided some suggestions on what nmap thought might be running on this particular port (highlighted in the white box). Also nmap also tried to [determine information about the operating system][15]running on this machine as well as its hostname (with great success too!).
|
||||
|
||||
Looking through this output should raise quite a few concerns for a network administrator. The very first line claims that VSftpd version 2.3.4 is running on this machine! That’s a REALLY old version of VSftpd.
|
||||
|
||||
Searching through ExploitDB, a serious vulnerability was found back in 2011 for this particular version (ExploitDB ID – 17491).
|
||||
|
||||
Let’s have nmap take a closer look at this particular port and see what can be determined.
|
||||
|
||||
```
|
||||
# nmap -sC 192.168.56.102 -p 21
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][14]
|
||||
|
||||
Nmap – Scan Particular Post on Machine
|
||||
|
||||
With this command, nmap was instructed to run its default script (-sC) on the FTP port (-p 21) on the host. While it may or may not be an issue, nmap did find out that [anonymous FTP login is allowed][13] on this particular server.
|
||||
|
||||
This paired with the earlier knowledge about VSftd having an old vulnerability should raise some concern though. Let’s see if nmap has any scripts that attempt to check for the VSftpd vulnerability.
|
||||
|
||||
```
|
||||
# locate .nse | grep ftp
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][12]
|
||||
|
||||
Nmap – Scan VSftpd Vulnerability
|
||||
|
||||
Notice that nmap has a NSE script already built for the VSftpd backdoor problem! Let’s try running this script against this host and see what happens but first it may be important to know how to use the script.
|
||||
|
||||
```
|
||||
# nmap --script-help=ftp-vsftd-backdoor.nse
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][11]
|
||||
|
||||
Learn Nmap NSE Script Usage
|
||||
|
||||
Reading through this description, it is clear that this script can be used to attempt to see if this particular machine is vulnerable to ExploitDB issue identified earlier.
|
||||
|
||||
Let’s run the script and see what happens.
|
||||
|
||||
```
|
||||
# nmap --script=ftp-vsftpd-backdoor.nse 192.168.56.102 -p 21
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][10]
|
||||
|
||||
Nmap – Scan Host for Vulnerable
|
||||
|
||||
Yikes! Nmap’s script returned some dangerous news. This machine is likely a good candidate for a serious investigation. This doesn’t mean that the machine is compromised and being used for horrible/terrible things but it should bring some concerns to the network/security teams.
|
||||
|
||||
Nmap has the ability to be extremely selective and extremely quite. Most of what has been done so far has attempted to keep nmap’s network traffic moderately quiet however scanning a personally owned network in this fashion can be extremely time consuming.
|
||||
|
||||
Nmap has the ability to do a much more aggressive scan that will often yield much of the same information but in one command instead of several. Let’s take a look at the output of an aggressive scan (Do note – an aggressive scan can set off [intrusion detection/prevention systems][9]!).
|
||||
|
||||
```
|
||||
# nmap -A 192.168.56.102
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][8]
|
||||
|
||||
Nmap – Complete Network Scan on Host
|
||||
|
||||
Notice this time, with one command, nmap has returned a lot of the information it returned earlier about the open ports, services, and configurations running on this particular machine. Much of this information can be used to help determine [how to protect this machine][7] as well as to evaluate what software may be on a network.
|
||||
|
||||
This was just a short, short list of the many useful things that nmap can be used to find on a host or network segment. It is strongly urged that individuals continue to [experiment with nmap][6] in a controlled manner on a network that is owned by the individual (Do not practice by scanning other entities!).
|
||||
|
||||
There is a official guide on Nmap Network Scanning by author Gordon Lyon, available from Amazon.
|
||||
|
||||
<center style="border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline;">[
|
||||

|
||||
][5]</center>
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/nmap-network-security-scanner-in-kali-linux/
|
||||
|
||||
作者:[Rob Turner][a]
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/robturner/
|
||||
[1]:https://sourceforge.net/projects/metasploitable/files/Metasploitable2/
|
||||
[2]:http://www.tecmint.com/install-virtualbox-on-redhat-centos-fedora/
|
||||
[3]:http://www.tecmint.com/kali-linux-installation-guide
|
||||
[4]:http://www.tecmint.com/kali-linux-installation-guide
|
||||
[5]:http://amzn.to/2eFNYrD
|
||||
[6]:http://www.tecmint.com/nmap-command-examples/
|
||||
[7]:http://www.tecmint.com/security-and-hardening-centos-7-guide/
|
||||
[8]:http://www.tecmint.com/wp-content/uploads/2016/11/Nmap-Scan-Network-Host.png
|
||||
[9]:http://www.tecmint.com/protect-apache-using-mod_security-and-mod_evasive-on-rhel-centos-fedora/
|
||||
[10]:http://www.tecmint.com/wp-content/uploads/2016/11/Nmap-Scan-Host-for-Vulnerable.png
|
||||
[11]:http://www.tecmint.com/wp-content/uploads/2016/11/Nmap-Learn-NSE-Script.png
|
||||
[12]:http://www.tecmint.com/wp-content/uploads/2016/11/Nmap-Scan-Service-Vulnerability.png
|
||||
[13]:http://www.tecmint.com/setup-ftp-anonymous-logins-in-linux/
|
||||
[14]:http://www.tecmint.com/wp-content/uploads/2016/11/Nmap-Scan-Particular-Port-on-Host.png
|
||||
[15]:http://www.tecmint.com/commands-to-collect-system-and-hardware-information-in-linux/
|
||||
[16]:http://www.tecmint.com/wp-content/uploads/2016/11/Nmap-Scan-Network-Services-Ports.png
|
||||
[17]:http://www.tecmint.com/find-linux-processes-memory-ram-cpu-usage/
|
||||
[18]:http://www.tecmint.com/find-open-ports-in-linux/
|
||||
[19]:http://www.tecmint.com/find-open-ports-in-linux/
|
||||
[20]:http://www.tecmint.com/wp-content/uploads/2016/11/Nmap-Scan-for-Ports-on-Hosts.png
|
||||
[21]:http://www.tecmint.com/wp-content/uploads/2016/11/Nmap-Ping-All-Network-Live-Hosts.png
|
||||
[22]:http://www.tecmint.com/audit-network-performance-security-and-troubleshooting-in-linux/
|
||||
[23]:http://www.tecmint.com/wp-content/uploads/2016/11/Nmap-Scan-Network.png
|
||||
[24]:http://www.tecmint.com/wp-content/uploads/2016/11/Launch-Terminal-in-Kali-Linux.png
|
||||
[25]:http://www.tecmint.com/terminator-a-linux-terminal-emulator-to-manage-multiple-terminal-windows/
|
||||
[26]:http://www.tecmint.com/wp-content/uploads/2016/11/Start-Desktop-Environment-in-Kali-Linux.png
|
||||
[27]:http://www.tecmint.com/kali-linux-installation-guide
|
||||
[28]:http://insecure.org/fyodor/
|
||||
[29]:http://www.tecmint.com/bcc-best-linux-performance-monitoring-tools/
|
||||
[30]:http://www.tecmint.com/nmap-command-examples/
|
||||
119
sources/tech/20161109 How to Recover a Deleted File in Linux.md
Normal file
119
sources/tech/20161109 How to Recover a Deleted File in Linux.md
Normal file
@@ -0,0 +1,119 @@
|
||||
ucasFL translating
|
||||
# How to Recover a Deleted File in Linux
|
||||
|
||||
Did this ever happen to you? You realized that you had mistakenly deleted a file – either through the Del key, or using `rm` in the command line.
|
||||
|
||||
In the first case, you can always go to the Trash, [search for the file][6], and restore it to its original location. But what about the second case? As I am sure you probably know, the Linux command line does not send removed files anywhere – it REMOVES them. Bum. They’re gone.
|
||||
|
||||
In this article we will share a tip that may be helpful to prevent this from happening to you, and a tool that you may consider using if at any point you are careless enough to do it anyway.
|
||||
|
||||
### Create an alias to ‘rm -i’
|
||||
|
||||
The `-i` switch, when used with rm (and also other [file-manipulation tools such as cp or mv][5]) causes a prompt to appear before removing a file.
|
||||
|
||||
The same applies to [copying, moving, or renaming a file][4] in a location where one with the same name exists already.
|
||||
|
||||
This prompt gives you a second chance to consider if you actually want to remove the file – if you confirm the prompt, it will be gone. In that case, I’m sorry but this tip will not protect you from your own carelessness.
|
||||
|
||||
To replace rm with an alias to `'rm -i'`, do:
|
||||
|
||||
```
|
||||
alias rm='rm -i'
|
||||
|
||||
```
|
||||
|
||||
The alias command will confirm that rm is now aliased:
|
||||
|
||||
[
|
||||

|
||||
][3]
|
||||
|
||||
Add Alias rm Command
|
||||
|
||||
However, this will only last during the current user session in the current shell. To make the change permanent, you will have to save it to `~/.bashrc` (some distributions may use `~/.profile` instead) as shown below:
|
||||
|
||||
[
|
||||

|
||||
][2]
|
||||
|
||||
Add Alias Permanently in Linux
|
||||
|
||||
In order for the changes in `~/.bashrc` (or `~/.profile`) to take effect immediately, source the file from the current shell:
|
||||
|
||||
```
|
||||
. ~/.bashr
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][1]
|
||||
|
||||
Active Alias in Linux
|
||||
|
||||
### The forensics tool – Foremost
|
||||
|
||||
Hopefully, you will be careful with your files and will only need to use this tool while recovering a lost file from an external disk or USB drive.
|
||||
|
||||
However, if you realize you accidentally removed a file in your system and are going to panic – don’t. Let’s take a look at foremost, a forensics tool that was designed for this kind of scenarios.
|
||||
|
||||
To install foremost in CentOS/RHEL 7, you will need to enable Repoforge first:
|
||||
|
||||
```
|
||||
# rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
|
||||
# yum install foremost
|
||||
|
||||
```
|
||||
|
||||
Whereas in Debian and derivatives, just do
|
||||
|
||||
```
|
||||
# aptitude install foremost
|
||||
|
||||
```
|
||||
|
||||
Once the installation has completed, let’s proceed with a simple test. We will begin by removing an image file named `nosdos.jpg` from the /boot/images directory:
|
||||
|
||||
```
|
||||
# cd images
|
||||
# rm nosdos.jpg
|
||||
|
||||
```
|
||||
|
||||
To recover it, use foremost as follows (you’ll need to identify the underlying partition first – `/dev/sda1` is where `/boot` resides in this case):
|
||||
|
||||
```
|
||||
# foremost -t jpg -i /dev/sda1 -o /home/gacanepa/rescued
|
||||
|
||||
```
|
||||
|
||||
where /home/gacanepa/rescued is a directory on a separate disk – keep in mind that recovering files on the same drive where the removed ones were located is not a wise move.
|
||||
|
||||
If, during the recovery, you occupy the same disk sectors where the removed files used to be, it may not be possible to recover anything. Additionally, it is essential to stop all your activities before performing the recovery.
|
||||
|
||||
After foremost has finished executing, the recovered file (if recovery was possible) will be found inside the /home/gacanepa/rescued/jpg directory.
|
||||
|
||||
##### Summary
|
||||
|
||||
In this article we have explained how to avoid removing a file accidentally and how to attempt to recover it if such an undesired event happens. Be warned, however, that foremost can take quite a while to run depending on the size of the partition.
|
||||
|
||||
As always, don’t hesitate to let us know if you have questions or comments. Feel free to drop us a note using the form below.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/recover-deleted-file-in-linux/
|
||||
|
||||
作者:[ Gabriel Cánepa][a]
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/gacanepa/
|
||||
[1]:http://www.tecmint.com/wp-content/uploads/2016/11/Active-Alias-in-Linux.png
|
||||
[2]:http://www.tecmint.com/wp-content/uploads/2016/11/Add-Alias-Permanently-in-Linux.png
|
||||
[3]:http://www.tecmint.com/wp-content/uploads/2016/11/Add-Alias-rm-Command.png
|
||||
[4]:http://www.tecmint.com/rename-multiple-files-in-linux/
|
||||
[5]:http://www.tecmint.com/progress-monitor-check-progress-of-linux-commands/
|
||||
[6]:http://www.tecmint.com/linux-find-command-to-search-multiple-filenames-extensions/
|
||||
@@ -0,0 +1,182 @@
|
||||
# 4 Ways to Batch Convert Your PNG to JPG and Vice-Versa
|
||||
|
||||
In computing, Batch processing is the [execution of a series of tasks][11] in a program non-interactively. In this guide will offer you 4 simple ways to batch convert several `.PNG` images to `.JPG` and vice-versa using Linux command-line tools.
|
||||
|
||||
We will use convert command line tool in all the examples, however, you can as well make use of mogrify to achieve this.
|
||||
|
||||
The syntax for using convert is:
|
||||
|
||||
```
|
||||
$ convert input-option input-file output-option output-file
|
||||
|
||||
```
|
||||
|
||||
And for mogrify is:
|
||||
|
||||
```
|
||||
$ mogrify options input-file
|
||||
|
||||
```
|
||||
|
||||
Note: With mogrify, the original image file is replaced with the new image file by default, but it is possible to prevent this, by using certain options that you can find in the man page.
|
||||
|
||||
Below are the various ways to batch convert your all `.PNG` images to `.JPG` format, if you want to convert `.JPG`to `.PNG`, you can modify the commands according to your needs.
|
||||
|
||||
### 1\. Convert PNG to JPG Using ‘ls’ and ‘xargs’ Commands
|
||||
|
||||
The [ls command][10] allows you to list all your png images and xargs make it possible to build and execute a convert command from standard input to convert all `.png` images to `.jpg`.
|
||||
|
||||
```
|
||||
----------- Convert PNG to JPG -----------
|
||||
$ ls -1 *.png | xargs -n 1 bash -c 'convert "$0" "${0%.png}.jpg"'
|
||||
|
||||
----------- Convert JPG to PNG -----------
|
||||
$ ls -1 *.jpg | xargs -n 1 bash -c 'convert "$0" "${0%.jpg}.png"'
|
||||
|
||||
```
|
||||
|
||||
Explanation about the options used in the above command.
|
||||
|
||||
1. `-1` – flag tells ls to list one image per line.
|
||||
2. `-n` – specifies the maximum number of arguments, which is 1 for the case.
|
||||
3. `-c` – instructs bash to run the given command.
|
||||
4. `${0%.png}.jpg` – sets the name of the new converted image, the % sign helps to remove the old file extension.
|
||||
|
||||
[
|
||||

|
||||
][9]
|
||||
|
||||
Convert PNG to JPG Format in Linux
|
||||
|
||||
I used `ls -ltr` command to [list all files by modified date and time][8].
|
||||
|
||||
Similarly, you can use above command to convert all your `.jpg` images to `.png` by tweaking the above command.
|
||||
|
||||
### 2\. Convert PNG to JPG Using GNU ‘Parallel’ Command
|
||||
|
||||
GNU Parallel enables a user to build and execute shell commands from standard input in parallel. Make sure you have GNU Parallel installed on your system, otherwise install it using the appropriate commands below:
|
||||
|
||||
```
|
||||
$ sudo apt-get install parallel [On Debian/Ubuntu systems]
|
||||
$ sudo yum install parallel [On RHEL/CentOS and Fedora]
|
||||
|
||||
```
|
||||
|
||||
Once Parallel utility installed, you can run the following command to convert all `.png` images to `.jpg` format from the standard input.
|
||||
|
||||
```
|
||||
----------- Convert PNG to JPG -----------
|
||||
$ parallel convert '{}' '{.}.jpg' ::: *.png
|
||||
|
||||
----------- Convert JPG to PNG -----------
|
||||
$ parallel convert '{}' '{.}.png' ::: *.jpg
|
||||
|
||||
```
|
||||
|
||||
Where,
|
||||
|
||||
1. `{}` – input line which is a replacement string substituted by a complete line read from the input source.
|
||||
2. `{.}` – input line minus extension.
|
||||
3. `:::` – specifies input source, that is the command line for the example above where *png or *jpg is the argument.
|
||||
|
||||
[
|
||||

|
||||
][7]
|
||||
|
||||
Parallel Command – Converts All PNG Images to JPG Format
|
||||
|
||||
Alternatively, you can as well use [ls][6] and parallel commands together to batch convert all your images as shown:
|
||||
|
||||
```
|
||||
----------- Convert PNG to JPG -----------
|
||||
$ ls -1 *.png | parallel convert '{}' '{.}.jpg'
|
||||
|
||||
----------- Convert JPG to PNG -----------
|
||||
$ ls -1 *.jpg | parallel convert '{}' '{.}.png'
|
||||
|
||||
```
|
||||
|
||||
### 3\. Convert PNG to JPG Using ‘for loop’ Command
|
||||
|
||||
To avoid the hustle of writing a shell script, you can execute a `for loop` from the command line as follows:
|
||||
|
||||
```
|
||||
----------- Convert PNG to JPG -----------
|
||||
$ bash -c 'for image in *.png; do convert "$image" "${image%.png}.jpg"; echo “image $image converted to ${image%.png}.jpg ”; done'
|
||||
|
||||
----------- Convert JPG to PNG -----------
|
||||
$ bash -c 'for image in *.jpg; do convert "$image" "${image%.jpg}.png"; echo “image $image converted to ${image%.jpg}.png ”; done'
|
||||
|
||||
```
|
||||
|
||||
Description of each option used in the above command:
|
||||
|
||||
1. -c allows for execution of the for loop statement in single quotes.
|
||||
2. The image variable is a counter for number of images in the directory.
|
||||
3. For each conversion operation, the [echo command][1] informs the user that a png image has been converted to jpg format and vice-versa in the line $image converted to ${image%.png}.jpg”.
|
||||
4. “${image%.png}.jpg” creates the name of the converted image, where % removes the extension of the old image format.
|
||||
|
||||
[
|
||||

|
||||
][5]
|
||||
|
||||
for loop – Convert PNG to JPG Format
|
||||
|
||||
### 4\. Convert PNG to JPG Using Shell Script
|
||||
|
||||
If you do not want to make your command line dirty as in the previous example, write a small script like so:
|
||||
|
||||
Note: Appropriately interchange the `.png` and `.jpg` extensions as in the example below for conversion from one format to another.
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
#convert
|
||||
for image in *.png; do
|
||||
convert "$image" "${image%.png}.jpg"
|
||||
echo “image $image converted to ${image%.png}.jpg ”
|
||||
done
|
||||
exit 0
|
||||
|
||||
```
|
||||
|
||||
Save it as `convert.sh` and make the script executable and then run it from within the directory that has your images.
|
||||
|
||||
```
|
||||
$ chmod +x convert.sh
|
||||
$ ./convert.sh
|
||||
|
||||
```
|
||||
[
|
||||

|
||||
][4]
|
||||
|
||||
Batch Image Convert Using Shell Script
|
||||
|
||||
In summary, we covered some important ways to batch convert `.png` images to `.jpg` format and vice-versa. If you want to optimize images, you can go through our guide that shows [how to compress png and jpg images in Linux][3].
|
||||
|
||||
You can as well share with us any other methods including [Linux command line tools][2] for converting images from one format to another on the terminal, or ask a question via the comment section below.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/linux-image-conversion-tools/
|
||||
|
||||
作者:[Aaron Kili][a]
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/aaronkili/
|
||||
[1]:http://www.tecmint.com/echo-command-in-linux/
|
||||
[2]:http://www.tecmint.com/tag/linux-tricks/
|
||||
[3]:http://www.tecmint.com/optimize-and-compress-jpeg-or-png-batch-images-linux-commandline/
|
||||
[4]:http://www.tecmint.com/wp-content/uploads/2016/11/Batch-Image-Convert-Using-Shell-Script.png
|
||||
[5]:http://www.tecmint.com/wp-content/uploads/2016/11/Convert-PNG-to-JPG-Using-for-loop-Command.png
|
||||
[6]:http://www.tecmint.com/tag/linux-ls-command/
|
||||
[7]:http://www.tecmint.com/wp-content/uploads/2016/11/Convert-PNG-to-JPG-Using-Parallel-Command.png
|
||||
[8]:http://www.tecmint.com/sort-ls-output-by-last-modified-date-and-time/
|
||||
[9]:http://www.tecmint.com/wp-content/uploads/2016/11/Convert-PNG-to-JPG-in-Linux.png
|
||||
[10]:http://www.tecmint.com/tag/linux-ls-command/
|
||||
[11]:http://www.tecmint.com/using-shell-script-to-automate-linux-system-maintenance-tasks/
|
||||
@@ -1,44 +1,45 @@
|
||||
Training vs. hiring to meet the IT needs of today and tomorrow
|
||||
培训还是雇人,来满足当今和未来的 IT 需求
|
||||
已校对。
|
||||
|
||||
为满足当今和未来 IT 需求,培训员工还是雇佣新人?
|
||||
================================================================
|
||||
|
||||

|
||||
|
||||
在数字化时代,由于企业需要不断跟上工具和技术更新换代的步伐,对 IT 技能的需求也稳定增长。对于企业来说,寻找和雇佣那些拥有令人垂涎能力的创新人才,是非常不容易的。同时,培训内部员工来使他们接受新的技能和挑战,需要一定的时间。而且,这也往往满足不了需求。
|
||||
在数字化时代,由于IT工具不断更新,技术公司紧随其后,对 IT 技能的需求也不断变化。对于企业来说,寻找和雇佣那些拥有令人垂涎能力的创新人才,是非常不容易的。同时,培训内部员工来使他们接受新的技能和挑战,需要一定的时间,而时间要求常常是紧迫的。
|
||||
|
||||
[Sandy Hill][1] 对多种 IT 学科涉及到的多项技术都很熟悉。她作为 [Pegasystems][2] 项目的 IT 主管,负责的 IT 团队涉及的领域从应用的部署到数据中心的运营。更重要的是,Pegasystems 开发应用来帮助销售,市场,服务以及运行团队简化操作,联系客户。这意味着她需要掌握和利用 IT 内部资源的最佳方法,面对公司客户遇到的 IT 挑战。
|
||||
[Sandy Hill][1] 对 IT 涉及到的多项技术都很熟悉。她作为 [Pegasystems][2] 项目的 IT 总监,负责多个 IT 团队,从应用的部署到数据中心的运营都要涉及。更重要的是,Pegasystems 开发帮助销售、市场、服务以及运营团队流水化操作,以及客户联络的应用。这意味着她需要掌握使用 IT 内部资源的最佳方法,面对公司客户遇到的 IT 挑战。
|
||||
|
||||

|
||||
|
||||
**企业家项目(TEP):这些年你是如何调整培训重心的?**
|
||||
**TEP(企业家项目):这些年你是如何调整培训重心的?**
|
||||
|
||||
**Hill**:在过去的几十年中,我们经历了爆炸式的发展,所以现在我们要实现更多的全球化进程。随之而来的培训方面,将确保每个人都在同一起跑线上。
|
||||
**Hill**:在过去的几年中,我们经历了爆炸式的发展,现在我们要实现更多的全球化进程。因此,培训目标是确保每个人都在同一起跑线上。
|
||||
|
||||
我们大多的关注点已经转移到培养员工使用新的产品和工具上,这些新产品和工具的实现,能够推动创新,并提高工作效率。例如,我们实现了资产管理系统; 以前我们是没有的。因此我们需要为全部员工做培训,而不是雇佣那些已经知道该产品的人。当我们正在发展的时候,我们也试图保持紧张的预算和稳定的职员总数。所以,我们更愿意在内部培训而不是雇佣新人。
|
||||
我们主要的关注点在培养员工使用新产品和工具上,这些新产品和工具能够推动创新,提高工作效率。例如,我们使用了之前没有的资产管理系统。因此我们需要为全部员工做培训,而不是雇佣那些已经知道该产品的人。当我们正在发展的时候,我们也试图保持紧张的预算和稳定的职员总数。所以,我们更愿意在内部培训而不是雇佣新人。
|
||||
|
||||
**TEP:说说培训方法吧,你是怎样帮助你的员工发展他们的技能?**
|
||||
**TEP:说说培训方法吧,怎样帮助你的员工发展他们的技能?**
|
||||
|
||||
**Hill**:我要求每一位员工制定一个技术性的和非技术性的训练目标。这作为他们绩效评估的一部分。他们的技术性目标需要与他们的工作职能相符,非技术行目标则着重发展一项软技能,或是学一些专业领域之外的东西。我每年对职员进行一次评估,看看差距和不足之处,以使团队保持全面发展。
|
||||
**Hill**:我要求每一位员工制定一个技术性的和非技术性的训练目标。这作为他们绩效评估的一部分。他们的技术性目标需要与他们的工作职能相符,非技术行目标则随意,比如着重发展一项软技能,或是学一些专业领域之外的东西。我每年对职员进行一次评估,看看差距和不足之处,以使团队保持全面发展。
|
||||
|
||||
**TEP:你的训练计划能够在多大程度上减轻招聘和保留职员的问题?**
|
||||
**TEP:你的训练计划能够在多大程度上减轻招聘工作量, 保持职员的稳定性?**
|
||||
|
||||
**Hill**:使我们的职员对学习新的技术保持兴奋,让他们的技能更好。让职员知道我们重视他们并且让他们在擅长的领域成长和发展,以此激励他们。
|
||||
**Hill**:使我们的职员保持学习新技术的兴趣,可以让他们不断提高技能。让职员知道我们重视他们并且让他们在擅长的领域成长和发展,以此激励他们。
|
||||
|
||||
**TEP:你有没有发现哪种培训是最有效的?**
|
||||
**TEP:你们发现哪些培训是最有效的?**
|
||||
|
||||
**HILL**:我们使用几种不同的我们发现是有效的培训方法。当有新的或特殊的项目时,我们尝试加入一套由甲方(不会翻:乙方,卖方?)领导的培训课程,作为项目的一部分。要是这个方法不能实现,我们将进行异地培训。我们也会购买一些在线的培训课程。我也鼓励职员每年参加至少一次会议,以了解行业的动向。
|
||||
**HILL**:我们使用几种不同的培训方法,认为效果很好。对新的或特殊的项目,我们会由供应商提供培训课程,作为项目的一部分。要是这个方法不能实现,我们将进行脱产培训。我们也会购买一些在线的培训课程。我也鼓励职员每年参加至少一次会议,以了解行业的动向。
|
||||
|
||||
**TEP:你有没有发现有哪些技能,雇佣新人要比培训现有员工要好?**
|
||||
**TEP:哪些技能需求,更适合雇佣新人而不是培训现有员工?**
|
||||
|
||||
**Hill**:这和项目有关。有一个最近的计划,试图实现 OpenStack,而我们根本没有这方面的专家。所以我们与一家从事这一领域的咨询公司合作。我们利用他们的专业知识帮助我们运行项目,并现场培训我们的内部团队成员。让内部员工学习他们需要的技能,同时还要完成他们们天的工作,这是一项艰巨的任务。
|
||||
**Hill**:这和项目有关。最近有一个项目,需要使用 OpenStack,而我们根本没有这方面的专家。所以我们与一家从事这一领域的咨询公司合作。我们利用他们的专业人员运行该项目,并现场培训我们的内部团队成员。让内部员工学习他们需要的技能,同时还要完成他们的日常工作,是一项艰巨的任务。
|
||||
|
||||
顾问帮助我们确定我们需要的对某一技术熟练的的员工人数。这使我们能够对员工进行评估,看看是否存在缺口。如果存在人员上的缺口,我们还需要额外的培训或是员工招聘。我们也确实雇佣了一些承包商。另一个选择是让一些全职员工进行为期六至八周的培训,但我们的项目模式不容许这么做。
|
||||
顾问帮助我们确定我们需要的员工人数。这样我们就可以对员工进行评估,看是否存在缺口。如果存在人员上的缺口,我们还需要额外的培训或是员工招聘。我们也确实雇佣了一些合同工。另一个选择是对一些全职员工进行为期六至八周的培训,但我们的项目模式不容许这么做。
|
||||
|
||||
**TEP:想一下你最近雇佣的员工,他们的那些技能特别能够吸引到你?**
|
||||
**TEP:最近雇佣的员工,他们的那些技能特别能够吸引到你?**
|
||||
|
||||
**Hill**:在最近的招聘中,我侧重于软技能。除了扎实的技术能力外,他们需要能够在团队中进行有效的沟通和工作,要有说服他人,谈判和解决冲突的能力。
|
||||
**Hill**:在最近的招聘中,我更看重软技能。除了扎实的技术能力外,他们需要能够在团队中进行有效的沟通和工作,要有说服他人,谈判和解决冲突的能力。
|
||||
|
||||
IT 人一向独来独往。他们一般不是社交最多的人。现在,IT 越来越整合到组织中,它为其他业务部门提供有用的更新报告和状态报告的能力是至关重要的,这也表明 IT 是积极的存在,并将取得成功。
|
||||
IT 人常常独来独往,不擅社交。然而如今IT 与整个组织结合越来越紧密,为其他业务部门提供有用的更新和状态报告的能力至关重要,可展示 IT 部门存在的重要性。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@@ -46,7 +47,7 @@ via: https://enterprisersproject.com/article/2016/6/training-vs-hiring-meet-it-n
|
||||
|
||||
作者:[Paul Desmond][a]
|
||||
译者:[Cathon](https://github.com/Cathon)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[jasminepeng](https://github.com/jasminepeng)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ via: http://www.cio.com/article/3120235/open-source-tools/what-the-rise-of-permi
|
||||
|
||||
作者:[Paul Rubens ][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[jasminepeng](https://github.com/jasminepeng)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
|
||||
聊聊Docker Datacenter在AWS和AZURE上的应用
|
||||
===================================================
|
||||
|
||||
|
||||
三言两语介绍一下AWS快速启动应用和Azure Marketplace上产品化和高可用性的Docker部署模板。
|
||||
|
||||
Docker Datacenter AWS快速启动应用使用CloudFormation模板和AZure Marketpalce上预编译的模板来简化企业CaaS Docker环境在公有云基础设施下的部署。
|
||||
|
||||
|
||||
为敏捷应用而生的CasS平台,为各种规模企业提供容器、集群编排和管理等各种简单、安全和可伸缩的服务。使用为Docker Datacenter预编译的崭新的云模板,开发者和IT运维人员可以无缝的把它们的应用迁移到亚马逊EC2或者微软的Azure环境而无需修改任何代码。现在,企业可以快速实现更高的计算和运营效率,Docker可以通过短短几步操作支持容器管理和编排。
|
||||
|
||||
### 什么是Docker Datacenter ?
|
||||
|
||||
|
||||
Docker Datacenter包括Docker通用控制平面,Docker可信注册表和与客户的应用服务等级协议相匹配的商用CS Docker引擎。
|
||||
|
||||
|
||||
- Docker通用控制平面(UCP),一种企业级的集群管理方案,帮助客户通过单个管理仪表盘管理整个集群
|
||||
- Docker可信注册表(DTR), 一种映像管理方案,帮助客户安全存储和管理Docker映像
|
||||
- 商用版的Docker引擎
|
||||
|
||||

|
||||
|
||||
### 在AWS上快速布置Docker Datacenter
|
||||
|
||||
秉承Docker与AWS最佳实践,参照AWS快速启动教程,你可以在AWS云上快速部署Docker容器。Docker Datacenter快速应用基于模块化和可定制的CloudFormation模板,客户可以在其之上增加额外功能或者为自己的Docker部署修改模板。
|
||||
|
||||
[AWS的Docker Datacenter应用说明](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服务,它们启动、自动完成配置并在两个可用区(Availability Zone)之间提供弹性负载均衡。
|
||||
|
||||
除些之外,如有需要,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 Datacenter
|
||||
|
||||
1. 登录[Docker Store][1]获取[30天免费试用][2]或者[联系销售][4]
|
||||
2. 确认之后,提示“Launch Stack”,客户会被重定向到AWS Cloudformation入口
|
||||
3. 确认启动Docker的AWS区域
|
||||
4. 提供启动参数
|
||||
5. 确认并启动
|
||||
6. 启动完成之后,点击输出分页标签可以看到UCP/DTR的 URL、缺省用户名、密码和S3 bucket的名称
|
||||
|
||||
[Docker Datacenter需要2000美刀信用担保](https://aws.amazon.com/mp/contactdocker/)
|
||||
|
||||
|
||||
### 在Azure使用Azure Marketplace上预编译的模板部署
|
||||
|
||||
在Azure Marketplace上,Docker Datacenter是一个预先编译的模板,客户可以在Azure全球不同的数据中心即起即用。客户可以根据自己需求从Azure提供的各种VM中选择部署适合自己的Docker Datacenter。
|
||||
|
||||
|
||||
#### 架构
|
||||

|
||||
|
||||
|
||||
Azure部署进程开始于输入一些基本用户信息,如ssh-ing管理员用户名(系统级管理员)和资源组名称。你可以把资源组理解为一组有生命周期和部署边界的资源集合。你可以在这个链接了解更多关于资源组的信息:[azure.microsoft.com/en-us/documentation/articles/resource-group-overview/](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 Datacenter30天试用][5]许可或者[联系销售][6]
|
||||
2. [跳转到微软Azure Markplace的Docker Datacenter][7]
|
||||
3. [评审部署文档][8]
|
||||
|
||||
如果客户注册获取Docker Datacenter许可证,那么他们将授权启动AWS或者Azure模板.
|
||||
- [获取30天试用许可证][9]
|
||||
- [通过视频理解Docker Datacenter架构][10]
|
||||
- [观看演示视频][11]
|
||||
- [获取AWS提供的部署Docker Datacenter的75美元红包奖励][12]
|
||||
|
||||
### 了解有关Docker的更多信息
|
||||
- 初识Docker? 尝试一下10分钟[在线学习课程][20]
|
||||
- 分享映像,自动构建,或用一个[免费的Docker Hub账号][21]尝试更多
|
||||
- 阅读[Docker 1.12 发行说明][22]
|
||||
- 订阅[Docker Weekly][23]
|
||||
- 报名参加即将到来的[Docker Online Meetups][24]
|
||||
- 参加即将发生的[Docker Meetups][25]
|
||||
- 观看[DockerCon EU2015][26]视频
|
||||
- 开始为[Docker][27]贡献力量
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://blog.docker.com/2016/06/docker-datacenter-aws-azure-cloud/
|
||||
|
||||
作者:[Trisha McCanna][a]
|
||||
译者:[firstadream](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://blog.docker.com/author/trisha/
|
||||
[1]: https://store.docker.com/login?next=%2Fbundles%2Fdocker-datacenter%2Fpurchase?plan=free-trial
|
||||
[2]: https://store.docker.com/login?next=%2Fbundles%2Fdocker-datacenter%2Fpurchase?plan=free-trial
|
||||
[4]: https://goto.docker.com/contact-us.html
|
||||
[5]: https://store.docker.com/login?next=%2Fbundles%2Fdocker-datacenter%2Fpurchase?plan=free-trial
|
||||
[6]: https://goto.docker.com/contact-us.html
|
||||
[7]: https://azure.microsoft.com/en-us/marketplace/partners/docker/dockerdatacenterdocker-datacenter/
|
||||
[8]: https://success.docker.com/Datacenter/Apply/Docker_Datacenter_on_Azure
|
||||
[9]: http://www.docker.com/trial
|
||||
[10]: https://www.youtube.com/playlist?list=PLkA60AVN3hh8tFH7xzI5Y-vP48wUiuXfH
|
||||
[11]: https://www.youtube.com/playlist?list=PLkA60AVN3hh8a8JaIOA5Q757KiqEjPKWr
|
||||
[12]: https://aws.amazon.com/quickstart/promo/
|
||||
[20]: https://docs.docker.com/engine/understanding-docker/
|
||||
[21]: https://hub.docker.com/
|
||||
[22]: https://docs.docker.com/release-notes/
|
||||
[23]: https://www.docker.com/subscribe_newsletter/
|
||||
[24]: http://www.meetup.com/Docker-Online-Meetup/
|
||||
[25]: https://www.docker.com/community/meetup-groups
|
||||
[26]: https://www.youtube.com/playlist?list=PLkA60AVN3hh87OoVra6MHf2L4UR9xwJkv
|
||||
[27]: https://docs.docker.com/contributing/contributing/
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
拥有开源项目部门的公司可以从四个方面获益
|
||||
====
|
||||
|
||||

|
||||
|
||||
在我的第一篇关于开源项目部门的系列文章中,我深入剖析了[什么是开源项目部门,为什么你的公司需要一个开源项目部门][1]。接着我又说到了[谷歌是如何创建一个新的开源项目部门的][2]。而这篇文章,我将阐述拥有一个开源项目部门的好处。
|
||||
|
||||
乍一看,非软件开发公司会更加热情的去拥抱开源项目部门的一个重要原因是他们并没有什么损失。毕竟,他们并不需要依靠这些软件产品来获得收益。比如,Facebook 可以很轻易的释放出一个 “分布式键值数据存储” 作为开源项目,是因为他们并没有售卖一个叫做 “分布式键值数据存储” 的产品。这回答了关于风险的问题,但是并没有回答他们如何通过向开源生态共献代码而获益的问题。让我们逐个来推测和探讨其中可能的原因。你会发现开源项目供应商的许多动机都是相同的,但是也有些许不同。
|
||||
|
||||
### 招聘
|
||||
|
||||
招聘可能是一个最容易的方法将一个开源项目售卖给上层管理部门。向他们展示与招聘相关的成本,以及投资回报率,然后解释如何与天才工程师发展关系,从而与那些对这些项目感兴趣并且十分乐意在其中工作的天才开发者们建立联系。不需要我多说了,你懂的!
|
||||
|
||||
### 技术影响
|
||||
|
||||
曾几何时,那些没有专门从事软件销售的公司难以直接影响他们软件供应商的开发周期,尤其是他们并不是一个大客户时。开源完全改变了这一点,它将用户与供应商放在了一个更公平的竞争环境中。随着开源开发的兴起,任何人,假如他们愿意投入时间和资源的话,都可以将技术推向一个选定的方向。但是这些公司发现,虽然将投资用于开发上会带来丰硕的成果,但是总体战略的努力却更加有效——试想 bug 的修复 VS 软件的构建——大多数公司都将 bug 的修复推给上游的开源部门,但是一些公司开始认识到通过更深层次的回报承诺和更快的功能开发来协调持久的工作,将会更有利于业务。通过一个开源项目部门的模型,公司的职员能够从开源社区中准确嗅出战略重心,然后投入开发资源。
|
||||
|
||||
对于快速增长的公司,如 Google 和 Facebook,其对现有的开源项目提供的领导力仍然不足以满足业务的膨胀。面对激烈的增长和建立超大规模系统所带来的挑战,许多大型企业开始为软件构建仅供内部使用的高度定制的栈。除非他们能说服别人在一些基础设施项目上达成合作?因此,虽然他们保持在诸如 Linux 内核,Apache 和其他现有项目领域的投资,他们也开始推出自己的大型项目。Facebook 发布了 Cassandra,Twitter 创造了 Mesos,并且甚至谷歌也创建了 Kubernetes 项目。这些项目已成为行业创新的主要平台,证实该举措是相关公司引人注目的成功。(请注意,Facebook 内部停止使用 Cassandra 后,它需要创造一个新软件项目来解决更大规模的问题,但是,这时 Cassandra 已经变得流行,而 DataStax 已经开始承担开发任务)。所有这些项目已经促使了开发商、相关的项目、以及最终用户来供应加速的增长和发展的整个生态。
|
||||
|
||||
开源项目部门和公司战略举措是不可能不协调的。没有这种努力,每个所提到的公司依然在试图单独地和更慢解决这些问题。不仅拥有这些项目可以帮助解决内部业务问题,它们也帮助这些公司逐渐成为行业巨头。当然,谷歌当了好多年行业巨头,但是 Kubernetes 的发展确保了软件的质量,并且在容器技术未来的发展方向上有着直接的话语权,并且远超之前就有的话语权。这些公司目前还是闻名于他们超大规模的基础设施和硅谷的中坚份子。鲜为人知,但是更为重要的是它们与技术生产人员的亲密度。开源项目办公室凭借技术建议和与有影响力的开发者的关系,再加上在社区治理和人员管理方面深厚的专业知识来引领这些工作,并最大限度地发挥其影响力,
|
||||
|
||||
### 市场营销能力
|
||||
|
||||
与技术的影响齐头并进的是每个公司谈论如何开源的努力。通过推敲这些项目和社区周围的消息,一个开源项目部门能够通过有针对性的营销活动来提供最大的影响。营销在开放源码领域一直是一个肮脏的词汇,因为每个人都有一个由企业营销造成的糟糕的经历。在开源社区中,营销呈现出一种与传统方法截然不同的形式,他会更注重于我们的社区已经在战略方向上做了什么。因此,一个开源项目部门不可能去宣传一些根本还没有发布任何代码的项目,但是他们会讨论他们创造什么软件和参与了其他什么举措。基本上,不会有“雾件”。
|
||||
|
||||
想想谷歌的开源项目办公室作出的第一份工作。他们不只是简单的贡献代码给 Linux 内核或其他项目,他们更多的是谈论它,并经常在开源会议主题演讲。他们不仅仅是把钱给写开源的代码的学生,他们还创建了一个全球计划——“Google Summer of Code”,现在已经成为一种开源发展的文化试金石。这些市场营销的作用在 Kubernetes 开发完成之前就奠定了谷歌在开源世界巨头的地位。最终使得,谷歌在创建 GPLv3 授权协议期间拥有重要影响力,并且在科技活动中公司的发言人和开源项目部门代表人成为主要人物。开源项目部门是协调这些工作的最好的实体,并可以为母公司提供真正的价值。
|
||||
|
||||
###改善内部流程
|
||||
|
||||
改善内部流程听起来不像一个大好处,但克服混乱的内部流程对于每一个开源项目部门都是一个挑战,不论是软件开发商还是驱动开发公司。而软件供应商必须确保他们的流程不与他们发布的产品重叠(例如,不小心开源了他们的专业软件),用户更关心的是侵犯了知识产权(IP)法:专利、版权和商标。没有人想只是因为释放软件而被起诉。没有一个活跃的开源项目部门去管理和协调这些许可和其他法律问题,大公司在开源流程和管理上面临着巨大的困难。为什么这个很重要呢?如果不同的组释放的软件是在不兼容的许可证下,那么这不仅是一个坑爹的尴尬,它还将对实现最基本的目标改良协作产生巨大的障碍。
|
||||
|
||||
考虑到还有许多这样的公司仍在飞快的增长,如果无法建立基本流程规则的话,将可以预见到它们将会遇到阻力。我见过一个巨大的电子表格罗列着批准、未经批准的许可证,以及指导如何(或如何不)创建开源社区而遵守法律限制。关键是当开发者需要做出决定时要有一个可以依据的东西,并且每次当开发人员想要为一个开源社区贡献代码时,可以不产生大量的法律开销,和效率低下的知识产权检查。
|
||||
|
||||
有一个活跃的开放源码项目部门,负责维护许可规则和源的贡献,以及建立培训项目工程师,有助于避免潜在的法律缺陷和昂贵的诉讼。毕竟,良好的开源项目合作可以减少由于某人没有看许可证而导致公司赔钱这样的事件。好消息是,公司已经不用担心关于专有的知识产权与软件供应商冲突的事。坏消息是,它们的法律问题不够复杂,尤其是当他们直接需要软件供应商提供法律阻力时。
|
||||
|
||||
你的组织是如何受益于拥有一个开源项目部门的?可以在评论中与我们分享。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/business/16/9/4-big-ways-companies-benefit-having-open-source-program-offices
|
||||
|
||||
作者:[John Mark Walker][a]
|
||||
译者:[chao-zhi](https://github.com/chao-zhi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/johnmark
|
||||
[1]: https://opensource.com/business/16/5/whats-open-source-program-office
|
||||
[2]: https://opensource.com/business/16/8/google-open-source-program-office
|
||||
515
translated/tech/20161024 Getting Started with Webpack 2.md
Normal file
515
translated/tech/20161024 Getting Started with Webpack 2.md
Normal file
@@ -0,0 +1,515 @@
|
||||
OneNewLife translated
|
||||
|
||||
# Webpack 2 入门
|
||||
|
||||

|
||||
|
||||
Webpack 2 即将退出测试,[一旦文档完成][26]。不过这不意味着你现在不能开始使用第 2 版,前提是你知道怎么配置它。
|
||||
|
||||
### Webpack 是什么
|
||||
|
||||
官方的说法是最简单的 —— Webpack 是一个 JavaScript 模块打包器。然而,自从它发布以来,它发展成为了你所有前端代码的管理工具(有意地或社区的意愿)。
|
||||
|
||||

|
||||
|
||||
任务运行器,例如 Gulp,可以处理许多不同的预处理器和转换器,但是在所有的情景下,它都需要一个输入源并将其压缩到一个编译好的输出文件中。然而,它是在个案基础上这样做的,不用担心整个系统。这是开发者的负担:找到任务运行器中断的地方,并找到适当的方式将所有这些模块在生产中联合在一起。
|
||||
|
||||
Webpack 试图通过提出一个大胆的想法来减轻开发者的负担:如果有一部分开发过程可以自动处理依赖关系会怎样?如果我们可以简单地写代码,让构建过程只基于最终需求管理自己会怎样?
|
||||
|
||||

|
||||
|
||||
如果你过去几年一直是 web 社区的一员,你已经知道解决问题的首选方法:使用 JavaScript 来构建。因此 Webpack 尝试通过 JavaScript 传递依赖关系使构建过程更加容易。不过这个设计真正的亮点不是简单的代码管理部分,而是管理层由 100% 有效的 JavaScript 实现(具有 Nodejs 特性)。Webpack 能够让你写有效的 JavaScript,更好更全面地了解系统。
|
||||
|
||||
换句话来说:你不需要为 Webpack 写代码。你只需要写项目代码。而且 Webpack 会持续工作(当然需要一些配置)。
|
||||
|
||||
简而言之,如果你曾经遇到过以下任何一种情况:
|
||||
|
||||
* 意外引入一些你不需要在生产中用上的样式表和 JS 库,使项目膨胀
|
||||
* 遇到作用域的问题 —— CSS 和 JavaScript 都会有
|
||||
* 找到一个好的构建系统让你在 JavaScript 中使用 Node/Bower 模块,或者依靠一个疯狂的后端配置来正确地使用这些模块
|
||||
* 需要优化资产交付,但担心你会弄坏一些东西
|
||||
|
||||
那么你可以从 Webpack 中收益了。它通过让 JavaScript 毫不费力地担心你的依赖关系和加载顺序,而不是开发者的大脑。最好的部分是?Webpack 甚至可以纯粹在服务器端运行,这意味着你还可以使用 Webpack 构建[渐进增强][25]的网站。
|
||||
|
||||
### 第一步
|
||||
|
||||
我们将在本教程中使用 [Yarn][24](运行命令 `brew install yarn`) 代替 `npm`,不过这完全取决于你,它们做同样的事情。在我们的项目文件夹中,我们将在终端窗口中运行以下代码,将 Webpack 2 添加到我们的全局软件包以及本地项目中:
|
||||
|
||||
```
|
||||
yarn global add webpack@2.1.0-beta.25 webpack-dev-server@2.1.0-beta.9
|
||||
yarn add --dev webpack@2.1.0-beta.25 webpack-dev-server@2.1.0-beta.9
|
||||
```
|
||||
|
||||
我们接着会通过项目根目录的一个 `webpack.config.js` 文件来声明 webpack 的配置:
|
||||
|
||||
```
|
||||
'use strict';
|
||||
|
||||
const webpack = require('webpack');
|
||||
|
||||
module.exports = {
|
||||
context: __dirname + '/src',
|
||||
entry: {
|
||||
app: './app.js',
|
||||
},
|
||||
output: {
|
||||
path: __dirname + '/dist',
|
||||
filename: '[name].bundle.js',
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
注意:`__dirname` 是指你的项目根目录
|
||||
|
||||
记住,Webpack “知道”你的项目发生了什么。它通过阅读你的代码来实现(别担心,它签署了一个 NDA 协议)。Webpack 基本上执行以下操作:
|
||||
|
||||
1. 从 `context` 文件夹开始...
|
||||
2. ...它查找 `entry` 的文件名...
|
||||
3. ...并读取内容。每一个 `import`([ES6][7])或 `require()`(Nodejs)的依赖会在它解析代码的时候找到,它会在最终构建的时候打包这些依赖项。然后,它会搜索那些依赖项以及那些依赖项所依赖的依赖项,直到它到达“树”的最底端 —— 只是打包它所需要的,没有其它东西。
|
||||
4. Webpack 从 `context` 文件夹打包所有东西到 `output.path` 文件夹,使用 `output.filename` 命名模板来为其命名(其中 `[name]` 被替换成来自 `entry` 的对象键)。
|
||||
|
||||
所以如果我们的 `src/app.js` 文件看起来像这样(假设我们事先运行了 `yarn add --dev moment`):
|
||||
|
||||
```
|
||||
'use strict';
|
||||
|
||||
import moment from 'moment';
|
||||
var rightNow = moment().format('MMMM Do YYYY, h:mm:ss a');
|
||||
console.log( rightNow );
|
||||
|
||||
// "October 23rd 2016, 9:30:24 pm"
|
||||
```
|
||||
|
||||
我们应该运行:
|
||||
|
||||
```
|
||||
webpack -p
|
||||
```
|
||||
|
||||
注意:`p` 标志表示“生产”模式,这会压缩输出文件。
|
||||
|
||||
它会输出一个 `dist/app.bundle.js`,这会将当前日期和时间打印到控制台。要注意 Webpack 会自动识别 `'moment'` 指代什么(虽然如果你有一个 `moment.js` 文件在你的目录,默认情况下 Webpack 会优先考虑你的 `moment` Node 模块)。
|
||||
|
||||
### 使用多个文件
|
||||
|
||||
你可以通过仅仅修改 `entry` 对象来指定任意数量的输入/输出点。
|
||||
|
||||
#### 打包多个文件
|
||||
|
||||
```
|
||||
`'use strict';
|
||||
|
||||
const webpack = require("webpack");
|
||||
|
||||
module.exports = {
|
||||
context: __dirname + "/src",
|
||||
entry: {
|
||||
app: ["./home.js", "./events.js", "./vendor.js"],
|
||||
},
|
||||
output: {
|
||||
path: __dirname + "/dist",
|
||||
filename: "[name].bundle.js",
|
||||
},
|
||||
};`
|
||||
```
|
||||
|
||||
所有文件都会按照数组的顺序一起被打包成一个 `dist/app.bundle.js` 文件。
|
||||
|
||||
#### 输出多个文件
|
||||
|
||||
```
|
||||
`const webpack = require("webpack");
|
||||
|
||||
module.exports = {
|
||||
context: __dirname + "/src",
|
||||
entry: {
|
||||
home: "./home.js",
|
||||
events: "./events.js",
|
||||
contact: "./contact.js",
|
||||
},
|
||||
output: {
|
||||
path: __dirname + "/dist",
|
||||
filename: "[name].bundle.js",
|
||||
},
|
||||
};`
|
||||
```
|
||||
|
||||
或者,你可以选择打包成多个 JS 文件以便于分割应用的某些模块。这将被打包成 3 个文件:`dist/home.bundle.js`,`dist/events.bundle.js` 和 `dist/contact.bundle.js`。
|
||||
|
||||
#### 高级打包自动化
|
||||
|
||||
如果你将你的应用分割成多个 `output` 输出项(如果你的应用的一部分有大量你不需要预加载的 JS,这会很有用),你可能会重用这些文件的代码,因为它将分别解析每个依赖关系。幸运的是,Webpack 有一个内置的 `CommonsChunk` 插件来处理这个:
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
// …
|
||||
|
||||
plugins: [
|
||||
new webpack.optimize.CommonsChunkPlugin({
|
||||
name: "commons",
|
||||
filename: "commons.bundle.js",
|
||||
minChunks: 2,
|
||||
}),
|
||||
],
|
||||
|
||||
// …
|
||||
};
|
||||
```
|
||||
|
||||
现在,在你的 `output` 文件中,如果你有任何模块被加载 2 次以上(通过 `minChunks` 设置),它会把那个模块打包到 `common.js` 文件中,然后你可以将其缓存在客户端。这将生成一个额外的请求头,但是你防止了客户端多次下载同一个库。因此,在很多情景下,这会大大提升速度。
|
||||
|
||||
### 开发
|
||||
|
||||
Webpack actually has its own development server, so whether you’re developing a static site or are just prototyping your front-end, it’s perfect for either. To get that running, just add a `devServer` object to `webpack.config.js`:
|
||||
Webpack 实际上有自己的开发服务器,所以无论你是开发一个静态网站还是只是你的网站前端原型,它都是无可挑剔的。要运行那个服务器,只需要添加一个 `devServer` 对象到 `webpack.config.js`:
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
context: __dirname + "/src",
|
||||
entry: {
|
||||
app: "./app.js",
|
||||
},
|
||||
output: {
|
||||
filename: "[name].bundle.js",
|
||||
path: __dirname + "/dist/assets",
|
||||
publicPath: "/assets", // New
|
||||
},
|
||||
devServer: {
|
||||
contentBase: __dirname + "/src", // New
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
现在创建一个包含以下代码的 `src/index.html` 文件:
|
||||
|
||||
```
|
||||
<script src="/assets/app.bundle.js"></script>
|
||||
```
|
||||
|
||||
... 在你的终端运行:
|
||||
|
||||
```
|
||||
webpack-dev-server
|
||||
```
|
||||
|
||||
你的服务器现在运行在 `localhost:8080`。注意 `script` 标签里面的 `/assets` 是怎么匹配到 `output.publicPath` 的 —— 你可以随意更改它的名称(如果你需要一个 CDN 的时候这会很有用)。
|
||||
|
||||
Webpack 会热加载所有 JavaScript 更改,而不需要刷新你的浏览器。但是,所有 `webpack.config.js` 文件里面的更改都需要重新启动服务器才能生效。
|
||||
|
||||
### 全局访问方法
|
||||
|
||||
需要在全局空间使用你的函数?在 `webpack.config.js` 里面简单地设置 `output.library`:
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
output: {
|
||||
library: 'myClassName',
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
这会将你打包好的文件附加到一个 `window.myClassName` 实例。因此,使用该命名空间,你可以调用入口文件的可用方法(可以在[文档][23]中阅读有关此设置的更多信息)。
|
||||
|
||||
### 加载器
|
||||
|
||||
到目前为止,我们所做的一切只涉及 JavaScript。从一开始使用 JavaScript 是重要的,因为它是 Webpack 唯一支持的语言。事实上我们可以处理几乎所有文件类型,只要我们将其转换成 JavaScript。我们用加载器来实现这个功能。
|
||||
|
||||
加载器可以是 Sass 这样的预处理器,或者是 Babel 这样的转译器。在 NPM 上,它们通常被命名为 `*-loader`,例如 `sass-loader` 和 `babel-loader`。
|
||||
|
||||
#### Babel 和 ES6
|
||||
|
||||
如果我们想在项目中通过 [Babel][22] 来使用 ES6,我们首先需要在本地安装合适的加载器:
|
||||
|
||||
```
|
||||
yarn add --dev babel-loader babel-core babel-preset-es2015
|
||||
```
|
||||
|
||||
然后将它添加到 `webpack.config.js`,让 Webpack 知道在哪里使用它。
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
// …
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
use: [{
|
||||
loader: "babel-loader",
|
||||
options: { presets: ["es2015"] }
|
||||
}],
|
||||
},
|
||||
|
||||
// Loaders for other file types can go here
|
||||
],
|
||||
},
|
||||
|
||||
// …
|
||||
};
|
||||
```
|
||||
|
||||
Webpack 1 的用户注意:加载器的核心概念没有任何改变,但是语法改进了。直到官方文档完成之前,这可能不是确切的首选语法。
|
||||
|
||||
`/\.js$/` 这个正则表达式查找所有以 `.js` 结尾的待通过 Babel 加载的文件。Webpack 依靠正则检查给予你完全的控制权 —— 它不限制你的文件扩展名或者假设你的代码必须以某种方式组织。例如:也许你的 `/my_legacy_code/` 文件夹下的内容不是用 ES6 写的。所以你可以修改上述的 `test` 为 `/^((?!my_legacy_folder).)\.js$/`,这将会排除那个特定的文件夹,不过会用 Babel 处理其余的文件。
|
||||
|
||||
#### CSS 和 Style 加载器
|
||||
|
||||
如果我们只想加载 CSS 作为我们的应用程序,我们也可以这样做。假设我们有一个 `index.js` 文件,我们将从那里引入:
|
||||
|
||||
```
|
||||
import styles from './assets/stylesheets/application.css';
|
||||
```
|
||||
|
||||
我们会得到以下错误:`你可能需要一个合适的加载器来处理这种类型的文件`。记住,Webpack 只能识别 JavaScript,所以我们必须安装合适的加载器:
|
||||
|
||||
```
|
||||
yarn add --dev css-loader style-loader
|
||||
```
|
||||
|
||||
然后添加一条规则到 `webpack.config.js`:
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
// …
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: ["style-loader", "css-loader"],
|
||||
},
|
||||
|
||||
// …
|
||||
],
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
加载器以数组的逆序处理。这意味着 `css-loader` 会比 `style-loader` 先执行。
|
||||
|
||||
你可能会注意到,即使在生产版本中,这实际上是将你的 CSS 和 JavaScript 打包在一起,`style-loader` 手动将你的样式写到 `<head>`。乍一看,它可能看起来有点怪异,但你仔细想想这就慢慢开始变得更加有意义了。你已经节省了一个头部请求 —— 节省了一些连接上的时间。如果你用 JavaScript 来加载你的 DOM,无论如何,这从本质上消除了 [FOUC][21]。
|
||||
|
||||
你还会注意到一个开箱即用的特性 —— Webpack 已经通过将这些文件打包在一起以自动解决你所有的 `@import` 查询(而不是依靠 CSS 默认的 import 方式,这会导致无谓的头部请求以及资源加载缓慢)。
|
||||
|
||||
从你的 JS 加载 CSS 是非常惊人的,因为你现在可以用一种新的强大的方式将你的 CSS 模块化。仅仅通过加载 `button.js` 来加载 `button.css`。这将意味着如果 `button.js` 从来没有真正使用过的话,它的 CSS 就不会膨胀我们的生产版本。如果你坚持面向组件的 CSS 实践,如 SMACSS 或 BEM,你会看到更紧密地结合你的 CSS 和你的标记 + JavaScript 的价值。
|
||||
|
||||
#### CSS 和 Node 模块
|
||||
|
||||
我们可以使用 Webpack 来利用 Node 的使用 `~` 前缀导入 Node 模块的优势。如果我们运行 `yarn add normalize.css`,我们可以使用:
|
||||
|
||||
```
|
||||
@import "~normalize.css";
|
||||
```
|
||||
|
||||
并且充分利用 NPM 来管理我们的第三方样式 —— 版本控制、没有任何副本和粘贴的部分。此外,让 Webpack 为我们打包 CSS 比起使用 CSS 的默认导入方式有明显的优势 —— 节省无谓的头部请求和加载时间。
|
||||
|
||||
更新:这一节和下面一节已经更新为准确的用法,不再使用 CSS 模块简单地导入 Node 模块。感谢 [Albert Fernández][20] 的帮助!
|
||||
|
||||
#### CSS 模块
|
||||
|
||||
你可能听说过 [CSS 模块][19],它消除了 CSS 的层叠性。通常它的最适用场景是只有当你使用 JavaScript 构建 DOM 的时候,但实质上,它神奇地将你的 CSS 类放置到加载它的 JavaScript 文件([在这里了解更多][18])。如果你打算使用它,CSS 模块已经与 `css-loader` 封装在一起(`yarn add --dev css-loader`):
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
// …
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
"style-loader",
|
||||
{ loader: "css-loader", options: { modules: true } }
|
||||
],
|
||||
},
|
||||
|
||||
// …
|
||||
],
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
注意:对于 `css-loader`,我们现在使用扩展对象语法来给它传递一个选项。你可以使用一个更为精简的字符串来取代默认选项,正如我们仍然使用了 `'style-loader'`。
|
||||
|
||||
* * *
|
||||
|
||||
值得注意的是,当允许导入 CSS 模块的时候(例如:`@import 'normalize.css';`),你完全可以删除掉 `~`。但是,当你 `@import` 你自己的 CSS 的时候,你可能会遇到构建错误。如果你遇到“无法找到 ____”的错误,尝试添加一个 `resolve` 对象到 `webpack.config.js`,让 Webpack 更好地理解你的模块加载顺序。
|
||||
|
||||
```
|
||||
const path = require("path");
|
||||
|
||||
module.exports = {
|
||||
//…
|
||||
|
||||
resolve: {
|
||||
modules: [path.resolve(__dirname, "src"), "node_modules"]
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
我们首先指定源目录,然后指定 `node_modules`。因此,Webpack 会更好地处理解析度,按照既定的顺序(分别用你的源目录和 Node 模块的目录替换 `'src'` 和 `'node_modules'`),首先查找我们的源目录,然后再查找已安装的 Node 模块。
|
||||
|
||||
#### Sass
|
||||
|
||||
需要使用 Sass?没问题。安装:
|
||||
|
||||
```
|
||||
yarn add --dev sass-loader node-sass
|
||||
```
|
||||
|
||||
并添加新的规则:
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
// …
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.(sass|scss)$/,
|
||||
use: [
|
||||
"style-loader",
|
||||
"css-loader",
|
||||
"sass-loader",
|
||||
]
|
||||
}
|
||||
|
||||
// …
|
||||
],
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
然后当你的 Javascript 对一个 `.scss` 或 `.sass` 文件调用 `import` 方法的时候,Webpack 会处理的。
|
||||
|
||||
#### CSS 独立打包
|
||||
|
||||
或许你在处理渐进增强的问题;或许你因为其它原因需要一个单独的 CSS 文件。我们可以通过在我们的配置中用 `extract-text-webpack-plugin` 替换 `style-loader` 而轻易地做到这一点,这不需要更改任何代码。以我们的 `app.js` 文件为例:
|
||||
|
||||
```
|
||||
import styles from './assets/stylesheets/application.css';
|
||||
```
|
||||
|
||||
让我们安装这个插件到本地(我们需要 2016 年 10 月的 测试版本):
|
||||
|
||||
```
|
||||
yarn add --dev extract-text-webpack-plugin@2.0.0-beta.4
|
||||
```
|
||||
|
||||
并且添加到 `webpack.config.js`:
|
||||
|
||||
```
|
||||
const ExtractTextPlugin = require("extract-text-webpack-plugin");
|
||||
|
||||
module.exports = {
|
||||
// …
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
ExtractTextPlugin.extract("css"),
|
||||
{ loader: "css-loader", options: { modules: true } },
|
||||
],
|
||||
},
|
||||
|
||||
// …
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new ExtractTextPlugin({
|
||||
filename: "[name].bundle.css",
|
||||
allChunks: true,
|
||||
}),
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
现在当运行 `webpack -p` 的时候,你的 `output` 目录还会有一个 `app.bundle.css` 文件。只需要像往常一样简单地在你的 HTML 中向该文件添加一个 `<link>` 标签即可。
|
||||
|
||||
#### HTML
|
||||
|
||||
正如你可能已经猜到,Webpack 还有一个 `[html-loader][6]` 插件。但是,当我们用 JavaScript 加载 HTML 时,我们针对不同的场景分成了不同的方法,我无法想出一个单一的例子来为你计划下一步做什么。通常,你需要加载 HTML 以便于在更大的系统(如 [React][13]、[Angular][12]、[Vue][11] 或 [Ember][10])中使用 JavaScript 风格的标记,如 [JSX][16]、[Mustache][15] 或 [Handlebars][14]。
|
||||
|
||||
教程到此为止了:你可以用 Webpack 加载标记,但是进展到这一步的时候,关于你的架构,你将做出自己的决定,我和 Webpack 都无法左右你。不过参考以上的例子以及搜索 NPM 上适用的加载器应该足够你发展下去了。
|
||||
|
||||
### 从模块的角度思考
|
||||
|
||||
为了充分使用 Webpack,你必须从模块的角度来思考 —— 细粒度的、可复用的、用于高效处理每一件事的独立的处理程序。这意味着采取这样的方式:
|
||||
|
||||
```
|
||||
└── js/
|
||||
└── application.js // 300KB of spaghetti code
|
||||
```
|
||||
|
||||
将其转变成这样:
|
||||
|
||||
```
|
||||
└── js/
|
||||
├── components/
|
||||
│ ├── button.js
|
||||
│ ├── calendar.js
|
||||
│ ├── comment.js
|
||||
│ ├── modal.js
|
||||
│ ├── tab.js
|
||||
│ ├── timer.js
|
||||
│ ├── video.js
|
||||
│ └── wysiwyg.js
|
||||
│
|
||||
└── application.js // ~ 1KB of code; imports from ./components/
|
||||
```
|
||||
|
||||
结果呈现了整洁的、可复用的代码。每一个独立的组件依赖于 `import` 自身的依赖,并 `export` 它想要暴露给其它模块的部分。结合 Babel 和 ES6,你可以利用 [JavaScript 类][9] 来实现更强大的模块化,而不用考虑它的工作原理。
|
||||
|
||||
有关模块的更多信息,请参阅 Preethi Kasreddy [这篇优秀的文章][8].
|
||||
|
||||
* * *
|
||||
|
||||
### 延伸阅读
|
||||
|
||||
* [Webpack 2 的新特性][5]
|
||||
* [Webpack 配置文档][4]
|
||||
* [Webpack 范例][3]
|
||||
* [React + Webpack 入门套件][2]
|
||||
* [怎么使用 Webpack][1]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://blog.madewithenvy.com/getting-started-with-webpack-2-ed2b86c68783#.oozfpppao
|
||||
|
||||
作者:[Drew Powers][a]
|
||||
|
||||
译者:[OneNewLife](https://github.com/OneNewLife)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://blog.madewithenvy.com/@an_ennui
|
||||
[1]:https://github.com/petehunt/webpack-howto
|
||||
[2]:https://github.com/kriasoft/react-starter-kit
|
||||
[3]:https://github.com/webpack/webpack/tree/master/examples
|
||||
[4]:https://webpack.js.org/configuration/
|
||||
[5]:https://gist.github.com/sokra/27b24881210b56bbaff7
|
||||
[6]:https://github.com/webpack/html-loader
|
||||
[7]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
|
||||
[8]:https://medium.freecodecamp.com/javascript-modules-a-beginner-s-guide-783f7d7a5fcc
|
||||
[9]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
|
||||
[10]:http://emberjs.com/
|
||||
[11]:http://vuejs.org/
|
||||
[12]:https://angularjs.org/
|
||||
[13]:https://facebook.github.io/react/
|
||||
[14]:http://handlebarsjs.com/
|
||||
[15]:https://github.com/janl/mustache.js/
|
||||
[16]:https://jsx.github.io/
|
||||
[17]:https://github.com/webpack/html-loader
|
||||
[18]:https://github.com/css-modules/css-modules
|
||||
[19]:https://github.com/css-modules/css-modules
|
||||
[20]:https://medium.com/u/901a038e32e5
|
||||
[21]:https://en.wikipedia.org/wiki/Flash_of_unstyled_content
|
||||
[22]:https://babeljs.io/
|
||||
[23]:https://webpack.js.org/concepts/output/#output-library
|
||||
[24]:https://yarnpkg.com/
|
||||
[25]:https://www.smashingmagazine.com/2009/04/progressive-enhancement-what-it-is-and-how-to-use-it/
|
||||
[26]:https://github.com/webpack/webpack/issues/1545#issuecomment-255446425
|
||||
@@ -1,178 +0,0 @@
|
||||
# 删除在一个目录下除了一个或者一些带扩展名文件的其他所有文件的三种方法
|
||||
|
||||
有的时候,你可能会遇到这种情况,你需要删除一个目录下的所有文件,或者只是简单的通过删除除了一些指定类型(以指定扩展名结尾)的文件来清空一个目录。
|
||||
|
||||
在这篇文章,我们将会向你展现如何通过 rm、 find 和 globignore 命令删除一个目录下除了指定文件后缀或者类型的的文件。
|
||||
|
||||
在我们进一步深入之前,让我们开始简要的了解一下 Linux 中的一个重要的概念 —— 文件名模式匹配,它可以让我们解决眼前的问题。
|
||||
|
||||
在 Linux 下,一个 shell 模式一个包含以下特殊字符的字符串,称为通配符或者元字符:
|
||||
|
||||
1. `*` – 匹配 0 个或者多个字符
|
||||
2. `?` – 匹配任意单个字符
|
||||
3. `[seq]` – 匹配序列中的任意一个字符
|
||||
4. `[!seq]` – 匹配任意一个不再序列中的字符
|
||||
|
||||
我们将在这儿探索三种可能的办法,包括:
|
||||
|
||||
### 使用扩展模式匹配操作符删除文件
|
||||
|
||||
下来列出了不同的扩展模式匹配操作符,这些模式列表是一个用 `|` 分割包含一个或者多个文件名的列表:
|
||||
|
||||
1. `*(pattern-list)` – 匹配 0 个或者多个出现的指定模式
|
||||
2. `?(pattern-list)` – 匹配 0 个或者 1 个出现的指定模式
|
||||
4. `@(pattern-list)` – 匹配 1 个或者多个出现的指定模式
|
||||
5. `!(pattern-list)` – 匹配除了一个指定模式之外的任何内容
|
||||
|
||||
为了使用它们,像下面一样打开 extglob shell 选项:
|
||||
|
||||
```
|
||||
# shopt -s extglob
|
||||
|
||||
```
|
||||
|
||||
#### 1. 输入以下命令,删除一个目录下除了 filename 之外的所有文件
|
||||
|
||||
```
|
||||
$ rm -v !("filename")
|
||||
|
||||
```
|
||||
[][9]
|
||||
|
||||
删除 Linux 下除了一个文件之外的所有文件
|
||||
|
||||
#### 2. 删除除了 filename1 和 filename2 之外的所有文件
|
||||
|
||||
```
|
||||
$ rm -v !("filename1"|"filename2")
|
||||
|
||||
```
|
||||
[][8]
|
||||
|
||||
在 Linux 下删除除了一些文件之外的所有文件
|
||||
|
||||
#### 3. 下面的例子显示如何通过交互模式删除除了 `.zip` 之外的所有文件
|
||||
|
||||
```
|
||||
$ rm -i !(*.zip)
|
||||
|
||||
```
|
||||
[][7]
|
||||
|
||||
在 Linux 下删除除了 Zip 文件之外的所有文件
|
||||
|
||||
#### 4. 接下来,通过如下的方式你可以删除一个目录下除了所有的`.zip` 和 `.odt` 文件的所有文件,并且在删除的时候,显示正在删除的文件:
|
||||
|
||||
```
|
||||
$ rm -v !(*.zip|*.odt)
|
||||
|
||||
```
|
||||
[][6]
|
||||
|
||||
删除除了指定文件扩展的所有文件
|
||||
|
||||
一旦你已经执行了所有需要的命令,使用如下的方式关闭 extglob shell 选项。
|
||||
|
||||
```
|
||||
$ shopt -u extglob
|
||||
|
||||
```
|
||||
|
||||
### 使用 Linux 下的 find 命令删除文件
|
||||
|
||||
在这种方法下,我们可以[只使用 find 命令][5]的适当的选项或者采用管道配合 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
|
||||
|
||||
```
|
||||
[][4]
|
||||
|
||||
find 命令 —— 删除 .gz 之外的所有文件
|
||||
|
||||
#### 6. 使用管道和 xargs,你可以通过如下的方式修改上面的例子:
|
||||
|
||||
```
|
||||
$ find . -type f -not -name '*gz' -print0 | xargs -0 -I {} rm -v {}
|
||||
|
||||
```
|
||||
[][3]
|
||||
|
||||
使用 find 和 xargs 命令删除文件
|
||||
|
||||
#### 7. 让我们看一个额外的例子,下面的命令行将会抹除掉当前目录下除了 `.gz`、 `.odt` 和 `.jpg` 之外的所有文件:
|
||||
|
||||
```
|
||||
$ find . -type f -not \(-name '*gz' -or -name '*odt' -or -name '*.jpg' \) -delete
|
||||
|
||||
```
|
||||
[][2]
|
||||
|
||||
删除除了指定扩展文件的所有文件
|
||||
|
||||
### 通过 bash 中的 GLOBIGNORE 变量删除文件
|
||||
|
||||
然而,最后的方法,只适用于 bash。 GLOBIGNORE 变量存储了一个通过路径名扩展忽略的分离的模式(或者文件名)列表。
|
||||
|
||||
为了使用这种方法,移动到要删除文件的目录,像下面这样设置 GLOBIGNORE 变量:
|
||||
|
||||
```
|
||||
$ cd test
|
||||
$ GLOBIGNORE=*.odt:*.iso:*.txt
|
||||
|
||||
```
|
||||
|
||||
在这种情况下,除了 `.odt`、 `.iso` 和 `.txt` 之外的所有文件,都将从当前目录删除。
|
||||
|
||||
现在,运行如下的命令清空这个目录:
|
||||
|
||||
```
|
||||
$ rm -v *
|
||||
|
||||
```
|
||||
|
||||
之后,关闭 GLOBIGNORE 变量:
|
||||
|
||||
```
|
||||
$ unset GLOBIGNORE
|
||||
|
||||
```
|
||||
[][1]
|
||||
|
||||
使用 bash 变量 GLOBIGNORE 删除文件
|
||||
|
||||
注:为了理解上面的命令行采用的标识的意思,请参考我们在每一个插图中使用的命令对应的 man 手册。
|
||||
|
||||
就这些了!如果你心里有实现相同目录的其他命令行技术,不要忘了通过下面的反馈部分分享给我们。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/delete-all-files-in-directory-except-one-few-file-extensions/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+tecmint+%28Tecmint%3A+Linux+Howto%27s+Guide%29
|
||||
|
||||
作者:[ Aaron Kili][a]
|
||||
|
||||
译者:[yangmingming](https://github.com/yangmingming)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: http://www.tecmint.com/author/aaronkili/
|
||||
[1]:http://www.tecmint.com/wp-content/uploads/2016/10/Delete-Files-Using-Bash-GlobIgnore.png
|
||||
[2]:http://www.tecmint.com/wp-content/uploads/2016/10/Remove-All-Files-Except-File-Extensions.png
|
||||
[3]:http://www.tecmint.com/wp-content/uploads/2016/10/Remove-Files-Using-Find-and-Xargs-Command.png
|
||||
[4]:http://www.tecmint.com/wp-content/uploads/2016/10/Remove-All-Files-Except-gz-Files.png
|
||||
[5]:http://www.tecmint.com/35-practical-examples-of-linux-find-command/
|
||||
[6]:http://www.tecmint.com/wp-content/uploads/2016/10/Delete-All-Files-Except-Certain-File-Extensions.png
|
||||
[7]:http://www.tecmint.com/wp-content/uploads/2016/10/Delete-All-Files-Except-Zip-Files-in-Linux.png
|
||||
[8]:http://www.tecmint.com/wp-content/uploads/2016/10/Delete-All-Files-Except-Few-Files-in-Linux.png
|
||||
[9]:http://www.tecmint.com/wp-content/uploads/2016/10/DeleteAll-Files-Except-One-File-in-Linux.png
|
||||
@@ -0,0 +1,119 @@
|
||||
在 Linux 上检测硬盘坏道和坏块
|
||||
===
|
||||
|
||||
让我们从定义坏道和坏块开始说起,它们是一块磁盘或闪存上不再能够被读写的部分,一般是由于磁盘表面特定的[物理损坏][7]或闪存晶体管失效导致的。
|
||||
|
||||
随着坏道的继续积累,它们会对你的磁盘或闪存容量产生令人不快或破坏性的影响,甚至可能会导致硬件失效。
|
||||
|
||||
同时还需要注意的是坏块的存在警示你应该开始考虑买块新磁盘了,或者简单地将坏块标记为不可用。
|
||||
|
||||
因此,在这篇文章中,我们通过几个必要的步骤,使用特定的[磁盘扫描工具][6]让你能够判断 Linux 磁盘或闪存是否存在坏道。
|
||||
|
||||
以下就是步骤:
|
||||
|
||||
### 在 Linux 上使用坏块工具检查坏道
|
||||
|
||||
坏块工具可以让用户扫描设备检查坏道或坏块。设备可以是一个磁盘或外置磁盘,由一个如 /dev/sdc 这样的文件代表。
|
||||
|
||||
首先,通过超级用户权限执行 [fdisk 命令][5]来显示你的所有磁盘或闪存的信息以及它们的分区信息:
|
||||
|
||||
```
|
||||
$ sudo fdisk -l
|
||||
|
||||
```
|
||||
|
||||
[][4]
|
||||
|
||||
列出 Linux 文件系统分区
|
||||
|
||||
然后用这个命令检查你的 Linux 硬盘上的坏道/坏块:
|
||||
|
||||
```
|
||||
$ sudo badblocks -v /dev/sda10 > badsectors.txt
|
||||
|
||||
```
|
||||
|
||||
[][3]
|
||||
|
||||
在 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(Self-Monitoring, Analysis and Reporting Technology,自我监控分析报告技术)系统的现代磁盘(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
|
||||
|
||||
```
|
||||
|
||||
[][2]
|
||||
|
||||
检查 Linux 硬盘健康
|
||||
|
||||
上面的结果指出你的硬盘很健康,近期内不大可能发生硬件失效。
|
||||
|
||||
要获取磁盘信息总览,使用 `-a` 或 `--all` 选项来显示关于磁盘所有的 SMART 信息,`-x` 或 `--xall` 来显示所有关于磁盘的 SMART 信息以及非 SMART 信息。
|
||||
|
||||
在这个教程中,我们覆盖了有关[磁盘健康诊断][1]的重要话题,你可以下面的反馈区来分享你的想法或提问,并且记得多回来看看。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/check-linux-hard-disk-bad-sectors-bad-blocks/
|
||||
|
||||
|
||||
作者:[Aaron Kili][a]
|
||||
|
||||
译者:[alim0x](https://github.com/alim0x)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: http://www.tecmint.com/author/aaronkili/
|
||||
[1]:http://www.tecmint.com/defragment-linux-system-partitions-and-directories/
|
||||
[2]:http://www.tecmint.com/wp-content/uploads/2016/10/Check-Linux-Hard-Disk-Health.png
|
||||
[3]:http://www.tecmint.com/wp-content/uploads/2016/10/Scan-Hard-Disk-Bad-Sectors-in-Linux.png
|
||||
[4]:http://www.tecmint.com/wp-content/uploads/2016/10/List-Linux-Filesystem-Partitions.png
|
||||
[5]:http://www.tecmint.com/fdisk-commands-to-manage-linux-disk-partitions/
|
||||
[6]:http://www.tecmint.com/ncdu-a-ncurses-based-disk-usage-analyzer-and-tracker/
|
||||
[7]:http://www.tecmint.com/defragment-linux-system-partitions-and-directories/
|
||||
@@ -0,0 +1,138 @@
|
||||
# 如何在 Linux 中将文件编码转换为 UTF-8
|
||||
|
||||
在这篇教程中,我们将解释字符编码的含义,然后给出一些使用命令行工具将使用某种字符编码的文件转化为另一种编码的例子。最后,我们将一起看一看如何在 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
|
||||
```
|
||||
[
|
||||

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

|
||||
][2]
|
||||
|
||||
列出所有已有编码字符集
|
||||
|
||||
### 将文件从 ISO-8859-1 编码转换为 UTF-8 编码
|
||||
|
||||
下面,我们将学习如何将一种编码方案转换为另一种编码方案。下面的命令将会将 ISO-8859-1 编码转换为 UTF-8 编码。
|
||||
|
||||
Consider a file named `input.file` which contains the characters:
|
||||
考虑如下文件 `input.file`,其中包含这几个字符:
|
||||
|
||||
```
|
||||
<EFBFBD> <20> <20> <20>
|
||||
```
|
||||
|
||||
我们从查看这个文件的编码开始,然后来查看文件内容。最后,我们可以把所有字符转换为 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
|
||||
```
|
||||
[
|
||||

|
||||
][1]
|
||||
|
||||
在 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` 的手册页 (man page)。
|
||||
|
||||
```
|
||||
$ man iconv
|
||||
```
|
||||
|
||||
将这篇指南总结一下,理解字符编码的概念、了解如何将一种编码方案转换为另一种,是一个电脑用户处理文本时必须要掌握的知识,程序员更甚。
|
||||
|
||||
最后,你可以在下面的评论部分中与我们联系,提出问题或反馈。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/convert-files-to-utf-8-encoding-in-linux/#
|
||||
|
||||
作者:[Aaron Kili][a]
|
||||
|
||||
译者:[StdioA](https://github.com/StdioA)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/aaronkili/
|
||||
[1]:http://www.tecmint.com/wp-content/uploads/2016/10/Converts-UTF8-to-ASCII-in-Linux.png
|
||||
[2]:http://www.tecmint.com/wp-content/uploads/2016/10/List-Coded-Charsets-in-Linux.png
|
||||
[3]:http://www.tecmint.com/wp-content/uploads/2016/10/Check-File-Encoding-in-Linux.png
|
||||
@@ -0,0 +1,287 @@
|
||||
# 4 种简单方法让你在 Linux 下生成一个高强度密码
|
||||
|
||||

|
||||
图片来源: Google.
|
||||
|
||||
昨天,我们已经分享了如何 [要求用户在基于 DEB 的系统中使用一个高强度的密码][8],例如在 Debian,Ubuntu,Linux Mint, Elementary OS 等系统中。那么,你可能会疑惑一个高强度的密码究竟是什么样的呢?怎么才能生成一个那样的密码呢?不用担心,下面我们将介绍 4 种简单方法让你在 Linux 中生成一个高强度密码。当然,已经有很多免费的工具或者方式来完成这个任务,但这里我们仅考虑那些简单直接的方法。下面就让我们开始吧。
|
||||
|
||||
下载 – [免费电子书:“Ubuntu 16.04 入门”][7]
|
||||
|
||||
### 1. 在 Linux 中使用 OpenSSL 来生成一个高强度密码
|
||||
|
||||
OpenSSL 在所有的类 Unix 发行版本,Solaris,Mac OS X 和 Windows 中都可以获取到。
|
||||
|
||||
要使用 OpenSSL 生成一个随机密码,唤起你的终端并运行下面的命令:
|
||||
|
||||
```
|
||||
openssl rand 14 -base64
|
||||
```
|
||||
|
||||
上面的 `-base64` 字符串将确保生成的密码可以被键盘敲出来。
|
||||
|
||||
样例输出:
|
||||
|
||||
```
|
||||
wXCHXlxuhrFrFMQLqik=
|
||||
```
|
||||
|
||||
[
|
||||

|
||||
][6]
|
||||
|
||||
上面的命令将生成一个随机的、长度为 14 个字符的高强度密码。记住我们强烈推荐你生成 14 个字符的密码。
|
||||
当然你可以使用 OpenSSL 生成任意长度的密码。
|
||||
|
||||
要了解更多信息,可以参考联机手册:
|
||||
|
||||
```
|
||||
man openssl
|
||||
```
|
||||
|
||||
### 2. 在 Linux 中使用 Pwgen 来生成一个高强度密码
|
||||
|
||||
pwgen 是一个简单却非常有用的命令行工具,用它可以在短时间内生成一个随机且高强度的密码。它设计出的安全密码可以被人们更容易地记住。在大多数的类 Unix 系统中都可以获取到它。
|
||||
|
||||
在基于 DEB 的系统中安装 pwgen 请运行:
|
||||
|
||||
```
|
||||
sudo apt-get install pwgen
|
||||
```
|
||||
|
||||
在基于 RPM 的系统中,运行:
|
||||
|
||||
```
|
||||
sudo yum install pwgen
|
||||
```
|
||||
|
||||
在基于 Arch 的系统中,则运行:
|
||||
|
||||
```
|
||||
sudo pacman -S pwgen
|
||||
```
|
||||
|
||||
一旦 pwgen 安装完成后,便可以使用下面的命令来生成 1 个长度为 14 个字符的随机高强度密码:
|
||||
|
||||
```
|
||||
pwgen 14 1
|
||||
```
|
||||
|
||||
样例输出:
|
||||
|
||||
```
|
||||
Choo4aicozai3a
|
||||
```
|
||||
|
||||
[
|
||||

|
||||
][5]
|
||||
|
||||
上面的命令将只生成 1 个长度为 14 个字符的密码,如果要生成 2 个长度为 14 个字符的不同密码,则可以运行:
|
||||
|
||||
```
|
||||
pwgen 14 2
|
||||
```
|
||||
|
||||
样例输出:
|
||||
|
||||
```
|
||||
xee7seerez6Kau Aeshu0geveeji8
|
||||
```
|
||||
|
||||
如果要生成 100 个(尽管可能没有必要生成那么多)长度为 14 个字符的不同密码,则可以运行:
|
||||
|
||||
```
|
||||
pwgen 14
|
||||
```
|
||||
|
||||
样例输出:
|
||||
|
||||
```
|
||||
kaeNg3EiVei4ei Oo0iehiJaix5Ae aenuv2eree2Quo iaT7zahH1eN2Aj Bie2owaiFahsie
|
||||
gaan9zu5Xeh5ah ahGeeth8ea5ooh Ir0ueda5poogh5 uo0ohqu2ufaiX2 Mei0pee6Og3zae
|
||||
Oofeiceer8Aipu sheew3aeReidir Dee4Heib2eim2o eig6jar8giPhae Zahde9nae1Niew
|
||||
quatol5Oi3Bah2 quue4eebaiNgaa oGoahieSh5oL4m aequeeQue2piti laige5seePhugo
|
||||
iiGo9Uthee4ros WievaiQu2xech6 shaeve0maaK3ae ool8Pai2eighis EPheiRiet1ohci
|
||||
ZieX9outhoht8N Uh1UoPhah2Thee reaGhohZae5idi oiG4ooshiyi5in keePh1ohshei8y
|
||||
aim5Eevah2thah Xaej8tha5eisho IeGie1Anaalaev gaoY3ohthooh3x chaebeesahTh8e
|
||||
soh7oosieY5eiD ahmoh6Ihii6que Shoowoo5dahbah ieW0aiChubee7I Caet6aikai6aex
|
||||
coo1du2Re9aika Ohnei5Egoh7leV aiyie6Ahdeipho EiV0aeToeth1da iNgaesu4eeyu0S
|
||||
Eeb1suoV3naera railai2Vaina8u xu3OhVee1reeyu Og0eavae3oohoh audahneihaeK8a
|
||||
foo6iechi5Eira oXeixoh6EwuboD we1eiDahNgoh9s ko1Eeju1iedu1z aeP7achiisohr7
|
||||
phang5caeGei5j ait4Shuo5Aitai no4eis9Tohd8oh Quiet6oTaaQuei Dei2pu2NaefeCa
|
||||
Shiim9quiuy0ku yiewooph3thieL thu8Aphai1ieDa Phahnahch1Aam1 oocex7Yaith8oo
|
||||
eraiGaech5ahNg neixa3malif5Ya Eux7chah8ahXix eex1lahXae4Mei uGhahzonu6airu
|
||||
yah8uWahn3jeiW Yi4ye4Choongie io1Vo3aiQuahpi rie4Rucheet6ae Dohbieyaeleis5
|
||||
xi1Zaushohbei7 jeeb9EiSiech0u eewo0Oow7ielie aiquooZamah5th kouj7Jaivohx9o
|
||||
biyeeshesaDi9e she9ooj3zuw6Ah Eit7dei1Yei5la xohN0aeSheipaa Eeg9Phob6neema
|
||||
eengoneo4saeL4 aeghi4feephu6W eiWash2Vie1mee chieceish5ioPe ool4Hongo7ef1o
|
||||
jahBe1pui9thou eeV2choohoa4ee Ohmae0eef4ic8I Eet0deiyohdiew Ke9ue5thohzei3
|
||||
aiyoxeiva8Maih gieRahgh8anahM ve2ath9Eyi5iet quohg6ok3Ahgee theingaech5Nef
|
||||
```
|
||||
|
||||
[
|
||||

|
||||
][4]
|
||||
|
||||
如果要在密码中包含至少 1 个数字,则可以运行:
|
||||
|
||||
```
|
||||
pwgen 14 1 -n 1
|
||||
```
|
||||
|
||||
样例输出:
|
||||
|
||||
```
|
||||
xoiFush3ceiPhe
|
||||
```
|
||||
|
||||
另外,pwgen 命令还有一些很实用的选项:
|
||||
|
||||
```
|
||||
-c 或 --capitalize (在密码中包含至少一个大写字母)
|
||||
|
||||
-A 或 --no-capitalize (在密码中不包含大写字母)
|
||||
|
||||
-n 或 --numerals (在密码中包含至少一个数字)
|
||||
|
||||
-0 或 --no-numerals (在密码中不包含数字)
|
||||
|
||||
-y 或 --symbols (在密码中包含至少一个特殊字符)
|
||||
|
||||
-s 或 --secure (生成完全随机的密码)
|
||||
|
||||
-B 或 --ambiguous (在密码中不包含双关词语)
|
||||
|
||||
-h 或 --help (输出帮助信息)
|
||||
|
||||
-H 或 --sha1=path/to/file[#seed] (使用某个给定文件的 sha1 哈希值来作为随机数的生成种子)
|
||||
|
||||
-C (按列输出生成好的密码)
|
||||
|
||||
-1 (不按列输出生成好的密码)
|
||||
|
||||
-v 或 --no-vowels (不使用任何元音字母,以防止生成下流的词语)
|
||||
```
|
||||
|
||||
若想了解更多信息,请查阅其联机手册:
|
||||
|
||||
```
|
||||
man pwgen
|
||||
```
|
||||
|
||||
### 3. 在 Linux 中使用 GPG 来生成一个高强度密码
|
||||
|
||||
GPG (GnuPG or GNU Privacy Guard) 是一个免费的命令行程序,可以用于替代赛门铁克的 PGP 加密软件。在类 Unix 操作系统、Microsoft Windows 和 Android 中都可以获取到它。
|
||||
|
||||
要使用 PGP 生成 1 个长度为 14 个字符的高强度密码,请在终端中运行下面的命令:
|
||||
|
||||
```
|
||||
gpg --gen-random --armor 1 14
|
||||
```
|
||||
|
||||
样例输出:
|
||||
|
||||
```
|
||||
DkmsrUy3klzzbIbavx8=
|
||||
```
|
||||
|
||||
[
|
||||

|
||||
][3]
|
||||
|
||||
上面的命令将生成一个安全、随机、高强度且基于 base64 编码的密码。
|
||||
|
||||
### 4. 在 Linux 中使用 Perl 来生成一个高强度密码
|
||||
|
||||
Perl 在大多数 Linux 发行版本的默认软件仓库中都可以获取到,你可以使用相应的包管理器来安装它。
|
||||
|
||||
例如在基于 DEB 的系统中,可以运行下面的命令来安装 Perl:
|
||||
|
||||
```
|
||||
sudo apt-get install perl
|
||||
```
|
||||
|
||||
在基于 RPM 的系统中安装 Perl ,可以运行:
|
||||
|
||||
```
|
||||
sudo yum install perl
|
||||
```
|
||||
|
||||
在基于 Arch 的系统中,则运行:
|
||||
|
||||
```
|
||||
sudo pacman -S perl
|
||||
```
|
||||
|
||||
一旦 Perl 安装完成,使用下面的命令创建一个文件:
|
||||
|
||||
```
|
||||
vi password.pl
|
||||
```
|
||||
|
||||
接着添加下面的内容到这个文件中:
|
||||
|
||||
```
|
||||
#!/usr/bin/perl
|
||||
|
||||
my @alphanumeric = ('a'..'z', 'A'..'Z', 0..9);
|
||||
my $randpassword = join '', map $alphanumeric[rand @alphanumeric], 0..8;
|
||||
print "$randpassword\n"
|
||||
```
|
||||
|
||||
[
|
||||

|
||||
][2]
|
||||
|
||||
保存并关闭该文件。
|
||||
|
||||
接着,切换到你刚才保存文件的地方,并运行下面的命令:
|
||||
|
||||
```
|
||||
perl password.pl
|
||||
```
|
||||
|
||||
使用你自己定义的文件名来替换上面命令中的 `password.pl` 。
|
||||
|
||||
样例输出:
|
||||
|
||||
```
|
||||
3V4CJJnYd
|
||||
```
|
||||
|
||||
[
|
||||

|
||||
][1]
|
||||
|
||||
注: 我无法找到这个脚本的原有作者,假如你知道作者的名字,请在下面的评论部分让我知晓,我将在这篇指南中添加上该作者的名字。
|
||||
|
||||
Please note that you must memorize or keep the passwords you have generated in a safe place in your computer. I recommend you to memorize the password and delete it from your system. It is much better in case your system is compromised by any hackers.
|
||||
请注意:对于你生成的密码,你必须记住它,或者将它保存到你电脑中一个安全的地方。我建议你记住密码并将它从你的系统中删除,因为这总比你的系统被黑客控制要好。
|
||||
|
||||
伙计们,今天就是这么多了。不久我将带来另一篇有意思的文章。在此之前,敬请关注 OSTechNix。
|
||||
|
||||
Happy Weekend!
|
||||
|
||||
Cheers!!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/4-easy-ways-to-generate-a-strong-password-in-linux/
|
||||
|
||||
作者:[ SK ][a]
|
||||
|
||||
译者:[FSSlc](https://github.com/FSSlc)
|
||||
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.ostechnix.com/author/sk/
|
||||
[1]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@sk_002.png
|
||||
[2]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@sk_001.png
|
||||
[3]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@sk_006.png
|
||||
[4]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@sk_005.png
|
||||
[5]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@sk_004.png
|
||||
[6]:http://www.ostechnix.com/wp-content/uploads/2016/11/sk@sk_003.png
|
||||
[7]:http://ostechnix.tradepub.com/free/w_ubun08/prgm.cgi?a=1
|
||||
[8]:https://www.ostechnix.com/force-users-use-strong-passwords-debian-ubuntu/
|
||||
Reference in New Issue
Block a user