mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-06 23:50:16 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
749fca235a
@ -1,13 +1,13 @@
|
||||
gdb 如何调用函数?
|
||||
============================================================
|
||||
|
||||
(之前的 gdb 系列文章:[gdb 如何工作(2016)][4] 和[通过 gdb 你能够做的三件事(2014)][5])
|
||||
(之前的 gdb 系列文章:[gdb 如何工作(2016)][4] 和[三步上手 gdb(2014)][5])
|
||||
|
||||
在这个周,我发现,我可以从 gdb 上调用 C 函数。这看起来很酷,因为在过去我认为 gdb 最多只是一个只读调试工具。
|
||||
在这周,我发现我可以从 gdb 上调用 C 函数。这看起来很酷,因为在过去我认为 gdb 最多只是一个只读调试工具。
|
||||
|
||||
我对 gdb 能够调用函数感到很吃惊。正如往常所做的那样,我在 [Twitter][6] 上询问这是如何工作的。我得到了大量的有用答案。我最喜欢的答案是 [Evan Klitzke 的示例 C 代码][7],它展示了 gdb 如何调用函数。代码能够运行,这很令人激动!
|
||||
|
||||
我相信(通过一些跟踪和实验)那个示例 C 代码和 gdb 实际上如何调用函数不同。因此,在这篇文章中,我将会阐述 gdb 是如何调用函数的,以及我是如何知道的。
|
||||
我(通过一些跟踪和实验)认为那个示例 C 代码和 gdb 实际上如何调用函数不同。因此,在这篇文章中,我将会阐述 gdb 是如何调用函数的,以及我是如何知道的。
|
||||
|
||||
关于 gdb 如何调用函数,还有许多我不知道的事情,并且,在这儿我写的内容有可能是错误的。
|
||||
|
||||
@ -15,17 +15,14 @@ gdb 如何调用函数?
|
||||
|
||||
在开始讲解这是如何工作之前,我先快速的谈论一下我是如何发现这件令人惊讶的事情的。
|
||||
|
||||
所以,你已经在运行一个 C 程序(目标程序)。你可以运行程序中的一个函数,只需要像下面这样做:
|
||||
假如,你已经在运行一个 C 程序(目标程序)。你可以运行程序中的一个函数,只需要像下面这样做:
|
||||
|
||||
* 暂停程序(因为它已经在运行中)
|
||||
|
||||
* 找到你想调用的函数的地址(使用符号表)
|
||||
|
||||
* 使程序(目标程序)跳转到那个地址
|
||||
|
||||
* 当函数返回时,恢复之前的指令指针和寄存器
|
||||
|
||||
通过符号表来找到想要调用的函数的地址非常容易。下面是一段非常简单但能够工作的代码,我在 Linux 上使用这段代码作为例子来讲解如何找到地址。这段代码使用 [elf crate][8]。如果我想找到 PID 为 2345 的进程中的 foo 函数的地址,那么我可以运行 `elf_symbol_value("/proc/2345/exe", "foo")`。
|
||||
通过符号表来找到想要调用的函数的地址非常容易。下面是一段非常简单但能够工作的代码,我在 Linux 上使用这段代码作为例子来讲解如何找到地址。这段代码使用 [elf crate][8]。如果我想找到 PID 为 2345 的进程中的 `foo` 函数的地址,那么我可以运行 `elf_symbol_value("/proc/2345/exe", "foo")`。
|
||||
|
||||
```
|
||||
fn elf_symbol_value(file_name: &str, symbol_name: &str) -> Result<u64, Box<std::error::Error>> {
|
||||
@ -42,7 +39,6 @@ fn elf_symbol_value(file_name: &str, symbol_name: &str) -> Result<u64, Box<std::
|
||||
}
|
||||
None.ok_or("No symbol found")?
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
这并不能够真的发挥作用,你还需要找到文件的内存映射,并将符号偏移量加到文件映射的起始位置。找到内存映射并不困难,它位于 `/proc/PID/maps` 中。
|
||||
@ -55,7 +51,7 @@ fn elf_symbol_value(file_name: &str, symbol_name: &str) -> Result<u64, Box<std::
|
||||
|
||||
### 如何从 gdb 中调用 C 函数
|
||||
|
||||
首先,这是可能的。我写了一个非常简洁的 C 程序,它所做的事只有 sleep 1000 秒,把这个文件命名为 `test.c` :
|
||||
首先,这是可能的。我写了一个非常简洁的 C 程序,它所做的事只有 `sleep` 1000 秒,把这个文件命名为 `test.c` :
|
||||
|
||||
```
|
||||
#include <unistd.h>
|
||||
@ -66,7 +62,6 @@ int foo() {
|
||||
int main() {
|
||||
sleep(1000);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
接下来,编译并运行它:
|
||||
@ -74,7 +69,6 @@ int main() {
|
||||
```
|
||||
$ gcc -o test test.c
|
||||
$ ./test
|
||||
|
||||
```
|
||||
|
||||
最后,我们使用 gdb 来跟踪 `test` 这一程序:
|
||||
@ -84,54 +78,42 @@ $ sudo gdb -p $(pgrep -f test)
|
||||
(gdb) p foo()
|
||||
$1 = 3
|
||||
(gdb) quit
|
||||
|
||||
```
|
||||
|
||||
我运行 `p foo()` 然后它运行了这个函数!这非常有趣。
|
||||
|
||||
### 为什么这是有用的?
|
||||
### 这有什么用?
|
||||
|
||||
下面是一些可能的用途:
|
||||
|
||||
* 它使得你可以把 gdb 当成一个 C 应答式程序,这很有趣,我想对开发也会有用
|
||||
|
||||
* 它使得你可以把 gdb 当成一个 C 应答式程序(REPL),这很有趣,我想对开发也会有用
|
||||
* 在 gdb 中进行调试的时候展示/浏览复杂数据结构的功能函数(感谢 [@invalidop][1])
|
||||
|
||||
* [在进程运行时设置一个任意的名字空间][2](我的同事 [nelhage][3] 对此非常惊讶)
|
||||
|
||||
* 可能还有许多我所不知道的用途
|
||||
|
||||
### 它是如何工作的
|
||||
|
||||
当我在 Twitter 上询问从 gdb 中调用函数是如何工作的时,我得到了大量有用的回答。许多答案是”你从符号表中得到了函数的地址“,但这并不是完整的答案。
|
||||
当我在 Twitter 上询问从 gdb 中调用函数是如何工作的时,我得到了大量有用的回答。许多答案是“你从符号表中得到了函数的地址”,但这并不是完整的答案。
|
||||
|
||||
有个人告诉了我两篇关于 gdb 如何工作的系列文章:[和本地人一起调试-第一部分][9],[和本地人一起调试-第二部分][10]。第一部分讲述了 gdb 是如何调用函数的(指出了 gdb 实际上完成这件事并不简单,但是我将会尽力)。
|
||||
有个人告诉了我两篇关于 gdb 如何工作的系列文章:[原生调试:第一部分][9],[原生调试:第二部分][10]。第一部分讲述了 gdb 是如何调用函数的(指出了 gdb 实际上完成这件事并不简单,但是我将会尽力)。
|
||||
|
||||
步骤列举如下:
|
||||
|
||||
1. 停止进程
|
||||
|
||||
2. 创建一个新的栈框(远离真实栈)
|
||||
|
||||
3. 保存所有寄存器
|
||||
|
||||
4. 设置你想要调用的函数的寄存器参数
|
||||
|
||||
5. 设置栈指针指向新的栈框
|
||||
|
||||
5. 设置栈指针指向新的<ruby>栈框<rt>stack frame</rt></ruby>
|
||||
6. 在内存中某个位置放置一条陷阱指令
|
||||
|
||||
7. 为陷阱指令设置返回地址
|
||||
|
||||
8. 设置指令寄存器的值为你想要调用的函数地址
|
||||
|
||||
9. 再次运行进程!
|
||||
|
||||
(LCTT 译注:如果将这个调用的函数看成一个单独的线程,gdb 实际上所做的事情就是一个简单的线程上下文切换)
|
||||
|
||||
我不知道 gdb 是如何完成这些所有事情的,但是今天晚上,我学到了这些所有事情中的其中几件。
|
||||
|
||||
**创建一个栈框**
|
||||
#### 创建一个栈框
|
||||
|
||||
如果你想要运行一个 C 函数,那么你需要一个栈来存储变量。你肯定不想继续使用当前的栈。准确来说,在 gdb 调用函数之前(通过设置函数指针并跳转),它需要设置栈指针到某个地方。
|
||||
|
||||
@ -154,14 +136,13 @@ Breakpoint 1 at 0x40052a
|
||||
Breakpoint 1, 0x000000000040052a in foo ()
|
||||
(gdb) p $rsp
|
||||
$8 = (void *) 0x7ffea3d0bc00
|
||||
|
||||
```
|
||||
|
||||
这看起来符合”gdb 在当前栈的栈顶构造了一个新的栈框“这一理论。因为栈指针(`$rsp`)从 `0x7ffea3d0bca8` 变成了 `0x7ffea3d0bc00` - 栈指针从高地址往低地址长。所以 `0x7ffea3d0bca8` 在 `0x7ffea3d0bc00` 的后面。真是有趣!
|
||||
这看起来符合“gdb 在当前栈的栈顶构造了一个新的栈框”这一理论。因为栈指针(`$rsp`)从 `0x7ffea3d0bca8` 变成了 `0x7ffea3d0bc00` —— 栈指针从高地址往低地址长。所以 `0x7ffea3d0bca8` 在 `0x7ffea3d0bc00` 的后面。真是有趣!
|
||||
|
||||
所以,看起来 gdb 只是在当前栈所在位置创建了一个新的栈框。这令我很惊讶!
|
||||
|
||||
**改变指令指针**
|
||||
#### 改变指令指针
|
||||
|
||||
让我们来看一看 gdb 是如何改变指令指针的!
|
||||
|
||||
@ -181,7 +162,7 @@ $3 = (void (*)()) 0x40052a <foo+4>
|
||||
|
||||
我盯着输出看了很久,但仍然不理解它是如何改变指令指针的,但这并不影响什么。
|
||||
|
||||
**如何设置断点**
|
||||
#### 如何设置断点
|
||||
|
||||
上面我写到 `break foo` 。我跟踪 gdb 运行程序的过程,但是没有任何发现。
|
||||
|
||||
@ -202,10 +183,9 @@ $3 = (void (*)()) 0x40052a <foo+4>
|
||||
// 将 0x400528 处的指令更改为之前的样子
|
||||
25622 ptrace(PTRACE_PEEKTEXT, 25618, 0x400528, [0x5d00000003cce589]) = 0
|
||||
25622 ptrace(PTRACE_POKEDATA, 25618, 0x400528, 0x5d00000003b8e589) = 0
|
||||
|
||||
```
|
||||
|
||||
**在某处放置一条陷阱指令**
|
||||
#### 在某处放置一条陷阱指令
|
||||
|
||||
当 gdb 运行一个函数的时候,它也会在某个地方放置一条陷阱指令。这是其中一条。它基本上是用 `cc` 来替换一条指令(`int3`)。
|
||||
|
||||
@ -213,7 +193,6 @@ $3 = (void (*)()) 0x40052a <foo+4>
|
||||
5908 ptrace(PTRACE_PEEKTEXT, 5810, 0x7f6fa7c0b260, [0x48f389fd89485355]) = 0
|
||||
5908 ptrace(PTRACE_PEEKTEXT, 5810, 0x7f6fa7c0b260, [0x48f389fd89485355]) = 0
|
||||
5908 ptrace(PTRACE_POKEDATA, 5810, 0x7f6fa7c0b260, 0x48f389fd894853cc) = 0
|
||||
|
||||
```
|
||||
|
||||
`0x7f6fa7c0b260` 是什么?我查看了进程的内存映射,发现它位于 `/lib/x86_64-linux-gnu/libc-2.23.so` 中的某个位置。这很奇怪,为什么 gdb 将陷阱指令放在 libc 中?
|
||||
@ -226,7 +205,7 @@ $3 = (void (*)()) 0x40052a <foo+4>
|
||||
|
||||
我将要在这儿停止了(现在已经凌晨 1 点),但是我知道的多一些了!
|
||||
|
||||
看起来”gdb 如何调用函数“这一问题的答案并不简单。我发现这很有趣并且努力找出其中一些答案,希望你也能够找到。
|
||||
看起来“gdb 如何调用函数”这一问题的答案并不简单。我发现这很有趣并且努力找出其中一些答案,希望你也能够找到。
|
||||
|
||||
我依旧有很多未回答的问题,关于 gdb 是如何完成这些所有事的,但是可以了。我不需要真的知道关于 gdb 是如何工作的所有细节,但是我很开心,我有了一些进一步的理解。
|
||||
|
||||
@ -236,7 +215,7 @@ via: https://jvns.ca/blog/2018/01/04/how-does-gdb-call-functions/
|
||||
|
||||
作者:[Julia Evans][a]
|
||||
译者:[ucasFL](https://github.com/ucasFL)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
@ -244,8 +223,8 @@ via: https://jvns.ca/blog/2018/01/04/how-does-gdb-call-functions/
|
||||
[1]:https://twitter.com/invalidop/status/949161146526781440
|
||||
[2]:https://github.com/baloo/setns/blob/master/setns.c
|
||||
[3]:https://github.com/nelhage
|
||||
[4]:https://jvns.ca/blog/2016/08/10/how-does-gdb-work/
|
||||
[5]:https://jvns.ca/blog/2014/02/10/three-steps-to-learning-gdb/
|
||||
[4]:https://linux.cn/article-9491-1.html
|
||||
[5]:https://linux.cn/article-9276-1.html
|
||||
[6]:https://twitter.com/b0rk/status/948060808243765248
|
||||
[7]:https://github.com/eklitzke/ptrace-call-userspace/blob/master/call_fprintf.c
|
||||
[8]:https://cole14.github.io/rust-elf
|
@ -1,29 +1,28 @@
|
||||
查看 Linux 发行版名称和版本号的8种方法
|
||||
查看 Linux 发行版名称和版本号的 8 种方法
|
||||
======
|
||||
|
||||
如果你加入了一家新公司,要为开发团队安装所需的软件并重启服务,这个时候首先要弄清楚它们运行在什么发行版以及哪个版本的系统上,你才能正确完成后续的工作。作为系统管理员,充分了解系统信息是首要的任务。
|
||||
|
||||
查看 Linux 发行版名称和版本号有很多种方法。你可能会问,为什么要去了解这些基本信息呢?
|
||||
|
||||
因为对于诸如 RHEL、Debian、openSUSE、Arch Linux 这几种主流发行版来说,它们各自拥有不同的包管理器来管理系统上的软件包,如果不知道所使用的是哪一个发行版的系统,在包安装的时候就会无从下手,而且由于大多数发行版都是用 systemd 命令而不是 SysVinit 脚本,在重启服务的时候也难以执行正确的命令。
|
||||
因为对于诸如 RHEL、Debian、openSUSE、Arch Linux 这几种主流发行版来说,它们各自拥有不同的包管理器来管理系统上的软件包,如果不知道所使用的是哪一个发行版的系统,在软件包安装的时候就会无从下手,而且由于大多数发行版都是用 systemd 命令而不是 SysVinit 脚本,在重启服务的时候也难以执行正确的命令。
|
||||
|
||||
下面来看看可以使用那些基本命令来查看 Linux 发行版名称和版本号。
|
||||
|
||||
### 方法总览
|
||||
|
||||
* lsb_release command
|
||||
* /etc/*-release file
|
||||
* uname command
|
||||
* /proc/version file
|
||||
* dmesg Command
|
||||
* YUM or DNF Command
|
||||
* RPM command
|
||||
* APT-GET command
|
||||
* `lsb_release` 命令
|
||||
* `/etc/*-release` 文件
|
||||
* `uname` 命令
|
||||
* `/proc/version` 文件
|
||||
* `dmesg` 命令
|
||||
* YUM 或 DNF 命令
|
||||
* RPM 命令
|
||||
* APT-GET 命令
|
||||
|
||||
### 方法 1: lsb_release 命令
|
||||
|
||||
|
||||
### 方法1: lsb_release 命令
|
||||
|
||||
LSB(Linux Standard Base,Linux 标准库)能够打印发行版的具体信息,包括发行版名称、版本号、代号等。
|
||||
LSB(<ruby>Linux 标准库<rt>Linux Standard Base</rt></ruby>)能够打印发行版的具体信息,包括发行版名称、版本号、代号等。
|
||||
|
||||
```
|
||||
# lsb_release -a
|
||||
@ -32,12 +31,11 @@ Distributor ID: Ubuntu
|
||||
Description: Ubuntu 16.04.3 LTS
|
||||
Release: 16.04
|
||||
Codename: xenial
|
||||
|
||||
```
|
||||
|
||||
### 方法2: /etc/arch-release /etc/os-release File
|
||||
### 方法 2: /etc/*-release 文件
|
||||
|
||||
版本文件通常被视为操作系统的标识。在 `/etc` 目录下放置了很多记录着发行版各种信息的文件,每个发行版都各自有一套这样记录着相关信息的文件。下面是一组在 Ubuntu/Debian 系统上显示出来的文件内容。
|
||||
release 文件通常被视为操作系统的标识。在 `/etc` 目录下放置了很多记录着发行版各种信息的文件,每个发行版都各自有一套这样记录着相关信息的文件。下面是一组在 Ubuntu/Debian 系统上显示出来的文件内容。
|
||||
|
||||
```
|
||||
# cat /etc/issue
|
||||
@ -67,10 +65,10 @@ UBUNTU_CODENAME=xenial
|
||||
|
||||
# cat /etc/debian_version
|
||||
9.3
|
||||
|
||||
```
|
||||
|
||||
下面这一组是在 RHEL/CentOS/Fedora 系统上显示出来的文件内容。其中 `/etc/redhat-release` 和 `/etc/system-release` 文件是指向 `/etc/[发行版名称]-release` 文件的一个连接。
|
||||
|
||||
```
|
||||
# cat /etc/centos-release
|
||||
CentOS release 6.9 (Final)
|
||||
@ -100,34 +98,34 @@ Fedora release 27 (Twenty Seven)
|
||||
|
||||
# cat /etc/system-release
|
||||
Fedora release 27 (Twenty Seven)
|
||||
|
||||
```
|
||||
|
||||
### 方法3: uname 命令
|
||||
### 方法 3: uname 命令
|
||||
|
||||
uname(unix name) 是一个打印系统信息的工具,包括内核名称、版本号、系统详细信息以及所运行的操作系统等等。
|
||||
uname(unix name 的意思) 是一个打印系统信息的工具,包括内核名称、版本号、系统详细信息以及所运行的操作系统等等。
|
||||
|
||||
- **建议阅读:** [6种查看系统 Linux 内核的方法][1]
|
||||
|
||||
**建议阅读:** [6种查看系统 Linux 内核的方法][1]
|
||||
```
|
||||
# uname -a
|
||||
Linux localhost.localdomain 4.12.14-300.fc26.x86_64 #1 SMP Wed Sep 20 16:28:07 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
|
||||
|
||||
```
|
||||
|
||||
以上运行结果说明使用的操作系统版本是 Fedora 26。
|
||||
|
||||
### 方法4: /proc/version File
|
||||
### 方法 4: /proc/version 文件
|
||||
|
||||
这个文件记录了 Linux 内核的版本、用于编译内核的 gcc 的版本、内核编译的时间,以及内核编译者的用户名。
|
||||
|
||||
```
|
||||
# cat /proc/version
|
||||
Linux version 4.12.14-300.fc26.x86_64 ([email protected]) (gcc version 7.2.1 20170915 (Red Hat 7.2.1-2) (GCC) ) #1 SMP Wed Sep 20 16:28:07 UTC 2017
|
||||
|
||||
```
|
||||
|
||||
### Method-5: dmesg 命令
|
||||
### 方法 5: dmesg 命令
|
||||
|
||||
dmesg(<ruby>展示信息<rt>display message</rt></ruby> 或<ruby>驱动程序信息<rt>driver message</rt></ruby>)是大多数类 Unix 操作系统上的一个命令,用于打印内核的消息缓冲区的信息。
|
||||
|
||||
dmesg(display message/driver message,展示信息/驱动程序信息)是大多数类 Unix 操作系统上的一个命令,用于打印内核上消息缓冲区的信息。
|
||||
```
|
||||
# dmesg | grep "Linux"
|
||||
[ 0.000000] Linux version 4.12.14-300.fc26.x86_64 ([email protected]) (gcc version 7.2.1 20170915 (Red Hat 7.2.1-2) (GCC) ) #1 SMP Wed Sep 20 16:28:07 UTC 2017
|
||||
@ -139,14 +137,14 @@ dmesg(display message/driver message,展示信息/驱动程序信息)是
|
||||
[ 0.688949] usb usb2: Manufacturer: Linux 4.12.14-300.fc26.x86_64 ohci_hcd
|
||||
[ 2.564554] SELinux: Disabled at runtime.
|
||||
[ 2.564584] SELinux: Unregistering netfilter hooks
|
||||
|
||||
```
|
||||
|
||||
### Method-6: Yum/Dnf 命令
|
||||
### 方法 6: Yum/Dnf 命令
|
||||
|
||||
Yum(Yellowdog Updater Modified)是 Linux 操作系统上的一个包管理工具,而 `yum` 命令则是一些基于 RedHat 的 Linux 发行版上用于安装、更新、查找、删除软件包的命令。
|
||||
Yum(<ruby>Yellowdog 更新器修改版<rt>Yellowdog Updater Modified</rt></ruby>)是 Linux 操作系统上的一个包管理工具,而 `yum` 命令被用于一些基于 RedHat 的 Linux 发行版上安装、更新、查找、删除软件包。
|
||||
|
||||
- **建议阅读:** [在 RHEL/CentOS 系统上使用 yum 命令管理软件包][2]
|
||||
|
||||
**建议阅读:** [在 RHEL/CentOS 系统上使用 yum 命令管理软件包][2]
|
||||
```
|
||||
# yum info nano
|
||||
Loaded plugins: fastestmirror, ovl
|
||||
@ -165,10 +163,10 @@ Summary : A small text editor
|
||||
URL : http://www.nano-editor.org
|
||||
License : GPLv3+
|
||||
Description : GNU nano is a small and friendly text editor.
|
||||
|
||||
```
|
||||
|
||||
下面的 `yum repolist` 命令执行后显示了 yum 的基础源仓库、额外源仓库、更新源仓库都来自 CentOS 7 仓库。
|
||||
|
||||
```
|
||||
# yum repolist
|
||||
Loaded plugins: fastestmirror, ovl
|
||||
@ -181,12 +179,12 @@ base/7/x86_64 CentOS-7 - Base 9591
|
||||
extras/7/x86_64 CentOS-7 - Extras 388
|
||||
updates/7/x86_64 CentOS-7 - Updates 1929
|
||||
repolist: 11908
|
||||
|
||||
```
|
||||
|
||||
使用 `dnf` 命令也同样可以查看发行版名称和版本号。
|
||||
|
||||
**建议阅读:** [在 Fedora 系统上使用 DNF(YUM 的一个分支)命令管理软件包][3]
|
||||
- **建议阅读:** [在 Fedora 系统上使用 DNF(YUM 的一个分支)命令管理软件包][3]
|
||||
|
||||
```
|
||||
# dnf info nano
|
||||
Last metadata expiration check: 0:01:25 ago on Thu Feb 15 01:59:31 2018.
|
||||
@ -203,25 +201,25 @@ Summary : A small text editor
|
||||
URL : https://www.nano-editor.org
|
||||
License : GPLv3+
|
||||
Description : GNU nano is a small and friendly text editor.
|
||||
|
||||
```
|
||||
|
||||
### Method-7: RPM 命令
|
||||
### 方法 7: RPM 命令
|
||||
|
||||
RPM(RedHat Package Manager, RedHat 包管理器)是在 CentOS、Oracle Linux、Fedora 这些基于 RedHat 的操作系统上的一个强大的命令行包管理工具,同样也可以帮助我们查看系统的版本信息。
|
||||
RPM(<ruby>红帽包管理器<rt>RedHat Package Manager</rt></ruby>)是在 CentOS、Oracle Linux、Fedora 这些基于 RedHat 的操作系统上的一个强大的命令行包管理工具,同样也可以帮助我们查看系统的版本信息。
|
||||
|
||||
- **建议阅读:** [在基于 RHEL 的系统上使用 RPM 命令管理软件包][4]
|
||||
|
||||
**建议阅读:** [在基于 RHEL 的系统上使用 RPM 命令管理软件包][4]
|
||||
```
|
||||
# rpm -q nano
|
||||
nano-2.8.7-1.fc27.x86_64
|
||||
|
||||
```
|
||||
|
||||
### Method-8: APT-GET 命令
|
||||
### 方法 8: APT-GET 命令
|
||||
|
||||
Apt-Get(Advanced Packaging Tool)是一个强大的命令行工具,可以自动下载安装新软件包、更新已有的软件包、更新软件包列表索引,甚至更新整个 Debian 系统。
|
||||
Apt-Get(<ruby>高级打包工具<rt>Advanced Packaging Tool</rt></ruby>)是一个强大的命令行工具,可以自动下载安装新软件包、更新已有的软件包、更新软件包列表索引,甚至更新整个 Debian 系统。
|
||||
|
||||
- **建议阅读:** [在基于 Debian 的系统上使用 Apt-Get 和 Apt-Cache 命令管理软件包][5]
|
||||
|
||||
**建议阅读:** [在基于 Debian 的系统上使用 Apt-Get 和 Apt-Cache 命令管理软件包][5]
|
||||
```
|
||||
# apt-cache policy nano
|
||||
nano:
|
||||
@ -233,7 +231,6 @@ nano:
|
||||
100 /var/lib/dpkg/status
|
||||
2.5.3-2 500
|
||||
500 http://nova.clouds.archive.ubuntu.com/ubuntu xenial/main amd64 Packages
|
||||
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -242,7 +239,7 @@ via: https://www.2daygeek.com/check-find-linux-distribution-name-and-version/
|
||||
|
||||
作者:[Magesh Maruthamuthu][a]
|
||||
译者:[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/) 荣誉推出
|
||||
|
74
published/20180226 5 keys to building open hardware.md
Normal file
74
published/20180226 5 keys to building open hardware.md
Normal file
@ -0,0 +1,74 @@
|
||||
构建开源硬件的 5 个关键点
|
||||
======
|
||||
|
||||
> 最大化你的项目影响。
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/openhardwaretools.png?itok=DC1RC_1f)
|
||||
|
||||
科学社区正在加速拥抱<ruby>自由及开源硬件<rt>Free and Open Source Hardware</rt></ruby>([FOSH][1])。 研究员正忙于[改进他们自己的装备][2]并创造数以百计的基于分布式数字制造模型的设备来推动他们的研究。
|
||||
|
||||
热衷于 FOSH 的主要原因还是钱: 有研究表明,和专用设备相比,FOSH 可以[节省 90% 到 99% 的花费][3]。基于[开源硬件商业模式][4]的科学 FOSH 的商业化已经推动其快速地发展为一个新的工程领域,并为此定期[举行 GOSH 年会][5]。
|
||||
|
||||
特别的是,不止一本,而是关于这个主题的[两本学术期刊]:[Journal of Open Hardware] (由 Ubiquity 出版,一个新的自由访问出版商,同时出版了 [Journal of Open Research Software][8] )以及 [HardwareX][9](由 Elsevier 出版的一种[自由访问期刊][10],它是世界上最大的学术出版商之一)。
|
||||
|
||||
由于学术社区的支持,科学 FOSH 的开发者在获取制作乐趣并推进科学快速发展的同时获得学术声望。
|
||||
|
||||
### 科学 FOSH 的5个步骤
|
||||
|
||||
Shane Oberloier 和我在名为 Designs 的自由访问工程期刊上共同发表了一篇关于设计 FOSH 科学设备原则的[文章][11]。我们以滑动式烘干机为例,制造成本低于 20 美元,仅是专用设备价格的三百分之一。[科学][1]和[医疗][12]设备往往比较复杂,开发 FOSH 替代品将带来巨大的回报。
|
||||
|
||||
我总结了 5 个步骤(包括 6 条设计原则),它们在 Shane Oberloier 和我发表的文章里有详细阐述。这些设计原则也可以推广到非科学设备,而且制作越复杂的设计越能带来更大的潜在收益。
|
||||
|
||||
如果你对科学项目的开源硬件设计感兴趣,这些步骤将使你的项目的影响最大化。
|
||||
|
||||
1. 评估类似现有工具的功能,你的 FOSH 设计目标应该针对实际效果而不是现有的设计(LCTT 译注:作者的意思应该是不要被现有设计缚住手脚)。必要的时候需进行概念证明。
|
||||
2. 使用下列设计原则:
|
||||
* 在设备生产中,仅使用自由和开源的软件工具链(比如,开源的 CAD 工具,例如 [OpenSCAD][13]、 [FreeCAD][14] 或 [Blender][15])和开源硬件。
|
||||
* 尝试减少部件的数量和类型并降低工具的复杂度
|
||||
* 减少材料的数量和制造成本。
|
||||
* 尽量使用能够分发的部件或使用方便易得的工具(比如 [RepRap 3D 打印机][16])进行部件的数字化生产。
|
||||
* 对部件进行[参数化设计][17],这使他人可以对你的设计进行个性化改动。相较于特例化设计,参数化设计会更有用。在未来的项目中,使用者可以通过修改核心参数来继续利用它们。
|
||||
* 所有不能使用现有的开源硬件以分布式的方式轻松且经济地制造的零件,必须选择现货产品以方便采购。
|
||||
3. 验证功能设计。
|
||||
4. 提供关于设计、生产、装配、校准和操作的详尽设备文档。包括原始设计文件而不仅仅是用于生产的。<ruby>开源硬件协会<rt>Open Source Hardware Association</rt></ruby>对于开源设计的发布和文档化有额外的[指南][18],总结如下:
|
||||
* 以通用的形式分享设计文件。
|
||||
* 提供详尽的材料清单,包括价格和采购信息。
|
||||
* 如果涉及软件,确保代码对大众来说清晰易懂。
|
||||
* 作为生产时的参考,必须提供足够的照片,以确保没有任何被遮挡的部分。
|
||||
* 在描述方法的章节,整个制作过程必须被细化成简单步骤以便复制此设计。
|
||||
* 在线上分享并指定许可证。这为用户提供了合理使用该设计的信息。
|
||||
5. 主动分享!为了使 FOSH 发扬光大,设计必须被广泛、频繁和有效地分享以提升它们的存在感。所有的文档应该在自由访问文献中发表,并与适当的社区共享。<ruby>[开源科学框架][19]<rt>Open Science Framework</rt></ruby>是一个值得考虑的优雅的通用存储库,它由<ruby>开源科学中心<rt>Center for Open Science</rt></ruby>主办,该中心设置为接受任何类型的文件并处理大型数据集。
|
||||
|
||||
这篇文章得到了 [Fulbright Finland][20] 的支持,该公司赞助了芬兰 Fulbright-Aalto 大学的特聘校席 Joshua Pearce 在开源科学硬件方面的研究工作。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/2/5-steps-creating-successful-open-hardware
|
||||
|
||||
作者:[Joshua Pearce][a]
|
||||
译者:[kennethXia](https://github.com/kennethXia)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/jmpearce
|
||||
[1]:https://opensource.com/business/16/4/how-calculate-open-source-hardware-return-investment
|
||||
[2]:https://opensource.com/node/16840
|
||||
[3]:http://www.appropedia.org/Open-source_Lab
|
||||
[4]:https://www.academia.edu/32004903/Emerging_Business_Models_for_Open_Source_Hardware
|
||||
[5]:http://openhardware.science/
|
||||
[6]:https://opensource.com/life/16/7/hardwarex-open-access-journal
|
||||
[7]:https://openhardware.metajnl.com/
|
||||
[8]:https://openresearchsoftware.metajnl.com/
|
||||
[9]:https://www.journals.elsevier.com/hardwarex
|
||||
[10]:https://opensource.com/node/30041
|
||||
[11]:https://www.academia.edu/35603319/General_Design_Procedure_for_Free_and_Open-Source_Hardware_for_Scientific_Equipment
|
||||
[12]:https://www.academia.edu/35382852/Maximizing_Returns_for_Public_Funding_of_Medical_Research_with_Open_source_Hardware
|
||||
[13]:http://www.openscad.org/
|
||||
[14]:https://www.freecadweb.org/
|
||||
[15]:https://www.blender.org/
|
||||
[16]:http://reprap.org/
|
||||
[17]:https://en.wikipedia.org/wiki/Parametric_design
|
||||
[18]:https://www.oshwa.org/sharing-best-practices/
|
||||
[19]:https://osf.io/
|
||||
[20]:http://www.fulbright.fi/en
|
@ -1,4 +1,4 @@
|
||||
10 easy steps from proprietary to open source
|
||||
Translating by FelixYFZ 10 easy steps from proprietary to open source
|
||||
======
|
||||
"But surely open source software is less secure, because everybody can see it, and they can just recompile it and replace it with bad stuff they've written." Hands up: who's heard this?1
|
||||
|
||||
|
@ -1,319 +0,0 @@
|
||||
A Simple Command-line Snippet Manager
|
||||
======
|
||||
|
||||
![](https://www.ostechnix.com/wp-content/uploads/2018/01/pet-6-720x340.png)
|
||||
|
||||
We can't remember all the commands, right? Yes. Except the frequently used commands, it is nearly impossible to remember some long commands that we rarely use. That's why we need to some external tools to help us to find the commands when we need them. In the past, we have reviewed two useful utilities named [**" Bashpast"**][1] and [**" Keep"**][2]. Using Bashpast, we can easily bookmark the Linux commands for easier repeated invocation. And, the Keep utility can be used to keep the some important and lengthy commands in your Terminal, so you can use them on demand. Today, we are going to see yet another tool in the series to help you remembering commands. Say hello to **" Pet"**, a simple command-line snippet manager written in **Go** language.
|
||||
|
||||
Using Pet, you can;
|
||||
|
||||
* Register/add your important, long and complex command snippets.
|
||||
* Search the saved command snippets interactively.
|
||||
* Run snippets directly without having to type over and over.
|
||||
* Edit the saved command snippets easily.
|
||||
* Sync the snippets via Gist.
|
||||
* Use variables in snippets.
|
||||
* And more yet to come.
|
||||
|
||||
|
||||
|
||||
#### Installing Pet CLI Snippet Manager
|
||||
|
||||
Since it is written in Go language, make sure you have installed Go in your system.
|
||||
|
||||
After Go language, grab the latest binaries from [**the releases page**][3].
|
||||
```
|
||||
wget https://github.com/knqyf263/pet/releases/download/v0.2.4/pet_0.2.4_linux_amd64.zip
|
||||
```
|
||||
|
||||
For 32 bit:
|
||||
```
|
||||
wget https://github.com/knqyf263/pet/releases/download/v0.2.4/pet_0.2.4_linux_386.zip
|
||||
```
|
||||
|
||||
Extract the downloaded archive:
|
||||
```
|
||||
unzip pet_0.2.4_linux_amd64.zip
|
||||
```
|
||||
|
||||
32 bit:
|
||||
```
|
||||
unzip pet_0.2.4_linux_386.zip
|
||||
```
|
||||
|
||||
Copy the pet binary file to your PATH (i.e **/usr/local/bin** or the like).
|
||||
```
|
||||
sudo cp pet /usr/local/bin/
|
||||
```
|
||||
|
||||
Finally, make it executable:
|
||||
```
|
||||
sudo chmod +x /usr/local/bin/pet
|
||||
```
|
||||
|
||||
If you're using Arch based systems, then you can install it from AUR using any AUR helper tools.
|
||||
|
||||
Using [**Pacaur**][4]:
|
||||
```
|
||||
pacaur -S pet-git
|
||||
```
|
||||
|
||||
Using [**Packer**][5]:
|
||||
```
|
||||
packer -S pet-git
|
||||
```
|
||||
|
||||
Using [**Yaourt**][6]:
|
||||
```
|
||||
yaourt -S pet-git
|
||||
```
|
||||
|
||||
Using [**Yay** :][7]
|
||||
```
|
||||
yay -S pet-git
|
||||
```
|
||||
|
||||
Also, you need to install **[fzf][8]** or [**peco**][9] tools to enable interactive search. Refer the official GitHub links to know how to install these tools.
|
||||
|
||||
#### Usage
|
||||
|
||||
Run 'pet' without any arguments to view the list of available commands and general options.
|
||||
```
|
||||
$ pet
|
||||
pet - Simple command-line snippet manager.
|
||||
|
||||
Usage:
|
||||
pet [command]
|
||||
|
||||
Available Commands:
|
||||
configure Edit config file
|
||||
edit Edit snippet file
|
||||
exec Run the selected commands
|
||||
help Help about any command
|
||||
list Show all snippets
|
||||
new Create a new snippet
|
||||
search Search snippets
|
||||
sync Sync snippets
|
||||
version Print the version number
|
||||
|
||||
Flags:
|
||||
--config string config file (default is $HOME/.config/pet/config.toml)
|
||||
--debug debug mode
|
||||
-h, --help help for pet
|
||||
|
||||
Use "pet [command] --help" for more information about a command.
|
||||
```
|
||||
|
||||
To view the help section of a specific command, run:
|
||||
```
|
||||
$ pet [command] --help
|
||||
```
|
||||
|
||||
**Configure Pet**
|
||||
|
||||
It just works fine with default values. However, you can change the default directory to save snippets, choose the selector (fzf or peco) to use, the default text editor to edit snippets, add GIST id details etc.
|
||||
|
||||
To configure Pet, run:
|
||||
```
|
||||
$ pet configure
|
||||
```
|
||||
|
||||
This command will open the default configuration in the default text editor (for example **vim** in my case). Change/edit the values as per your requirements.
|
||||
```
|
||||
[General]
|
||||
snippetfile = "/home/sk/.config/pet/snippet.toml"
|
||||
editor = "vim"
|
||||
column = 40
|
||||
selectcmd = "fzf"
|
||||
|
||||
[Gist]
|
||||
file_name = "pet-snippet.toml"
|
||||
access_token = ""
|
||||
gist_id = ""
|
||||
public = false
|
||||
~
|
||||
```
|
||||
|
||||
**Creating Snippets**
|
||||
|
||||
To create a new snippet, run:
|
||||
```
|
||||
$ pet new
|
||||
```
|
||||
|
||||
Add the command and the description and hit ENTER to save it.
|
||||
```
|
||||
Command> echo 'Hell1o, Welcome1 2to OSTechNix4' | tr -d '1-9'
|
||||
Description> Remove numbers from output.
|
||||
```
|
||||
|
||||
[![][10]][11]
|
||||
|
||||
This is a simple command to remove all numbers from the echo command output. You can easily remember it. But, if you rarely use it, you may forgot it completely after few days. Of course we can search the history using "CTRL+r", but "Pet" is much easier. Also, Pet can help you to add any number of entries.
|
||||
|
||||
Another cool feature is we can easily add the previous command. To do so, add the following lines in your **.bashrc** or **.zshrc** file.
|
||||
```
|
||||
function prev() {
|
||||
PREV=$(fc -lrn | head -n 1)
|
||||
sh -c "pet new `printf %q "$PREV"`"
|
||||
}
|
||||
```
|
||||
|
||||
Do the following command to take effect the saved changes.
|
||||
```
|
||||
source .bashrc
|
||||
```
|
||||
|
||||
Or,
|
||||
```
|
||||
source .zshrc
|
||||
```
|
||||
|
||||
Now, run any command, for example:
|
||||
```
|
||||
$ cat Documents/ostechnix.txt | tr '|' '\n' | sort | tr '\n' '|' | sed "s/.$/\\n/g"
|
||||
```
|
||||
|
||||
To add the above command, you don't have to use "pet new" command. just do:
|
||||
```
|
||||
$ prev
|
||||
```
|
||||
|
||||
Add the description to the command snippet and hit ENTER to save.
|
||||
|
||||
[![][10]][12]
|
||||
|
||||
**List snippets**
|
||||
|
||||
To view the saved snippets, run:
|
||||
```
|
||||
$ pet list
|
||||
```
|
||||
|
||||
[![][10]][13]
|
||||
|
||||
**Edit Snippets**
|
||||
|
||||
If you want to edit the description or the command of a snippet, run:
|
||||
```
|
||||
$ pet edit
|
||||
```
|
||||
|
||||
This will open all saved snippets in your default text editor. You can edit or change the snippets as you wish.
|
||||
```
|
||||
[[snippets]]
|
||||
description = "Remove numbers from output."
|
||||
command = "echo 'Hell1o, Welcome1 2to OSTechNix4' | tr -d '1-9'"
|
||||
output = ""
|
||||
|
||||
[[snippets]]
|
||||
description = "Alphabetically sort one line of text"
|
||||
command = "\t prev"
|
||||
output = ""
|
||||
```
|
||||
|
||||
**Use Tags in snippets**
|
||||
|
||||
To use tags to a snippet, use **-t** flag like below.
|
||||
```
|
||||
$ pet new -t
|
||||
Command> echo 'Hell1o, Welcome1 2to OSTechNix4' | tr -d '1-9
|
||||
Description> Remove numbers from output.
|
||||
Tag> tr command examples
|
||||
|
||||
```
|
||||
|
||||
**Execute Snippets**
|
||||
|
||||
To execute a saved snippet, run:
|
||||
```
|
||||
$ pet exec
|
||||
```
|
||||
|
||||
Choose the snippet you want to run from the list and hit ENTER to run it.
|
||||
|
||||
[![][10]][14]
|
||||
|
||||
Remember you need to install fzf or peco to use this feature.
|
||||
|
||||
**Search Snippets**
|
||||
|
||||
If you have plenty of saved snippets, you can easily search them using a string or key word like below.
|
||||
```
|
||||
$ pet search
|
||||
```
|
||||
|
||||
Enter the search term or keyword to narrow down the search results.
|
||||
|
||||
[![][10]][15]
|
||||
|
||||
**Sync Snippets**
|
||||
|
||||
First, you need to obtain the access token. Go to this link <https://github.com/settings/tokens/new> and create access token (only need "gist" scope).
|
||||
|
||||
Configure Pet using command:
|
||||
```
|
||||
$ pet configure
|
||||
```
|
||||
|
||||
Set that token to **access_token** in **[Gist]** field.
|
||||
|
||||
After setting, you can upload snippets to Gist like below.
|
||||
```
|
||||
$ pet sync -u
|
||||
Gist ID: 2dfeeeg5f17e1170bf0c5612fb31a869
|
||||
Upload success
|
||||
|
||||
```
|
||||
|
||||
You can also download snippets on another PC. To do so, edit configuration file and set **Gist ID** to **gist_id** in **[Gist]**.
|
||||
|
||||
Then, download the snippets using command:
|
||||
```
|
||||
$ pet sync
|
||||
Download success
|
||||
|
||||
```
|
||||
|
||||
For more details, refer the help section:
|
||||
```
|
||||
pet -h
|
||||
```
|
||||
|
||||
Or,
|
||||
```
|
||||
pet [command] -h
|
||||
```
|
||||
|
||||
And, that's all. Hope this helps. As you can see, Pet usage is fairly simple and easy to use! If you're having hard time remembering lengthy commands, Pet utility can definitely be useful.
|
||||
|
||||
Cheers!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/pet-simple-command-line-snippet-manager/
|
||||
|
||||
作者:[SK][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.ostechnix.com/author/sk/
|
||||
[1]:https://www.ostechnix.com/bookmark-linux-commands-easier-repeated-invocation/
|
||||
[2]:https://www.ostechnix.com/save-commands-terminal-use-demand/
|
||||
[3]:https://github.com/knqyf263/pet/releases
|
||||
[4]:https://www.ostechnix.com/install-pacaur-arch-linux/
|
||||
[5]:https://www.ostechnix.com/install-packer-arch-linux-2/
|
||||
[6]:https://www.ostechnix.com/install-yaourt-arch-linux/
|
||||
[7]:https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/
|
||||
[8]:https://github.com/junegunn/fzf
|
||||
[9]:https://github.com/peco/peco
|
||||
[10]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[11]:http://www.ostechnix.com/wp-content/uploads/2018/01/pet-1.png ()
|
||||
[12]:http://www.ostechnix.com/wp-content/uploads/2018/01/pet-2.png ()
|
||||
[13]:http://www.ostechnix.com/wp-content/uploads/2018/01/pet-3.png ()
|
||||
[14]:http://www.ostechnix.com/wp-content/uploads/2018/01/pet-4.png ()
|
||||
[15]:http://www.ostechnix.com/wp-content/uploads/2018/01/pet-5.png ()
|
@ -1,75 +0,0 @@
|
||||
构建开源硬件的5个关键点
|
||||
======
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/openhardwaretools.png?itok=DC1RC_1f)
|
||||
科学社区正在加速拥抱自由和开源硬件([FOSH][1]). 研究员正忙于[改进他们自己的装备][2]并创造数以百计基于分布式数字制造模型的设备来推动他们的研究。
|
||||
|
||||
热衷于 FOSH 的主要原因还是钱: 有研究表明,和专用设备相比,FOSH 可以[节省90%到99%的花费][3]。基于[开源硬件商业模式][4]的科学 FOSH 的商业化已经推动其快速地发展为一个新的工程领域,并为此定期[举行年会][5]。
|
||||
|
||||
特别的是,不止一本,而是关于这个主题的[两本学术期刊]:[Journal of Open Hardware] (由Ubiquity出版,一个新的自由访问出版商,同时出版了[Journal of Open Research Software][8])以及[HardwareX][9](由Elsevier出版的一种[自由访问期刊][10],它是世界上最大的学术出版商之一)。
|
||||
|
||||
由于学术社区的支持,科学 FOSH 的开发者在获取制作乐趣并推进科学快速发展的同时获得学术声望。
|
||||
|
||||
### 科学 FOSH 的5个步骤
|
||||
|
||||
协恩 (Shane Oberloier)和我在名为Designes的自由问工程期刊上共同发表了一篇关于设计 FOSH 科学设备原则的[文章][11]。我们以滑动烘干机为例,制造成本低于20美元,仅是专用设备价格的三百分之一。[科学][1]和[医疗][12]设备往往比较复杂,开发 FOSH 替代品将带来巨大的回报。
|
||||
|
||||
我总结了5个步骤(包括6条设计原则),它们在协恩和我发表的文章里有详细阐述。这些设计原则也推广到非科学设备,而且制作越复杂的设计越能带来更大的潜在收益。
|
||||
|
||||
如果你对科学项目的开源硬件设计感兴趣,这些步骤将使你的项目的影响最大化。
|
||||
|
||||
1. 评估类似现有工具的功能,你的 FOSH 设计目标应该针对实际效果而不是现有的设计(译者注:作者的意思应该是不要被现有设计缚住手脚)。必要的时候需进行概念证明。
|
||||
|
||||
2. 使用下列设计原则:
|
||||
|
||||
* 在设备生产中,仅适用自由和开源的软件工具链(比如,开源的CAD工具,例如[OpenSCAD][13], [FreeCAD][14], or [Blender][15])和开源硬件。
|
||||
* 尝试减少部件的数量和类型并降低工具的复杂度
|
||||
* 减少材料的数量和制造成本。
|
||||
* 尽量使用方便易得的工具(比如 [RepRap 3D 打印机][16])进行部件的分布式或数字化生产。
|
||||
* 对部件进行[参数化设计][17],这使他人可以对你的设计进行个性化改动。相较于特例化设计,参数化设计会更有用。在未来的项目中,使用者可以通过修改核心参数来继续利用它们。
|
||||
?* 所有不能使用开源硬件进行分布制造的零件,必须选择现货产品以方便采购。
|
||||
|
||||
3. 验证功能设计
|
||||
|
||||
?4. 提供关于设计、生产、装配、校准和操作的详尽文档。包括原始设计文件而不仅仅是设计输出。开源硬件协会对于开源设计的发布和文档化有额外的[指南][18],总结如下:
|
||||
|
||||
* 以通用的形式分享设计文件
|
||||
* 提供详尽的材料清单,包括价格和采购信息
|
||||
* 如果包含软件,确保代码对大众来说清晰易懂
|
||||
* 作为生产时的参考,必须提供足够的照片,以确保没有任何被遮挡的部分。
|
||||
* 在描述方法的章节,整个制作过程必须被细化成简单步骤以便复制此设计。
|
||||
* 在线上分享并指定许可证。这为用户提供了合理使用设计的信息。
|
||||
|
||||
?5. 主动分享!为了使 FOSH 发扬光大,设计必须被广泛、频繁和有效地分享以提升他们的存在感。所有的文档应该在自由访问文献中发表,并与适当的社区共享。[开源科学框架][19]是一个值得考虑的优雅的通用存储库,它由开源科学中心主办,该中心设置为接受任何类型的文件并处理大型数据集。
|
||||
|
||||
这篇文章得到了 [Fulbright Finland][20] 的支持,该公司赞助了芬兰 Fulbright-Aalto 大学的特聘校席 Joshua Pearce 在开源科学硬件方面的研究工作。
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/2/5-steps-creating-successful-open-hardware
|
||||
|
||||
作者:[Joshua Pearce][a]
|
||||
译者:[kennethXia](https://github.com/kennethXia)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/jmpearce
|
||||
[1]:https://opensource.com/business/16/4/how-calculate-open-source-hardware-return-investment
|
||||
[2]:https://opensource.com/node/16840
|
||||
[3]:http://www.appropedia.org/Open-source_Lab
|
||||
[4]:https://www.academia.edu/32004903/Emerging_Business_Models_for_Open_Source_Hardware
|
||||
[5]:http://openhardware.science/
|
||||
[6]:https://opensource.com/life/16/7/hardwarex-open-access-journal
|
||||
[7]:https://openhardware.metajnl.com/
|
||||
[8]:https://openresearchsoftware.metajnl.com/
|
||||
[9]:https://www.journals.elsevier.com/hardwarex
|
||||
[10]:https://opensource.com/node/30041
|
||||
[11]:https://www.academia.edu/35603319/General_Design_Procedure_for_Free_and_Open-Source_Hardware_for_Scientific_Equipment
|
||||
[12]:https://www.academia.edu/35382852/Maximizing_Returns_for_Public_Funding_of_Medical_Research_with_Open_source_Hardware
|
||||
[13]:http://www.openscad.org/
|
||||
[14]:https://www.freecadweb.org/
|
||||
[15]:https://www.blender.org/
|
||||
[16]:http://reprap.org/
|
||||
[17]:https://en.wikipedia.org/wiki/Parametric_design
|
||||
[18]:https://www.oshwa.org/sharing-best-practices/
|
||||
[19]:https://osf.io/
|
||||
[20]:http://www.fulbright.fi/en
|
@ -0,0 +1,318 @@
|
||||
一个简单的命令行片段管理器
|
||||
=====
|
||||
|
||||
![](https://www.ostechnix.com/wp-content/uploads/2018/01/pet-6-720x340.png)
|
||||
我们不可能记住所有的命令,对吧?是的。除了经常使用的命令之外,我们几乎不可能记住一些很少使用的长命令。这就是为什么需要一些外部工具来帮助我们在需要时找到命令。在过去,我们已经审查了两个有用的工具,名为 "Bashpast" 和 "Keep"。使用 Bashpast,我们可以轻松地为 Linux 命令添加书签,以便更轻松地重复调用。而且,Keep 实用程序可以用来在终端中保留一些重要且冗长的命令,以便你可以按需使用它们。今天,我们将看到该系列中的另一个工具,以帮助你记住命令。现在向 "Pet" 打个招呼,这是一个用 Go 语言编写的简单的命令行代码管理器。
|
||||
|
||||
使用 Pet,你可以:
|
||||
|
||||
* 注册/添加你重要的,冗长和复杂的命令片段。
|
||||
* 以交互方式来搜索保存的命令片段。
|
||||
* 直接运行代码片段而无须一遍又一遍地输入。
|
||||
* 轻松编辑保存的代码片段。
|
||||
* 通过 Gist 同步片段。
|
||||
* 在片段中使用变量
|
||||
* 还有很多特性即将来临。
|
||||
|
||||
|
||||
#### 安装 Pet 命令行接口代码管理器
|
||||
|
||||
由于它是用 Go 语言编写的,所以确保你在系统中已经安装了 Go。
|
||||
|
||||
安装 Go 后,从 [**Pet 发布页面**][3] 获取最新的二进制文件。
|
||||
```
|
||||
wget https://github.com/knqyf263/pet/releases/download/v0.2.4/pet_0.2.4_linux_amd64.zip
|
||||
```
|
||||
|
||||
对于 32 位计算机:
|
||||
```
|
||||
wget https://github.com/knqyf263/pet/releases/download/v0.2.4/pet_0.2.4_linux_386.zip
|
||||
```
|
||||
|
||||
解压下载的文件:
|
||||
```
|
||||
unzip pet_0.2.4_linux_amd64.zip
|
||||
```
|
||||
|
||||
对于 32 位:
|
||||
```
|
||||
unzip pet_0.2.4_linux_386.zip
|
||||
```
|
||||
|
||||
将 pet 二进制文件复制到 PATH(即 **/usr/local/bin** 之类的)。
|
||||
```
|
||||
sudo cp pet /usr/local/bin/
|
||||
```
|
||||
|
||||
最后,让它可以执行:
|
||||
```
|
||||
sudo chmod +x /usr/local/bin/pet
|
||||
```
|
||||
|
||||
如果你使用的是基于 Arch 的系统,那么你可以使用任何 AUR 帮助工具从 AUR 安装它。
|
||||
|
||||
使用 [**Pacaur**][4]:
|
||||
```
|
||||
pacaur -S pet-git
|
||||
```
|
||||
|
||||
使用 [**Packer**][5]:
|
||||
```
|
||||
packer -S pet-git
|
||||
```
|
||||
|
||||
使用 [**Yaourt**][6]:
|
||||
```
|
||||
yaourt -S pet-git
|
||||
```
|
||||
|
||||
使用 [**Yay** :][7]
|
||||
```
|
||||
yay -S pet-git
|
||||
```
|
||||
|
||||
此外,你需要安装 **[fzf][8]** 或 [**peco**][9] 工具已启用交互式搜索。请参阅官方 GitHub 链接了解如何安装这些工具。
|
||||
|
||||
#### 用法
|
||||
|
||||
运行没有任何参数的 'pet' 来查看可用命令和常规选项的列表。
|
||||
```
|
||||
$ pet
|
||||
pet - Simple command-line snippet manager.
|
||||
|
||||
Usage:
|
||||
pet [command]
|
||||
|
||||
Available Commands:
|
||||
configure Edit config file
|
||||
edit Edit snippet file
|
||||
exec Run the selected commands
|
||||
help Help about any command
|
||||
list Show all snippets
|
||||
new Create a new snippet
|
||||
search Search snippets
|
||||
sync Sync snippets
|
||||
version Print the version number
|
||||
|
||||
Flags:
|
||||
--config string config file (default is $HOME/.config/pet/config.toml)
|
||||
--debug debug mode
|
||||
-h, --help help for pet
|
||||
|
||||
Use "pet [command] --help" for more information about a command.
|
||||
```
|
||||
|
||||
要查看特定命令的帮助部分,运行:
|
||||
```
|
||||
$ pet [command] --help
|
||||
```
|
||||
|
||||
**配置 Pet**
|
||||
|
||||
它只适用于默认值。但是,你可以更改默认目录来保存片段,选择要使用的选择器 (fzf 或 peco),默认文本编辑器编辑片段,添加 GIST id 详细信息等。
|
||||
|
||||
|
||||
要配置 Pet,运行:
|
||||
```
|
||||
$ pet configure
|
||||
```
|
||||
|
||||
该命令将在默认的文本编辑器中打开默认配置(例如我是 **vim**),根据你的要求更改或编辑特定值。
|
||||
```
|
||||
[General]
|
||||
snippetfile = "/home/sk/.config/pet/snippet.toml"
|
||||
editor = "vim"
|
||||
column = 40
|
||||
selectcmd = "fzf"
|
||||
|
||||
[Gist]
|
||||
file_name = "pet-snippet.toml"
|
||||
access_token = ""
|
||||
gist_id = ""
|
||||
public = false
|
||||
~
|
||||
```
|
||||
|
||||
**创建片段**
|
||||
|
||||
为了创建一个新的片段,运行:
|
||||
```
|
||||
$ pet new
|
||||
```
|
||||
|
||||
添加命令和描述,然后按下 ENTER 键保存它。
|
||||
```
|
||||
Command> echo 'Hell1o, Welcome1 2to OSTechNix4' | tr -d '1-9'
|
||||
Description> Remove numbers from output.
|
||||
```
|
||||
|
||||
[![][10]][11]
|
||||
|
||||
这是一个简单的命令,用于从 echo 命令输出中删除所有数字。你可以很轻松地记住它。但是,如果你很少使用它,几天后你可能会完全忘记它。当然,我们可以使用 "CTRL+r" 搜索历史记录,但 "Pet" 会更容易。另外,Pet 可以帮助你添加任意数量的条目。
|
||||
|
||||
另一个很酷的功能是我们可以轻松添加以前的命令。为此,在你的 **.bashrc** 或 **.zshrc** 文件中添加以下行。
|
||||
```
|
||||
function prev() {
|
||||
PREV=$(fc -lrn | head -n 1)
|
||||
sh -c "pet new `printf %q "$PREV"`"
|
||||
}
|
||||
```
|
||||
|
||||
执行以下命令来使保存的更改生效。
|
||||
```
|
||||
source .bashrc
|
||||
```
|
||||
|
||||
或者
|
||||
```
|
||||
source .zshrc
|
||||
```
|
||||
|
||||
现在,运行任何命令,例如:
|
||||
```
|
||||
$ cat Documents/ostechnix.txt | tr '|' '\n' | sort | tr '\n' '|' | sed "s/.$/\\n/g"
|
||||
```
|
||||
|
||||
要添加上述命令,你不必使用 "pet new" 命令。只需要:
|
||||
```
|
||||
$ prev
|
||||
```
|
||||
|
||||
将说明添加到命令代码片段中,然后按下 ENTER 键保存。
|
||||
|
||||
![][12]
|
||||
|
||||
**片段列表**
|
||||
|
||||
要查看保存的片段,运行:
|
||||
```
|
||||
$ pet list
|
||||
```
|
||||
|
||||
![][13]
|
||||
|
||||
**编辑片段**
|
||||
|
||||
如果你想编辑描述或代码片段的命令,运行:
|
||||
```
|
||||
$ pet edit
|
||||
```
|
||||
|
||||
这将在你的默认文本编辑器中打开所有保存的代码片段,你可以根据需要编辑或更改片段。
|
||||
```
|
||||
[[snippets]]
|
||||
description = "Remove numbers from output."
|
||||
command = "echo 'Hell1o, Welcome1 2to OSTechNix4' | tr -d '1-9'"
|
||||
output = ""
|
||||
|
||||
[[snippets]]
|
||||
description = "Alphabetically sort one line of text"
|
||||
command = "\t prev"
|
||||
output = ""
|
||||
```
|
||||
|
||||
**在片段中使用标签**
|
||||
|
||||
要将标签用于判断,使用下面的 **-t** 标志。
|
||||
```
|
||||
$ pet new -t
|
||||
Command> echo 'Hell1o, Welcome1 2to OSTechNix4' | tr -d '1-9
|
||||
Description> Remove numbers from output.
|
||||
Tag> tr command examples
|
||||
|
||||
```
|
||||
|
||||
**执行片段**
|
||||
|
||||
要执行一个保存的片段,运行:
|
||||
```
|
||||
$ pet exec
|
||||
```
|
||||
|
||||
从列表中选择你要运行的代码段,然后按 ENTER 键来运行它:
|
||||
|
||||
![][14]
|
||||
|
||||
记住你需要安装 fzf 或 peco 才能使用此功能。
|
||||
|
||||
**寻找片段**
|
||||
|
||||
如果你有很多要保存的片段,你可以使用字符串或关键词如 below.qjz 轻松搜索它们。
|
||||
```
|
||||
$ pet search
|
||||
```
|
||||
|
||||
输入搜索字词或关键字以缩小搜索结果范围。
|
||||
|
||||
![][15]
|
||||
|
||||
**同步片段**
|
||||
|
||||
首先,你需要获取访问令牌。转到此链接 <https://github.com/settings/tokens/new> 并创建访问令牌(只需要 "gist" 范围)。
|
||||
|
||||
使用以下命令来配置 Pet:
|
||||
```
|
||||
$ pet configure
|
||||
```
|
||||
|
||||
将标记设置到 **[Gist]** 字段中的 **access_token**。
|
||||
|
||||
设置完成后,你可以像下面一样将片段上传到 Gist。
|
||||
```
|
||||
$ pet sync -u
|
||||
Gist ID: 2dfeeeg5f17e1170bf0c5612fb31a869
|
||||
Upload success
|
||||
|
||||
```
|
||||
|
||||
你也可以在其他 PC 上下载片段。为此,编辑配置文件并在 **[Gist]** 中将 **Gist ID** 设置为 **gist_id**。
|
||||
|
||||
之后,下载片段使用以下命令:
|
||||
```
|
||||
$ pet sync
|
||||
Download success
|
||||
|
||||
```
|
||||
|
||||
获取更多细节,参阅 help 选项:
|
||||
```
|
||||
pet -h
|
||||
```
|
||||
|
||||
或者
|
||||
```
|
||||
pet [command] -h
|
||||
```
|
||||
|
||||
这就是全部了。希望这可以帮助到你。正如你所看到的,Pet 使用相当简单易用!如果你很难记住冗长的命令,Pet 实用程序肯定会有用。
|
||||
|
||||
干杯!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/pet-simple-command-line-snippet-manager/
|
||||
|
||||
作者:[SK][a]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://www.ostechnix.com/author/sk/
|
||||
[1]:https://www.ostechnix.com/bookmark-linux-commands-easier-repeated-invocation/
|
||||
[2]:https://www.ostechnix.com/save-commands-terminal-use-demand/
|
||||
[3]:https://github.com/knqyf263/pet/releases
|
||||
[4]:https://www.ostechnix.com/install-pacaur-arch-linux/
|
||||
[5]:https://www.ostechnix.com/install-packer-arch-linux-2/
|
||||
[6]:https://www.ostechnix.com/install-yaourt-arch-linux/
|
||||
[7]:https://www.ostechnix.com/yay-found-yet-another-reliable-aur-helper/
|
||||
[8]:https://github.com/junegunn/fzf
|
||||
[9]:https://github.com/peco/peco
|
||||
[10]:data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
|
||||
[11]:http://www.ostechnix.com/wp-content/uploads/2018/01/pet-1.png
|
||||
[12]:http://www.ostechnix.com/wp-content/uploads/2018/01/pet-2.png
|
||||
[13]:http://www.ostechnix.com/wp-content/uploads/2018/01/pet-3.png
|
||||
[14]:http://www.ostechnix.com/wp-content/uploads/2018/01/pet-4.png
|
||||
[15]:http://www.ostechnix.com/wp-content/uploads/2018/01/pet-5.png
|
Loading…
Reference in New Issue
Block a user