mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-24 02:20:09 +08:00
Merge branch 'master' of github.com:LCTT/TranslateProject
update
This commit is contained in:
commit
afd0349cb3
@ -1,10 +1,11 @@
|
||||
12 条实用的 zypper 命令范例
|
||||
======
|
||||
zypper 是 Suse Linux 系统的包和补丁管理器,你可以根据下面的 12 条附带输出示例的实用范例来学习 zypper 命令的使用。
|
||||
|
||||
`zypper` 是 Suse Linux 系统的包和补丁管理器,你可以根据下面的 12 条附带输出示例的实用范例来学习 `zypper` 命令的使用。
|
||||
|
||||
![zypper 命令示例][1]
|
||||
|
||||
Suse Linux 使用 zypper 进行包管理,其是一个由 [ZYpp 包管理引擎][2]提供技术支持的包管理系统。在此篇文章中我们将分享 12 条附带输出示例的实用 zypper 命令,能帮助你处理日常的系统管理任务。
|
||||
Suse Linux 使用 `zypper` 进行包管理,其是一个由 [ZYpp 包管理引擎][2]提供的包管理系统。在此篇文章中我们将分享 12 条附带输出示例的实用 `zypper` 命令,能帮助你处理日常的系统管理任务。
|
||||
|
||||
不带参数的 `zypper` 命令将列出所有可用的选项,这比参考详细的 man 手册要容易上手得多。
|
||||
|
||||
@ -18,12 +19,12 @@ root@kerneltalks # zypper
|
||||
--help, -h 帮助
|
||||
--version, -V 输出版本号
|
||||
--promptids 输出 zypper 用户提示符列表
|
||||
--config, -c <file> 使用制定的配置文件来替代默认的
|
||||
--config, -c <file> 使用指定的配置文件来替代默认的
|
||||
--userdata <string> 在历史和插件中使用的用户自定义事务 id
|
||||
--quiet, -q 忽略正常输出,只打印错误信息
|
||||
--verbose, -v 增加冗长程度
|
||||
--color
|
||||
--no-color 是否启用彩色模式如果 tty 支持
|
||||
--no-color 是否启用彩色模式,如果 tty 支持的话
|
||||
--no-abbrev, -A 表格中的文字不使用缩写
|
||||
--table-style, -s 表格样式(整型)
|
||||
--non-interactive, -n 不询问任何选项,自动使用默认答案
|
||||
@ -43,7 +44,7 @@ root@kerneltalks # zypper
|
||||
--gpg-auto-import-keys 自动信任并导入新仓库的签名密钥
|
||||
--plus-repo, -p <URI> 使用附加仓库
|
||||
--plus-content <tag> 另外使用禁用的仓库来提供特定的关键词
|
||||
尝试 '--plus-content debug' 选项来启用仓库
|
||||
尝试使用 '--plus-content debug' 选项来启用仓库
|
||||
--disable-repositories 不从仓库中读取元数据
|
||||
--no-refresh 不刷新仓库
|
||||
--no-cd 忽略 CD/DVD 中的仓库
|
||||
@ -55,11 +56,11 @@ root@kerneltalks # zypper
|
||||
--disable-system-resolvables
|
||||
不读取已安装包
|
||||
|
||||
命令:
|
||||
命令:
|
||||
help, ? 打印帮助
|
||||
shell, sh 允许多命令
|
||||
|
||||
仓库管理:
|
||||
仓库管理:
|
||||
repos, lr 列出所有自定义仓库
|
||||
addrepo, ar 添加一个新仓库
|
||||
removerepo, rr 移除指定仓库
|
||||
@ -68,14 +69,14 @@ root@kerneltalks # zypper
|
||||
refresh, ref 刷新所有仓库
|
||||
clean 清除本地缓存
|
||||
|
||||
服务管理:
|
||||
服务管理:
|
||||
services, ls 列出所有自定义服务
|
||||
addservice, as 添加一个新服务
|
||||
modifyservice, ms 修改指定服务
|
||||
removeservice, rs 移除指定服务
|
||||
refresh-services, refs 刷新所有服务
|
||||
|
||||
软件管理:
|
||||
软件管理:
|
||||
install, in 安装包
|
||||
remove, rm 移除包
|
||||
verify, ve 确认包依赖的完整性
|
||||
@ -83,7 +84,7 @@ root@kerneltalks # zypper
|
||||
install-new-recommends, inr
|
||||
安装由已安装包建议一并安装的新包
|
||||
|
||||
更新管理:
|
||||
更新管理:
|
||||
update, up 更新已安装包至更新版本
|
||||
list-updates, lu 列出可用更新
|
||||
patch 安装必要的补丁
|
||||
@ -91,7 +92,7 @@ root@kerneltalks # zypper
|
||||
dist-upgrade, dup 进行发行版更新
|
||||
patch-check, pchk 检查补丁
|
||||
|
||||
查询:
|
||||
查询:
|
||||
search, se 查找符合匹配模式的包
|
||||
info, if 展示特定包的完全信息
|
||||
patch-info 展示特定补丁的完全信息
|
||||
@ -103,27 +104,28 @@ root@kerneltalks # zypper
|
||||
products, pd 列出所有可用的产品
|
||||
what-provides, wp 列出提供特定功能的包
|
||||
|
||||
包锁定:
|
||||
包锁定:
|
||||
addlock, al 添加一个包锁定
|
||||
removelock, rl 移除一个包锁定
|
||||
locks, ll 列出当前的包锁定
|
||||
cleanlocks, cl 移除无用的锁定
|
||||
|
||||
其他命令:
|
||||
其他命令:
|
||||
versioncmp, vcmp 比较两个版本字符串
|
||||
targetos, tos 打印目标操作系统 ID 字符串
|
||||
licenses 打印已安装包的证书和 EULAs 报告
|
||||
download 使用命令行下载指定 rpm 包到本地目录
|
||||
source-download 下载所有已安装包的源码 rpm 包到本地目录
|
||||
|
||||
子命令:
|
||||
子命令:
|
||||
subcommand 列出可用子命令
|
||||
|
||||
输入 'zypper help <command>' 来获得特定命令的帮助。
|
||||
```
|
||||
##### 如何使用 zypper 安装包
|
||||
|
||||
`zypper` 通过 `in` 或 `install` 开关来在你的系统上安装包。它的用法与 [yum package installation][3] 相同。你只需要提供包名作为参数,包管理器(此处是 zypper)就会处理所有的依赖并与你指定的包一并安装。
|
||||
### 如何使用 zypper 安装包
|
||||
|
||||
`zypper` 通过 `in` 或 `install` 子命令来在你的系统上安装包。它的用法与 [yum 软件包安装][3] 相同。你只需要提供包名作为参数,包管理器(此处是 `zypper`)就会处理所有的依赖并与你指定的包一并安装。
|
||||
|
||||
```
|
||||
# zypper install telnet
|
||||
@ -147,11 +149,11 @@ Checking for file conflicts: ...................................................
|
||||
|
||||
以上是我们安装 `telnet` 包时的输出,供你参考。
|
||||
|
||||
推荐阅读 : [在 YUM 和 APT 系统中安装包][3]
|
||||
推荐阅读:[在 YUM 和 APT 系统中安装包][3]
|
||||
|
||||
##### 如何使用 zypper 移除包
|
||||
### 如何使用 zypper 移除包
|
||||
|
||||
要在 Suse Linux 中擦除或移除包,使用 `zypper` 命令附带 `remove` 或 `rm` 开关。
|
||||
要在 Suse Linux 中擦除或移除包,使用 `zypper` 附带 `remove` 或 `rm` 子命令。
|
||||
|
||||
```
|
||||
root@kerneltalks # zypper rm telnet
|
||||
@ -167,13 +169,14 @@ After the operation, 113.3 KiB will be freed.
|
||||
Continue? [y/n/...? shows all options] (y): y
|
||||
(1/1) Removing telnet-1.2-165.63.x86_64 ..........................................................................................................................[done]
|
||||
```
|
||||
|
||||
我们在此处移除了先前安装的 telnet 包。
|
||||
|
||||
##### 使用 zypper 检查依赖或者认证已安装包的完整性
|
||||
### 使用 zypper 检查依赖或者认证已安装包的完整性
|
||||
|
||||
有时可以通过强制忽略依赖关系来安装软件包。`zypper` 使你能够扫描所有已安装的软件包并检查其依赖性。如果缺少任何依赖项,它将提供你安装或重新安装它的机会,从而保持已安装软件包的完整性。
|
||||
|
||||
使用附带 `verify` 或 `ve` 开关的 `zypper` 命令来检查已安装包的完整性。
|
||||
使用附带 `verify` 或 `ve` 子命令的 `zypper` 命令来检查已安装包的完整性。
|
||||
|
||||
```
|
||||
root@kerneltalks # zypper ve
|
||||
@ -184,9 +187,10 @@ Reading installed packages...
|
||||
|
||||
Dependencies of all installed packages are satisfied.
|
||||
```
|
||||
|
||||
在上面的输出中,你能够看到最后一行说明已安装包的所有依赖都已安装完全,并且无需更多操作。
|
||||
|
||||
##### 如何在 Suse Linux 中使用 zypper 下载包
|
||||
### 如何在 Suse Linux 中使用 zypper 下载包
|
||||
|
||||
`zypper` 提供了一种方法使得你能够将包下载到本地目录而不去安装它。你可以在其他具有同样配置的系统上使用这个已下载的软件包。包会被下载至 `/var/cache/zypp/packages/<repo>/<arch>/` 目录。
|
||||
|
||||
@ -206,13 +210,14 @@ total 52
|
||||
-rw-r--r-- 1 root root 53025 Feb 21 03:17 telnet-1.2-165.63.x86_64.rpm
|
||||
|
||||
```
|
||||
|
||||
你能看到我们使用 `zypper` 将 telnet 包下载到了本地。
|
||||
|
||||
推荐阅读 : [在 YUM 和 APT 系统中只下载包而不安装][4]
|
||||
推荐阅读:[在 YUM 和 APT 系统中只下载包而不安装][4]
|
||||
|
||||
##### 如何使用 zypper 列出可用包更新
|
||||
### 如何使用 zypper 列出可用包更新
|
||||
|
||||
`zypper` 允许你浏览已安装包的所有可用更新,以便你可以提前计划更新活动。使用 `list-updates` 或 `lu` 开关来显示已安装包的所有可用更新。
|
||||
`zypper` 允许你浏览已安装包的所有可用更新,以便你可以提前计划更新活动。使用 `list-updates` 或 `lu` 子命令来显示已安装包的所有可用更新。
|
||||
|
||||
```
|
||||
root@kerneltalks # zypper lu
|
||||
@ -229,11 +234,12 @@ v | SLE-Module-Containers12-Updates | containerd | 0.2.5+gitr6
|
||||
v | SLES12-SP3-Updates | crash | 7.1.8-4.3.1 | 7.1.8-4.6.2 | x86_64
|
||||
v | SLES12-SP3-Updates | rsync | 3.1.0-12.1 | 3.1.0-13.10.1 | x86_64
|
||||
```
|
||||
|
||||
输出特意被格式化以便于阅读。每一列分别代表包所属仓库名称、包名、已安装版本、可用的更新版本和架构。
|
||||
|
||||
##### 在 Suse Linux 中列出和安装补丁
|
||||
### 在 Suse Linux 中列出和安装补丁
|
||||
|
||||
使用 `list-patches` 或 `lp` 开关来显示你的 Suse Linux 系统需要被应用的所有可用补丁。
|
||||
使用 `list-patches` 或 `lp` 子命令来显示你的 Suse Linux 系统需要被应用的所有可用补丁。
|
||||
|
||||
```
|
||||
root@kerneltalks # zypper lp
|
||||
@ -260,9 +266,9 @@ Found 37 applicable patches:
|
||||
|
||||
你可以通过发出 `zypper patch` 命令安装所有需要的补丁。
|
||||
|
||||
##### 如何使用 zypper 更新包
|
||||
### 如何使用 zypper 更新包
|
||||
|
||||
要使用 zypper 更新包,使用 `update` 或 `up` 开关后接包名。在上述列出的更新命令中,我们知道在我们的服务器上 `rsync` 包更新可用。让我们现在来更新它吧!
|
||||
要使用 `zypper` 更新包,使用 `update` 或 `up` 子命令后接包名。在上述列出的更新命令中,我们知道在我们的服务器上 `rsync` 包更新可用。让我们现在来更新它吧!
|
||||
|
||||
```
|
||||
root@kerneltalks # zypper update rsync
|
||||
@ -284,9 +290,9 @@ Checking for file conflicts: ...................................................
|
||||
(1/1) Installing: rsync-3.1.0-13.10.1.x86_64 .....................................................................................................................[done]
|
||||
```
|
||||
|
||||
##### 在 Suse Linux 上使用 zypper 查找包
|
||||
### 在 Suse Linux 上使用 zypper 查找包
|
||||
|
||||
如果你不确定包的全名也不要担心。你可以使用 zypper 附带 `se` 或 `search` 开关并提供查找字符串来查找包。
|
||||
如果你不确定包的全名也不要担心。你可以使用 `zypper` 附带的 `se` 或 `search` 子命令并提供查找字符串来查找包。
|
||||
|
||||
```
|
||||
root@kerneltalks # zypper se lvm
|
||||
@ -303,14 +309,15 @@ S | Name | Summary | Type
|
||||
| llvm-devel | Header Files for LLVM | package
|
||||
| lvm2 | Logical Volume Manager Tools | srcpackage
|
||||
i+ | lvm2 | Logical Volume Manager Tools | package
|
||||
| lvm2-devel | Development files for LVM2 | package
|
||||
|
||||
| lvm2-devel | Development files for LVM2 | package
|
||||
```
|
||||
在上述示例中我们查找了 `lvm` 字符串并得到了如上输出列表。你能在 zypper install/remove/update 命令中使用 `Name` 字段的名字。
|
||||
|
||||
##### 使用 zypper 检查已安装包信息
|
||||
在上述示例中我们查找了 `lvm` 字符串并得到了如上输出列表。你能在 `zypper install/remove/update` 命令中使用 `Name` 字段的名字。
|
||||
|
||||
### 使用 zypper 检查已安装包信息
|
||||
|
||||
你能够使用 `zypper` 检查已安装包的详细信息。`info` 或 `if` 子命令将列出已安装包的信息。它也可以显示未安装包的详细信息,在该情况下,`Installed` 参数将返回 `No` 值。
|
||||
|
||||
你能够使用 zypper 检查已安装包的详细信息。`info` 或 `if` 开关将列出已安装包的信息。它也可以显示未安装包的详细信息,在该情况下,`Installed` 参数将返回 `No` 值。
|
||||
```
|
||||
root@kerneltalks # zypper info rsync
|
||||
Refreshing service 'SMT-http_smt-ec2_susecloud_net'.
|
||||
@ -343,9 +350,9 @@ Description :
|
||||
for backups and mirroring and as an improved copy command for everyday use.
|
||||
```
|
||||
|
||||
##### 使用 zypper 列出仓库
|
||||
### 使用 zypper 列出仓库
|
||||
|
||||
使用 zypper 命令附带 `lr` 或 `repos` 开关列出仓库。
|
||||
使用 `zypper` 命令附带 `lr` 或 `repos` 子命令列出仓库。
|
||||
|
||||
```
|
||||
root@kerneltalks # zypper lr
|
||||
@ -364,7 +371,7 @@ Repository priorities are without effect. All enabled repositories share the sam
|
||||
|
||||
此处你需要检查 `enabled` 列来确定哪些仓库是已被启用的而哪些没有。
|
||||
|
||||
##### 在 Suse Linux 中使用 zypper 添加或移除仓库
|
||||
### 在 Suse Linux 中使用 zypper 添加或移除仓库
|
||||
|
||||
要添加仓库你需要仓库或 .repo 文件的 URI,否则你会遇到如下错误。
|
||||
|
||||
@ -390,16 +397,17 @@ Priority : 99 (default priority)
|
||||
Repository priorities are without effect. All enabled repositories share the same priority.
|
||||
```
|
||||
|
||||
在 Suse 中使用附带 `addrepo` 或 `ar` 开关的 `zypper` 命令添加仓库,后接 URI 以及你需要提供一个别名。
|
||||
在 Suse 中使用附带 `addrepo` 或 `ar` 子命令的 `zypper` 命令添加仓库,后接 URI 以及你需要提供一个别名。
|
||||
|
||||
要在 Suse 中移除一个仓库,使用附带 `removerepo` 或 `rr` 子命令的 `zypper` 命令。
|
||||
|
||||
要在 Suse 中移除一个仓库,使用附带 `removerepo` 或 `rr` 开关的 `zypper` 命令。
|
||||
```
|
||||
root@kerneltalks # zypper removerepo nVidia-Driver-SLE12-SP3
|
||||
Removing repository 'nVidia-Driver-SLE12-SP3' ....................................................................................................................[done]
|
||||
Repository 'nVidia-Driver-SLE12-SP3' has been removed.
|
||||
```
|
||||
|
||||
##### 清除 zypper 本地缓存
|
||||
### 清除 zypper 本地缓存
|
||||
|
||||
使用 `zypper clean` 命令清除 zypper 本地缓存。
|
||||
|
||||
@ -414,7 +422,7 @@ via: https://kerneltalks.com/commands/12-useful-zypper-command-examples/
|
||||
|
||||
作者:[KernelTalks][a]
|
||||
译者:[cycoe](https://github.com/cycoe)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -0,0 +1,138 @@
|
||||
在 Linux 命令行下进行时间管理
|
||||
======
|
||||
|
||||
> 学习如何在命令行下用这些方法自己组织待办事项。
|
||||
|
||||

|
||||
|
||||
关于如何在命令行下进行<ruby>时间管理<rt>getting things done</rt></ruby>(GTD)有很多讨论。不知有多少文章在讲使用 ls 晦涩的选项、配合 Sed 和 Awk 的一些神奇的正则表达式,以及用 Perl 解析一大堆的文本。但这些都不是问题的重点。
|
||||
|
||||
本文章是关于“[如何完成][1]”,在我们不需要图形桌面、网络浏览器或网络连接情况下,用命令行操作能实际完成事务的跟踪。为了达到这一点,我们将介绍四种跟踪待办事项的方式:纯文件文件、Todo.txt、TaskWarrior 和 Org 模式。
|
||||
|
||||
### 简单纯文本
|
||||
|
||||
![纯文本][3]
|
||||
|
||||
*我喜欢用 Vim,其实你也可以用 Nano。*
|
||||
|
||||
最直接管理你的待办事项的方式就是用纯文本文件来编辑。只需要打开一个空文件,每一行添加一个任务。当任务完成后,删除这一行。简单有效,无论你用它做什么都没关系。不过这个方法也有两个缺点,一但你删除一行并保存了文件,它就是永远消失了。如果你想知道本周或者上周都做了哪些事情,就成了问题。使用简单文本文件很方便却也容易导致混乱。
|
||||
|
||||
### Todo.txt: 纯文件的升级版
|
||||
|
||||
![todo.txt 截屏][5]
|
||||
|
||||
*整洁,有条理,易用*
|
||||
|
||||
这就是我们要说的 [Todo.txt][6] 文件格式和应用程序。安装很简单,可从 GitHub [下载][7]最新的版本解压后并执行命令 `sudo make install` 。
|
||||
|
||||
![安装 todo.txt][9]
|
||||
|
||||
*也可以从 Git 克隆一个。*
|
||||
|
||||
Todo.txt 可以很容易的增加新任务,并能显示任务列表和已完成任务的标记:
|
||||
|
||||
| 命令 | 说明 |
|
||||
| ------------- |:-------------|
|
||||
| `todo.sh add "某任务"` | 增加 “某任务” 到你的待办列表 |
|
||||
| `todo.sh ls` | 显示所有的任务 |
|
||||
| `todo.sh ls due:2018-02-15` | 显示2018-02-15之前的所有任务 |
|
||||
| `todo.sh do 3` | 标记任务3 为已完成任务 |
|
||||
|
||||
这个清单实际上仍然是纯文本,你可以用你喜欢的编辑器遵循[正确的格式][10]编辑它。
|
||||
|
||||
该应用程序同时也内置了一个强大的帮助系统。
|
||||
|
||||
![在 todo.txt 中语法高亮][12]
|
||||
|
||||
*你可以使用语法高亮的功能*
|
||||
|
||||
此外,还有许多附加组件可供选择,以及编写自己的附件组件规范。甚至有浏览器组件、移动设备应用程序和桌面应用程序支持 Todo.txt 的格式。
|
||||
|
||||
![GNOME extensions in todo.txt][14]
|
||||
|
||||
*GNOME的扩展组件*
|
||||
|
||||
Todo.txt 最大的缺点是缺少自动或内置的同步机制。大多数(不是全部)的浏览器扩展程序和移动应用程序需要用 Dropbox 实现桌面系统和应用程序直接的数据同步。如果你想内置同步机制,我们有……
|
||||
|
||||
### Taskwarrior: 现在我们用 Python 做事了
|
||||
|
||||
![Taskwarrior][25]
|
||||
|
||||
*花哨吗?*
|
||||
|
||||
[Taskwarrior][15] 是一个与 Todo.txt 有许多相同功能的 Python 工具。但不同的是它的数据保存在数据库里并具有内置的数据同步功能。它还可以跟踪即将要做的任务,可以提醒某个任务持续了多久,可以提醒你一些重要的事情应该马上去做。
|
||||
|
||||
![][26]
|
||||
|
||||
*看起来不错*
|
||||
|
||||
[安装][16] Taskwarrior 可以通过通过发行版自带的包管理器,或通过 Python 命令 `pip` 安装,或者用源码编译。用法也和 Todo.txt 的命令完全一样:
|
||||
|
||||
| 命令 | 说明 |
|
||||
| ------------- |:-------------|
|
||||
| `task add "某任务"` | 增加 “某任务” 到任务清单 |
|
||||
| `task list` | 列出所有任务 |
|
||||
| `task list due ``:today` | 列出截止今天的任务 |
|
||||
| `task do 3` | 标记编号是3的任务为完成状态 |
|
||||
|
||||
Taskwarrior 还有漂亮的文本用户界面。
|
||||
|
||||
![Taskwarrior in Vit][18]
|
||||
|
||||
*我喜欢 Vit, 它的设计灵感来自 Vim*
|
||||
|
||||
不同于 Todo.txt,Taskwarrior 可以和本地或远程服务器同步信息。如果你希望运行自己的同步服务器可以使用名为 `taskd` 的非常基本的服务器,如果不使用自己的服务器也有好几个可用服务器。
|
||||
|
||||
Taskwarriot 还拥有一个蓬勃发展的插件和扩展生态系统,以及移动和桌面系统的应用。
|
||||
|
||||
![GNOME in Taskwarrior ][20]
|
||||
|
||||
*在 GNOME 下的 Taskwarrior 看起来还是很漂亮的。*
|
||||
|
||||
Taskwarrior 有一个唯一的缺点,你是不能直接修改待办任务的,这和其他的工具不一样。你只能把任务清单按照格式导出,然后修改导出文件后,重新再导入,这样相对于编辑器直接编辑任务还是挺麻烦的。
|
||||
|
||||
谁能给我们带来最大的希望呢……
|
||||
|
||||
### Emacs Org 模式:牛X的任务收割机
|
||||
|
||||
![Org-mode][22]
|
||||
|
||||
*Emacs 啥都有*
|
||||
|
||||
Emacs [Org 模式][23] 是目前为止最强大、最灵活的开源待办事项管理器。它支持多文件、使用纯文本、高度可定制、自动识别日期、截止日期和任务计划。相对于我们这里介绍的其他工具,它的配置也更复杂一些。但是一旦配置好,它可以比其他工具完成更多功能。如果你是熟悉或者是 [Bullet Journals][24] 的粉丝,Org 模式可能是在桌面程序里最像[Bullet Journals][24] 的了。
|
||||
|
||||
Emacs 能运行,Org 模式就能运行,一些移动应用程序可以和它很好交互。但是不幸的是,目前没有桌面程序或浏览器插件支持 Org 模式。尽管如此,Org 模式仍然是跟踪待办事项最好的应用程序之一,因为它确实很强大。
|
||||
|
||||
### 选择适合自己的工具
|
||||
|
||||
最后,这些程序目的是帮助你跟踪待办事项,并确保不会忘记做某个事情。这些程序的基础功能都大同小异,那一款适合你取决于多种因素。有的人需要自带同步功能,有的人需要一个移动客户端,有的人要必须支持插件。不管你选择什么,请记住程序本身不会让你更有调理,但是可以帮助你。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/2/getting-to-done-agile-linux-command-line
|
||||
|
||||
作者:[Kevin Sonney][a]
|
||||
译者:[guevaraya](https://github.com/guevaraya)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/ksonney (Kevin Sonney)
|
||||
[1]:https://www.scruminc.com/getting-done/
|
||||
[3]:https://opensource.com/sites/default/files/u128651/plain-text.png (plaintext)
|
||||
[5]:https://opensource.com/sites/default/files/u128651/todo-txt.png (todo.txt screen)
|
||||
[6]:http://todotxt.org/
|
||||
[7]:https://github.com/todotxt/todo.txt-cli/releases
|
||||
[9]:https://opensource.com/sites/default/files/u128651/todo-txt-install.png (Installing todo.txt)
|
||||
[10]:https://github.com/todotxt/todo.txt
|
||||
[12]:https://opensource.com/sites/default/files/u128651/todo-txt-vim.png (Syntax highlighting in todo.txt)
|
||||
[14]:https://opensource.com/sites/default/files/u128651/tod-txt-gnome.png (GNOME extensions in todo.txt)
|
||||
[15]:https://taskwarrior.org/
|
||||
[16]:https://taskwarrior.org/download/
|
||||
[18]:https://opensource.com/sites/default/files/u128651/taskwarrior-vit.png (Taskwarrior in Vit)
|
||||
[20]:https://opensource.com/sites/default/files/u128651/taskwarrior-gnome.png (Taskwarrior on GNOME)
|
||||
[22]:https://opensource.com/sites/default/files/u128651/emacs-org-mode.png (Org-mode)
|
||||
[23]:https://orgmode.org/
|
||||
[24]:http://bulletjournal.com/
|
||||
[25]:https://opensource.com/sites/default/files/u128651/taskwarrior.png
|
||||
[26]:https://opensource.com/sites/default/files/u128651/taskwarrior-complains.png
|
@ -0,0 +1,72 @@
|
||||
Emacs 系列(四):使用 Org 模式自动管理邮件及同步文档
|
||||
======
|
||||
|
||||
这是 [Emacs 和 Org 模式系列][4]的第四篇。
|
||||
|
||||
至今为止,你已经见识到了 Org 模式的强大和高效,如果你像我一样,你可能会想:
|
||||
|
||||
> “我真的很想让它在我所有的设备上同步。”
|
||||
|
||||
或者是说:
|
||||
|
||||
> “我能在 Org 模式中转发邮件吗?”
|
||||
|
||||
答案当然是肯定的,因为这就是 Emacs。
|
||||
|
||||
### 同步
|
||||
|
||||
由于 Org 模式只使用文本文件,所以使用任意工具都可以很容易地实现同步。我使用的是 git 的 `git-remote-gcrypt`。由于 `git-remote-gcrypt` 的一些限制,每台机器都倾向于推到自己的分支,并使用命令来控制。每台机器都会先合并其它所有的分支,然后再将合并后的结果推送到主干上。cron 作业可以实现将机器上的分支推送上去,而 elisp 会协调这一切 —— 确保在同步之前保存缓冲区,在同步之后从磁盘刷新缓冲区,等等。
|
||||
|
||||
这篇文章的代码有点多,所以我将把它链接到 github 上,而不是写在这里。
|
||||
|
||||
|
||||
我有一个用来存放我所有的 Org 模式的文件的目录 `$HOME/org`,在 `~/org` 目录下有个 [Makefile][2] 文件来处理同步。该文件定义了以下目标:
|
||||
|
||||
* `push`: 添加、提交和推送到以主机命名的分支上
|
||||
* `fetch`: 一个简单的 `git fetch` 操作
|
||||
* `sync`: 添加、提交和拉取远程的修改,合并,并(假设合并成功)将其推送到以主机命名的分支和主干上
|
||||
|
||||
现在,在我的用户 crontab 中有这个:
|
||||
|
||||
```
|
||||
*/15 * * * * make -C $HOME/org push fetch 2>&1 | logger --tag 'orgsync'
|
||||
```
|
||||
|
||||
[与之相关的 elisp 代码][3] 定义了一个快捷键(`C-c s`)来调用同步。多亏了 cronjob,只要文件被保存 —— 即使我没有在另一个机器上同步 —— 它们也会被拉取进来。
|
||||
|
||||
我发现这个设置非常好用。
|
||||
|
||||
### 用 Org 模式发邮件
|
||||
|
||||
在继续下去之前,首先要问自己一下:你真的需要它吗? 我用的是带有 [mu4e][4] 的 Org 模式,而且它集成的也很好;任何 Org 模式的任务都可以通过 `Message-id` 链接到电子邮件,这很理想 —— 它可以让一个人做一些事情,比如提醒他在一周内回复一条消息。
|
||||
|
||||
然而,Org 模式不仅仅只有提醒。它还是一个知识库、创作系统等,但是并不是我所有的邮件客户端都使用 mu4e。(注意:移动设备中有像 MobileOrg 这样的应用)。我并没有像我想的那样经常使用它,但是它有它的用途,所以我认为我也应该在这里记录它。
|
||||
|
||||
现在我不仅想处理纯文本电子邮件。我希望能够处理附件、HTML 邮件等。这听起来很快就有问题了 —— 但是通过使用 ripmime 和 pandoc 这样的工具,情况还不错。
|
||||
|
||||
第一步就是要用某些方法将获取到的邮件放入指定的文件夹下。扩展名、特殊用户等。然后我用一个 [fetchmail 配置][5] 来将它拉取下来并运行我自己的 [insorgmail][6] 脚本。
|
||||
|
||||
这个脚本就是处理所有有趣的部分了。它开始用 ripmime 处理消息,用 pandoc 将 HTML 的部分转换为 Org 模式的格式。 Org 模式的层次结构是用来尽可能最好地表示 email 的结构。使用 HTML 和其他工具时,email 可能会变得相当复杂,但我发现这对于我来说是可以接受的。
|
||||
|
||||
### 下一篇
|
||||
|
||||
我最后一篇关于 Org 模式的文章将讨论如何使用它来编写文档和准备幻灯片 —— 我发现自己对 Org 模式的使用非常满意,但这需要一些调整。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://changelog.complete.org/archives/9898-emacs-4-automated-emails-to-org-mode-and-org-mode-syncing
|
||||
|
||||
作者:[John Goerzen][a]
|
||||
译者:[oneforalone](https://github.com/oneforalone)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://changelog.complete.org/
|
||||
[1]:https://changelog.complete.org/archives/tag/emacs2018
|
||||
[2]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/Makefile
|
||||
[3]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/emacs-config.org
|
||||
[4]:https://www.emacswiki.org/emacs/mu4e
|
||||
[5]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/fetchmailrc.orgmail
|
||||
[6]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/insorgmail
|
95
published/20181112 The Source History of Cat.md
Normal file
95
published/20181112 The Source History of Cat.md
Normal file
@ -0,0 +1,95 @@
|
||||
Cat 命令的源码历史
|
||||
======
|
||||
|
||||
以前我和我的一些亲戚争论过计算机科学的学位值不值得读。当时我正在上大学,并要决定是不是该主修计算机。我姨和我表姐觉得我不应该主修计算机。她们承认知道如何编程肯定是很有用且对自己有利的一件事,但是她们认为计算机科学现在发展的如此迅速以至于我学的东西几乎马上就过时了。建议我更好是把编程作为辅业,选择一个基础原理可以受用终身的领域主修,比如经济学或物理学。
|
||||
|
||||
我知道我姨和我表姐说的不对,并决定主修计算机科学。(对不住啊!)平常人可能会觉得像计算机科学领域和软件工程专业每隔几年就完全和之前不一样了。其原因很容易理解。我们有了个人电脑,然后有了互联网,有了手机,之后还有了机器学习…… 科技总是在更新,支撑科技发展的原理和技能当然也在改变。当然,最惊人的是其实原理的改变竟然如此之小。我敢肯定,大多数人在知道了他们电脑里一些重要的软件的历史是多么久远时他们一定会深感震惊。当然我不是说那些刷版本号的浮夸软件 —— 我电脑上的 Firefox 浏览器副本,可能是我用的最多的软件,可能两周前就更新过。如果你看了比如 `grep` 的手册页,你就会发现它在 2010 年后就没有过更新了(至少在 MacOS 上如此)。初版 `grep` 是在 1974 年写就的,那时可以算是计算机世界的侏罗纪了。直到现在,人们(还有程序)仍然依赖 `grep` 来完成日常工作。
|
||||
|
||||
我姨和我表姐认为计算机技术就像一系列日渐精致的沙堡,在潮水抹净沙滩后新的沙堡完全取代旧的。但事实上,在很多领域上,我们都是不断积累能够解决问题的程序。我们可能不得不偶尔修改这些程序以避免软件无法使用,但大多数情况下我们都可以不修改。`grep` 是一个简单的程序,可以解决一个仍然存在的需求,所以它能够存活下来。 大多数应用程序编程都是在非常高的级别上完成的,它们建立在解决了旧问题的旧程序的金字塔上。 30 年或 40 年前的思路和概念,远非过时,在很多情况下它们依然在您的笔记本电脑上软件中存在着。
|
||||
|
||||
我想追溯这样的老程序自第一次写就以来改变了多少回很有趣。 `cat` 可能是所有 Unix 实用程序中最简单的,因此我们以它为例。Ken Thompson 于 1969 年编写了 `cat` 的原始实现。如果我告诉别人我的电脑上安装了个来自 1969 年的程序,这准确吗?我们电脑上的程序多大了?
|
||||
|
||||
感谢这种[这种][1]仓库,我们可以完整的看到 `cat` 自 1969 年后是如何发展的。我会先聚焦于可以算得上是我的 MacBook 上的 `cat` 的祖先的 `cat` 实现。随着我们从 Unix 上的第一版 `cat` 追踪到现在 MacOS 上的 `cat`,你会发现,这个程序被重写的次数比你想的还要多 —— 但是直到现在它运行的方式和五十年前多少是完全一致的。
|
||||
|
||||
### 研究 Unix
|
||||
|
||||
Ken Thompson 和 Dennis Ritchie 在 PDP 7 上开始写 Unix。那还是 1969 年,C 还没被发明出来,因此所有早期的 Unix 软件都是用 PDP 7 汇编实现的。他们使用的汇编种类是 Unix 特有的,Ken Thompson 在 DEC(PDP 7 的厂商)提供的汇编器之上加了些特性,实现了自己的汇编器。Thompson 的更改在[最初的 Unix 程序员手册][2]的 `as`(也就是汇编器)条目下均有所记录。
|
||||
|
||||
因此,[最初的][3] `cat` 也是使用 PDP 7 汇编实现的。 我添加了一些注释,试图解释每条指令的作用,但除非你理解 Thompson 在编写汇编器时加的特性,否则程序仍然很难理解。在那些特性中有两个很重要:其一是 `;` 这个字符可以在一行中用来分隔多条语句,它多出现于在使用 `sys` 指令时将系统调用的多个参数放在同一行上。其二是, Thompson 的汇编器支持使用 0 到 9 作为“临时标签”,这是在程序内可以重用的标签。因此。就如 Unix 程序员手册中所说:“对程序员的想象力和汇编程序的符号空间的要求都降低了”。在任何给定的指令内,你都可以使用 `nf` 和 `nb` 来引用下一个或最近的临时标签 `n`。 例如,如果存在标记为 `1:` 的代码块,你就可以使用指令 `jmp 1b` 从下游代码跳回该块。 (但是你不使用 `jmp 1f` 的话就没法从上面的代码跳到这里。)
|
||||
|
||||
初版 `cat` 最有趣的就是它包含着我们应该认识的符号。有一块指令块标记为 `getc`,还有一个标记为 `putc`,可以看到这两个符号比 C 标准还古老。第一版的 `cat` 函数实际上已经包含了这两个函数的实现。该实现做了输入缓存,这样它就不需要一次只读写一个字母。
|
||||
|
||||
`cat` 的第一个版本并没有持续多久。 Ken Thompson 和 Dennis Ritchie 说服贝尔实验室购买了 PDP 11,这样他们就能够继续扩展和改进 Unix。 PDP 11 的指令集和之前不一样,因此必须重写 `cat`。 我也注释了[这个第二版][4] `cat`。 它为新的指令集使用新的汇编程序助记符,并利用了 PDP 11 的各种[寻址模式][5]。(如果你对源代码中的括号和美元符号感到困惑,那是因为这些符号用于指示不同的寻址模式。)但它也使用 `;` 字符和临时标签,和 `cat` 的第一个版本一样,这意味着当把 `as` 移植到 PDP 11 上时,必须要保留这些功能。
|
||||
|
||||
`cat` 的第二个版本比第一个版本简单得多。 它也更有 Unix 味儿,它不只是依靠参数列表,一旦没给参数列表,它将从 `stdin` 读取数据,这也就是今天 `cat` 仍在做的事情。 你也可以在此版本的 `cat` 中以 `-` 为参数,以表示它应该从`stdin`读取。
|
||||
|
||||
在 1973 年,为了准备发布第四版 Unix,大部分代码都用 C 语言重写了。但是 `cat` 似乎在之后一段时间内并没有使用 C 重写。 [cat 的第一个 C 语言实现][6]出现在第七版 Unix 中。 这个实现非常有趣,因为它很简单。 在所有以后的实现中,这个实现和在 K&R 的 C 语言教科书中用作教学示范的理想化 `cat` 最相似。这个程序的核心就是经典的两行:
|
||||
|
||||
```
|
||||
while ((c = getc(fi)) != EOF)
|
||||
putchar(c);
|
||||
```
|
||||
|
||||
当然实际代码要比这多一些,额外的代码主要是为了确保你没有在读/写同一个文件。另一个有趣的事情是,`cat` 的这一版实现只识别一个标志位 `-u`。 `-u` 标志可用于避免缓冲输入和输出,否则 `cat` 将以 512 字节为块进行输入输出。
|
||||
|
||||
### BSD
|
||||
|
||||
在第七版 Unix 之后,Unix 出现了各种衍生品和分支。 MacOS 建立于 Darwin 之上,而 Darwin 又源自<ruby>伯克利软件分发版<rt>Berkeley Software Distribution</rt></ruby>(BSD),因此 BSD 是我们最感兴趣的 Unix 分支。 BSD 最初只是 Unix 中的实用程序和附加组件的集合,但它最终成为了一个完整的操作系统。直到第四版 BSD,人称 4BSD,为一大堆新标志添加了支持之前,BSD 似乎还是依赖于最初的 `cat` 实现的。`cat` 的 [4BSD 实现][7] 显然是从原始实现中衍生出来的,尽管它添加了一个新函数来实现由新标志触发的行为。已经在文件中使用的 `fflg` 变量(用于标记输入是从 `stdin` 还是文件读取的)的命名约定,被新添加的 `nflg`、`bflg`、`vflg`、`sflg`、`eflg` 和 `tflg` 沿袭了下来,这些变量记录了在调用程序时是否使用了这些新标志。这些是最后一批添加到 `cat` 的命令行标志。如今 `cat` 的手册页列出了这些标志,没有其他的标志了,至少在 Mac OS 上是如此。 4BSD 于 1980 年发布,因此这套标志已有 38 年历史。
|
||||
|
||||
`cat` 最后一次被完全重写是在 BSD NET/2 上,其目的是通过替换 AT&T 发布的全部 Unix 源代码来规避许可证问题。BSD Net/2 在 1991 年发布。这一版本的 `cat` 是由 Kevin Fall 重写的。 Kevin Fall 于 1988 年毕业于加州大学伯克利分校并在下一年成为<ruby>计算机系统研究组<rt>Computer Systems Research Group</rt></ruby>(CSRG)的组员,Fall 和我说当时使用 AT&T 代码的 Unix 工具被列在了 CSRG 的墙上,组员需要从中选出他们想要重写的工具; Fall 选了 `cat` 以及 `mknod`。 MacOS 系统内自带的 `cat` 实现源码的最上面还有着他的名字。他的这一版 `cat`,尽管平淡无奇,在今天还是被无数人使用着。
|
||||
|
||||
[Fall 的原始 cat 实现][8] 比我们迄今为止看到的版本都要长。 除了支持 `-?` 帮助标志外,它没有增加任何新功能。 从概念上讲,它与 4BSD 的实现非常相似。 它长是因为 Fall 将实现分为 “原始” 模式和 “加工” 模式。 “原始” 模式是 `cat` 的经典实现;它一个字符一个字符的打印文件。 “加工” 模式是带有所有 4BSD 命令行选项的 `cat`。 如此区别不无道理,但这么办也扩充了实现规模,因此乍一看其源码似乎比实际上更复杂。文件末尾还有一个奇特的错误处理函数,进一步地增加了实现的长度。
|
||||
|
||||
### MacOS
|
||||
|
||||
在 2001 年,苹果发布了 MacOS X。这一发布对苹果意义重大。因为苹果用了多年的时间尝试以取代其现有的老旧操作系统(经典的 Mac OS),但是都失败了。 在 Mac OS X 之前苹果两次尝试在内部创建一个新的操作系统,但两者都无疾而终。 最后,苹果收购了史蒂夫·乔布斯的 NeXT 公司,后者开发了一个名为 NeXTSTEP 的操作系统和面向对象编程框架。 苹果将 NeXTSTEP 作为 Mac OS X 的基础。因为 NeXTSTEP 部分基于 BSD,使以 NeXTSTEP 为基础的 Mac OS X 的自然就把 BSD 系的代码直接带入苹果宇宙的中心。
|
||||
|
||||
因此,Mac OS X 的非常早期的第一个版本包含了从 NetBSD 项目中提取的 `cat` 的[实现][9]。如今仍保持开发的 NetBSD 最初是 386BSD 的分支,而后者又直接基于 BSD Net/2。所以 Mac OS X 里面的第一个 `cat` 的实现就是 Kevin Fall 的 `cat`。唯一改变的是,Fall 的错误处理函数 `err()` 被 `err.h` 提供的 `err()` 函数取代了。 `err.h` 是 C 标准库的 BSD 扩展。
|
||||
|
||||
之后不久,这里的 `cat` 的 NetBSD 实现被换成了 FreeBSD 中的 `cat` 实现。 [根据维基百科][10],苹果在 Mac OS X 10.3(Panther)中开始使用 FreeBSD 的实现而不是 NetBSD 的实现。但根据苹果自己开源的版本,`cat` 的 Mac OS X 实现在 2007 年发布的 Mac OS X 10.5(Leopard)之前没有被替换。苹果为 Leopard 替换的的 [FreeBSD 实现][11]与今天苹果计算机上的实现相同。截至 2018 年,2007 年以来的这个实现仍未被更新或修改。
|
||||
|
||||
所以 Mac OS 上的 `cat` 已经很老了。实际上,这一实现在 2007 年在 MacOS X 上露面两年前就被发布了。 [这个 2005 年的修改][12] 在 FreeBSD 的 Github 镜像中可见,是在苹果将其合并入 Mac OS X 前对 FreeBSD 的 `cat` 实现进行的最后一次更改。所以 Mac OS X 中的实现没有与 FreeBSD 的 `cat` 实现保持同步,它如今已经 13 岁了。对于软件修改了多少代码才能仍是算是同一软件这一话题有着旷日持久的争论。不过,在这种情况下,源文件自 2005 年以来根本没有变化。
|
||||
|
||||
现在 Mac OS 使用的 `cat` 实现与 Fall 1991 年为 BSD Net/2 版本编写的实现没有什么不同。最大的区别是添加了一个全新的功能来提供 Unix 域套接字支持。FreeBSD 开发人员似乎将 Fall 的 `raw_args()` 函数和 `cook_args()` 函数组合成一个名为`scanfiles()` 的函数。否则,程序的核心就仍是 Fall 的代码。
|
||||
|
||||
我问过 Fall 对编写了如今被数以百万计的苹果用户(直接或者间接通过依赖 `cat` 的某些程序)使用的 `cat` 实现有何感想。Fall,如今是一位顾问,也是最新版《TCP/IP 详解》的合著者,他说,当人们从了解他对 `cat` 所做的工作中收获颇丰时,他感到很惊讶。 Fall 在计算机领域有着悠久的职业生涯,曾参与许多备受瞩目的项目,但似乎很多人仍对他在 1989 年重写 `cat` 的那六个月的工作感到最为兴奋。
|
||||
|
||||
### 百年老程序
|
||||
|
||||
在宏伟的发明史中,计算机并不是一项古老的发明。我们已经习惯了百年的照片甚至是百年的视频短片。但是计算机程序不一样 —— 它们代表着高科技和新技术。至少,他们是现代的技术造出来的。随着计算行业的成熟,我们有朝一日会发现自己正在使用有着接近百年历史的程序吗?
|
||||
|
||||
计算机硬件可能会发生较大的变化,使得我们也许无法让现在编译的可执行文件在一个世纪后的硬件上运行。也许编程语言设计的进步让未来没有人能理解 C 语言,`cat` 将来也可能也被别的语言重写很久了。 (尽管 C 已经存在了五十年了,而且它似乎不会很快就被替换掉。)但除此之外,为什么不永远使用我们现在的 `cat`?
|
||||
|
||||
我认为 `cat` 的历史表明,计算机科学中的一些想法确实非常持久。事实上,对于 `cat`,这个想法和程序本身都很古老。不准确地说,我的电脑上的 `cat` 来自 1969 年。但我也可以说我的计算机上的 `cat` 来自1989 年,当时 Fall 写了他的 `cat` 实现。许多其他软件也同样古老。因此,也许我们不应该把计算机科学和软件开发视为不断破坏现状和发明新事物的领域。我们的计算机系统是由诸多历史文物构建的。有时,我们可能会花费更多时间在理解和维护这些历史文物上,而不是花在编写新代码上。
|
||||
|
||||
如果你喜欢本文,你可能更喜欢两周来一篇更新!在推特上关注 [@TwoBitHistory][13] 或者订阅这个 [RSS 源][14] 以保证接受到新的文章。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://twobithistory.org/2018/11/12/cat.html
|
||||
|
||||
作者:[Two-Bit History][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[name1e5s](https://github.com/name1e5s)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://twobithistory.org
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://github.com/dspinellis/unix-history-repo
|
||||
[2]: https://www.bell-labs.com/usr/dmr/www/man11.pdf
|
||||
[3]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-1-cat-pdp7-s
|
||||
[4]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-2-cat-pdp11-s
|
||||
[5]: https://en.wikipedia.org/wiki/PDP-11_architecture#Addressing_modes
|
||||
[6]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-3-cat-v7-c
|
||||
[7]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-4-cat-bsd4-c
|
||||
[8]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-5-cat-net2-c
|
||||
[9]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-6-cat-macosx-c
|
||||
[10]: https://en.wikipedia.org/wiki/Darwin_(operating_system)
|
||||
[11]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-7-cat-macos-10-13-c
|
||||
[12]: https://github.com/freebsd/freebsd/commit/a76898b84970888a6fd015e15721f65815ea119a#diff-6e405d5ab5b47ca2a131ac7955e5a16b
|
||||
[13]: https://twitter.com/TwoBitHistory
|
||||
[14]: https://twobithistory.org/feed.xml
|
||||
[15]: https://twitter.com/TwoBitHistory/status/1051826516844322821?ref_src=twsrc%5Etfw
|
@ -0,0 +1,60 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: subject: (10 ways to give thanks to open source and free software maintainers)
|
||||
[#]: via: (https://opensource.com/article/18/11/ways-give-thanks-open-source)
|
||||
[#]: author: (Moshe Zadka https://opensource.com/users/moshez)
|
||||
[#]: url: (https://linux.cn/article-10333-1.html)
|
||||
|
||||
感谢开源和自由软件维护者的 10 种方法
|
||||
=======
|
||||
|
||||
> 如何表达你的感激之情。
|
||||
|
||||

|
||||
|
||||
每天,我使用的那些高质量的软件 —— 开发和维护这些软件的人不需要我为之付款,他们尊重我的自由,并且慷慨地付出时间和精力。
|
||||
|
||||
在这个感恩的季节,我鼓励那些也使用和欣赏开源和自由软件维护者工作的人表达你的感激之情。以下是十种方法:
|
||||
|
||||
### 容易做到的
|
||||
|
||||
1、发送电子邮件感谢开发人员。具体点说,告诉他们你使用他们的什么软件以及它是如何帮助了你。
|
||||
|
||||
2、使用你最喜爱的社交媒体平台宣传它。
|
||||
|
||||
3、写一篇关于你最喜欢的软件的博客文章。
|
||||
|
||||
### 捐款
|
||||
|
||||
4、如果你最喜欢的开源项目接受捐款,请汇款。
|
||||
|
||||
5、如果你受雇于使用开源软件的公司,看你是否可以说服管理层赞助某些项目。
|
||||
|
||||
6、尽你所能地捐款。社交动机能做的不可思议!
|
||||
|
||||
### 花费时间
|
||||
|
||||
7、帮助审查补丁。
|
||||
|
||||
8、帮助分类 bug。
|
||||
|
||||
9、回答 IRC、邮件列表或 [Stack Overflow][1] 中的问题。
|
||||
|
||||
**10、额外的:**如果你像我一样,你在某个时候对开源社区的其他人说了一些严厉的话。承诺做得更好:用善良和开放沟通。感谢的最好方式是让开源社区成为人们能舒适沟通的地方。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/11/ways-give-thanks-open-source
|
||||
|
||||
作者:[Moshe Zadka][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/moshez
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://meta.stackoverflow.com/
|
@ -1,13 +1,13 @@
|
||||
[#]: collector: "lujun9972"
|
||||
[#]: translator: "qhwdw"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: reviewer: "wxy"
|
||||
[#]: publisher: "wxy"
|
||||
[#]: subject: "OpenSnitch – an Application Firewall for Linux [Review]"
|
||||
[#]: via: "https://itsfoss.com/opensnitch-firewall-linux/"
|
||||
[#]: author: "[John Paul](https://itsfoss.com/author/john/)"
|
||||
[#]: url: " "
|
||||
[#]: author: "John Paul https://itsfoss.com/author/john/"
|
||||
[#]: url: "https://linux.cn/article-10337-1.html"
|
||||
|
||||
OpenSnitch – 一个 Linux 上的应用程序防火墙
|
||||
OpenSnitch:一个 Linux 上的应用程序防火墙
|
||||
======
|
||||
|
||||
不能因为 Linux 比 Windows 更安全,就可以在 Linux 上放松警惕。Linux 上可以使用的防火墙很多,它们可以让你的 Linux 系统更安全。今天,我们将带你了解一个这样的防火墙工具,它就是 OpenSnitch。
|
||||
@ -20,9 +20,11 @@ OpenSnitch – 一个 Linux 上的应用程序防火墙
|
||||
|
||||
OpenSnitch 所做的主要事情就是跟踪你机器上安装的应用程序所发起的互联网请求。OpenSnitch 允许你去创建规则以同意或阻止那个应用程序发起的互联网访问。当一个应用程序尝试去访问互联网而没有相应的访问规则存在时,就会出现一个对话框,这个对话框让你去选择允许还是阻止那个连接。
|
||||
|
||||
你也可以决定这个新规则是应用到进程上、精确的 URL 上、域名上、单个实例上,以及本次会话还是永久有效。
|
||||
你也可以决定这个新规则是应用到进程上、具体的 URL 上、域名上、单个实例上,以及本次会话还是永久有效。
|
||||
|
||||
![OpenSnitch firewall app in Linux][5]OpenSnatch 规则请求
|
||||
![OpenSnitch firewall app in Linux][5]
|
||||
|
||||
*OpenSnatch 规则请求*
|
||||
|
||||
你创建的所有规则都保存为 [JSON 文件][6],如果以后需要修改它,就可以去修改这个文件。比如说,你错误地阻止了一个应用程序。
|
||||
|
||||
@ -33,17 +35,17 @@ OpenSnitch 也有一个漂亮的、一目了然的图形用户界面:
|
||||
* 属主用户是谁
|
||||
* 使用哪个端口
|
||||
|
||||
|
||||
|
||||
如果你愿意,也可以将这些信息导出到一个 CSV 文件中。
|
||||
|
||||
OpenSnitch 遵循 GPL v3 许可证使用。
|
||||
|
||||
![OpenSnitch firewall interface][7]OpenSnitch 进程标签页
|
||||
![OpenSnitch firewall interface][7]
|
||||
|
||||
*OpenSnitch 进程标签页*
|
||||
|
||||
### 在 Linux 中安装 OpenSnitch
|
||||
|
||||
[OpenSnitch GitHub 页面][8] 上的安装介绍是针对 Ubuntu 用户的。如果你使用的是其它发行版,你需要调整一下相关的命令。据我所知,这个应用程序仅打包到 [Arch User Repository][9] 中。
|
||||
[OpenSnitch GitHub 页面][8] 上的安装介绍是针对 Ubuntu 用户的。如果你使用的是其它发行版,你需要调整一下相关的命令。据我所知,这个应用程序仅在 [Arch User Repository][9] 中打包了。
|
||||
|
||||
在你开始之前,你必须正确安装了 Go,并且已经定义好了 `$GOPATH` 环境变量。
|
||||
|
||||
@ -67,7 +69,7 @@ go get github.com/evilsocket/opensnitch
|
||||
cd $GOPATH/src/github.com/evilsocket/opensnitch
|
||||
```
|
||||
|
||||
如果没有正确设置 `$GOPATH` 环境变量,运行上面的命令时将会出现一个 “no such folder found” 的错误信息。只需要进入到你刚才克隆仓库位置的 “evilsocket/opensnitch” 文件夹中即可。
|
||||
如果没有正确设置 `$GOPATH` 环境变量,运行上面的命令时将会出现一个 “no such folder found” 的错误信息。只需要进入到你刚才克隆仓库位置的 `evilsocket/opensnitch` 文件夹中即可。
|
||||
|
||||
现在,我们构建并安装它。
|
||||
|
||||
@ -77,7 +79,7 @@ make
|
||||
sudo make install
|
||||
```
|
||||
|
||||
如果出现 “`dep` command could not be found” 的错误信息,在 `PATH` 中添加 `GOPATH/bin` 即可。
|
||||
如果出现 “dep command could not be found” 的错误信息,在 `$PATH` 中添加 `$GOPATH/bin` 即可。
|
||||
|
||||
安装完成后,我们将要启动它的守护程序和图形用户界面。
|
||||
|
||||
@ -90,7 +92,8 @@ opensnitch-ui
|
||||
```
|
||||
|
||||
![OpenSnitch firewall interface][10]
|
||||
运行在 Manjaro 上的 OpenSnitch
|
||||
|
||||
*运行在 Manjaro 上的 OpenSnitch*
|
||||
|
||||
### 使用体验
|
||||
|
||||
@ -98,7 +101,7 @@ opensnitch-ui
|
||||
|
||||
不幸的是,我安装之后,不能启动图形用户界面。因此,我手动去运行最后三个步骤。一切似乎很顺利。如果我想让 Firefox 去访问 Manjaro 的网站,对话框就会弹出来询问我。
|
||||
|
||||
有趣的是,当我运行一个 [AUR 工具][11] `yay` 去更新我的系统时,弹出对话框要求了 `yay`、`pacman`、`pamac`、和 `git` 的访问规则。后来,我关闭并重启动 GUI,因为它是活动的。当我重启动它时,它不再要求我去创建规则了。我安装了 Falkon,而 OpenSnitch 并没有询问我去授予它任何权限。它甚至在 OpenSnitch 的 GUI 中没有列出 Falkon。我重新安装了 OpenSnitch 后,这个问题依旧存在。
|
||||
有趣的是,当我运行一个 [AUR 工具][11] `yay` 去更新我的系统时,弹出对话框要求了 `yay`、`pacman`、`pamac`、和 `git` 的访问规则。后来,我关闭并重启动 GUI,因为它当前是激活的。当我重启动它时,它不再要求我去创建规则了。我安装了 Falkon,而 OpenSnitch 并没有询问我去授予它任何权限。它甚至在 OpenSnitch 的 GUI 中没有列出 Falkon。我重新安装了 OpenSnitch 后,这个问题依旧存在。
|
||||
|
||||
然后,我转到 Ubuntu Mate 上安装 OpenSnitch,因为安装介绍就是针对 Ubuntu 所写的,进展很顺利。但是,我遇到了几个问题。我调整了一下上面介绍的安装过程以解决我遇到的问题。
|
||||
|
||||
@ -106,7 +109,9 @@ opensnitch-ui
|
||||
|
||||
GUI 也有一点需要去改进。由于某些原因,每次窗口都被放在顶部。而且不能通过设置来修改这个问题。如果能够从 GUI 中改变规则将是一个不错的选择。
|
||||
|
||||
![][12]OpenSnitch 的 hosts 标签
|
||||
![][12]
|
||||
|
||||
*OpenSnitch 的 hosts 标签*
|
||||
|
||||
### 对 OpenSnitch 的最后意见
|
||||
|
||||
@ -125,7 +130,7 @@ via: https://itsfoss.com/opensnitch-firewall-linux/
|
||||
作者:[John Paul][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[qhwdw](https://github.com/qhwdw)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,31 +1,30 @@
|
||||
无服务器架构的三个意义
|
||||
======
|
||||
对于<ruby>无服务器<rt>Serverless</rt></ruby>架构,什么时候该用,什么时候不该用呢?
|
||||
|
||||
> 以及,对于<ruby>无服务器<rt>Serverless</rt></ruby>架构,什么时候该用,什么时候不该用呢?
|
||||
|
||||

|
||||
|
||||
如果将如今互联网体验中最方便实用的那一部分去掉,那么留下来的基本就是<ruby>客户端-服务端<rt>client-server</rt></ruby>模式了。这一个模式在互联网建立初期就已经在使用了,直到目前都没有太大的变化,也就是说,这个模式仍然在为我们服务。
|
||||
|
||||
那么,当人们谈论无服务器架构的时候,到底是指什么呢?其实,无服务器架构并不是说不使用服务器了。恰恰相反,客户端-服务端模式仍然在其中发挥着重要的作用。
|
||||
那么,当人们谈论<ruby>无服务器<rt>Serverless</rt></ruby>架构的时候,到底是指什么呢?其实,无服务器架构并不是说不使用服务器了。恰恰相反,客户端-服务端模式仍然在其中发挥着重要的作用。
|
||||
|
||||
无服务器架构实际上指的是能够让开发者在不需要关心服务器上架、为操作系统打补丁、创建容器镜像这些工作的情况下,就能够完成编码、部署和创建应用这一整套流程的架构。
|
||||
|
||||
### 无服务器架构的三个重要意义
|
||||
|
||||
1. 一些缺乏开发经验的人员现在要参与到开发工作中来了。无服务器架构能够让他们尽量只学习必要的工作内容,把更多的时间放在更具创造性的开发工作中。
|
||||
2. 开发者不再需要重复造轮子。运行和维护服务器、为操作系统打补丁、创建容器等这一系列工作,都可以由更专业的无服务器架构提供商来完成。
|
||||
3. 最现实的一点是,如果不使用无服务器架构,那么在服务器管理方面,总需要有一个作最终决策的人。当服务器发生崩溃时,或是需要在服务器上执行某些操作时,总是需要这样一个统领全局的人来作出决策。因此最佳的方案是使用无服务器架构。
|
||||
|
||||
|
||||
1. 一些缺乏开发经验的人员现在要参与到开发工作中来了。无服务器架构能够让他们尽量只学习必要的工作内容,把更多的时间放在更具创造性的开发工作中。
|
||||
2. 开发者不再需要重复造轮子。运行和维护服务器、为操作系统打补丁、创建容器等这一系列工作,都可以由更专业的无服务器架构提供商来完成。
|
||||
3. 最现实的一点是,如果不使用无服务器架构,那么在服务器管理方面,总需要有一个作最终决策的人。当服务器发生崩溃时,或是需要在服务器上执行某些操作时,总是需要这样一个统领全局的人来作出决策。因此最佳的方案是使用无服务器架构。
|
||||
|
||||
### 什么时候该用或者不该用无服务器架构?
|
||||
|
||||
听起来无服务器架构是个好东西。但事实上,无服务器架构并不是万能的,在使用之前还需要考虑以下这些因素:
|
||||
|
||||
1. 成本
|
||||
2. 使用范围
|
||||
3. 时间
|
||||
4. 控制方式
|
||||
1. 成本
|
||||
2. 使用范围
|
||||
3. 时间
|
||||
4. 控制方式
|
||||
|
||||
其中值得注意的是控制方式。现在已经有一些项目为开发者提供了操作和控制无服务器架构计算环境的工具了,[Apache OpenWhisk][1] 就是其中之一。
|
||||
|
||||
@ -40,7 +39,7 @@ via: https://opensource.com/article/18/12/serverless-podcast-command-line-heros
|
||||
作者:[Jen Wike Huger][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[HankChow](https://github.com/HankChow)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
62
sources/talk/20181209 Open source DIY ethics.md
Normal file
62
sources/talk/20181209 Open source DIY ethics.md
Normal file
@ -0,0 +1,62 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Open source DIY ethics)
|
||||
[#]: via: (https://arp242.net/weblog/diy.html)
|
||||
[#]: author: (Martin Tournoij https://arp242.net/)
|
||||
|
||||
Open source DIY ethics
|
||||
======
|
||||
|
||||
I moved to New Zealand last week, and as a proper Dutch person one of the first things I did after arriving was getting a bicycle.
|
||||
|
||||
I was recommended [a great place][1] where they collect old bikes and provide people with the parts and tools to fix up the bikes. Want a bike? Choose one, fix it, and it’s yours. There are helpful and knowledgable volunteers who will gladly help you and explain how things work, but in the end you’ll have to fix your own bike; they’re not going to do it for you.
|
||||
|
||||
I like this DIY attitude; I built my own fixie (which I unfortunately couldn’t bring) years ago and had been maintaining it myself ever since, but there are many different aspects I never touched on (different brake systems, gears, etc.) and fixing my bike with some help and explanation was a useful experience which taught me a thing or two that I’ll be sure to use in the future.
|
||||
|
||||
My attitude to open source projects tends to be similar: I’ll gladly assist you or explain things, but you will have to do the work. This is especially true when it comes to feature requests or very specific scenarios.
|
||||
|
||||
Open source software is fundamentally a [DIY ethic][2] for many – though not all – people who participate in it. It certainly is for me. I just fix stuff I want myself. Since I take some amount of pride in my work and want things to work well for others I’ll also gladly fix most bugs that are reported, but sometimes people will post an enhancement or feature request and just expect me to implement it. It’s sometimes even combined with a “but project X does it!”-comment. Well, feck off and use project X then (I don’t actually say this, just think it).
|
||||
|
||||
I’ve seen more than a few people get frustrated by this attitude especially — though hardly exclusively — in the OpenBSD and suckless communities ([recent example that prompted this post][3]), partly because it’s not infrequently communicated in a somewhat unhelpful fashion (the OpenBSD saying is “shut up and hack”), but also because some people seem to misunderstand what it means to be a maintainer of an open source project. Open source software isn’t a service I provide to the world; it’s something I DIY’d myself and make available to the world because why not?
|
||||
|
||||
Some open source software is supported by companies. Only about [14% of the contributions to the Linux kernel are not affiliated with a company][4]. I don’t think this matters: these are companies who are DIY-ing as well.
|
||||
|
||||
Are there people who contribute to open source for other reasons? Sure. Some do because they really believe in [Free Software][5], or because they like programming as a hobby. But those are not the majority.
|
||||
|
||||
Not all contributions that aren’t code are useless. Sometimes someone will have a great idea for an enhancement or feature that I hadn’t thought of myself and this can be a very valuable contribution. But those types of constructive contributions are usually easy to recognize: they consist of more than just a single paragraph, are respectful, show a clear understanding of what the project is supposed to do, if they don’t understand a certain aspect they’ll ask instead of bombastically claiming that it’s “broken”, and perhaps most importantly, they show a willingness to constructively contribute, rather than just trying to tell you how to run your project.
|
||||
|
||||
This attitude isn’t limited to open source; to quote Neil Gaiman when talking about A Song of Ice and Fire fans demanding George R.R. Martin work harder on the next instalment of the series: “[George R.R. Martin is not your bitch][6]”.
|
||||
|
||||
I can’t help George with his next book, but I can help with software projects, which is really neat. Not everyone is a computer programmer, but the vast majority of projects I’ve worked on are used exclusively by programmers.
|
||||
|
||||
In the two months that it took me to finish this post (cleaning up drafts always takes forever) there have been a number of incidents in various communities that touched upon a mismatch in expectations between open source authors/maintainers and the users. “It’s not fun anymore, you get nothing from maintaining a popular package”, to quote one maintainer, or “I’m frustrated because I can’t handle the volume of emails” to quote another.
|
||||
|
||||
The situation would be vastly improved if more people start seeing and treating open source more like the DIY that it is and assume responsibility for that bug you’ve encountered or enhancement you want, rather than offloading all responsibility to the maintainer. This won’t fix everything, but it’s a good start. Note that plenty of people — including myself — already do this.
|
||||
|
||||
Both authors and users will benefit; authors will be frustrated less with “entitled” users, and users will be frustrated less by “rude” authors, and in the end the software will work better as users will be more willing to spend some time fixing stuff themselves, rather than just expecting other people to do it for them.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://arp242.net/weblog/diy.html
|
||||
|
||||
作者:[Martin Tournoij][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://arp242.net/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.facebook.com/TheCrookedSpoke
|
||||
[2]: https://en.wikipedia.org/wiki/DIY_ethic
|
||||
[3]: https://www.reddit.com/r/suckless/comments/9mhwg8/why_does_sts_latency_suck_so_bad/e7fu9sj/
|
||||
[4]: https://www.linux.com/publications/linux-kernel-development-how-fast-it-going-who-doing-it-what-they-are-doing-and-who-0
|
||||
[5]: https://www.gnu.org/philosophy/free-sw.html
|
||||
[6]: http://journal.neilgaiman.com/2009/05/entitlement-issues.html
|
||||
[7]: mailto:martin@arp242.net
|
||||
[8]: https://github.com/Carpetsmoker/arp242.net/issues/new
|
@ -1,526 +0,0 @@
|
||||
GraveAccent翻译中 Command Line Tricks For Data Scientists • kade killary
|
||||
======
|
||||
|
||||

|
||||
|
||||
For many data scientists, data manipulation begins and ends with Pandas or the Tidyverse. In theory, there is nothing wrong with this notion. It is, after all, why these tools exist in the first place. Yet, these options can often be overkill for simple tasks like delimiter conversion.
|
||||
|
||||
Aspiring to master the command line should be on every developer’s list, especially data scientists. Learning the ins and outs of your shell will undeniably make you more productive. Beyond that, the command line serves as a great history lesson in computing. For instance, awk - a data-driven scripting language. Awk first appeared in 1977 with the help of [Brian Kernighan][1], the K in the legendary [K&R book][2]. Today, some near 50 years later, awk remains relevant with [new books][3] still appearing every year! Thus, it’s safe to assume that an investment in command line wizardry won’t depreciate any time soon.
|
||||
|
||||
### What We’ll Cover
|
||||
|
||||
* ICONV
|
||||
* HEAD
|
||||
* TR
|
||||
* WC
|
||||
* SPLIT
|
||||
* SORT & UNIQ
|
||||
* CUT
|
||||
* PASTE
|
||||
* JOIN
|
||||
* GREP
|
||||
* SED
|
||||
* AWK
|
||||
|
||||
|
||||
|
||||
### ICONV
|
||||
|
||||
File encodings can be tricky. For the most part files these days are all UTF-8 encoded. To understand some of the magic behind UTF-8, check out this [excellent video][4]. Nonetheless, there are times where we receive a file that isn’t in this format. This can lead to some wonky attempts at swapping the encoding schema. Here, `iconv` is a life saver. Iconv is a simple program that will take text in one encoding and output the text in another.
|
||||
```
|
||||
# Converting -f (from) latin1 (ISO-8859-1)
|
||||
# -t (to) standard UTF_8
|
||||
|
||||
iconv -f ISO-8859-1 -t UTF-8 < input.txt > output.txt
|
||||
|
||||
```
|
||||
|
||||
* Useful options:
|
||||
|
||||
* `iconv -l` list all known encodings
|
||||
* `iconv -c` silently discard characters that cannot be converted
|
||||
|
||||
|
||||
|
||||
### HEAD
|
||||
|
||||
If you are a frequent Pandas user then `head` will be familiar. Often when dealing with new data the first thing we want to do is get a sense of what exists. This leads to firing up Pandas, reading in the data and then calling `df.head()` \- strenuous, to say the least. Head, without any flags, will print out the first 10 lines of a file. The true power of `head` lies in testing out cleaning operations. For instance, if we wanted to change the delimiter of a file from commas to pipes. One quick test would be: `head mydata.csv | sed 's/,/|/g'`.
|
||||
```
|
||||
# Prints out first 10 lines
|
||||
|
||||
head filename.csv
|
||||
|
||||
# Print first 3 lines
|
||||
|
||||
head -n 3 filename.csv
|
||||
|
||||
```
|
||||
|
||||
* Useful options:
|
||||
|
||||
* `head -n` print a specific number of lines
|
||||
* `head -c` print a specific number of bytes
|
||||
|
||||
|
||||
|
||||
### TR
|
||||
|
||||
Tr is analogous to translate. This powerful utility is a workhorse for basic file cleaning. An ideal use case is for swapping out the delimiters within a file.
|
||||
```
|
||||
# Converting a tab delimited file into commas
|
||||
|
||||
cat tab_delimited.txt | tr "\t" "," comma_delimited.csv
|
||||
|
||||
```
|
||||
|
||||
Another feature of `tr` is all the built in `[:class:]` variables at your disposal. These include:
|
||||
```
|
||||
[:alnum:] all letters and digits
|
||||
[:alpha:] all letters
|
||||
[:blank:] all horizontal whitespace
|
||||
[:cntrl:] all control characters
|
||||
[:digit:] all digits
|
||||
[:graph:] all printable characters, not including space
|
||||
[:lower:] all lower case letters
|
||||
[:print:] all printable characters, including space
|
||||
[:punct:] all punctuation characters
|
||||
[:space:] all horizontal or vertical whitespace
|
||||
[:upper:] all upper case letters
|
||||
[:xdigit:] all hexadecimal digits
|
||||
|
||||
```
|
||||
|
||||
You can chain a variety of these together to compose powerful programs. The following is a basic word count program you could use to check your READMEs for overuse.
|
||||
```
|
||||
cat README.md | tr "[:punct:][:space:]" "\n" | tr "[:upper:]" "[:lower:]" | grep . | sort | uniq -c | sort -nr
|
||||
|
||||
```
|
||||
|
||||
Another example using basic regex:
|
||||
```
|
||||
# Converting all upper case letters to lower case
|
||||
|
||||
cat filename.csv | tr '[A-Z]' '[a-z]'
|
||||
|
||||
```
|
||||
|
||||
* Useful options:
|
||||
|
||||
* `tr -d` delete characters
|
||||
* `tr -s` squeeze characters
|
||||
* `\b` backspace
|
||||
* `\f` form feed
|
||||
* `\v` vertical tab
|
||||
* `\NNN` character with octal value NNN
|
||||
|
||||
|
||||
|
||||
### WC
|
||||
|
||||
Word count. Its value is primarily derived from the `-l` flag, which will give you the line count.
|
||||
```
|
||||
# Will return number of lines in CSV
|
||||
|
||||
wc -l gigantic_comma.csv
|
||||
|
||||
```
|
||||
|
||||
This tool comes in handy to confirm the output of various commands. So, if we were to convert the delimiters within a file and then run `wc -l` we would expect the total lines to be the same. If not, then we know something went wrong.
|
||||
|
||||
* Useful options:
|
||||
|
||||
* `wc -c` print the byte counts
|
||||
* `wc -m` print the character counts
|
||||
* `wc -L` print length of longest line
|
||||
* `wc -w` print word counts
|
||||
|
||||
|
||||
|
||||
### SPLIT
|
||||
|
||||
File sizes can range dramatically. And depending on the job, it could be beneficial to split up the file - thus `split`. The basic syntax for split is:
|
||||
```
|
||||
# We will split our CSV into new_filename every 500 lines
|
||||
|
||||
split -l 500 filename.csv new_filename_
|
||||
|
||||
# filename.csv
|
||||
# ls output
|
||||
# new_filename_aaa
|
||||
# new_filename_aab
|
||||
# new_filename_aac
|
||||
|
||||
```
|
||||
|
||||
Two quirks are the naming convention and lack of file extensions. The suffix convention can be numeric via the `-d` flag. To add file extensions, you’ll need to run the following `find` command. It will change the names of ALL files within the current directory by appending `.csv`, so be careful.
|
||||
```
|
||||
find . -type f -exec mv '{}' '{}'.csv \;
|
||||
|
||||
# ls output
|
||||
# filename.csv.csv
|
||||
# new_filename_aaa.csv
|
||||
# new_filename_aab.csv
|
||||
# new_filename_aac.csv
|
||||
|
||||
```
|
||||
|
||||
* Useful options:
|
||||
|
||||
* `split -b` split by certain byte size
|
||||
* `split -a` generate suffixes of length N
|
||||
* `split -x` split using hex suffixes
|
||||
|
||||
|
||||
|
||||
### SORT & UNIQ
|
||||
|
||||
The preceding commands are obvious: they do what they say they do. These two provide the most punch in tandem (i.e. unique word counts). This is due to `uniq`, which only operates on duplicate adjacent lines. Thus, the reason to `sort` before piping the output through. One interesting note is that `sort -u` will achieve the same results as the typical `sort file.txt | uniq` pattern.
|
||||
|
||||
Sort does have a sneakily useful ability for data scientists: the ability to sort an entire CSV based on a particular column.
|
||||
```
|
||||
# Sorting a CSV file by the second column alphabetically
|
||||
|
||||
sort -t"," -k2,2 filename.csv
|
||||
|
||||
# Numerically
|
||||
|
||||
sort -t"," -k2n,2 filename.csv
|
||||
|
||||
# Reverse order
|
||||
|
||||
sort -t"," -k2nr,2 filename.csv
|
||||
|
||||
```
|
||||
|
||||
The `-t` option here is to specify the comma as our delimiter. More often than not spaces or tabs are assumed. Furthermore, the `-k` flag is for specifying our key. The syntax for this is `-km,n`, with `m` being the starting field and `n` being the last.
|
||||
|
||||
* Useful options:
|
||||
|
||||
* `sort -f` ignore case
|
||||
* `sort -r` reverse sort order
|
||||
* `sort -R` scramble order
|
||||
* `uniq -c` count number of occurrences
|
||||
* `uniq -d` only print duplicate lines
|
||||
|
||||
|
||||
|
||||
### CUT
|
||||
|
||||
Cut is for removing columns. To illustrate, if we only wanted the first and third columns.
|
||||
```
|
||||
cut -d, -f 1,3 filename.csv
|
||||
|
||||
```
|
||||
|
||||
To select every column other than the first.
|
||||
```
|
||||
cut -d, -f 2- filename.csv
|
||||
|
||||
```
|
||||
|
||||
In combination with other commands, `cut` serves as a filter.
|
||||
```
|
||||
# Print first 10 lines of column 1 and 3, where "some_string_value" is present
|
||||
|
||||
head filename.csv | grep "some_string_value" | cut -d, -f 1,3
|
||||
|
||||
```
|
||||
|
||||
Finding out the number of unique values within the second column.
|
||||
```
|
||||
cat filename.csv | cut -d, -f 2 | sort | uniq | wc -l
|
||||
|
||||
# Count occurences of unique values, limiting to first 10 results
|
||||
|
||||
cat filename.csv | cut -d, -f 2 | sort | uniq -c | head
|
||||
|
||||
```
|
||||
|
||||
### PASTE
|
||||
|
||||
Paste is a niche command with an interesting function. If you have two files that you need merged, and they are already sorted, `paste` has you covered.
|
||||
```
|
||||
# names.txt
|
||||
adam
|
||||
john
|
||||
zach
|
||||
|
||||
# jobs.txt
|
||||
lawyer
|
||||
youtuber
|
||||
developer
|
||||
|
||||
# Join the two into a CSV
|
||||
|
||||
paste -d ',' names.txt jobs.txt > person_data.txt
|
||||
|
||||
# Output
|
||||
adam,lawyer
|
||||
john,youtuber
|
||||
zach,developer
|
||||
|
||||
```
|
||||
|
||||
For a more SQL_-esque variant, see below.
|
||||
|
||||
### JOIN
|
||||
|
||||
Join is a simplistic, quasi-tangential, SQL. The largest differences being that `join` will return all columns and matches can only be on one field. By default, `join` will try and use the first column as the match key. For a different result, the following syntax is necessary:
|
||||
```
|
||||
# Join the first file (-1) by the second column
|
||||
# and the second file (-2) by the first
|
||||
|
||||
join -t"," -1 2 -2 1 first_file.txt second_file.txt
|
||||
|
||||
```
|
||||
|
||||
The standard join is an inner join. However, an outer join is also viable through the `-a` flag. Another noteworthy quirk is the `-e` flag, which can be used to substitute a value if a missing field is found.
|
||||
```
|
||||
# Outer join, replace blanks with NULL in columns 1 and 2
|
||||
# -o which fields to substitute - 0 is key, 1.1 is first column, etc...
|
||||
|
||||
join -t"," -1 2 -a 1 -a2 -e ' NULL' -o '0,1.1,2.2' first_file.txt second_file.txt
|
||||
|
||||
```
|
||||
|
||||
Not the most user-friendly command, but desperate times, desperate measures.
|
||||
|
||||
* Useful options:
|
||||
|
||||
* `join -a` print unpairable lines
|
||||
* `join -e` replace missing input fields
|
||||
* `join -j` equivalent to `-1 FIELD -2 FIELD`
|
||||
|
||||
|
||||
|
||||
### GREP
|
||||
|
||||
Global search for a regular expression and print, or `grep`; likely, the most well known command, and with good reason. Grep has a lot of power, especially for finding your way around large codebases. Within the realm of data science, it acts as a refining mechanism for other commands. Although its standard usage is valuable as well.
|
||||
```
|
||||
# Recursively search and list all files in directory containing 'word'
|
||||
|
||||
grep -lr 'word' .
|
||||
|
||||
# List number of files containing word
|
||||
|
||||
grep -lr 'word' . | wc -l
|
||||
|
||||
```
|
||||
|
||||
Count total number of lines containing word / pattern.
|
||||
```
|
||||
grep -c 'some_value' filename.csv
|
||||
|
||||
# Same thing, but in all files in current directory by file name
|
||||
|
||||
grep -c 'some_value' *
|
||||
|
||||
```
|
||||
|
||||
Grep for multiple values using the or operator - `\|`.
|
||||
```
|
||||
grep "first_value\|second_value" filename.csv
|
||||
|
||||
```
|
||||
|
||||
* Useful options
|
||||
|
||||
* `alias grep="grep --color=auto"` make grep colorful
|
||||
* `grep -E` use extended regexps
|
||||
* `grep -w` only match whole words
|
||||
* `grep -l` print name of files with match
|
||||
* `grep -v` inverted matching
|
||||
|
||||
|
||||
|
||||
### THE BIG GUNS
|
||||
|
||||
Sed and Awk are the two most powerful commands in this article. For brevity, I’m not going to go into exhausting detail about either. Instead, I will cover a variety of commands that prove their impressive might. If you want to know more, [there is a book][5] just for that.
|
||||
|
||||
### SED
|
||||
|
||||
At its core `sed` is a stream editor. It excels at substitutions, but can also be leveraged for all out refactoring.
|
||||
|
||||
The most basic `sed` command consists of `s/old/new/g`. This translates to search for old value, replace with new globally. Without the `/g` our command would terminate after the first occurrence.
|
||||
|
||||
To get a quick taste of the power lets dive into an example. In this scenario you’ve been given the following file:
|
||||
```
|
||||
balance,name
|
||||
$1,000,john
|
||||
$2,000,jack
|
||||
|
||||
```
|
||||
|
||||
The first thing we may want to do is remove the dollar signs. The `-i` flag indicates in-place. The `''` is to indicate a zero-length file extension, thus overwriting our initial file. Ideally, you would test each of these individually and then output to a new file.
|
||||
```
|
||||
sed -i '' 's/\$//g' data.txt
|
||||
|
||||
# balance,name
|
||||
# 1,000,john
|
||||
# 2,000,jack
|
||||
|
||||
```
|
||||
|
||||
Next up, the commas in our `balance` column values.
|
||||
```
|
||||
sed -i '' 's/\([0-9]\),\([0-9]\)/\1\2/g' data.txt
|
||||
|
||||
# balance,name
|
||||
# 1000,john
|
||||
# 2000,jack
|
||||
|
||||
```
|
||||
|
||||
Lastly, Jack up and decided to quit one day. So, au revoir, mon ami.
|
||||
```
|
||||
sed -i '' '/jack/d' data.txt
|
||||
|
||||
# balance,name
|
||||
# 1000,john
|
||||
|
||||
```
|
||||
|
||||
As you can see, `sed` packs quite a punch, but the fun doesn’t stop there.
|
||||
|
||||
### AWK
|
||||
|
||||
The best for last. Awk is much more than a simple command: it is a full-blown language. Of everything covered in this article, `awk` is by far the coolest. If you find yourself impressed there are loads of great resources - see [here][6], [here][7] and [here][8].
|
||||
|
||||
Common use cases for `awk` include:
|
||||
|
||||
* Text processing
|
||||
* Formatted text reports
|
||||
* Performing arithmetic operations
|
||||
* Performing string operations
|
||||
|
||||
|
||||
|
||||
Awk can parallel `grep` in its most nascent form.
|
||||
```
|
||||
awk '/word/' filename.csv
|
||||
|
||||
```
|
||||
|
||||
Or with a little more magic the combination of `grep` and `cut`. Here, `awk` prints the third and fourth column, tab separated, for all lines with our word. `-F,` merely changes our delimiter to a comma.
|
||||
```
|
||||
awk -F, '/word/ { print $3 "\t" $4 }' filename.csv
|
||||
|
||||
```
|
||||
|
||||
Awk comes with a lot of nifty variables built-in. For instance, `NF` \- number of fields - and `NR` \- number of records. To get the fifty-third record in a file:
|
||||
```
|
||||
awk -F, 'NR == 53' filename.csv
|
||||
|
||||
```
|
||||
|
||||
An added wrinkle is the ability to filter based off of one or more values. The first example, below, will print the line number and columns for records where the first column equals string.
|
||||
```
|
||||
awk -F, ' $1 == "string" { print NR, $0 } ' filename.csv
|
||||
|
||||
# Filter based off of numerical value in second column
|
||||
|
||||
awk -F, ' $2 == 1000 { print NR, $0 } ' filename.csv
|
||||
|
||||
```
|
||||
|
||||
Multiple numerical expressions:
|
||||
```
|
||||
# Print line number and columns where column three greater
|
||||
# than 2005 and column five less than one thousand
|
||||
|
||||
awk -F, ' $3 >= 2005 && $5 <= 1000 { print NR, $0 } ' filename.csv
|
||||
|
||||
```
|
||||
|
||||
Sum the third column:
|
||||
```
|
||||
awk -F, '{ x+=$3 } END { print x }' filename.csv
|
||||
|
||||
```
|
||||
|
||||
The sum of the third column, for values where the first column equals “something”.
|
||||
```
|
||||
awk -F, '$1 == "something" { x+=$3 } END { print x }' filename.csv
|
||||
|
||||
```
|
||||
|
||||
Get the dimensions of a file:
|
||||
```
|
||||
awk -F, 'END { print NF, NR }' filename.csv
|
||||
|
||||
# Prettier version
|
||||
|
||||
awk -F, 'BEGIN { print "COLUMNS", "ROWS" }; END { print NF, NR }' filename.csv
|
||||
|
||||
```
|
||||
|
||||
Print lines appearing twice:
|
||||
```
|
||||
awk -F, '++seen[$0] == 2' filename.csv
|
||||
|
||||
```
|
||||
|
||||
Remove duplicate lines:
|
||||
```
|
||||
# Consecutive lines
|
||||
awk 'a !~ $0; {a=$0}']
|
||||
|
||||
# Nonconsecutive lines
|
||||
awk '! a[$0]++' filename.csv
|
||||
|
||||
# More efficient
|
||||
awk '!($0 in a) {a[$0];print}
|
||||
|
||||
```
|
||||
|
||||
Substitute multiple values using built-in function `gsub()`.
|
||||
```
|
||||
awk '{gsub(/scarlet|ruby|puce/, "red"); print}'
|
||||
|
||||
```
|
||||
|
||||
This `awk` command will combine multiple CSV files, ignoring the header and then append it at the end.
|
||||
```
|
||||
awk 'FNR==1 && NR!=1{next;}{print}' *.csv > final_file.csv
|
||||
|
||||
```
|
||||
|
||||
Need to downsize a massive file? Welp, `awk` can handle that with help from `sed`. Specifically, this command breaks one big file into multiple smaller ones based on a line count. This one-liner will also add an extension.
|
||||
```
|
||||
sed '1d;$d' filename.csv | awk 'NR%NUMBER_OF_LINES==1{x="filename-"++i".csv";}{print > x}'
|
||||
|
||||
# Example: splitting big_data.csv into data_(n).csv every 100,000 lines
|
||||
|
||||
sed '1d;$d' big_data.csv | awk 'NR%100000==1{x="data_"++i".csv";}{print > x}'
|
||||
|
||||
```
|
||||
|
||||
### CLOSING
|
||||
|
||||
The command line boasts endless power. The commands covered in this article are enough to elevate you from zero to hero in no time. Beyond those covered, there are many utilities to consider for daily data operations. [Csvkit][9], [xsv][10] and [q][11] are three of note. If you’re looking to take an even deeper dive into command line data science, then look no further than [this book][12]. It’s also available online [for free][13]!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://kadekillary.work/post/cli-4-ds/
|
||||
|
||||
作者:[Kade Killary][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://kadekillary.work/authors/kadekillary
|
||||
[1]:https://en.wikipedia.org/wiki/Brian_Kernighan
|
||||
[2]:https://en.wikipedia.org/wiki/The_C_Programming_Language
|
||||
[3]:https://www.amazon.com/Learning-AWK-Programming-cutting-edge-text-processing-ebook/dp/B07BT98HDS
|
||||
[4]:https://www.youtube.com/watch?v=MijmeoH9LT4
|
||||
[5]:https://www.amazon.com/sed-awk-Dale-Dougherty/dp/1565922255/ref=sr_1_1?ie=UTF8&qid=1524381457&sr=8-1&keywords=sed+and+awk
|
||||
[6]:https://www.amazon.com/AWK-Programming-Language-Alfred-Aho/dp/020107981X/ref=sr_1_1?ie=UTF8&qid=1524388936&sr=8-1&keywords=awk
|
||||
[7]:http://www.grymoire.com/Unix/Awk.html
|
||||
[8]:https://www.tutorialspoint.com/awk/index.htm
|
||||
[9]:http://csvkit.readthedocs.io/en/1.0.3/
|
||||
[10]:https://github.com/BurntSushi/xsv
|
||||
[11]:https://github.com/harelba/q
|
||||
[12]:https://www.amazon.com/Data-Science-Command-Line-Time-Tested/dp/1491947853/ref=sr_1_1?ie=UTF8&qid=1524390894&sr=8-1&keywords=data+science+at+the+command+line
|
||||
[13]:https://www.datascienceatthecommandline.com/
|
@ -1,3 +1,4 @@
|
||||
Translating by qhwdw
|
||||
An Introduction to Quantum Computing with Open Source Cirq Framework
|
||||
======
|
||||
As the title suggests what we are about to begin discussing, this article is an effort to understand how far we have come in Quantum Computing and where we are headed in the field in order to accelerate scientific and technological research, through an Open Source perspective with Cirq.
|
||||
|
@ -1,86 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: subject: (SMPlayer in Linux: Features, Download and Installation)
|
||||
[#]: via: (https://itsfoss.com/smplayer/)
|
||||
[#]: author: (Aquil Roshan;Abhishek Prakash https://itsfoss.com/author/aquil/)
|
||||
[#]: url: ( )
|
||||
|
||||
SMPlayer in Linux: Features, Download and Installation
|
||||
======
|
||||
|
||||
One of the [things you’ll notice after a fresh install of Ubuntu][1], or pretty much any other Linux distribution, is this message when you try to play certain video files.
|
||||
|
||||
![][2]
|
||||
Default media player is not good with codecs
|
||||
|
||||
It means that the [codecs needed][3] to play the media are not installed on the system. Now, due to some copyright issues, some Linux based operating systems cannot pre-pack the codecs in the installation media. But they do allow you to download and install the codecs with just a click, or you could just install a media player which has all the multimedia codecs, to begin with. Checkout [SMPlayer][4].
|
||||
|
||||
### Meet SMPlayer: A Better Media Player for Linux
|
||||
|
||||
SMPlayer is a free and open-source media player built on the powerful [MPlayer][5] media engine. SMPlayer is capable of playing avi, mp4, mkv, mpeg, mov, divx, h.264 and pretty much any other major media format out there. And the cherry on top is, it can play [YouTube][6] videos too, ad-free.
|
||||
|
||||
![SMPlayer default interface][7]
|
||||
|
||||
SMPlayer is a complete media solution. It is cross-platform, so available on all the operating systems. If you have a dual boot, you can install it on your Windows and Linux OS to get a uniform experience on both the systems. It also supports convertible laptops with touch support.
|
||||
|
||||
You can play YouTube on SMPlayer too. I know it’s impractical to copy-paste the video URL and play on an external player every time. But SMPlayer is particularly useful when you are watching comparatively lengthy videos. SMPlayer plays YouTube videos in a very good quality and I felt the videos play out much better than the in-browser videos. And by playing the lengthier videos on SMPlayer, you can stay clear of the mid-roll ads that pop up on the lengthier videos.
|
||||
|
||||
If you’re watching a movie which doesn’t have subtitles, You can directly download the subtitles through SMPlayer. It comes with [opensubtitles.org][8] integration. So none of that, open the browser, search for subtitles, download the appropriate ones, unzip, place them in the video folder and connect the subtitles to the movie. No Sir! SMPlayer at your service.
|
||||
|
||||
![Automatic subtitle download in SMPlayer][9]
|
||||
|
||||
SMPlayer is available in more than 30 languages and it is highly customizable. It has both applications theming and a ton of icon sets in it.
|
||||
|
||||
If you feel that the default interface of SMPlayer doesn’t look good, in a few clicks you can make it look like this:
|
||||
|
||||
![SMPlayer skin change][10]
|
||||
|
||||
SMPlayer comes with a lot of tools and features for the power users. It has an equalizer, video speed controls, aspect ratio and zoom controls, video filters, screenshot ripping and lot more.
|
||||
|
||||
All in all, I really liked SMPlayer. It has a lot to offer in a small and lightweight package. I think it is a must have video player on your Linux PC. Along with playing all the media formats easily it also provides a ton of power controls.
|
||||
|
||||
### Installing SMPlayer on Linux
|
||||
|
||||
SMPlayer should be available in the software center of all major Linux distributions. You can search for it and install it from there itself.
|
||||
|
||||
On Ubuntu/ Linux Mint/ Elementary OS, you can also install SMPlayer by running the following command in the terminal
|
||||
|
||||
```
|
||||
sudo apt install smplayer
|
||||
```
|
||||
|
||||
Alternatively, you can download the package for Fedora, Arch Linux, OpenSUSE and Debian [here.][11]
|
||||
|
||||
### Wrapping Up
|
||||
|
||||
There are a good number of full-fledged media players out there like the VLC media player. SMPlayer is one of the best ones with a full functionality and great add-on benefits. I’ll consider it one of the [must-have applications for Linux][12].
|
||||
|
||||
Do give it a try and share your thoughts with us in the comments section below.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/smplayer/
|
||||
|
||||
作者:[Aquil Roshan;Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者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/aquil/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/things-to-do-after-installing-ubuntu-18-04/
|
||||
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-warning.jpg?fit=800%2C450&ssl=1
|
||||
[3]: https://packages.ubuntu.com/trusty/ubuntu-restricted-extras
|
||||
[4]: https://www.smplayer.info/
|
||||
[5]: http://www.mplayerhq.hu/design7/news.html
|
||||
[6]: https://www.youtube.com/
|
||||
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-coco.jpg?fit=800%2C450&ssl=1
|
||||
[8]: https://www.opensubtitles.org/en/search
|
||||
[9]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-icon-packs.jpg?fit=800%2C450&ssl=1
|
||||
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-theme.jpg?fit=800%2C450&ssl=1
|
||||
[11]: https://software.opensuse.org/download.html?project=home%3Asmplayerdev&package=smplayer
|
||||
[12]: https://itsfoss.com/essential-linux-applications/
|
@ -0,0 +1,153 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Four Easy Ways to Search Or Find Files And Folders in Linux)
|
||||
[#]: via: (https://www.2daygeek.com/four-easy-ways-to-search-or-find-files-and-folders-in-linux/)
|
||||
[#]: author: (Prakash Subramanian https://www.2daygeek.com/author/prakash/)
|
||||
|
||||
Four Easy Ways to Search Or Find Files And Folders in Linux
|
||||
======
|
||||
|
||||
Linux admins can’t able to leave a day without performing a file search as this one of the activity for their routine.
|
||||
|
||||
It’s good to know all the file search stuffs because it would help you in many ways when you are working on headless server.
|
||||
|
||||
These commands are not complicate to remember because these are using a standard syntax.
|
||||
|
||||
This can be performed through Four Linux commands and each command has their own unique feature.
|
||||
|
||||
### Method-1: Search Files And Folders in Linux Using find Command
|
||||
|
||||
Find command is widely used and very famous command to search files and folders in Linux. It searches given files in the current directory and recursively through its sub-directories based on the search criteria.
|
||||
|
||||
It allow users to perform all kind of file searches based on the criteria lie by size, name, owner, group, type, permissions, date, and other criteria.
|
||||
|
||||
Run the following command to find a given file in system.
|
||||
|
||||
```
|
||||
# find / -iname "sshd_config"
|
||||
/etc/ssh/sshd_config
|
||||
```
|
||||
|
||||
Run the following command to find a given folder in system. To search a folder in Linux we need to use `-type` parameter.
|
||||
|
||||
```
|
||||
# find / -type d -iname "ssh"
|
||||
/usr/lib/ssh
|
||||
/usr/lib/go/src/cmd/vendor/golang.org/x/crypto/ssh
|
||||
/usr/lib/go/pkg/linux_amd64/cmd/vendor/golang.org/x/crypto/ssh
|
||||
/etc/ssh
|
||||
```
|
||||
|
||||
Use wildcard option to search set of files on your system. We are going to search all files available in the system with `.config` extension.
|
||||
|
||||
```
|
||||
# find / -name "*.config"
|
||||
/usr/lib/mono/gac/avahi-sharp/1.0.0.0__4d116c78973743f5/avahi-sharp.dll.config
|
||||
/usr/lib/mono/gac/avahi-ui-sharp/0.0.0.0__4d116c78973743f5/avahi-ui-sharp.dll.config
|
||||
/usr/lib/python2.7/config/Setup.config
|
||||
/usr/share/git/mw-to-git/t/test.config
|
||||
/var/lib/lightdm/.config
|
||||
/home/daygeek/.config
|
||||
/root/.config
|
||||
/etc/skel/.config
|
||||
```
|
||||
|
||||
Use the following command format to find an empty files and folders in system.
|
||||
|
||||
```
|
||||
# find / -empty
|
||||
```
|
||||
|
||||
Use the following command combination to find all files containing specific text on Linux.
|
||||
|
||||
```
|
||||
# find / -type f -exec grep "Port 22" '{}' \; -print
|
||||
# find / -type f -print | xargs grep "Port 22"
|
||||
# find / -type f | xargs grep 'Port 22'
|
||||
# find / -type f -exec grep -H 'Port 22' {} \;
|
||||
```
|
||||
|
||||
### Method-2: Search Files And Folders in Linux Using locate command
|
||||
|
||||
locate command works faster than the find command because it uses updatedb database, whereas the find command searches in the real system.
|
||||
|
||||
It uses a database rather than hunting individual directory paths to get a given file.
|
||||
|
||||
locate command doesn’t pre-installed in most of the distributions so, use your distribution package manager to install it.
|
||||
|
||||
The database is updated regularly through cron, however we can manually update it by running the following command.
|
||||
|
||||
```
|
||||
$ sudo updatedb
|
||||
```
|
||||
|
||||
Simply run the following command to list the given file or folder. There is no specific options need to be specified in locate command to print file or folder.
|
||||
|
||||
To search `ssh` folder in system.
|
||||
|
||||
```
|
||||
# locate --basename '\ssh'
|
||||
/etc/ssh
|
||||
/usr/bin/ssh
|
||||
/usr/lib/ssh
|
||||
/usr/lib/go/pkg/linux_amd64/cmd/vendor/golang.org/x/crypto/ssh
|
||||
/usr/lib/go/src/cmd/go/testdata/failssh/ssh
|
||||
/usr/lib/go/src/cmd/vendor/golang.org/x/crypto/ssh
|
||||
```
|
||||
|
||||
To search `ssh_config` file in system.
|
||||
|
||||
```
|
||||
# locate --basename '\sshd_config'
|
||||
/etc/ssh/sshd_config
|
||||
```
|
||||
|
||||
### Method-3: Search Files in Linux Using which command
|
||||
|
||||
TThe which command returns the full path of the executable that would have been executed when the command had been entered in terminal.
|
||||
|
||||
It’s very useful when you want to create a desktop shortcut or symbolic link for executable files.
|
||||
|
||||
Which command searches the directories listed in the current user’s PATH environment variable not for all the users. I mean, when you are logged in your own account and you can’t able to search for root user file or directory.
|
||||
|
||||
Run the following command to print the full path of the vim executable file location.
|
||||
|
||||
```
|
||||
# which vi
|
||||
/usr/bin/vi
|
||||
```
|
||||
|
||||
Alternatively, it’s allowing user to perform multiple file search in one shot.
|
||||
|
||||
```
|
||||
# which -a vi sudo
|
||||
/usr/bin/vi
|
||||
/bin/vi
|
||||
/usr/bin/sudo
|
||||
/bin/sudo
|
||||
```
|
||||
|
||||
### Method-4: Search Files in Linux Using whereis command
|
||||
|
||||
The whereis command used to search the binary, source, and man page files for a given command.
|
||||
|
||||
```
|
||||
# whereis vi
|
||||
vi: /usr/bin/vi /usr/share/man/man1/vi.1p.gz /usr/share/man/man1/vi.1.gz
|
||||
```
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/four-easy-ways-to-search-or-find-files-and-folders-in-linux/
|
||||
|
||||
作者:[Prakash Subramanian][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.2daygeek.com/author/prakash/
|
||||
[b]: https://github.com/lujun9972
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (HankChow)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: subject: (Bash Variables: Environmental and Otherwise)
|
||||
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: subject: (Bring some color to your Linux terminal with lolcat)
|
||||
|
@ -1,92 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: subject: (Easily Convert Audio File Formats with SoundConverter in Linux)
|
||||
[#]: via: (https://itsfoss.com/sound-converter-linux/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
[#]: url: ( )
|
||||
|
||||
Easily Convert Audio File Formats with SoundConverter in Linux
|
||||
======
|
||||
|
||||
**If you are looking for converting audio file formats to wav, mp3, ogg or any other format, SoundConverter is the tool you need in Linux.**
|
||||
|
||||
![Audio Converter in Linux][1]
|
||||
|
||||
So recently I purchased some DRM-free music. I got it from [SaReGaMa][2], the oldest and the largest music labels in India. The downloaded files were in HD quality and in WAV format.
|
||||
|
||||
Unfortunately, Rhythmbox doesn’t play the WAV files. On top of that, a single file was around 70 MB in size. Imagine transferring such large music files to smartphones. It would eat up a lot of space unnecessarily.
|
||||
|
||||
So I thought it was time to convert the WAV files to MP3, the evergreen and the most popular music file format.
|
||||
|
||||
And for this task, I needed an audio converter in Linux. In this quick tutorial, I’ll show you how can you convert your audio files from one format to another easily with a GUI tool called SoundCoverter.
|
||||
|
||||
### Installing SoundConverter in Linux
|
||||
|
||||
[SoundConverter][3] is a popular free and open source software. It should be available in the official repository of most Linux distributions.
|
||||
|
||||
Ubuntu/Linux Mint users can simply search for SoundConverter in the software center and install it from there.
|
||||
|
||||
![SoundConverter application in Software Center of Ubuntu][4]SoundConverter can be installed from Software Center
|
||||
|
||||
Alternatively, you can use the command line way. In Debian and Ubuntu based systems, you can use the following command:
|
||||
|
||||
```
|
||||
sudo apt install soundconverter
|
||||
```
|
||||
|
||||
For Arch, Fedora and other non-Debian based distributions, you can use the software center or the package manager of your distribution.
|
||||
|
||||
### Using SoundConverter to convert audio file formats in Linux
|
||||
|
||||
Once you have installed SoundConverter, search for it in the menu and start it.
|
||||
|
||||
The default interface looks like this and it cannot be more simple than this:
|
||||
|
||||
![SoundConverter application interface in Linux][5]Simple Interface
|
||||
|
||||
Converting audio file format is as easy as selecting the file and clicking on convert.
|
||||
|
||||
However, I would advise you to check the default settings at least on the first run. By default it converts the audio file to OGG file format and you may not want that.
|
||||
|
||||
![Preferences in SoundConverter][6]Default output settings can be changed in Preferences
|
||||
|
||||
To change the default output settings, click on the Preferences icon visible on the interface. You’ll see plenty of options to change here.
|
||||
|
||||
You can change the default output format, bitrate, quality etc. You can also choose if you want to keep the converted files in the same folder as the original or not.
|
||||
|
||||
There is also an option of automatically deleting the original file after conversion. I don’t think you should use that option.
|
||||
|
||||
You can also change the output file name. By default, it will just change the suffix but you can also choose to name it based on track number, title, artist etc. For that to happen, you should have proper metadata on the original file.
|
||||
|
||||
Speaking of metadata, have you heard of [MusicBrainz Picard][7]? This tool helps you automatically updates the metadata of your local music files.
|
||||
|
||||
### Conclusion
|
||||
|
||||
I have discussed [recording audio in Linux][8] previously with a similar tiny application. Such nifty tools actually make life easier with their focused aim of completing a certain task. You may use full-fledged and a lot better audio editing tool like [Audacity][9] but that may be complicated to use for smaller tasks like converting audio file formats.
|
||||
|
||||
I hope you like SoundConverter. If you use some other tool, do mention that in the comments and I may cover it here on It’s FOSS. Enjoy!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/sound-converter-linux/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者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/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/Convert-audio-file-format-linux.png?resize=800%2C450&ssl=1
|
||||
[2]: https://en.wikipedia.org/wiki/Saregama
|
||||
[3]: http://soundconverter.org/
|
||||
[4]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/sound-converter-software-center.png?ssl=1
|
||||
[5]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2018/12/sound-converter-app-linux.jpeg?ssl=1
|
||||
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/sound-converter-app-linux-preferences.jpeg?resize=800%2C431&ssl=1
|
||||
[7]: https://itsfoss.com/musicbrainz-picard/
|
||||
[8]: https://itsfoss.com/record-streaming-audio/
|
||||
[9]: https://www.audacityteam.org/
|
@ -0,0 +1,257 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (5 Ways To Check Laptop Battery Status And Level From Linux Terminal)
|
||||
[#]: via: (https://www.2daygeek.com/check-laptop-battery-status-and-charging-state-in-linux-terminal/)
|
||||
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
|
||||
|
||||
5 Ways To Check Laptop Battery Status And Level From Linux Terminal
|
||||
======
|
||||
|
||||
We can easily check the battery status through GUI such as current battery percentage, whether it’s charging or not charging and how long it will be usable without charging, but we can’t able to check the battery health and other related information.
|
||||
|
||||
In this scenario what will be the solutions.
|
||||
|
||||
Yes, we have few utilities available for this in Linux and it can be achieved through command line.
|
||||
|
||||
We are going to discuss about this topic today through this article and i will try to cover possible information i can.
|
||||
|
||||
Checking your battery health monthly once is something good. It will help you to identify whether we are facing any battery or charge related issues.
|
||||
|
||||
Also, we can see battery model name, power source, vendor and battery technology, etc,.
|
||||
|
||||
Power management is a feature that turns off the power or switches system’s components to a low-power state when inactive.
|
||||
|
||||
### Following Utilities are available in Linux to Check Battery Status.
|
||||
|
||||
* `upower`: upower is a command line tool which provides an interface to enumerate power sources on the system.
|
||||
* `acpi`: acpi Shows information from the /proc or the /sys filesystem, such as battery status or thermal information.
|
||||
* `batstat`: batstat is a command line tool to print battery status for linux.
|
||||
* `tlp`: TLP brings you the benefits of advanced power management for Linux without changing any configuration.
|
||||
* `class file`: The sysfs filesystem is a pseudo-filesystem which provides an interface to kernel data structures.
|
||||
|
||||
|
||||
|
||||
### How to Check Laptop Battery Status Using upower Command?
|
||||
|
||||
[upower][1] is a command line tool that provides an interface to enumerate power sources on the system. It control the latency of different operations on your computer, which enables you to save significant amounts of power.
|
||||
|
||||
Just run the following command to get the battery and it’s related information on Linux.
|
||||
|
||||
```
|
||||
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0
|
||||
native-path: BAT0
|
||||
vendor: SMP
|
||||
model: L14M4P23
|
||||
serial: 756
|
||||
power supply: yes
|
||||
updated: Monday 03 December 2018 07:56:18 PM IST (95 seconds ago)
|
||||
has history: yes
|
||||
has statistics: yes
|
||||
battery
|
||||
present: yes
|
||||
rechargeable: yes
|
||||
state: discharging
|
||||
warning-level: none
|
||||
energy: 28.23 Wh
|
||||
energy-empty: 0 Wh
|
||||
energy-full: 52.26 Wh
|
||||
energy-full-design: 60 Wh
|
||||
energy-rate: 10.714 W
|
||||
voltage: 14.819 V
|
||||
time to empty: 2.6 hours
|
||||
percentage: 54%
|
||||
capacity: 87.1%
|
||||
technology: lithium-ion
|
||||
icon-name: 'battery-good-symbolic'
|
||||
History (charge):
|
||||
1543847178 54.000 discharging
|
||||
History (rate):
|
||||
1543847178 10.714 discharging
|
||||
```
|
||||
|
||||
To check the specific information about battery, use the following format.
|
||||
|
||||
```
|
||||
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -i "state\|percentage\|time to empty"
|
||||
state: discharging
|
||||
time to empty: 2.1 hours
|
||||
percentage: 43%
|
||||
```
|
||||
|
||||
It’s same as above, but it’s taken after power cable plugged in, that’s why the state showing charging.
|
||||
|
||||
```
|
||||
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -i "state\|percentage\|time to empty"
|
||||
state: charging
|
||||
percentage: 41%
|
||||
```
|
||||
|
||||
### How to Check Laptop Battery Status Using TLP Command?
|
||||
|
||||
TLP is a free opensource feature-rich command line tool which optimize laptop battery without making any configuration change.
|
||||
|
||||
TLP brings you the benefits of advanced power management for Linux without the need to understand every technical detail. TLP comes with a default configuration already optimized for battery life, so you may just install and forget it. Nevertheless TLP is highly customizable to fulfil your specific requirements.
|
||||
|
||||
TLP package is available in most of the Linux distribution official repository such as Arch, Debian, Fedora, Gentoo, openSUSE, etc. Use your distribution Package Manager to install the TLP utility.
|
||||
|
||||
Just run the following command to get the battery and it’s related information on Linux.
|
||||
|
||||
```
|
||||
$ sudo tlp-stat -b
|
||||
--- TLP 1.1 --------------------------------------------
|
||||
|
||||
+++ Battery Status
|
||||
/sys/class/power_supply/BAT0/manufacturer = SMP
|
||||
/sys/class/power_supply/BAT0/model_name = L14M4P23
|
||||
/sys/class/power_supply/BAT0/cycle_count = (not supported)
|
||||
/sys/class/power_supply/BAT0/energy_full_design = 60000 [mWh]
|
||||
/sys/class/power_supply/BAT0/energy_full = 52260 [mWh]
|
||||
/sys/class/power_supply/BAT0/energy_now = 21950 [mWh]
|
||||
/sys/class/power_supply/BAT0/power_now = 10923 [mW]
|
||||
/sys/class/power_supply/BAT0/status = Discharging
|
||||
|
||||
Charge = 42.0 [%]
|
||||
Capacity = 87.1 [%]
|
||||
```
|
||||
|
||||
To see other information as well.
|
||||
|
||||
```
|
||||
$ sudo tlp-stat -s
|
||||
--- TLP 1.1 --------------------------------------------
|
||||
|
||||
+++ System Info
|
||||
System = LENOVO Lenovo ideapad Y700-15ISK 80NV
|
||||
BIOS = CDCN35WW
|
||||
Release = "Manjaro Linux"
|
||||
Kernel = 4.19.6-1-MANJARO #1 SMP PREEMPT Sat Dec 1 12:21:26 UTC 2018 x86_64
|
||||
/proc/cmdline = BOOT_IMAGE=/boot/vmlinuz-4.19-x86_64 root=UUID=69d9dd18-36be-4631-9ebb-78f05fe3217f rw quiet resume=UUID=a2092b92-af29-4760-8e68-7a201922573b
|
||||
Init system = systemd
|
||||
Boot mode = BIOS (CSM, Legacy)
|
||||
|
||||
+++ TLP Status
|
||||
State = enabled
|
||||
Last run = 07:16:12 IST, 4362 sec(s) ago
|
||||
Mode = battery
|
||||
Power source = battery
|
||||
```
|
||||
|
||||
### How to Check Laptop Battery Status Using ACPI Command?
|
||||
|
||||
ACPI stands for Advanced Configuration and Power Interface modules are kernel modules for different ACPI parts. They enable special ACPI functions or add information to /proc or /sys. These information can be parsed by acpid for events or other monitoring applications.
|
||||
|
||||
```
|
||||
$ acpi
|
||||
Battery 0: Charging, 43%, 01:05:11 until charged
|
||||
```
|
||||
|
||||
To see battery capacity.
|
||||
|
||||
```
|
||||
$ acpi -i
|
||||
Battery 0: Charging, 43%, 01:05:07 until charged
|
||||
Battery 0: design capacity 3817 mAh, last full capacity 3324 mAh = 87%
|
||||
```
|
||||
|
||||
To see more details about battery and related information.
|
||||
|
||||
```
|
||||
$ acpi -V
|
||||
Battery 0: Charging, 43%, 01:05:07 until charged
|
||||
Battery 0: design capacity 3815 mAh, last full capacity 3323 mAh = 87%
|
||||
Adapter 0: on-line
|
||||
Cooling 0: Processor 0 of 10
|
||||
Cooling 1: Processor 0 of 10
|
||||
Cooling 2: Processor 0 of 10
|
||||
Cooling 3: iwlwifi 0 of 19
|
||||
Cooling 4: Processor 0 of 10
|
||||
Cooling 5: iwlwifi no state information available
|
||||
Cooling 6: Processor 0 of 10
|
||||
Cooling 7: Processor 0 of 10
|
||||
Cooling 8: Processor 0 of 10
|
||||
Cooling 9: intel_powerclamp no state information available
|
||||
Cooling 10: x86_pkg_temp no state information available
|
||||
Cooling 11: Processor 0 of 10
|
||||
```
|
||||
|
||||
### How to Check Laptop Battery Status Using Batstat Command?
|
||||
|
||||
batstat is a command line tool to print battery status in linux terminal.
|
||||
|
||||
```
|
||||
Status: Charging
|
||||
Max energy: 50.00 Wh
|
||||
Energy left: 24.50 Wh
|
||||
Power Consumption: 26.40 W
|
||||
Percentage left: 49.00%
|
||||
Average power Consumption: 0.00 W
|
||||
Time elapsed: 0: 0:12 since 49.00%
|
||||
= Time ======== Percent ============================================
|
||||
0: 0: 0 49.00%
|
||||
```
|
||||
|
||||
### How to Check Laptop Battery Status Using sysfs filesystem?
|
||||
|
||||
The sysfs filesystem is a pseudo-filesystem which provides an interface to kernel data structures. The files under sysfs provide information about devices, kernel modules, filesystems, and other kernel components.
|
||||
|
||||
The sysfs filesystem is commonly mounted at /sys. Typically, it is mounted automatically by the system, but it can also be mounted manually using a command such as `mount -t sysfs sysfs /sys`
|
||||
|
||||
Many of the files in the sysfs filesystem are read-only, but some files are writable, allowing kernel variables to be changed. To avoid redundancy, symbolic links are heavily used to connect entries across the filesystem tree.
|
||||
|
||||
```
|
||||
$ cat /sys/class/power_supply/BAT0/*
|
||||
0
|
||||
51
|
||||
Normal
|
||||
0
|
||||
cat: /sys/class/power_supply/BAT0/device: Is a directory
|
||||
52260000
|
||||
60000000
|
||||
26660000
|
||||
SMP
|
||||
L14M4P23
|
||||
cat: /sys/class/power_supply/BAT0/power: Is a directory
|
||||
27656000
|
||||
1
|
||||
756
|
||||
Charging
|
||||
cat: /sys/class/power_supply/BAT0/subsystem: Is a directory
|
||||
Li-ion
|
||||
Battery
|
||||
POWER_SUPPLY_NAME=BAT0
|
||||
POWER_SUPPLY_STATUS=Charging
|
||||
POWER_SUPPLY_PRESENT=1
|
||||
POWER_SUPPLY_TECHNOLOGY=Li-ion
|
||||
POWER_SUPPLY_CYCLE_COUNT=0
|
||||
POWER_SUPPLY_VOLTAGE_MIN_DESIGN=14800000
|
||||
POWER_SUPPLY_VOLTAGE_NOW=15840000
|
||||
POWER_SUPPLY_POWER_NOW=27656000
|
||||
POWER_SUPPLY_ENERGY_FULL_DESIGN=60000000
|
||||
POWER_SUPPLY_ENERGY_FULL=52260000
|
||||
POWER_SUPPLY_ENERGY_NOW=26660000
|
||||
POWER_SUPPLY_CAPACITY=51
|
||||
POWER_SUPPLY_CAPACITY_LEVEL=Normal
|
||||
POWER_SUPPLY_MODEL_NAME=L14M4P23
|
||||
POWER_SUPPLY_MANUFACTURER=SMP
|
||||
POWER_SUPPLY_SERIAL_NUMBER= 756
|
||||
14800000
|
||||
15840000
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/check-laptop-battery-status-and-charging-state-in-linux-terminal/
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.2daygeek.com/author/magesh/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://upower.freedesktop.org/
|
113
sources/tech/20181210 How to get started in AI.md
Normal file
113
sources/tech/20181210 How to get started in AI.md
Normal file
@ -0,0 +1,113 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to get started in AI)
|
||||
[#]: via: (https://opensource.com/article/18/12/how-get-started-ai)
|
||||
[#]: author: (Gordon Haff https://opensource.com/users/ghaff)
|
||||
|
||||
How to get started in AI
|
||||
======
|
||||
Before you can begin working in artificial intelligence, you need to acquire some human intelligence.
|
||||

|
||||
|
||||
I've both asked and been asked about the best way to learn more about artificial intelligence (AI). What should I read? What should I watch? I'll get to that. But, first, it's useful to break down this question, given that AI covers a lot of territory.
|
||||
|
||||
One important distinction to draw is between the research side of AI and the applied side. Cassie Kozyrkov of Google [drew this distinction][1] in a talk at the recent O'Reilly Artificial Intelligence Conference in London, and it's a good one.
|
||||
|
||||
Research AI is rather academic in nature and requires a heavy dose of math across a variety of disciplines before you even get to those parts that are specific to AI. This aspect of AI focuses on the algorithms and tools that drive the state of AI forward. For example, what neural network structures might improve vision recognition results? How might we make unsupervised learning a more generally useful approach? Can we find ways to understand better how deep learning pipelines come up with the answers they do?
|
||||
|
||||
Applied AI, on the other hand, is more about using existing tools to obtain useful results. Open source has played a big role here in providing free and often easy-to-use software in a variety of languages. Public cloud providers have also devoted a lot of attention to providing machine learning services, models, and datasets that make the onramp to getting started with AI much simpler than it would be otherwise.
|
||||
|
||||
I'll add at this point that applied AI practitioners shouldn't treat their tools as some sort of black box that spits out answers for mysterious reasons. At a minimum, they need to understand the limits and potential biases of different techniques, models, and data collection approaches. It's just that they don't necessarily need to delve deeply into all the theory underpinning every part of their toolchain.
|
||||
|
||||
Although it's probably less important for working in AI on a day-to-day basis, it's also useful to understand the broader context of AI. It goes beyond the narrow scope of deep learning on neural networks that have been so important to the gains made in reinforcement learning and supervised learning to date. For example, AI is often viewed as a way to augment (rather than replace) human judgment and decisions. But the handoff between machine and human has its own pitfalls.
|
||||
|
||||
With that background, here are some study areas and resources you may find useful.
|
||||
|
||||
### Research AI
|
||||
|
||||
In a lot of respects, a list of resources for research AI mirror those in an undergraduate (or even graduate) computer science program that's focused on AI. The main difference is that the syllabus you draw up may be more interdisciplinary than more traditionally focused university curricula.
|
||||
|
||||
Where you start will depend on your computer science and math background.
|
||||
|
||||
If it's minimal or rusty, but you still want to develop a deep understanding of AI fundamentals, you'll benefit from taking some math courses to start. There are many options on massive online open courses (MOOCs) like the nonprofit [edX][2] platform and [Coursera][3]. (Both platforms charge for certifications, but edX makes all the content available for free to people just auditing the course.)
|
||||
|
||||
Typical foundational courses could include:
|
||||
|
||||
+ [MIT's Calculus courses][22], starting with differentiation
|
||||
+ [Linear Algebra][23] (University of Texas)
|
||||
+ Probability and statistics, such as MIT's [Probability—The Science of Uncertainty and Data][24]
|
||||
|
||||
|
||||
To get deeper into AI from a research perspective, you'll probably want to get into all these areas of mathematics and more. But the above should give you an idea of the general branches of study that are probably most important before delving into machine learning and AI proper.
|
||||
|
||||
In addition to MOOCs, resources such as [MIT OpenCourseWare][4] provide the syllabus and various supporting materials for a wide range of mathematics and computer science courses.
|
||||
|
||||
With the foundations in place, you can move onto more specialized courses in AI proper. Andrew Ng's AI MOOC, from when he was teaching at Stanford, was one of the early courses to popularize the whole online course space. Today, his [Neural Networks and Deep Learning][5] is part of the Deep Learning specialization at Coursera. There are corresponding programs on edX. For example, Columbia offers an [Artificial Intelligence MicroMasters][6].
|
||||
|
||||
In addition to courses, a variety of textbooks and other learning material are also available online. These include:
|
||||
|
||||
* [Neural Networks and Deep Learning][7]
|
||||
* [Deep Learning][8] from MIT Press by Ian Goodfellow and Yoshua Bengio and Aaron Courville
|
||||
|
||||
### Applied AI
|
||||
|
||||
Applied AI is much more focused on using available tools than building new ones. Some appreciation of the mathematical underpinnings, especially statistics, is still useful—arguably even necessary—but you won't be majoring in that aspect of AI to the same degree you would in a research mode.
|
||||
|
||||
Programming is a core skill here. While different programming languages can come into play, a lot of libraries and toolsets—such as [PyTorch][9]—rely on Python, so that's a good skill to have. Especially if you have some level of programming background, MIT's [Introduction to Computer Science and Programming Using Python][10], based on its on-campus 6.001 course, is a good primer. If you're truly new to programming, Charles Severance's [Programming for Everybody (Getting Started with Python)][11] from the University of Michigan doesn't toss you into the deep end of the pool the way the MIT course does.
|
||||
|
||||
[The R programming language][12] is also a useful skill to add to your toolbox. While it's less used in machine learning (ML) per se, it's common for a variety of other data science tasks, and applied AI/ML and data science often blend in practice. For example, many tasks associated with organizing and cleaning data apply equally whatever analysis techniques you'll eventually use. A MOOC sequence like Harvard's [Data Science certificate][13] is an example of a set of courses that provide a good introduction to working with data.
|
||||
|
||||
Another open source software library you're likely to encounter if you do any work with AI is [TensorFlow][14]. It was originally developed by researchers and engineers from the Google Brain team within Google's AI organization. [Google offers a variety of tutorials][15] to get started with TensorFlow using the high-level Keras API. You can run TensorFlow locally as well as online in Google Cloud.
|
||||
|
||||
In general, all of the big public cloud providers offer online datasets and ML services that can be an easy way to get started. However, especially as you move beyond "play" datasets and applications, you need to start thinking seriously about the degree to which you want to be locked into a single provider.
|
||||
|
||||
Datasets for your exploratory learning projects are available from many different sources. In addition to the public cloud providers, [Kaggle][16] is another popular source and also a good learning resource more broadly. Government data is also increasingly available in digital form. The US Federal Government's [Data.gov][17] claims over 300,000 datasets. State and local governments also publish data on everything from restaurant health ratings to dogs' names.
|
||||
|
||||
### Miscellany
|
||||
|
||||
I'll close by noting that AI is a broad topic that isn't just about math, programming, and data. AI as a whole touches many other fields, including cognitive psychology, linguistics, game theory, operations research, and control systems. Indeed, a concern among at least some AI researchers today is that the field has become too fixated on a small number of techniques that have become powerful and interesting only quite recently because of the intersection of processing power and big data. Many longstanding problems in understanding how humans learn and reason remain largely unsolved. Developing at least some appreciation for these broader problem spaces will better enable you to place AI within a broader context.
|
||||
|
||||
One of my favorite examples is the [Humans and Autonomy Lab][18] at Duke. The work in this lab touches on all the challenges of humans working with machines, such as how autopilots can create ["Children of the Magenta"][19] who are unable to take control quickly if the automation fails. A basic brain-science course, such as MIT's [Introduction to Psychology][20], provides some useful context for the relationship between human intelligence and machine intelligence. Another course in a similar vein, but taught by the late Marvin Minsky from MIT's Electrical Engineering and Computer Science department, is [The Society of Mind][21].
|
||||
|
||||
If there's one key challenge to learning about AI, it's not that raw materials and tools aren't readily available. It's that there are so many of them. My objective hasn't been to give you a comprehensive set of pointers. Rather, it's been to both point out the different paths you can take and provide you with some possible starting points. Happy learning!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/12/how-get-started-ai
|
||||
|
||||
作者:[Gordon Haff][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/ghaff
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.youtube.com/watch?v=RLtI7r3QUyY
|
||||
[2]: https://www.edx.org/
|
||||
[3]: https://www.coursera.org/
|
||||
[4]: https://ocw.mit.edu/index.htm
|
||||
[5]: https://www.coursera.org/learn/neural-networks-deep-learning
|
||||
[6]: https://www.edx.org/micromasters/columbiax-artificial-intelligence
|
||||
[7]: http://neuralnetworksanddeeplearning.com/
|
||||
[8]: http://www.deeplearningbook.org/
|
||||
[9]: https://pytorch.org/
|
||||
[10]: https://www.edx.org/course/introduction-to-computer-science-and-programming-using-python
|
||||
[11]: https://www.coursera.org/learn/python
|
||||
[12]: https://www.r-project.org/about.html
|
||||
[13]: https://www.edx.org/professional-certificate/harvardx-data-science
|
||||
[14]: https://www.tensorflow.org/
|
||||
[15]: https://www.tensorflow.org/tutorials/
|
||||
[16]: https://www.kaggle.com/
|
||||
[17]: https://www.data.gov/
|
||||
[18]: https://hal.pratt.duke.edu/
|
||||
[19]: https://99percentinvisible.org/episode/children-of-the-magenta-automation-paradox-pt-1/
|
||||
[20]: https://ocw.mit.edu/courses/brain-and-cognitive-sciences/9-00sc-introduction-to-psychology-fall-2011/
|
||||
[21]: https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-868j-the-society-of-mind-fall-2011/
|
||||
[22]: https://www.edx.org/course/calculus-1a-differentiation
|
||||
[23]: https://www.edx.org/course/linear-algebra-foundations-to-frontiers
|
||||
[24]: https://courses.edx.org/courses/course-v1:MITx+6.431x+3T2018/course/
|
@ -0,0 +1,160 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (McFly – A Replacement To ‘Ctrl+R’ Bash History Search Feature)
|
||||
[#]: via: (https://www.ostechnix.com/mcfly-a-replacement-to-ctrlr-bash-history-search-feature/)
|
||||
[#]: author: (SK https://www.ostechnix.com/author/sk/)
|
||||
|
||||
McFly – A Replacement To ‘Ctrl+R’ Bash History Search Feature
|
||||
======
|
||||

|
||||
If you spend a lot of time on CLI mode, you should definitely used or heard about **reverse search** function in BASH. The keyboard shortcut to do reverse search in Bash is **Ctrl+r**. Using bash reverse search, we can bring up all commands which we used previously executed without having to re-type them every time. You can, of course, use UP/DOWN arrows to search your bash history. However, Ctrl+r will make this process much easier and faster. Today, I Stumbled upon a replacement to ‘Ctrl+r’ Bash history search feature. Meet **“McFly”** , a simple tool written in **Rust** programming language that replaces the default Ctrl+r Bash history search with an intelligent search engine. All command suggestions made by McFly are prioritized in real time with a small **neural network**.
|
||||
|
||||
McFly rebinds Ctrl+r functionality to bring up all recently executed commands from your Bash history. It augments your shell history by tracking the following:
|
||||
|
||||
* Command exit status,
|
||||
* timestamp (When you run the command),
|
||||
* and execution directory (Where you run the command).
|
||||
|
||||
|
||||
|
||||
It saves all tracking details in a SQLite database. Since it tracks the command’s historical exit status, you can simply ignore the old failed commands. Cool, yeah?
|
||||
|
||||
When suggesting a command, McFly considers the following facts:
|
||||
|
||||
* On which directory you ran the command. You’re likely to repeat that command in the same directory in future.
|
||||
* What commands you typed before the command.
|
||||
* How often you run the command.
|
||||
* When you last ran the command.
|
||||
* If you’ve selected the command in McFly before.
|
||||
* The command’s historical exit status. Because, you probably don’t want to run old failed commands, right?
|
||||
|
||||
|
||||
|
||||
McFly maintains your default Bash history file, so you can stop using McFly at any time. McFly is not just for BASH, it is also extendable for other shells as well.
|
||||
|
||||
### Installing McFly
|
||||
|
||||
McFly can be installed using Linuxbrew on Linux. If you haven’t installed Linuxbrew yet, refer the following link.
|
||||
|
||||
[Linuxbrew – A Common Package Manager For Linux And Mac OS X][1]
|
||||
|
||||
Once Linuxbrew installed, run the following commands to install McFly:
|
||||
|
||||
```
|
||||
$ brew tap cantino/mcfly https://github.com/cantino/mcfly
|
||||
|
||||
$ brew install mcfly
|
||||
```
|
||||
|
||||
After the installation is completed, you will see the following output.
|
||||
|
||||
```
|
||||
==> Installing mcfly from cantino/mcfly
|
||||
==> Downloading https://github.com/cantino/mcfly/releases/download/v0.2.5/mcfly-v0
|
||||
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.c
|
||||
######################################################################## 100.0%
|
||||
==> ONE MORE STEP! Edit ~/.bashrc and add the following:
|
||||
|
||||
if [ -f $(brew --prefix)/opt/mcfly/mcfly.bash ]; then
|
||||
. $(brew --prefix)/opt/mcfly/mcfly.bash
|
||||
fi
|
||||
🍺 /home/linuxbrew/.linuxbrew/Cellar/mcfly/v0.2.5: 4 files, 3.5MB, built in 33 seconds
|
||||
```
|
||||

|
||||
As you can see, we need to do one more step before start using McFly.
|
||||
|
||||
Add the following lines to your **~/.bashrc** file:
|
||||
|
||||
```
|
||||
if [ -f $(brew --prefix)/opt/mcfly/mcfly.bash ]; then
|
||||
. $(brew --prefix)/opt/mcfly/mcfly.bash
|
||||
fi
|
||||
```
|
||||
|
||||
Finally, run the following command to take effects changes:
|
||||
|
||||
```
|
||||
$ source ~/.bashrc
|
||||
```
|
||||
|
||||
Your BASH history will be imported to McFly database when you run this command for the first time. It will take a few moments depending upon size of your bash history file. Once the import is done, you will see the following message.
|
||||
|
||||
```
|
||||
McFly: Importing Bash history for the first time. This may take a minute or two...done.
|
||||
```
|
||||
|
||||
You can now start using McFly.
|
||||
|
||||
|
||||
### Usage
|
||||
|
||||
To search through your command history, just type ‘mcfly search’ followed by the part of the command name and hit ENTER key. Mcfly will display the command suggestions based on the search query you just type.
|
||||
|
||||
```
|
||||
$ mcfly search <part-of-the-command>
|
||||
```
|
||||
|
||||
For instance, I type the following command:
|
||||
|
||||
```
|
||||
$ mcfly search mk
|
||||
```
|
||||
|
||||
Here is the sample output from my Ubuntu machine:
|
||||
|
||||

|
||||
|
||||
As you can see, I have used ‘mkdir’ command two times. If you want to run a command from the list of suggestions, just use **UP/DOWN** arrows to select it and hit ENTER to run it immediately. If you want to edit a command, choose it and hit **TAB** key to bring it back to your Terminal and then edit before running it. To delete the selected command from the history, just press **F2**.
|
||||
|
||||
Alternatively, type the following command to open the history search and then type any command or part of the command to view the suggestions from your history.
|
||||
|
||||
```
|
||||
$ mcfly search
|
||||
```
|
||||
|
||||
McFly will display the command suggestions as you type.
|
||||
|
||||
Here is a short video demonstration of McFly:
|
||||

|
||||
View help:
|
||||
|
||||
```
|
||||
$ mcfly --help
|
||||
```
|
||||
|
||||
|
||||
### Remove McFly
|
||||
|
||||
Don’t like McFly, no problem! Remove it using the following commands:
|
||||
|
||||
```
|
||||
$ brew uninstall mcfly
|
||||
|
||||
$ brew untap cantino/mcfly
|
||||
```
|
||||
|
||||
Finally, remove the lines which we added earlier from **~/.bashrc** file.
|
||||
|
||||
And, that’s all for now. More good stuffs to come. Stay tuned!
|
||||
|
||||
Cheers!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/mcfly-a-replacement-to-ctrlr-bash-history-search-feature/
|
||||
|
||||
作者:[SK][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者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/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.ostechnix.com/linuxbrew-common-package-manager-linux-mac-os-x/
|
@ -0,0 +1,52 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Snake your way across your Linux terminal)
|
||||
[#]: via: (https://opensource.com/article/18/12/linux-toy-snake)
|
||||
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
|
||||
|
||||
Snake your way across your Linux terminal
|
||||
======
|
||||
Python isn't the only snake you'll find at the Linux command line with this classic 1970s game remake.
|
||||

|
||||
|
||||
Welcome back to the Linux command-line toys advent calendar. If this is your first visit to the series, you might be asking yourself what a command-line toy even is. It's hard to say exactly, but my definition is anything that helps you have fun at the terminal.
|
||||
|
||||
We've been on a roll with games over the weekend, and it was fun, so let's look at one more game today, Snake!
|
||||
|
||||
Snake is an oldie but goodie; versions of it have been around seemingly forever. The first version I remember playing was one called [Nibbles][1] that came packaged with [QBasic][2] in the 1990s, and was probably pretty important to my understanding of what a programming language even was. Here I had the source code to a game that I could modify and just see what happens, and maybe learn something about what all of those funny little words that made up a programming language were all about.
|
||||
|
||||
Today's [Snake][3] is written in Go, and while it's simple, it's just as much fun as the original. Like most simple old games, there are a ton of versions to choose from. In Snake's case, there's even a version in the classic [bsdgames][4] package that's almost certainly packaged for your distribution.
|
||||
|
||||
But what I like about this version of Snake is that it's packaged for Docker so I can easily run it in one line from my terminal without worrying about anything disto-specific. That, and it makes use of 15 randomized food emojis for the snake to eat. I'm a sucker for food emojis. Anyway, give it a try using:
|
||||
|
||||
```
|
||||
$ docker run -ti dyego/snake-game
|
||||
```
|
||||
|
||||
This Snake is licensed as open source under an MIT license, and you can check out the source code [on GitHub][3].
|
||||

|
||||
Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.
|
||||
|
||||
Check out yesterday's toy, [Powers of two, powers of Linux: 2048 at the command line][5], and check back tomorrow for another!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/12/linux-toy-snake
|
||||
|
||||
作者:[Jason Baker][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/jason-baker
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://en.wikipedia.org/wiki/Nibbles_(video_game)
|
||||
[2]: https://en.wikipedia.org/wiki/QBasic
|
||||
[3]: https://github.com/DyegoCosta/snake-game
|
||||
[4]: https://github.com/vattam/BSDGames
|
||||
[5]: https://opensource.com/article/18/12/linux-toy-2048
|
@ -0,0 +1,265 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How To Benchmark Linux Commands And Programs From Commandline)
|
||||
[#]: via: (https://www.ostechnix.com/how-to-benchmark-linux-commands-and-programs-from-commandline/)
|
||||
[#]: author: (SK https://www.ostechnix.com/author/sk/)
|
||||
|
||||
How To Benchmark Linux Commands And Programs From Commandline
|
||||
======
|
||||
|
||||

|
||||
|
||||
A while ago, I have written a guide about the [**alternatives to ‘top’, the command line utility**][1]. Some of the users asked me which one among those tools is best and on what basis (like features, contributors, years active, page requests etc.) I compared those tools. They also asked me to share the bench-marking results If I have any. Unfortunately, I didn’t even know how to benchmark programs at that time. While searching for some simple and easy to use bench-marking tools to compare the Linux programs, I stumbled upon two utilities named **‘Bench’** and **‘Hyperfine’**. These are simple and easy-to-use command line tools to benchmark Linux commands and programs on Unix-like systems.
|
||||
|
||||
### 1\. Bench Tool
|
||||
|
||||
The **‘Bench’** utility benchmarks one or more given commands/programs using **Haskell’s criterion** library and displays the output statistics in an easy-to-understandable format. This tool can be helpful where you need to compare similar programs based on the bench-marking result. We can also export the results to HTML format or CSV or templated output.
|
||||
|
||||
#### Installing Bench Utility
|
||||
|
||||
The bench utility can be installed in three methods.
|
||||
|
||||
**1\. Using Linuxbrew**
|
||||
|
||||
We can install Bench utility using Linuxbrew package manager. If you haven’t installed Linuxbrew yet, refer the following link.
|
||||
|
||||
After installing Linuxbrew, run the following command to install Bench:
|
||||
|
||||
```
|
||||
$ brew install bench
|
||||
```
|
||||
|
||||
**2\. Using Haskell’s stack tool**
|
||||
|
||||
First, install Haskell as described in the following link.
|
||||
|
||||
And then, run the following commands to install Bench.
|
||||
|
||||
```
|
||||
$ stack setup
|
||||
|
||||
$ stack install bench
|
||||
```
|
||||
|
||||
The ‘stack’ will install bench to **~/.local/bin** or something similar. Make sure that the installation directory is on your executable search path before using bench tool. You will be reminded to do this even if you forgot.
|
||||
|
||||
**3\. Using Nix package manager**
|
||||
|
||||
Another way to install Bench is using **Nix** package manager. Install Nix as shown in the below link.
|
||||
|
||||
After installing Nix, install Bench tool using command:
|
||||
|
||||
```
|
||||
$ nix-env -i bench
|
||||
```
|
||||
|
||||
#### Benchmark Linux Commands And Programs Using Bench
|
||||
|
||||
It is time to start benchmarking the programs.
|
||||
|
||||
For instance, let me show you the benchmark result of ‘ls -al’ command.
|
||||
|
||||
```
|
||||
$ bench 'ls -al'
|
||||
```
|
||||
|
||||
**Sample output:**
|
||||
|
||||

|
||||
|
||||
You must quote the commands when you use flags/options with them.
|
||||
|
||||
Similarly, you can benchmark any programs installed in your system. The following commands shows the benchmarking result of ‘htop’ and ‘ptop’ programs.
|
||||
|
||||
```
|
||||
$ bench htop
|
||||
|
||||
$ bench ptop
|
||||
```
|
||||

|
||||
Bench tool can benchmark multiple programs at once as well. Here is the benchmarking result of ls, htop, ptop programs.
|
||||
|
||||
```
|
||||
$ bench ls htop ptop
|
||||
```
|
||||
|
||||
Sample output:
|
||||

|
||||
|
||||
We can also export the benchmark result to a HTML like below.
|
||||
|
||||
```
|
||||
$ bench htop --output example.html
|
||||
```
|
||||
|
||||
To export the result to CSV, just run:
|
||||
|
||||
```
|
||||
$ bench htop --csv FILE
|
||||
```
|
||||
|
||||
View help section:
|
||||
|
||||
```
|
||||
$ bench --help
|
||||
```
|
||||
|
||||
### **2. Hyperfine Benchmark Tool
|
||||
|
||||
**
|
||||
|
||||
**Hyperfine** is yet another command line benchmarking tool inspired by the ‘Bench’ tool which we just discussed above. It is free, open source, cross-platform benchmarking program and written in **Rust** programming language. It has few additional features compared to the Bench tool as listed below.
|
||||
|
||||
* Statistical analysis across multiple runs.
|
||||
* Support for arbitrary shell commands.
|
||||
* Constant feedback about the benchmark progress and current estimates.
|
||||
* Perform warmup runs before the actual benchmark.
|
||||
* Cache-clearing commands can be set up before each timing run.
|
||||
* Statistical outlier detection.
|
||||
* Export benchmark results to various formats, such as CSV, JSON, Markdown.
|
||||
* Parameterized benchmarks.
|
||||
|
||||
|
||||
|
||||
#### Installing Hyperfine
|
||||
|
||||
We can install Hyperfine using any one of the following methods.
|
||||
|
||||
**1\. Using Linuxbrew**
|
||||
|
||||
```
|
||||
$ brew install hyperfine
|
||||
```
|
||||
|
||||
**2\. Using Cargo**
|
||||
|
||||
Make sure you have installed Rust as described in the following link.
|
||||
|
||||
After installing Rust, run the following command to install Hyperfine via Cargo:
|
||||
|
||||
```
|
||||
$ cargo install hyperfine
|
||||
```
|
||||
|
||||
**3\. Using AUR helper programs**
|
||||
|
||||
Hyperfine is available in [**AUR**][2]. So, you can install it on Arch-based systems using any helper programs, such as [**YaY**][3], like below.
|
||||
|
||||
```
|
||||
$ yay -S hyperfine
|
||||
```
|
||||
|
||||
**4\. Download and install the binaries**
|
||||
|
||||
Hyperfine is available in binaries for Debian-based systems. Download the latest .deb binary file from the [**releases page**][4] and install it using ‘dpkg’ package manager. As of writing this guide, the latest version was **1.4.0**.
|
||||
|
||||
```
|
||||
$ wget https://github.com/sharkdp/hyperfine/releases/download/v1.4.0/hyperfine_1.4.0_amd64.deb
|
||||
|
||||
$ sudo dpkg -i hyperfine_1.4.0_amd64.deb
|
||||
|
||||
$ sudo apt install -f
|
||||
```
|
||||
|
||||
#### Benchmark Linux Commands And Programs Using Hyperfine
|
||||
|
||||
To run a benchmark using Hyperfine, simply run it along with the program/command as shown below.
|
||||
|
||||
```
|
||||
$ hyperfine 'ls -al'
|
||||
```
|
||||
|
||||

|
||||
|
||||
Benchmark multiple commands/programs:
|
||||
|
||||
```
|
||||
$ hyperfine htop ptop
|
||||
```
|
||||
|
||||
Sample output:
|
||||
|
||||

|
||||
|
||||
As you can see at the end of the output, Hyperfine mentiones – **‘htop ran 1.96 times faster than ptop’** , so we can immediately conclude htop performs better than Ptop. This will help you to quickly find which program performs better when benchmarking multiple programs. We don’t get this detailed output in Bench utility though.
|
||||
|
||||
Hyperfine will automatically determine the number of runs to perform for each command. By default, it will perform at least **10 benchmarking runs**. If you want to set the **minimum number of runs** (E.g 5 runs), use the `-m` **/`--min-runs`** option like below:
|
||||
|
||||
```
|
||||
$ hyperfine --min-runs 5 htop ptop
|
||||
```
|
||||
|
||||
Or,
|
||||
|
||||
```
|
||||
$ hyperfine -m 5 htop ptop
|
||||
```
|
||||
|
||||
Similarly, to perform **maximum number of runs** for each command, the command would be:
|
||||
|
||||
```
|
||||
$ hyperfine --max-runs 5 htop ptop
|
||||
```
|
||||
|
||||
Or,
|
||||
|
||||
```
|
||||
$ hyperfine -M 5 htop ptop
|
||||
```
|
||||
|
||||
We can even perform **exact number of runs** for each command using the following command:
|
||||
|
||||
```
|
||||
$ hyperfine -r 5 htop ptop
|
||||
```
|
||||
|
||||
As you may know, if the program execution time is limited by disk I/O, the benchmarking results can be heavily influenced by disk caches and whether they are cold or warm. Luckily, Hyperfine has the options to perform a certain number of program executions before performing the actual benchmark.
|
||||
|
||||
To perform NUM warmup runs (E.g 3) before the actual benchmark, use the **`-w`/**`--warmup` option like below:
|
||||
|
||||
```
|
||||
$ hyperfine --warmup 3 htop
|
||||
```
|
||||
|
||||
Just like Bench utility, Hyperfine also allows us to export the benchmark results to a given file. We can export the results to CSV, JSON, and Markdown formats.
|
||||
|
||||
For instance, to export the results in Markdown format, use the following command:
|
||||
|
||||
```
|
||||
$ hyperfine htop ptop --export-markdown <FILE-NAME>
|
||||
```
|
||||
|
||||
For more options and usage details, refer the help secion:
|
||||
|
||||
```
|
||||
$ hyperfine --help
|
||||
```
|
||||
|
||||
And, that’s all for now. If you ever be in a situation where you need to benchmark similar and alternative programs, these tools might help to compare how they performs and share the details with your peers and colleagues.
|
||||
|
||||
More good stuffs to come. Stay tuned!
|
||||
|
||||
Cheers!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/how-to-benchmark-linux-commands-and-programs-from-commandline/
|
||||
|
||||
作者:[SK][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者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/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.ostechnix.com/some-alternatives-to-top-command-line-utility-you-might-want-to-know/
|
||||
[2]: https://aur.archlinux.org/packages/hyperfine
|
||||
[3]: https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/
|
||||
[4]: https://github.com/sharkdp/hyperfine/releases
|
@ -0,0 +1,111 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to Install Putty on Ubuntu and Other Linux Distributions)
|
||||
[#]: via: (https://itsfoss.com/putty-linux/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
How to Install Putty on Ubuntu and Other Linux Distributions
|
||||
======
|
||||
|
||||
If I am not wrong, [Putty][1] is perhaps the most popular SSH client for Windows.
|
||||
|
||||
In IT companies, the development environment is usually on a remote Linux system while the developers use Windows as their local system. Putty is used for connecting to the remote Linux system from the Windows machine.
|
||||
|
||||
Putty is not limited to Windows only. You can also use this open source software on Linux and macOS.
|
||||
|
||||
But wait! Why would you use a separate SSH client on Linux when you already have the ‘real’ Linux terminal with you? There are several reasons why you would want to use Putty on Linux.
|
||||
|
||||
* You have used Putty for so long on Windows that you are more comfortable with it.
|
||||
* You find it difficult to manually edit SSH config file to save the various SSH sessions. You prefer Putty’s graphical way of storing SSH connection.
|
||||
* You want to debug by connecting to raw sockets and serial ports.
|
||||
|
||||
|
||||
|
||||
Whatever may be the reason, if you want to use Putty on Ubuntu or any other Linux, you can certainly do so. Let me show you how to do that.
|
||||
|
||||
### Installing Putty on Ubuntu Linux
|
||||
|
||||
![Installing Putty on Linux][2]
|
||||
|
||||
The good news for the Ubuntu users is that Putty is available in the universe repository of Ubuntu.
|
||||
|
||||
To install Putty on Ubuntu, you should first make sure that the universe repository is enabled.
|
||||
|
||||
```
|
||||
sudo add-apt-repository universe
|
||||
```
|
||||
|
||||
Once you have the universe repository enabled, you should update Ubuntu with this command:
|
||||
|
||||
```
|
||||
sudo apt update
|
||||
```
|
||||
|
||||
After this, you can install Putty with this command:
|
||||
|
||||
```
|
||||
sudo apt install putty
|
||||
```
|
||||
|
||||
Once installed, you can start Putty by finding it in the menu.
|
||||
|
||||
As you can see in the screenshot below, the Linux version of Putty looks the same as the Windows version. That’s a relief because you won’t have to fiddle around trying to find your way through a new and changed settings.
|
||||
|
||||
![Putty in Linux][3]
|
||||
|
||||
When you enter the remote system’s [hostname][4] or IP address and connect to it, Putty will utilize the already saved SSH keys in your home directory.
|
||||
|
||||
![Using Putty in Ubuntu Linux][5]
|
||||
|
||||
### Installing Putty on other Linux distributions
|
||||
|
||||
[Putty is available for Debian][6] so you just need to use apt-get or aptitude for installing it.
|
||||
|
||||
```
|
||||
sudo apt-get install putty
|
||||
```
|
||||
|
||||
Putty is also available for Fedora/Red Hat and can be installed using the default package manager.
|
||||
|
||||
```
|
||||
sudo dnf install putty
|
||||
```
|
||||
|
||||
You can also easily install Putty in Arch Linux based distributions.
|
||||
|
||||
```
|
||||
sudo pacman -S putty
|
||||
```
|
||||
|
||||
Remember that Putty is an open source software. You can also install it via source code if you really want to. You can get the source code of Putty from the link below.
|
||||
|
||||
[Download Putty Source Code][8]
|
||||
|
||||
I would always prefer the native Linux terminal over an SSH client like Putty. I feel more at home with the GNOME terminal or [Terminator][7]. However, it’s up to an individual’s choice to use the default terminal or Putty in Linux
|
||||
|
||||
What do you use for managing multiple SSH connections on Linux?
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/putty-linux/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者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/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.putty.org/
|
||||
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/Putty-linux.png?resize=800%2C450&ssl=1
|
||||
[3]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/putty-interface-ubuntu.jpeg?resize=800%2C503&ssl=1
|
||||
[4]: https://itsfoss.com/change-hostname-ubuntu/
|
||||
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/12/putty-interface-ubuntu-1.jpeg?resize=800%2C430&ssl=1
|
||||
[6]: https://packages.debian.org/jessie/putty
|
||||
[7]: https://launchpad.net/terminator
|
||||
[8]: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
|
85
sources/tech/20181211 Winterize your Bash prompt in Linux.md
Normal file
85
sources/tech/20181211 Winterize your Bash prompt in Linux.md
Normal file
@ -0,0 +1,85 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Winterize your Bash prompt in Linux)
|
||||
[#]: via: (https://opensource.com/article/18/12/linux-toy-bash-prompt)
|
||||
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
|
||||
|
||||
Winterize your Bash prompt in Linux
|
||||
======
|
||||
Your Linux terminal probably supports Unicode, so why not take advantage of that and add a seasonal touch to your prompt?
|
||||

|
||||
|
||||
Hello once again for another installment of the Linux command-line toys advent calendar. If this is your first visit to the series, you might be asking yourself what a command-line toy even is? Really, we're keeping it pretty open-ended: It's anything that's a fun diversion at the terminal, and we're giving bonus points for anything holiday-themed.
|
||||
|
||||
Maybe you've seen some of these before, maybe you haven't. Either way, we hope you have fun.
|
||||
|
||||
Today's toy is super-simple: It's your Bash prompt. Your Bash prompt? Yep! We've got a few more weeks of the holiday season left to stare at it, and even more weeks of winter here in the northern hemisphere, so why not have some fun with it.
|
||||
|
||||
Your Bash prompt currently might be a simple dollar sign ( **$** ), or more likely, it's something a little longer. If you're not sure what makes up your Bash prompt right now, you can find it in an environment variable called $PS1. To see it, type:
|
||||
|
||||
```
|
||||
echo $PS1
|
||||
```
|
||||
|
||||
For me, this returns:
|
||||
|
||||
```
|
||||
[\u@\h \W]\$
|
||||
```
|
||||
|
||||
The **\u** , **\h** , and **\W** are special characters for username, hostname, and working directory. There are others you can use as well; for help building out your Bash prompt, you can use [EzPrompt][1], an online generator of PS1 configurations that includes lots of options including date and time, Git status, and more.
|
||||
|
||||
You may have other variables that make up your Bash prompt set as well; **$PS2** for me contains the closing brace of my command prompt. See [this article][2] for more information.
|
||||
|
||||
To change your prompt, simply set the environment variable in your terminal like this:
|
||||
|
||||
```
|
||||
$ PS1='\u is cold: '
|
||||
jehb is cold:
|
||||
```
|
||||
|
||||
To set it permanently, add the same code to your **/etc/bashrc **using your favorite text editor.
|
||||
|
||||
So what does this have to do with winterization? Well, chances are on a modern machine, your terminal support Unicode, so you're not limited to the standard ASCII character set. You can use any emoji that's a part of the Unicode specification, including a snowflake ❄, a snowman ☃, or a pair of skis 🎿. You've got plenty of wintery options to choose from.
|
||||
|
||||
```
|
||||
🎄 Christmas Tree
|
||||
🧥 Coat
|
||||
🦌 Deer
|
||||
🧤 Gloves
|
||||
🤶 Mrs. Claus
|
||||
🎅 Santa Claus
|
||||
🧣 Scarf
|
||||
🎿 Skis
|
||||
🏂 Snowboarder
|
||||
❄ Snowflake
|
||||
☃ Snowman
|
||||
⛄ Snowman Without Snow
|
||||
🎁 Wrapped Gift
|
||||
```
|
||||
|
||||
Pick your favorite, and enjoy some winter cheer. Fun fact: modern filesystems also support Unicode characters in their filenames, meaning you can technically name your next program **"❄❄❄❄❄.py"**. That said, please don't.
|
||||
|
||||
Do you have a favorite command-line toy that you think I ought to include? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.
|
||||
|
||||
Check out yesterday's toy, [Snake your way across your Linux terminal][3], and check back tomorrow for another!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/12/linux-toy-bash-prompt
|
||||
|
||||
作者:[Jason Baker][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/jason-baker
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: http://ezprompt.net/
|
||||
[2]: https://access.redhat.com/solutions/505983
|
||||
[3]: https://opensource.com/article/18/12/linux-toy-snake
|
@ -1,94 +0,0 @@
|
||||
The Source History of Cat
|
||||
======
|
||||
以前我和我的一些亲戚争论过计算机科学的学位值不值得读。当时我正在上大学,并要决定是不是该主修计算机。我姨和我一表姐觉得我不应该主修计算机。她们承认知道如何编程肯定是很有用且对自己有利的一件事,但是她们认为计算机科学现在发展的如此迅速以至于我学的东西几乎马上就过时了。建议我更好是把编程作为辅业,选择一个基础原理可以受用终身的领域主修,比如经济学或物理学。
|
||||
|
||||
我知道我姨和我表姐说的不对,并决定主修计算机科学。(对不住啊!)平常人可能会觉得像计算机科学领域和软件工程专业每隔几年就完全和之前不一样了。其原因很容易理解。我们有了个人电脑,然后有了互联网,有了手机,之后还有了机器学习…… 科技总是在更新,支撑科技发展的原理和技能当然也在改变。当然,最惊人的是其实原理的改变竟然如此之小。我敢肯定,大多数人在知道了他们电脑里一些重要的软件的历史是多么久远时他们一定会深感震惊。当然我不是说那些刷版本号的浮夸软件 —— 我电脑上的 Firefox 浏览器副本,可能是我用的最多的软件,可能才更新不到两周。如果你看了比如 `grep` 的手册页,你就会发现他在 2010 年后就没有过更新了(至少在 MacOS 上如此)。初版 `grep` 是在 1974 年写就的,那时可以算是计算机世界的侏罗纪了。直到现在,人们(还有程序)仍然依赖 `grep` 来完成日常工作。
|
||||
|
||||
我姨和我表姐认为计算机技术就像一系列日渐精致的沙堡,在潮水抹净沙滩后新的沙堡完全取代旧的。但事实上,在很多领域上,我们都是不断积累能够解决问题的程序。我们可能不得不偶尔修改这些程序以避免软件无法使用,但大多数情况下我们都可以不修改。 `grep` 是一个简单的程序,可以解决一个仍然存在的问题,所以它能够存活下来。 大多数应用程序编程都是在非常高的级别上完成的,他们建立在解决了旧问题的程序的金字塔上。 30年或40年前的想法和概念,远非过时,在很多情况下他们依然在您的笔记本电脑上软件中存在着。
|
||||
|
||||
我想追溯这样的老程序自第一次写就以来改变了多少回很有趣。 `cat`可能是所有 Unix 实用程序中最简单的,因此我们以它为例。 Ken Thompson于 1969 年编写了 `cat` 的原始实现。如果我告诉别人我的电脑上安了个 1969 年的程序,这准确吗?我们电脑上的程序多大了?
|
||||
|
||||
感谢这种[这种][1]仓库,我们可以完整的看到 `cat` 自 1969 年后是如何发展的。我会先聚焦于可以算得上是我的 MacBook 上的 `cat` 的祖先的 `cat` 实现。随着我们从 Unix 上的第一版 `cat` 追踪到现在 MacOS 上的 `cat`,你会发现,这个程序被重写的次数比你想的还要多 —— 但是直到现在它运行的方式和五十年前多少是完全一致的。
|
||||
|
||||
### 研究 Unix
|
||||
|
||||
Ken Thompson 和 Dennis Ritchie 在 PDP 7 上开始写 Unix。那还是 1969 年,C 还没被发明出来,因此所有早期的 Unix 软件都是用 PDP 7 汇编实现的。他们使用的汇编种类是 Unix 特有的,Ken Thompson 在 DEC,也就是 PDP 7 的厂商提供的汇编器之上加了些特性,实现了自己的汇编器。Thompson 的更改在[最初的 Unix 程序员手册][2]的 `as`(也就是汇编器)条目下均有所记录。
|
||||
|
||||
因此,[最初的][3] `cat` 也是使用 PDP 7 汇编实现的。 我添加了一些注释,试图解释每条指令的作用,但除非你理解 Thompson 在编写汇编器时加的特性,否则程序仍然很难理解。在那些特性中有两个很重要:其一是 `;` 这个字符可以在一行中用来分隔多条语句,它多出现于在使用 `sys` 指令时将系统调用的多个参数放在同一行上。其二是, Thompson 的汇编器支持使用 0 到 9 作为“临时标签”,也就是在程序内可以重用的标签。因此。就如 Unix 程序员手册中所说:“对程序员的想象力和汇编程序的符号空间的要求都降低了”。在任何给定的指令内,你都可以使用 `nf` 和 `nb` 来引用下一个或最近的临时标签 `n`。 例如,如果存在标记为 `1:` 的代码块,你就可以使用指令 `jmp 1b` 从下游代码跳回该块。 (但是你不使用 `jmp 1f` 的话就没法从上面的代码跳到这里。)
|
||||
|
||||
初版 `cat` 最有趣的就是它包含着我们应该认识的符号。有一块指令快标记为 `getc`,还有一个标记为 `putc`,可以看到这两个符号比 C 标准还古老。第一版的 `cat` 函数实际上已经包含了这两个函数的实现。这个 `cat` 实现做了缓存,这样他就不需要一次只读写一个字母。
|
||||
|
||||
`cat` 的第一个版本并没有持续多久。 Ken Thompson 和 Dennis Ritchie 说服贝尔实验室购买了 PDP 11,这样他们就能够继续扩展和改进 Unix。 PDP 11 的指令集和之前不一样,因此必须重写 `cat`。 我也注释了[这个第二版][4] `cat`。 它为新的指令集使用新的汇编程序助记符,并利用了 PDP 11 的各种[寻址模式][5]。(如果你对源代码中的括号和美元符号感到困惑,那是因为这些符号用于指示不同的寻址模式。)但它也使用 `;` 字符和临时标签,和 `cat` 的第一个版本一样,这意味着当把 `as` 移植到 PDP 11 上时,必须要保留这些功能。
|
||||
|
||||
`cat` 的第二个版本比第一个版本简单得多。 它也更有 Unix 味儿,它不只是依靠参数列表,一旦没给参数列表,它将从 `stdin` 读取数据,这也就是今天 `cat` 仍在做的事情。 你也也可以在此版本的 `cat` 中以 `-` 为参数,以表示它应该从`stdin`读取。
|
||||
|
||||
在 1973 年,为了准备发布第四版 Unix,大部分代码都用 C 语言重写了。但是 `cat` 似乎在之后一段时间内并没有使用 C 重写。 [`cat` 的第一个 C 语言实现][6]出现在第七版 Unix 中。 这个实现非常有趣,因为它很简单。 在所有要以后的实现中,这个实现和在 K&R 的 C语言教科书中用作教学示范的理想化 `cat` 最相似。这个程序的核心就是经典的两行:
|
||||
|
||||
```
|
||||
while ((c = getc(fi)) != EOF)
|
||||
putchar(c);
|
||||
```
|
||||
|
||||
当然实际代码要比这多一些,额外的代码主要是为了确保你没有在读/写同一个文件。另一个有趣的事情是,`cat` 的这一版实现只识别一个标志位 `-u`。 `-u` 标志可用于避免缓冲输入和输出,否则 `cat` 将以 512 字节为块进行输入输出。
|
||||
|
||||
### BSD
|
||||
|
||||
在第七版之后,Unix 出现了了各种衍生品和分支。 MacOS 建立于 Darwin 之上,而 Darwin 又源自 Berkeley Software Distribution(BSD),因此 BSD 是我们最感兴趣的Unix 分支。 BSD 最初只是 Unix 中的实用程序和附加组件的集合,但它最终成为了一个完整的操作系统。直到第四版 BSD,人称 4BSD,为一大堆新标志添加了支持之前,BSD 似乎还是依赖于最初的 `cat` 实现的。`cat` 的 [4BSD 实现][7] 显然是从原始实现中衍生出来的,尽管它添加了一个新函数来实现新标志触发的行为。按照已经在文件中使用由用于标记输入是从`stdin`还是文件读取的 `fflg` 变量指定的命名约定。被新添加的 `nflg`,`bflg`,`vflg`,`sflg`,`eflg`和`tflg` 保存了下来,这些变量记录了在调用程序时是否使用了这些新标志。这些是最后一批添加到 `cat` 的命令行标志。如今 `cat` 的手册页列出了这些标志,没有其他的标志了,至少在Mac OS上是如此。 4BSD 于1980年发布,因此这套标志已有 38 年历史。
|
||||
|
||||
`cat` 最后一次被完全重写是在 BSD NET/2 上,其目的是通过替换全部 AT&T 发布的 Unix 源代码来规避许可证问题。BSD Net/2 在 1991 年发布。这一版本的 `cat` 是由 Kevin Fall 重写的。 Kevin Fall 于 1988 年毕业于加州大学伯克利分校并在下一年成为计算机系统研究组(CSRG)的组员,Fall 和我说当时使用 AT&T 代码的 Unix 工具被列在了 CSRG 的墙上,组员需要从中选出他们想要重写的工具; Fall 选了 `cat` 以及 `mknod`。 MacOS 系统内自带的 `cat` 实现源码的最上面还有着他的名字。他的这一版 `cat`,尽管平淡无奇,在今天还是被无数人使用着。
|
||||
|
||||
[Fall的原始 `cat `实现][8] 比我们迄今为止看到的程序都要长。 除了支持 `-?` 帮助标志外,它没有增加任何新功能。 从概念上讲,它与 4BSD 的实现非常相似。 它长是因为 Fall 将实现分为 “原始” 模式和 “熟” 模式。 “原始” 模式是 `cat ` 的经典实现; 它一个字符一个字符的打印文件。 “熟” 模式是带有所有 4BSD 命令行选项的 `cat`。 如此区别不无道理,但这么办也扩充了实现规模,因此乍一看其源码似乎比实际上更复杂。文件末尾还有一个奇特的错误处理函数,进一步地增加了实现的长度。
|
||||
|
||||
### MacOS
|
||||
|
||||
在 2001 年,苹果发布了 MacOS X。这一发布对苹果意义重大。因为苹果花了很多年时间来尝试并且取代现有的过时操作系统(经典的Mac OS),但是都失败了。 在 Mac OS X 之前苹果两次尝试在内部创建一个新的操作系统,但两者都无疾而终。 最后,苹果收购了史蒂夫 · 乔布斯的 NeXT 公司,后者开发了一个名为 NeXTSTEP 的操作系统和面向对象编程框架。 苹果将 NeXTSTEP 作为Mac OS X的基础。因为 NeXTSTEP 部分基于 BSD,使以 NeXTSTEP 为基础的 Mac OS X的自然就把 BSD 系的代码直接带入苹果宇宙的中心。
|
||||
|
||||
因此,Mac OS X的第一个版本包含了从 NetBSD 项目中提取的 `cat` 的[实现][9]。如今仍在开发中的 NetBSD 最初是 386BSD 的分支,而后者又直接基于 BSD Net/2。所以Mac OS X里面的第一个 `cat` 的实现就是 Kevin Fall的 `cat`。唯一改变的是,Fall 的错误处理函数 `err()` 被 `err.h` 提供的`err()` 函数取代了。 `err.h` 是 C 标准库的 BSD 扩展。
|
||||
|
||||
之后不久,`cat` 的 NetBSD 实现被换成了 FreeBSD 中的 `cat` 实现。 [根据维基百科][10],苹果在Mac OS X 10.3(Panther) 中开始使用 FreeBSD 的实现而不是 NetBSD 的实现。但根据苹果自己开源的版本,`cat` 的Mac OS X实现在2007年发布的 Mac OS X 10.5(Leopard) 之前没有被替换。苹果为 Leopard 替换的的 [FreeBSD 实现][11]与今天苹果计算机上的实现相同。截至 2018 年,此实现仍未被更新或修改。
|
||||
|
||||
所以Mac OS 上的 `cat` 已经很老了。实际上,这一实现在 2007 年在 MacOS X 上露面两年前就被发布了。 [这个 2005 年的修改][12] 在 FreeBSD 的 Github 镜像中可见,是在苹果将其合并入 Mac OS X 前对 FreeBSD 的 `cat` 实现进行的最后一次更改。所以 Mac OS X 的没有与 FreeBSD 的 `cat` 实现保持同步的 `cat`实现,如今 13 岁了。对于软件修改了多少代码才能仍是算是同一软件这一话题有着旷日持久的争论。不过,在这种情况下,源文件自 2005 年以来根本没有变化。
|
||||
|
||||
现在 Mac OS 使用的 `cat` 实现与 Fall 1991年为 BSD Net/2 版本编写的实现没有什么不同。最大的区别是添加了一个全新的功能来提供 Unix 域套接字支持。FreeBSD 开发人员似乎将 Fall 的 `raw_args()` 函数和 `cook_args()` 函数组合成一个名为`scanfiles()`的函数。要没有的话,程序的核心就仍是 Fall 的代码。
|
||||
|
||||
我问过 Fall 对编写如今被数以百万计的苹果用户直接或者通过依赖 `cat` 的程序间接使用的 `cat` 实现有何感想。Fall,如今是最新版 TCP/IP 详解的顾问和合著者,说,当人们从了解他对 `cat` 所做的的工作中收获颇丰时,他感到很惊讶。 Fall 在计算机领域有着悠久的职业生涯,曾参与许多备受瞩目的项目,但似乎很多人仍对他在 1989 年重写 `cat` 的那六个月的工作感到最为兴奋。
|
||||
|
||||
### 百年老程序
|
||||
|
||||
在宏伟的发明史中,计算机并不是一项古老的发明。我们已经习惯了百年的照片甚至是百年的视频短片。但是计算机程序不一样 - 它们代表着高科技和新技术。至少,他们是现代的技术造出来的。随着计算行业的成熟,我们有朝一日会发现自己正在使用有着接近百年历史的程序吗?
|
||||
|
||||
计算机硬件可能会发生较大的变化,使得我们也许无法让现在编译的可执行文件在一个世纪后的硬件上运行。也许编程语言设计的进步让未来没有人能理解 C 语言,`cat` 将来也可能也被别的语言重写很久了。 (尽管 C已经存在了五十年了,而且它似乎不会很快就被替换掉。)但除此之外,为什么不永远使用我们现在的 `cat`?
|
||||
|
||||
我认为 `cat` 的历史表明,计算机科学中的一些想法确实非常持久。事实上,对于 `cat`,这个想法和程序本身都很古老。不准确地说,我的电脑上的 `cat` 来自1969 年。但我也可以说我的计算机上的 `cat` 来自1989 年,当时 Fall 写了他的 `cat` 实现。许多其他软件也同样古老。因此,也许我们不应该把计算机科学和软件开发视为不断破坏现状和发明新事物的领域。我们的计算机系统是由诸多历史文物构建的。有时,我们可能会花费更多时间在理解和维护这些历史文物上,而不是花在编写新代码上。
|
||||
|
||||
如果你喜欢本文,你可能更喜欢两周来一篇更新!在推特上关注 [@TwoBitHistory][13] 或者订阅这个 [RSS 源][14] 以保证接受到新的文章。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://twobithistory.org/2018/11/12/cat.html
|
||||
|
||||
作者:[Two-Bit History][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[name1e5s](https://github.com/name1e5s)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://twobithistory.org
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://github.com/dspinellis/unix-history-repo
|
||||
[2]: https://www.bell-labs.com/usr/dmr/www/man11.pdf
|
||||
[3]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-1-cat-pdp7-s
|
||||
[4]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-2-cat-pdp11-s
|
||||
[5]: https://en.wikipedia.org/wiki/PDP-11_architecture#Addressing_modes
|
||||
[6]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-3-cat-v7-c
|
||||
[7]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-4-cat-bsd4-c
|
||||
[8]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-5-cat-net2-c
|
||||
[9]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-6-cat-macosx-c
|
||||
[10]: https://en.wikipedia.org/wiki/Darwin_(operating_system)
|
||||
[11]: https://gist.github.com/sinclairtarget/47143ba52b9d9e360d8db3762ee0cbf5#file-7-cat-macos-10-13-c
|
||||
[12]: https://github.com/freebsd/freebsd/commit/a76898b84970888a6fd015e15721f65815ea119a#diff-6e405d5ab5b47ca2a131ac7955e5a16b
|
||||
[13]: https://twitter.com/TwoBitHistory
|
||||
[14]: https://twobithistory.org/feed.xml
|
||||
[15]: https://twitter.com/TwoBitHistory/status/1051826516844322821?ref_src=twsrc%5Etfw
|
@ -1,58 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: subject: (10 ways to give thanks to open source and free software maintainers)
|
||||
[#]: via: (https://opensource.com/article/18/11/ways-give-thanks-open-source)
|
||||
[#]: author: (Moshe Zadka https://opensource.com/users/moshez)
|
||||
[#]: url: ( )
|
||||
|
||||
感谢开源和自由软件维护者的 10 种方法
|
||||
======
|
||||
如何表达你的感激之情。
|
||||

|
||||
|
||||
每天,我都使用高质量的软件,这些软件由没有要求付款的人开发和维护,他们尊重我的自由,并且慷慨地付出时间和精力。
|
||||
|
||||
在这个感恩的季节,我鼓励那些也使用和欣赏开源和自由软件维护者工作的人表达你的感激之情。以下是十种方法:
|
||||
|
||||
### 容易做到的
|
||||
|
||||
1. 发送电子邮件,感谢开发人员。具体点说,告诉他们你使用他们的什么软件以及你如何获益的。
|
||||
2. 使用你最喜爱的社交媒体平台宣传它。
|
||||
3. 写一篇关于你最喜欢的软件的博客文章。
|
||||
|
||||
|
||||
|
||||
### 捐款
|
||||
|
||||
4. 如果你最喜欢的开源项目接受捐款,请汇款。
|
||||
5. 如果你受雇于使用开源软件的公司,看你是否可以说服管理层赞助某些项目。
|
||||
6. 提供最高设置额度的捐款。社交动机能做的不可思议!
|
||||
|
||||
|
||||
|
||||
### 花费时间
|
||||
|
||||
7. 帮助查看补丁。
|
||||
8. 帮助分类 bug。
|
||||
9. 回答 IRC、邮件列表或 [Stack Overflow][1] 中的问题。
|
||||
|
||||
|
||||
|
||||
**10. 额外的:**如果你像我一样,你在某个时候对开源社区的其他人说了一些严厉的话。承诺做得更好:用善良和开放沟通。感谢的最好方式是让开源社区成为人们能舒适沟通的地方。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/11/ways-give-thanks-open-source
|
||||
|
||||
作者:[Moshe Zadka][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/moshez
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://meta.stackoverflow.com/
|
@ -1,128 +0,0 @@
|
||||
享受Linux下命令行全操作
|
||||
======
|
||||
|
||||

|
||||
很多文章讨论关于命令行下如何做事情。有多少文章要么用晦涩的方式介绍 `ls` ,要么介绍关于 Sed 和 Awk 一些有意思的正则表达式,要么就是介绍一大堆的 perl 脚本是如何解析的?这些都不是命令行操作的重点。
|
||||
|
||||
本文章是关于[享受命令行全操作][1],在我们不需要图形桌面,网络浏览器或网络连接情况下,用命令行操作能完成实际事务的跟踪。为了达到这一点,我们将介绍四个途径跟踪你的待办清单:纯文件文件,Todo.txt,TaskWarrior,Org-mode。
|
||||
|
||||
### 纯文本
|
||||
|
||||
![plaintext][3]
|
||||
|
||||
我喜欢用 Vim ,其实你也可以喜欢 Nano。
|
||||
|
||||
最直接管理管理你的待办清单的方式就是用纯文本文件来编辑。只需要打开一个空文件,每一行添加一个任务。当任务完成后,删除这一行,简单有效,不用再关心这一行之前干什么用的了。不过这个方法也有缺点,一点你删除一行并保存了文件,它就是永远消失了。如果你想知道本周或者上周都做了哪些事情,就成了问题。使用简单文本文件很方便却也容易导致混乱。
|
||||
|
||||
### Todo.txt: 纯文件的升级版
|
||||
|
||||
|
||||
![todo.txt screen][5]
|
||||
|
||||
整洁,有条理,易用
|
||||
|
||||
这就是我们要说的 [Todo.txt][6] 格式文件和应用程序。安装可从 GitHub [下载][7]最新的版本解压后并执行命令 `sudo make install`
|
||||
|
||||
![安装 todo.txt][9]
|
||||
|
||||
也可以从 Git 克隆一个。
|
||||
|
||||
Todo.txt 可以很容易的增加新任务,并能显示任务列表和已完成任务的标记:
|
||||
|
||||
|||
|
||||
| ------------- |:-------------|
|
||||
| `todo.sh add "某任务"` | 增加 "某任务" 到你的待办列表 |
|
||||
| `todo.sh ls` | 显示所有的任务 |
|
||||
| `todo.sh ls due:2018-02-15` | 显示2018-02-15之前的所有任务 |
|
||||
| `todo.sh do 3` | 标记任务3 为已完成任务 |
|
||||
|
||||
清单实际上仍然是纯文本,你可以用你喜欢的编辑器遵循[正确的格式][10]编辑它。
|
||||
|
||||
应用程序同时也内置了一个强大的帮助。
|
||||
|
||||
|
||||
![在 todo.txt 中语法高亮][12]
|
||||
|
||||
你可以使用语法高亮的功能
|
||||
|
||||
此外,还有许多附加组件可供选择,以及编写自己的附件组件规范。甚至有浏览器组件,移动设备应用程序和桌面应用程序支持 Todo.txt 的格式。
|
||||
|
||||
|
||||
![GNOME extensions in todo.txt][14]
|
||||
|
||||
GNOME的扩展组件
|
||||
|
||||
Todo.txt 最大的缺点是缺少自动或内置的同步机制。大多数(不是全部)的浏览器扩展程序和移动应用程序需要用 Dropbox 实现桌面系统和应用程序直接的数据同步。如果你想内置同步机制,我们也有……
|
||||
|
||||
### Taskwarrior: 现在我们用 Python 做事了
|
||||
|
||||
[Taskwarrior][15] 是一个与Todo.txt 有许多相同功能的 Python 工具。但不同的是它的数据保存在数据库里并具有内置的数据同步功能。它还可以跟踪即将要做的任务,可以提醒某个任务持续了多久,可以提醒你一些重要的事情应该马上去做。
|
||||
|
||||
[安装][16] Taskwarrior 可以通过通过发行版自带的包管理器,或通过 Python 命令 `pip`安装,或者用源码编译。用法也和 Todo.txt 的命令完全一样:
|
||||
|
||||
|||
|
||||
| ------------- |:-------------|
|
||||
| `task add "某任务"` | 增加 "某任务" 到任务清单 |
|
||||
| `task list` | 列出所有任务 |
|
||||
| `task list due ``:today` |列出截止今天的任务 |
|
||||
| `task do 3` | 标记编号是3的任务为完成状态 |
|
||||
|
||||
Taskwarrior 还有漂亮的文本用户界面。
|
||||
|
||||
![Taskwarrior in Vit][18]
|
||||
|
||||
我喜欢 Vit, 它的设计灵感来自 Vim.
|
||||
|
||||
不同于 Todo.txt,Taskwarrior 可以和本地或远程服务器同步信息。如果你希望运行自己的同步服务器可以使用名为 `taskd` 的基础服务器,如果不使用自己的服务器也有好几个可用服务器。
|
||||
|
||||
Taskwarriot 还拥有一个蓬勃发展的插件和扩展生态系统,这和移动和桌面系统的应用生态类似。
|
||||
|
||||
![GNOME in Taskwarrior ][20]
|
||||
|
||||
在 GNOME 下的 Taskwarrior 看起来还是很漂亮的。
|
||||
|
||||
Taskwarrior 有一个唯一的缺点,你是不能直接修改待办任务的,这和其他的工具不一样。你只能把任务清单按照格式导出,然后修改导出文件后,重新再导入,这样相对于编辑器直接编辑任务还是挺麻烦的。
|
||||
|
||||
谁能给我们带来最大的希望呢......
|
||||
|
||||
### Emacs Org-mode: 牛逼的任务收割机
|
||||
|
||||
![Org-mode][22]
|
||||
|
||||
Emacs 具有所有优点。
|
||||
|
||||
Emacs [Org-mode][23] 是目前为止最强大,最灵活的开源待办任务管理器。它支持多文件,使用纯文本,高度定制和自动识别日期,截止日期和任务计划。相对于我们这里介绍的其他工具,它的配置也更复杂一些。但是一旦配置好,她可以比其他工具完成更多功能。如果你是熟悉或者是 [Bullet Journals][24] 的粉丝,Org-mode 可能是在桌面程序里最像[Bullet Journals][24]的了。
|
||||
|
||||
Org-mode 可以运行在任何 Emacs 运行的地方,一些移动应用程序可以和它很好交互。但是不幸的是,目前没有桌面程序或浏览器插件支持Org-mode。尽管如此,Org-mode仍然是跟踪待办事项最好的应用程序之一,因为他确实很强大。
|
||||
|
||||
### 选择适合自己的工具
|
||||
|
||||
最后,这些程序目的是帮助你跟踪待办事务并确保不会忘记做某个事情。这些程序的基础功能都大同小异,那一款适合你取决于多种因素。有的人需要自带同步功能,有的人需要一个移动客户端,有的人要必须支持插件。不管你选择什么,请记住程序本身不会让你更有调理,但是可以帮助你。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/2/getting-to-done-agile-linux-command-line
|
||||
|
||||
作者:[Kevin Sonney][a]
|
||||
译者:[guevaraya](https://github.com/guevaraya)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/ksonney (Kevin Sonney)
|
||||
[1]:https://www.scruminc.com/getting-done/
|
||||
[3]:https://opensource.com/sites/default/files/u128651/plain-text.png (plaintext)
|
||||
[5]:https://opensource.com/sites/default/files/u128651/todo-txt.png (todo.txt screen)
|
||||
[6]:http://todotxt.org/
|
||||
[7]:https://github.com/todotxt/todo.txt-cli/releases
|
||||
[9]:https://opensource.com/sites/default/files/u128651/todo-txt-install.png (Installing todo.txt)
|
||||
[10]:https://github.com/todotxt/todo.txt
|
||||
[12]:https://opensource.com/sites/default/files/u128651/todo-txt-vim.png (Syntax highlighting in todo.txt)
|
||||
[14]:https://opensource.com/sites/default/files/u128651/tod-txt-gnome.png (GNOME extensions in todo.txt)
|
||||
[15]:https://taskwarrior.org/
|
||||
[16]:https://taskwarrior.org/download/
|
||||
[18]:https://opensource.com/sites/default/files/u128651/taskwarrior-vit.png (Taskwarrior in Vit)
|
||||
[20]:https://opensource.com/sites/default/files/u128651/taskwarrior-gnome.png (Taskwarrior on GNOME)
|
||||
[22]:https://opensource.com/sites/default/files/u128651/emacs-org-mode.png (Org-mode)
|
||||
[23]:https://orgmode.org/
|
||||
[24]:http://bulletjournal.com/
|
@ -1,71 +0,0 @@
|
||||
Emacs #4:使用org-mode自动管理邮件及同步文档
|
||||
======
|
||||
这是 [Emacs 和 org-mode 系类][4]的第四篇。
|
||||
|
||||
至今为止,你已经见识到了 org-mode 的强大和高效,如果你像我一样,你可能会想:
|
||||
|
||||
“我真的很想让它在我所有的设备上同步。”
|
||||
|
||||
或者是说:
|
||||
|
||||
“我能在 org-mode 中转发邮件吗?”
|
||||
|
||||
答案当然是肯定的,因为这就是 Emacs。
|
||||
|
||||
### 同步
|
||||
|
||||
由于 org-mode 只使用文本文件,所以使用任意工具都可以很容易地实现同步。我使用的是 git 的 git-remote-gcrypt。由于 git-remote-gcrypt 的一些限制,每台机器都倾向于推到自己的分支,并使用命令来控制。每台机子都会先合并其他所有的 branch 然后再将合并后的结果 push 到 master 上。cron 作业可以实现将机器上的 branch push 上去,而 elisp 会协调这一切--确保在同步之前保存缓冲区,在同步之后从磁盘刷新缓冲区,等等。
|
||||
|
||||
这篇文章的代码有点多,所以我将把它链接到 github 上,而不是写在这里。
|
||||
|
||||
|
||||
我有一个用来存放我所有的 org-stuff 的目录 $HOME/org,在 ~/org 目录下有个 [Makefile][2] 文件来处理同步。该文件定义了一下目标:
|
||||
* push: 添加,提交和 push 到以主机命名的 branch 上
|
||||
* fetch: 一个简单的 git fetch
|
||||
* sync: 添加,提交和 pull 远程的修改,合并并将其 push 到以主机命名的 branch 和 master 上(假设合并成功)
|
||||
|
||||
|
||||
现在,在我的用户 crontab 中有这个:
|
||||
```
|
||||
*/15 * * * * make -C $HOME/org push fetch 2>&1 | logger --tag 'orgsync'
|
||||
|
||||
```
|
||||
[accompanying elisp code][3] 定义了一个快捷键(C-c s)来调用同步。多亏了 cronjob,只要文件被保存 -- 即使我没有在另一个 boxen 上同步 -- 它们也会被 pull 进来。
|
||||
|
||||
我发现这个设置非常好用。
|
||||
|
||||
### 用 org-mode 发邮件
|
||||
|
||||
在继续下去之前,首先要问自己一下:你真的需要它吗? 我用的是带有 [mu4e][4] 的 org-mode,而且它集成的也很好;任何组织任务都可以通过 message-id 链接到电子邮件,这很理想 -- 它可以让一个人做一些事情,比如提醒他在一周内回复一条消息。
|
||||
|
||||
然而,org 不仅仅只有提醒。它还是一个知识库、创作系统等,但是并不是我所有的邮件客户端都使用 mu4e。(注意:像 MobileOrg 是存在于移动设备中)。我并没有像我想的那样经常使用它,但是它有它的用途,所以我认为我也应该在这里记录它。
|
||||
|
||||
现在我不仅想处理纯文本电子邮件。我希望能够处理附件、HTML 邮件等。这听起来很快就有问题了 -- 但是通过使用 ripmime 和 pandoc 这样的工具,情况还不错。
|
||||
|
||||
第一步就是要用某些方法将获取到的邮件放入指定的文件夹下。扩展名,特殊用户等。然后我用 [fetchmail configuration][5] 来将它 pull 下来并运行我自己的 [insorgmail][6] 脚本。
|
||||
|
||||
这个脚本就是处理所有有趣的部分了。它从 ripmime 开始处理消息,用 pandoc 将HTML 的部分转换为 org 格式。 org 的层次结构是用来尽可能最好地表示 email 的结构。使用HTML和其他工具时,email 可能会变得相当复杂,但我发现这对于我来说是可以接受的。
|
||||
|
||||
### 下一篇
|
||||
|
||||
我最后一篇关于 org-mode 的文章将讨论如何使用它来编写文档和准备幻灯片 -- 我发现自己对 org-mode 的使用非常满意,但这需要一些调整。
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://changelog.complete.org/archives/9898-emacs-4-automated-emails-to-org-mode-and-org-mode-syncing
|
||||
|
||||
作者:[John Goerzen][a]
|
||||
译者:[oneforalone](https://github.com/oneforalone)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://changelog.complete.org/
|
||||
[1]:https://changelog.complete.org/archives/tag/emacs2018
|
||||
[2]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/Makefile
|
||||
[3]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/emacs-config.org
|
||||
[4]:https://www.emacswiki.org/emacs/mu4e
|
||||
[5]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/fetchmailrc.orgmail
|
||||
[6]:https://github.com/jgoerzen/public-snippets/blob/master/emacs/org-tools/insorgmail
|
@ -0,0 +1,469 @@
|
||||
数据科学家的命令行技巧
|
||||
======
|
||||
|
||||

|
||||
|
||||
对于许多数据科学家来说,数据操作始于和结束于 Pandas 或 Tidyverse。从理论上讲,这样做没有任何问题。毕竟,这就是这些工具存在的原因。然而,对于像分隔符转换这样的简单任务,这些工具是大材小用了。
|
||||
|
||||
立志掌握命令行应该在每个开发人员的清单上,特别是数据科学家。学习 shell 的来龙去脉将无可否认地提高你的生产力。除此之外,命令行还是计算领域的一个重要历史课程。例如,awk - 一种数据驱动的脚本语言。1977年,在传奇的 [K&R 书][2]中 K 即 [Brain Kernighan][1] 的帮助下,Awk 首次出现。今天,大约五十年过去了,awk 仍然和每年出现的[新书][3]相关。因此,可以安全地假设对命令行魔法的投资不会很快贬值。
|
||||
|
||||
### 我们将涵盖什么
|
||||
|
||||
* ICONV
|
||||
* HEAD
|
||||
* TR
|
||||
* WC
|
||||
* SPLIT
|
||||
* SORT & UNIQ
|
||||
* CUT
|
||||
* PASTE
|
||||
* JOIN
|
||||
* GREP
|
||||
* SED
|
||||
* AWK
|
||||
|
||||
|
||||
|
||||
### ICONV
|
||||
|
||||
文件编码可能会很棘手。现在大部分文件都是 UTF-8 编码的。要了解 UTF-8 背后的一些魔力,请查看这个出色的[视频][4]。尽管如此,有时我们收到的文件不是这种格式。这可能引起对改变编码模式的一些不靠谱尝试。这里,iconv 是一个拯救者。Iconv 是一个简单的程序,它将获取采用一种编码的文本并输出采用另一种编码的文本。
|
||||
```
|
||||
# Converting -f (from) latin1 (ISO-8859-1)
|
||||
# -t (to) standard UTF_8
|
||||
|
||||
iconv -f ISO-8859-1 -t UTF-8 < input.txt > output.txt
|
||||
```
|
||||
|
||||
* 实用选项:
|
||||
|
||||
* `iconv -l` 列出所有已知编码
|
||||
* `iconv -c` 默默丢弃无法转换的字符
|
||||
|
||||
|
||||
|
||||
### HEAD
|
||||
|
||||
如果你是一个频繁的 Pandas 用户,那么会很熟悉 `head`。通常在处理新数据时,我们想做的第一件事就是了解其内容。这导致启动 Pandas,读取数据然后调用 `df.head()` \- 这至少是费劲的。没有任何标志的 Head 将打印出文件的前10行。`head` 的真正力量在于测试出来干净利落的操作。例如,如果我们想将文件的分隔符从逗号更改为管道。一个快速测试将是:`head mydata.csv | sed 's/,/|/g'`。
|
||||
```bash
|
||||
# Prints out first 10 lines
|
||||
head filename.csv
|
||||
|
||||
# Print first 3 lines
|
||||
head -n 3 filename.csv
|
||||
```
|
||||
|
||||
* 实用选项:
|
||||
|
||||
* `head -n` 打印特定行数
|
||||
* `head -c` 打印具体的字节数
|
||||
|
||||
|
||||
|
||||
### TR
|
||||
|
||||
Tr 类似于翻译。这个功能强大的实用程序是基本文件清理的主力。理想的用例是交换文件中的分隔符。
|
||||
```bash
|
||||
# Converting a tab delimited file into commas
|
||||
cat tab_delimited.txt | tr "\t" "," comma_delimited.csv
|
||||
```
|
||||
|
||||
`tr` 另一个功能是在你支配中的内建 `[:class:]` 变量(POSIX 字符类)。这些包括了:
|
||||
|
||||
```
|
||||
[:alnum:] all letters and digits
|
||||
[:alpha:] all letters
|
||||
[:blank:] all horizontal whitespace
|
||||
[:cntrl:] all control characters
|
||||
[:digit:] all digits
|
||||
[:graph:] all printable characters, not including space
|
||||
[:lower:] all lower case letters
|
||||
[:print:] all printable characters, including space
|
||||
[:punct:] all punctuation characters
|
||||
[:space:] all horizontal or vertical whitespace
|
||||
[:upper:] all upper case letters
|
||||
[:xdigit:] all hexadecimal digits
|
||||
```
|
||||
|
||||
你可以将这些连接在一起以组成强大的程序。以下是一个基本的字数统计程序,可用于检查自述文件是否过度使用。
|
||||
```
|
||||
cat README.md | tr "[:punct:][:space:]" "\n" | tr "[:upper:]" "[:lower:]" | grep . | sort | uniq -c | sort -nr
|
||||
```
|
||||
|
||||
另一个使用基本正则表达式的例子:
|
||||
```
|
||||
# Converting all upper case letters to lower case
|
||||
cat filename.csv | tr '[A-Z]' '[a-z]'
|
||||
```
|
||||
|
||||
* 实用选项:
|
||||
|
||||
* `tr -d` 删除字符
|
||||
* `tr -s` 压缩字符
|
||||
* `\b` 退格
|
||||
* `\f` 换页
|
||||
* `\v` 垂直制表符
|
||||
* `\NNN` 八进制字符
|
||||
|
||||
|
||||
|
||||
### WC
|
||||
|
||||
单词数量。它的值主要来自 `-l` 标志,它会给你提供行数。
|
||||
```
|
||||
# Will return number of lines in CSV
|
||||
wc -l gigantic_comma.csv
|
||||
```
|
||||
|
||||
这个工具可以方便地确认各种命令的输出。所以,如果我们在转换文件中的分隔符之后运行 `wc -l`,我们会期待总行数是一样的,如果不一致,我们就知道有地方出错了。
|
||||
|
||||
* 实用选项:
|
||||
|
||||
* `wc -c` 打印字节数
|
||||
* `wc -m` 打印字符数
|
||||
* `wc -L` 打印最长行的长度
|
||||
* `wc -w` 打印单词数量
|
||||
|
||||
|
||||
|
||||
### SPLIT
|
||||
|
||||
文件大小的范围可以很广。取决于任务,拆分文件可以是有益的,所以使用 `split` 吧。split的基本语法是:
|
||||
```bash
|
||||
# We will split our CSV into new_filename every 500 lines
|
||||
split -l 500 filename.csv new_filename_
|
||||
# filename.csv
|
||||
# ls output
|
||||
# new_filename_aaa
|
||||
# new_filename_aab
|
||||
# new_filename_aa
|
||||
```
|
||||
|
||||
两个奇怪的地方是命名约定和缺少文件扩展名。后缀约定可以通过 `-d` 标志变为数字。要添加文件扩展名,你需要运行以下 `find` 命令。它将通过附加 `.csv`更改当前目录中所有文件的名称,所以小心了。
|
||||
```bash
|
||||
find . -type f -exec mv '{}' '{}'.csv \;
|
||||
# ls output
|
||||
# filename.csv.csv
|
||||
# new_filename_aaa.csv
|
||||
# new_filename_aab.csv
|
||||
# new_filename_aac.csv
|
||||
```
|
||||
|
||||
* 实用选项:
|
||||
|
||||
* `split -b` 按特定字节大小分割
|
||||
* `split -a` 生成长度为 N 的后缀
|
||||
* `split -x` 使用十六进制后缀分割
|
||||
|
||||
|
||||
|
||||
### SORT & UNIQ
|
||||
|
||||
以上两个命令很明显:他们的作用就是字面意思。这两者结合起来可以提供最强大的冲击 (i.e. 单独单词数量)。这是由于 `uniq` 只作用于重复的相邻行。这也是在输出前 `sort` 的原因。一个有趣的纪录是 `sort -u` 会达到和典型的 `sort file.txt | uniq` 模式一样的结果。
|
||||
|
||||
Sort 对数据科学家来说确实具有潜在的有用能力:能够根据特定列对整个 CSV 进行排序。
|
||||
```bash
|
||||
# Sorting a CSV file by the second column alphabetically
|
||||
sort -t"," -k2,2 filename.csv
|
||||
|
||||
# Numerically
|
||||
sort -t"," -k2n,2 filename.csv
|
||||
|
||||
# Reverse order
|
||||
sort -t"," -k2nr,2 filename.csv
|
||||
```
|
||||
|
||||
这里的 `-t` 选项将逗号指定为分隔符。通常假设分隔符是空格或制表符。此外,`-k` 标志是为了确定我们的 key。这里的语法是 `-km,n`,`m` 作为开始列,`n` 作为结束列。
|
||||
|
||||
* 实用选项:
|
||||
|
||||
* `sort -f` 忽略大小写
|
||||
* `sort -r` 反向排序
|
||||
* `sort -R` 乱序
|
||||
* `uniq -c` 统计出现次数
|
||||
* `uniq -d` 只打印重复行
|
||||
|
||||
|
||||
|
||||
### CUT
|
||||
|
||||
Cut 用于删除列。为了演示,如果我们只想删除第一和第三列。
|
||||
```bash
|
||||
cut -d, -f 1,3 filename.csv
|
||||
```
|
||||
|
||||
选择除了第一行外的所有行。
|
||||
```bash
|
||||
cut -d, -f 2- filename.csv
|
||||
```
|
||||
|
||||
结合其他命令,将`cut` 用作过滤器。
|
||||
```bash
|
||||
# Print first 10 lines of column 1 and 3, where "some_string_value" is present
|
||||
head filename.csv | grep "some_string_value" | cut -d, -f 1,3
|
||||
```
|
||||
|
||||
查出第二列中唯一值的数量。
|
||||
```bash
|
||||
cat filename.csv | cut -d, -f 2 | sort | uniq | wc -l
|
||||
|
||||
# Count occurences of unique values, limiting to first 10 results
|
||||
cat filename.csv | cut -d, -f 2 | sort | uniq -c | head
|
||||
```
|
||||
|
||||
### PASTE
|
||||
|
||||
Paste 是一个带有趣味性功能的粘贴命令。如果你有两个需要合并的文件,并且它们已经排序了,`paste` 帮你解决了接下来的步骤。
|
||||
```bash
|
||||
# names.txt
|
||||
adam
|
||||
john
|
||||
zach
|
||||
|
||||
# jobs.txt
|
||||
lawyer
|
||||
youtuber
|
||||
developer
|
||||
|
||||
# Join the two into a CSV
|
||||
paste -d ',' names.txt jobs.txt > person_data.txt
|
||||
|
||||
# Output
|
||||
adam,lawyer
|
||||
john,youtuber
|
||||
zach,developer
|
||||
```
|
||||
|
||||
查看更多 SQL_-esque 变种,见下文。
|
||||
|
||||
### JOIN
|
||||
|
||||
Join 是一个简单准切向的 SQL。最大的区别是 `join` 将返回所有列以及只能在一个字段上匹配。默认情况下,`join` 将尝试使用第一列作为匹配键。为了获得不同结果,必须使用以下语法:
|
||||
```bash
|
||||
# Join the first file (-1) by the second column
|
||||
# and the second file (-2) by the first
|
||||
join -t "," -1 2 -2 1 first_file.txt second_file.txt
|
||||
```
|
||||
|
||||
标准的 join 是内连接。然而,外连接通过 `-a` 标志也是可行的。另一个值得一提的技巧是 `-q` 标志,如果发现有缺失的字段,可用于替换值。
|
||||
```bash
|
||||
# Outer join, replace blanks with NULL in columns 1 and 2
|
||||
# -o which fields to substitute - 0 is key, 1.1 is first column, etc...
|
||||
join -t"," -1 2 -a 1 -a2 -e ' NULL' -o '0,1.1,2.2' first_file.txt second_file.txt
|
||||
```
|
||||
|
||||
不是最用户友好的命令,而是绝望时刻的绝望措施。
|
||||
|
||||
* 实用选项:
|
||||
|
||||
* `join -a` 打印不可配对的行
|
||||
* `join -e` 替换丢失的输入字段
|
||||
* `join -j` 相当于 `-1 FIELD -2 FIELD`
|
||||
|
||||
|
||||
|
||||
### GREP
|
||||
|
||||
用正则表达式全局搜索并且打印,或者 `grep`,可能是最有名的命令并且有充分的理由。Grep 很强大,特别适合在大型代码库中找到路径。在数据科学的王国里,它充当其他命令的提炼机制。虽然它的标准用途也很有价值。
|
||||
```
|
||||
# Recursively search and list all files in directory containing 'word'
|
||||
|
||||
grep -lr 'word' .
|
||||
|
||||
# List number of files containing word
|
||||
|
||||
grep -lr 'word' . | wc -l
|
||||
|
||||
```
|
||||
|
||||
计算包含单词或模式的总行数。
|
||||
```
|
||||
grep -c 'some_value' filename.csv
|
||||
|
||||
# Same thing, but in all files in current directory by file name
|
||||
|
||||
grep -c 'some_value' *
|
||||
```
|
||||
|
||||
使用 or 运算符 - `\|` 为多个值 Grep。
|
||||
```
|
||||
grep "first_value\|second_value" filename.csv
|
||||
```
|
||||
|
||||
* 实用选项:
|
||||
|
||||
* `alias grep="grep --color=auto"` 使 grep 丰富多彩
|
||||
* `grep -E` 使用扩展的 regexp
|
||||
* `grep -w` 只匹配整个单词
|
||||
* `grep -l` 打印匹配的文件名
|
||||
* `grep -v` 倒置匹配
|
||||
|
||||
|
||||
|
||||
### 大人物们
|
||||
|
||||
Sed 和 Awk 是本文中最强大的两个命令。为简介起见,我不打算详细讨论这两个命令。相反,我将介绍各种能证明其令人印象深刻的力量的命令。如果你想了解更多,[这儿就有一本书][5]是关于它们的。
|
||||
|
||||
### SED
|
||||
|
||||
`sed` 本质上是一个流编辑器。它擅长替换,但也可以用于所有输出重构。
|
||||
|
||||
最基本的 `sed` 命令由 `s/old/new/g` 组成。这转换为搜索旧值,全局替换为新值。 如果没有 `/g`,我们的命令将在旧值第一次出现后终止。
|
||||
|
||||
为了快速了解它的功能,我们可以深入了解一个例子。 在以下情景中,你已获得以下文件:
|
||||
```
|
||||
balance,name
|
||||
$1,000,john
|
||||
$2,000,jack
|
||||
```
|
||||
|
||||
我们可能想要做的第一件事是删除美元符号。`-i` 标志表示原位。`''` 表示零长度文件扩展名,从而覆盖我们的初始文件。理想情况下,你可以单独测试每个,然后输出到新文件。
|
||||
```
|
||||
sed -i '' 's/\$//g' data.txt
|
||||
# balance,name
|
||||
# 1,000,john
|
||||
# 2,000,jack
|
||||
```
|
||||
|
||||
接下来, `blance` 列的逗号。
|
||||
```
|
||||
sed -i '' 's/\([0-9]\),\([0-9]\)/\1\2/g' data.txt
|
||||
# balance,name
|
||||
# 1000,john
|
||||
# 2000,jack
|
||||
```
|
||||
|
||||
最后杰克有一天决定退出。所以,再见了,我的朋友。
|
||||
```
|
||||
sed -i '' '/jack/d' data.txt
|
||||
# balance,name
|
||||
# 1000,john
|
||||
```
|
||||
|
||||
正如你所看到的,`sed` 有很多强大的功能,但乐趣并不止于此。
|
||||
|
||||
### AWK
|
||||
|
||||
最好的留在最后。Awk 不仅仅是一个简单的命令:它是一个成熟的语言。在本文中涉及的所有内容中,`awk` 是目前为止最酷的。如果你发现自己对其印象深刻,这里有很多很棒的资源 - 看 [这里][6], [这里][7] 和 [这里][8]。
|
||||
|
||||
`awk` 的常见用例包括:
|
||||
|
||||
* 文字处理
|
||||
* 格式化文本报告
|
||||
* 执行算术运算
|
||||
* 执行字符串操作
|
||||
|
||||
|
||||
|
||||
Awk 可以以最原生的形式并行 `grep`。
|
||||
```
|
||||
awk '/word/' filename.csv
|
||||
```
|
||||
|
||||
或者更加神奇:将 `grep` 和 `cut` 组合起来。在这里,`awk` 打印第三和第四列,用 tab 分隔,对于所有带我们指定单词的行。`-F,` 只是改变我们的分隔符为逗号。
|
||||
```bash
|
||||
awk -F, '/word/ { print $3 "\t" $4 }' filename.csv
|
||||
```
|
||||
|
||||
Awk 内置了许多精巧的变量。比如,`NF` \- 字段数 - 和 `NR` \- 记录数。要获取文件中的第53条记录:
|
||||
```bash
|
||||
awk -F, 'NR == 53' filename.csv
|
||||
```
|
||||
|
||||
增加的代码是基于一个或多个值进行过滤的能力。下面的第一个示例将打印第一列等于给定字符串的记录的行号和列。
|
||||
```bash
|
||||
awk -F, ' $1 == "string" { print NR, $0 } ' filename.csv
|
||||
|
||||
# Filter based off of numerical value in second column
|
||||
awk -F, ' $2 == 1000 { print NR, $0 } ' filename.csv
|
||||
```
|
||||
|
||||
多个数值表达式:
|
||||
```bash
|
||||
# Print line number and columns where column three greater
|
||||
# than 2005 and column five less than one thousand
|
||||
|
||||
awk -F, ' $3 >= 2005 && $5 <= 1000 { print NR, $0 } ' filename.csv
|
||||
```
|
||||
|
||||
求出第三列的总和:
|
||||
```bash
|
||||
awk -F, '{ x+=$3 } END { print x }' filename.csv
|
||||
```
|
||||
|
||||
在第一列等于 “something”的那些行,求出第三列值的总和。
|
||||
```bash
|
||||
awk -F, '$1 == "something" { x+=$3 } END { print x }' filename.csv
|
||||
```
|
||||
|
||||
获取文件的尺寸:
|
||||
```bash
|
||||
awk -F, 'END { print NF, NR }' filename.csv
|
||||
|
||||
# Prettier version
|
||||
awk -F, 'BEGIN { print "COLUMNS", "ROWS" }; END { print NF, NR }' filename.csv
|
||||
```
|
||||
|
||||
打印出现了两次的行:
|
||||
```bash
|
||||
awk -F, '++seen[$0] == 2' filename.csv
|
||||
```
|
||||
|
||||
删除重复的行:
|
||||
```bash
|
||||
# Consecutive lines
|
||||
awk 'a !~ $0; {a=$0}']
|
||||
|
||||
# Nonconsecutive lines
|
||||
awk '! a[$0]++' filename.csv
|
||||
|
||||
# More efficient
|
||||
awk '!($0 in a) {a[$0];print}
|
||||
```
|
||||
|
||||
使用内置函数 `gsub()` 替换多个值。
|
||||
```bash
|
||||
awk '{gsub(/scarlet|ruby|puce/, "red"); print}'
|
||||
```
|
||||
|
||||
这个 `awk` 命令将组合多个 CSV 文件,忽略标题,然后在最后附加它。
|
||||
```bash
|
||||
awk 'FNR==1 && NR!=1{next;}{print}' *.csv > final_file.csv
|
||||
```
|
||||
|
||||
需要缩小一个庞大的文件? `awk` 可以在 `sed` 的帮助下处理它。具体来说,该命令根据行数将一个大文件分成多个较小的文件。这个 one-liner 也将增加一个扩展。
|
||||
```bash
|
||||
sed '1d;$d' filename.csv | awk 'NR%NUMBER_OF_LINES==1{x="filename-"++i".csv";}{print > x}'
|
||||
|
||||
# Example: splitting big_data.csv into data_(n).csv every 100,000 lines
|
||||
sed '1d;$d' big_data.csv | awk 'NR%100000==1{x="data_"++i".csv";}{print > x}'
|
||||
```
|
||||
|
||||
### 结语
|
||||
|
||||
命令行拥有无穷无尽的力量。本文中介绍的命令足以将你从一无所知提升到英雄人物。除了涵盖的内容之外,还有许多实用程序需要考虑用于日常数据操作。[Csvkit][9], [xsv][10] 还有 [q][11] 是需要记住的三个。如果你希望更深入地了解命令行数据科学,查看[这本书][12]。它也可以[免费][13]在线获得!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://kadekillary.work/post/cli-4-ds/
|
||||
|
||||
作者:[Kade Killary][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[GraveAccent](https://github.com/graveaccent)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://kadekillary.work/authors/kadekillary
|
||||
[1]:https://en.wikipedia.org/wiki/Brian_Kernighan
|
||||
[2]:https://en.wikipedia.org/wiki/The_C_Programming_Language
|
||||
[3]:https://www.amazon.com/Learning-AWK-Programming-cutting-edge-text-processing-ebook/dp/B07BT98HDS
|
||||
[4]:https://www.youtube.com/watch?v=MijmeoH9LT4
|
||||
[5]:https://www.amazon.com/sed-awk-Dale-Dougherty/dp/1565922255/ref=sr_1_1?ie=UTF8&qid=1524381457&sr=8-1&keywords=sed+and+awk
|
||||
[6]:https://www.amazon.com/AWK-Programming-Language-Alfred-Aho/dp/020107981X/ref=sr_1_1?ie=UTF8&qid=1524388936&sr=8-1&keywords=awk
|
||||
[7]:http://www.grymoire.com/Unix/Awk.html
|
||||
[8]:https://www.tutorialspoint.com/awk/index.htm
|
||||
[9]:http://csvkit.readthedocs.io/en/1.0.3/
|
||||
[10]:https://github.com/BurntSushi/xsv
|
||||
[11]:https://github.com/harelba/q
|
||||
[12]:https://www.amazon.com/Data-Science-Command-Line-Time-Tested/dp/1491947853/ref=sr_1_1?ie=UTF8&qid=1524390894&sr=8-1&keywords=data+science+at+the+command+line
|
||||
[13]:https://www.datascienceatthecommandline.com/
|
@ -0,0 +1,86 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: subject: (SMPlayer in Linux: Features, Download and Installation)
|
||||
[#]: via: (https://itsfoss.com/smplayer/)
|
||||
[#]: author: (Aquil Roshan;Abhishek Prakash https://itsfoss.com/author/aquil/)
|
||||
[#]: url: ( )
|
||||
|
||||
Linux 中的 SMPlayer:功能,下载和安装
|
||||
======
|
||||
|
||||
当你要播放视频时,你会在[全新安装的 Ubuntu][1],或其他许多发行版中,会注意到一个消息:
|
||||
|
||||
![][2]
|
||||
默认媒体播放器没有适合的编解码器
|
||||
|
||||
这意味着系统上没有安装播放媒体的[所需编解码器][3]。现在,由于某些版权问题,某些基于 Linux 的操作系统无法在安装介质中预先打包编解码器。但是它们能让你只需点击即可下载和安装编解码器,或者你可以安装拥有所有媒体编解码器的媒体播放器。了解一下 [SMPlayer][4]。
|
||||
|
||||
### 认识 SMPlayer:适用于 Linux 的更好的媒体播放器
|
||||
|
||||
SMPlayer 是一款免费的开源媒体播放器,它基于强大的 [MPlayer][5] 媒体引擎。SMPlayer 能够播放 avi、mp4、mkv、mpeg、mov、divx、h.264 以及其他任何主要媒体格式。锦上添花的是,它也可以播放 [YouTube][6] 视频,并且无广告。
|
||||
|
||||
![SMPlayer default interface][7]
|
||||
|
||||
SMPlayer 是一个完整的媒体解决方案。它是跨平台的,因此可在所有操作系统上使用。如果你是双启动,则可以将其安装在 Windows 和 Linux 操作系统上,以便在两个系统上获得统一的体验。它还支持带触摸的可变形笔记本。
|
||||
|
||||
你也可以在 SMPlayer 上播放 YouTube。我知道每次复制粘贴视频 URL 并在外部播放器上播放是不切实际的。但是当你观看相对较长的视频时,SMPlayer 特别有用。SMPlayer 以相当好的质量播放 YouTube 视频,我觉得比在浏览器中播放得更好。通过在 SMPlayer 上播放较长的视频,你可以远离视频中间弹出的插播广告。
|
||||
|
||||
如果你在观看没有字幕的电影,你可以直接通过 SMPlayer 下载字幕。它集成了 [opensubtitles.org][8]。所以,打开浏览器,搜索字幕,下载相应的字幕,解压缩,将它们放在视频文件夹中并将字幕连接到电影,这些都不需要!SMPlayer 会为你服务。
|
||||
|
||||
![Automatic subtitle download in SMPlayer][9]
|
||||
|
||||
SMPlayer 支持 30 多种语言,并可高度自定义。它还有应用主题和大量的图标集。
|
||||
|
||||
如果你觉得 SMPlayer 的默认界面看起来不太好,只需点击几下,它就可以看起来像这样:
|
||||
|
||||
![SMPlayer skin change][10]
|
||||
|
||||
SMPlayer 为高级用户提供了许多工具和功能。它有均衡器、视频速度控制、宽高比和缩放控制、视频过滤器、屏幕截图等等。
|
||||
|
||||
总而言之,我真的很喜欢 SMPlayer。它在一个小巧轻量级的安装包中提供了很多功能。我认为它是 Linux PC 上必备的视频播放器。除了轻松播放所有媒体格式外,它还提供了大量的控制。
|
||||
|
||||
### 在 Linux 上安装 SMPlayer
|
||||
|
||||
SMPlayer 应该可在所有主要 Linux 发行版的软件中心获取。你可以搜索它并从那里安装它。
|
||||
|
||||
在 Ubuntu/ Linux Mint/ Elementary OS 上,你还可以通过在终端中运行以下命令来安装 SMPlayer
|
||||
|
||||
```
|
||||
sudo apt install smplayer
|
||||
```
|
||||
|
||||
或者,你可以在[这里][11]下载 Fedora、Arch Linux、OpenSUSE 和 Debian 的软件包
|
||||
|
||||
### 总结
|
||||
|
||||
有很多像 VLC 媒体播放器那样成熟的播放器。SMPlayer 是拥有完整功能和插件优势的最佳产品之一。我认为它是[必备 Linux 应用][12]之一。
|
||||
|
||||
请尝试一下并在下面的评论栏与我们分享你的想法。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/smplayer/
|
||||
|
||||
作者:[Aquil Roshan;Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/aquil/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://itsfoss.com/things-to-do-after-installing-ubuntu-18-04/
|
||||
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-warning.jpg?fit=800%2C450&ssl=1
|
||||
[3]: https://packages.ubuntu.com/trusty/ubuntu-restricted-extras
|
||||
[4]: https://www.smplayer.info/
|
||||
[5]: http://www.mplayerhq.hu/design7/news.html
|
||||
[6]: https://www.youtube.com/
|
||||
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-coco.jpg?fit=800%2C450&ssl=1
|
||||
[8]: https://www.opensubtitles.org/en/search
|
||||
[9]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-icon-packs.jpg?fit=800%2C450&ssl=1
|
||||
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2018/11/SMPlayer-theme.jpg?fit=800%2C450&ssl=1
|
||||
[11]: https://software.opensuse.org/download.html?project=home%3Asmplayerdev&package=smplayer
|
||||
[12]: https://itsfoss.com/essential-linux-applications/
|
@ -7,26 +7,28 @@
|
||||
[#]: author: (Jason Baker https://opensource.com/users/jason-baker)
|
||||
[#]: url: ( )
|
||||
|
||||
Have a cow at the Linux command line
|
||||
|
||||
在Linux命令行上拥有一头奶牛
|
||||
======
|
||||
Bring a bovine voice to your terminal output with the cowsay utility.
|
||||
|
||||
使用 cowsay 实用程序将牛的声音带到你的终端输出。
|
||||
|
||||

|
||||
|
||||
Welcome to the fourth day of the Linux command-line toys advent calendar. If this is your first visit to the series, you might be asking yourself, what’s a command-line toy. We’re figuring that out as we go, but generally, it could be a game, or any simple diversion that helps you have fun at the terminal.
|
||||
欢迎来到 Linux 命令行玩具第四天。如果这是你第一次访问这个系列,你可能会问自己,什么是命令行玩具。我们也在考虑这一点,但是一般来说,这可能是一个游戏,或者任何简单的娱乐,可以帮助你在终端玩得开心。
|
||||
|
||||
Some of you will have seen various selections from our calendar before, but we hope there’s at least one new thing for everyone. Because just about everyone who I’ve mentioned this series to has asked me about it already, today’s selection is an obligatory one.
|
||||
你们中的一些人以前会看过我们日历上的各种选项,但是我们希望每个人都至少有一个新的选项。因为几乎所有我提到这个系列的人都已经问过我了,今天的选项是必须的。
|
||||
|
||||
You didn’t think we’d make it through this series without mentioning cowsay, did you?
|
||||
你不认为我们会在不提及 cowsay 的情况下完成这个系列,是吗?
|
||||
|
||||
Cowsay is an udderly fantastic utility that takes text and outputs it as the spoken text of an ASCII-art bovine.
|
||||
Cowsey 是一个神奇的实用程序,它将文本作为ASCII艺术牛的口语文本输出。
|
||||
|
||||
You’ll likely find cowsay packaged in your default repositories, and perhaps even already installed. For me, in Fedora, all it took to install was:
|
||||
你可能会发现 cowsey 打包在你的默认存储库中,甚至可能已经安装了。对我来说,在 Fedora,像这样安装:
|
||||
|
||||
```
|
||||
$ sudo dnf install -y cowsay
|
||||
```
|
||||
|
||||
Then, invoke it with cowsay followed by your message. Perhaps you’d like to pipe in the [fortune][1] [utility][1] we talked about yesterday.
|
||||
然后,用 cowsey 调用它,然后是你的消息。也许你想到昨天我们谈到的 [幸运][1] [应用][1]。
|
||||
|
||||
```
|
||||
$ fortune | cowsay
|
||||
@ -41,7 +43,7 @@ $ fortune | cowsay
|
||||
|| ||
|
||||
```
|
||||
|
||||
That’s it! **Cowsay** ships with few variations, called cow files, that can usually be found in **/usr/share/cowsay.** To see the cow file options available on your system, use **-l** flag after cowsay. Then, use the **-f** flag to try one out.
|
||||
就这样!**CowSay** 几乎没有变化,称为 cow 文件,通常可以在 **/usr/share/cowsay** ,要查看系统上可用的 cow 文件选项,请在 cowsay 之后使用 **-l** 。然后,用 **-f** 试试其中之一。
|
||||
|
||||
```
|
||||
$ cowsay -f dragon "Run for cover, I feel a sneeze coming on."
|
||||
@ -66,10 +68,10 @@ $ cowsay -f dragon "Run for cover, I feel a sneeze coming on."
|
||||
///-._ _ _ _ _ _ _}^ - - - - ~ ~-- ,.-~
|
||||
/.-~
|
||||
```
|
||||
我对 **cowsay** 的真正不满是,我今天没有足够的时间来为牛的挤奶。牛排太高了,我可能会开个玩笑。
|
||||
|
||||
My real beef with **cowsay** is that I don’t have enough time today to really milk the cow puns for all they are worth. The steaks are just too high, and I might butcher the joke.
|
||||
更严重的是,我已经完全忘记了 **cowsay** 直到我在学习可翻译的剧本时再次遇到它。如果你碰巧安装了 **cowyay**,当你运行脚本时,你会从一系列奶牛身上获得产出。例如,运行本脚本:
|
||||
|
||||
On a more serious note, I had completely forgotten about **cowsay** until I re-encountered it when learning Ansible playbooks. If you happen to have **cowsay** installed, when you run a playbook, you’ll get your output from a series of cows. For example, running this playbook:
|
||||
|
||||
```
|
||||
- hosts:
|
||||
@ -77,8 +79,7 @@ On a more serious note, I had completely forgotten about **cowsay** until I re-e
|
||||
tasks:
|
||||
- action: ping
|
||||
```
|
||||
|
||||
Might give you the following:
|
||||
可能会给你以下信息:
|
||||
|
||||
```
|
||||
$ ansible-playbook playbook.yml
|
||||
@ -122,14 +123,14 @@ ok: [localhost]
|
||||
|
||||
localhost : ok=2 changed=0 unreachable=0 failed=0
|
||||
```
|
||||
|
||||
**Cowsay** is available under a GPLv3 license, and you can find the Perl [source code][2] on GitHub. I’ve also seen versions floating around in other languages, so take a look around for other variants; here’s [one in R][3], for example. Implementing your own version in your language of choice might even be a fun programming learning task.
|
||||
**Cowsay** 在GPLV3许可证下可用,您可以在 GitHub 上找到 Perl [源代码][2]。我也见过其他语言的版本,所以看看其他变体;例如,这是 [R语言][3] 。用你选择的语言实现你自己的版本可能是一项有趣的编程学习任务。
|
||||
|
||||
Now that **cowsay** is out of the way, we can move on to greener pastures.
|
||||
既然 **cowsay** 不碍事了,我们可以去更绿色的牧场了。
|
||||
|
||||
Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.
|
||||
你有最喜欢的命令行玩具吗,你认为我应该对它进行分析?这个系列的日历大部分都填好了,但我还有一些地方。在下面的评论中让我知道,梦幻篮球来看看。如果有空间,梦幻篮球会尝试把它包括进去。如果没有,但是我收到了一些好的意见书,梦幻篮球在结尾做了一个荣誉提名的总结。
|
||||
|
||||
Check out yesterday's toy, [How to bring good fortune to your Linux terminal][1], and check back tomorrow for another!
|
||||
看看昨天的玩具,[如何给你的Linux终端带来好运][1],明天再来看看另一个!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -137,7 +138,7 @@ via: https://opensource.com/article/18/12/linux-toy-cowsay
|
||||
|
||||
作者:[Jason Baker][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
译者:[heguangzhi](https://github.com/heguangzhi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
@ -0,0 +1,94 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: subject: (Easily Convert Audio File Formats with SoundConverter in Linux)
|
||||
[#]: via: (https://itsfoss.com/sound-converter-linux/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
[#]: url: ( )
|
||||
|
||||
在 Linux 中使用 SoundConverter 轻松转换音频文件格式
|
||||
======
|
||||
|
||||
**如果你正在寻找将音频文件格式转换为 wav、mp3、ogg 或任何其他格式,SoundConverter 是你在 Linux 中需要的工具。**
|
||||
|
||||
![Audio Converter in Linux][1]
|
||||
|
||||
最近我购买了一些没有 DRM 的音乐。我是从 [SaReGaMa][2] 那里买的,这是一家印度历史最悠久,规模最大的音乐品牌。下载的文件采用高清质量的 WAV 格式。
|
||||
|
||||
不幸的是,Rhythmbox 无法播放 WAV。最重要的是,单个文件大小约为 70MB。想象一下,将这么大的音乐传输到智能手机。它会不必要地占用大量空间。
|
||||
|
||||
所以我认为是时候将 WAV 文件转换为 MP3,这个长青且最流行的音乐文件格式。
|
||||
|
||||
为此,我需要一个在 Linux 中的音频转换器。在这个教程中,我将向你展示如何使用名为 SoundCoverter 的 GUI 工具轻松地将音频文件从一种格式转换为另一种格式。
|
||||
|
||||
### 在 Linux 中安装 SoundConverter
|
||||
|
||||
[SoundConverter][3] 是一款流行的免费开源软件。它应该可以在大多数 Linux 发行版的官方仓库中找到。
|
||||
|
||||
Ubuntu/Linux Mint 用户只需在软件中心搜索 SoundConverter 并从那里安装即可。
|
||||
|
||||
![SoundConverter application in Software Center of Ubuntu][4]
|
||||
SoundConverter 可以从软件中心安装
|
||||
|
||||
或者,你可以使用命令行方式。在基于 Debian 和 Ubuntu 的系统中,你可以使用以下命令:
|
||||
|
||||
```
|
||||
sudo apt install soundconverter
|
||||
```
|
||||
|
||||
在 Arch、Fedora 和其他非基于 Debian 的发行版中,你可以使用你的发行版的软件中心或软件包管理器。
|
||||
|
||||
### 在 Linux 中使用 SoundConverter 转换音频文件格式
|
||||
|
||||
安装完 SoundConverter 后,在菜单中搜索并启动它。
|
||||
|
||||
默认界面看起来像这样,它不能比这简单:
|
||||
|
||||
![SoundConverter application interface in Linux][5]Simple Interface
|
||||
|
||||
转换音频文件格式只要选择文件并单击转换。
|
||||
|
||||
但是,我建议你至少在第一次运行时检查下默认设置。默认情况下,它会将音频文件转换为 OGG 文件格式,你可能不希望这样。
|
||||
|
||||
![Preferences in SoundConverter][6]
|
||||
可以在“首选项”中更改默认输出设置
|
||||
|
||||
要更改默认输出设置,请单击界面上的“首选项”图标。你会在这里看到很多可更改的选择。
|
||||
|
||||
你可以更改默认输出格式、比特率、质量等。你还可以选择是否要将转换后的文件保存在与原始文件相同的文件夹中。
|
||||
|
||||
转换后还可以选择自动删除原始文件。我不认为你应该使用那个选项。
|
||||
|
||||
你还可以更改输出文件名。默认情况下,它只会更改后缀,但你也可以选择根据曲目编号、标题、艺术家等进行命名。为此,原始文件中应包含适当的元数据。
|
||||
|
||||
说到元数据,你听说过 [MusicBrainz Picard][7]吗?此工具可帮助你自动更新本地音乐文件的元数据。
|
||||
|
||||
### 总结
|
||||
|
||||
我之前用讨论过用一个小程序[在 Linux 中录制音频][8]。这些很棒的工具通过专注某个特定的任务使得生活更轻松。你可以使用成熟和更好的音频编辑工具,如 [Audacity][9],但对于较小的任务,如转换音频文件格式,它可能用起来很复杂。
|
||||
|
||||
我希望你喜欢 SoundConverter。如果你使用其他工具,请在评论中提及,我会在 FOSS 中提及。使用开心!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/sound-converter-linux/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/Convert-audio-file-format-linux.png?resize=800%2C450&ssl=1
|
||||
[2]: https://en.wikipedia.org/wiki/Saregama
|
||||
[3]: http://soundconverter.org/
|
||||
[4]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/sound-converter-software-center.png?ssl=1
|
||||
[5]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2018/12/sound-converter-app-linux.jpeg?ssl=1
|
||||
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2018/12/sound-converter-app-linux-preferences.jpeg?resize=800%2C431&ssl=1
|
||||
[7]: https://itsfoss.com/musicbrainz-picard/
|
||||
[8]: https://itsfoss.com/record-streaming-audio/
|
||||
[9]: https://www.audacityteam.org/
|
Loading…
Reference in New Issue
Block a user