mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
7822350abd
154
published/20200615 How to use Bash history commands.md
Normal file
154
published/20200615 How to use Bash history commands.md
Normal file
@ -0,0 +1,154 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12344-1.html)
|
||||
[#]: subject: (How to use Bash history commands)
|
||||
[#]: via: (https://opensource.com/article/20/6/bash-history-commands)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
如何使用 Bash history 命令
|
||||
======
|
||||
|
||||
> Bash 的 history 命令在它提供的功能数量上超过了所有其他 Linux Shell 历史接口。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202006/24/101620c0uj0dgg0buo9nib.jpg)
|
||||
|
||||
Bash 有丰富的历史。也就是说,它是一个古老的的 shell,还有一个更古老的 Shell (Bourne shell)的前辈,但是它还有一个很棒的 `history` 命令,它提供的功能数量超过了所有其他 shell 的历史接口。 [Bash][2] 版本的 `history` 可进行反向搜索、快速调用、重写历史记录等。
|
||||
|
||||
`history` 命令与许多其他命令不同。你可能习惯于将命令作为可执行文件放在常见的系统级位置,例如 `/usr/bin`、`/usr/local/bin` 或者 `~/bin`。 内置的 `history` 命令不在你的 `PATH` 中并且没有物理位置:
|
||||
|
||||
|
||||
```
|
||||
$ which history
|
||||
|
||||
which: no history in [PATH]
|
||||
```
|
||||
|
||||
相反,`history` 是 shell 本身的内置函数:
|
||||
|
||||
```
|
||||
$ type history
|
||||
history is a shell builtin
|
||||
$ help history
|
||||
history: history [-c] [-d offset] [n] or
|
||||
history -anrw [filename] or
|
||||
history -ps arg [arg...]
|
||||
|
||||
Display or manipulate the history list.
|
||||
[...]
|
||||
```
|
||||
|
||||
出于这个原因,每个 shell 中的历史功能都是独特的,因此你在 Bash 中使用的功能可能无法在 Tcsh 或 Fish 或 Dash 中使用,而在这些 shell 中使用的功能可能也无法在 Bash 中使用。在某些情况下,了解 Bash 可以做什么可能会激发其他 shell 的用户创建有趣的改造来复制 Bash 行为,并且可能会解锁你从未知道的 Bash 功能。
|
||||
|
||||
### 查看你的 Bash 历史
|
||||
|
||||
`history` 命令最基本、最频繁的用法是查看 shell 会话的历史记录:
|
||||
|
||||
|
||||
```
|
||||
$ echo "hello"
|
||||
hello
|
||||
$ echo "world"
|
||||
world
|
||||
$ history
|
||||
1 echo "hello"
|
||||
2 echo "world"
|
||||
3 history
|
||||
```
|
||||
|
||||
### 事件指示器
|
||||
|
||||
<ruby>事件指示器<rt>Event designator</rt></ruby>按事件搜索你的历史记录。在这里,“事件”是指记录在历史中的命令,以换行符划定。换句话说,一行一个事件,以索引号来标记。
|
||||
|
||||
事件指示器大多以感叹号开头,有时也称为 “bang”(`!`)。
|
||||
|
||||
要从你的历史记录中重新运行命令,请使用感叹号,之后紧跟(之间没有空格)所需命令的索引号。例如,假设第 1 行包含命令 `echo "hello"`,你想要想再次运行它:
|
||||
|
||||
|
||||
```
|
||||
$ !1
|
||||
echo "hello"
|
||||
hello
|
||||
```
|
||||
|
||||
你可以使用相对定位,提供基于你历史中当前位置向后的负数行号。例如,返回到历史中倒数第三个条目:
|
||||
|
||||
```
|
||||
$ echo "foo"
|
||||
foo
|
||||
$ echo "bar"
|
||||
bar
|
||||
$ echo "baz"
|
||||
baz
|
||||
$ !-3
|
||||
echo "foo"
|
||||
foo
|
||||
```
|
||||
|
||||
如果只想回去一行,那么可以使用速记 `!!` 代替 `!-1`。这节省了按键时间!
|
||||
|
||||
```
|
||||
$ echo "foo"
|
||||
$ !!
|
||||
echo "foo"
|
||||
foo
|
||||
```
|
||||
|
||||
### 字符串搜索
|
||||
|
||||
你也可以对条目搜索特定的字符串,反过来搜索要运行命令。要搜索以指定字符串*开始*的命令,请使用感叹号,之后紧跟(没有空格)要搜索的字符串:
|
||||
|
||||
```
|
||||
$ echo "foo"
|
||||
$ true
|
||||
$ false
|
||||
$ !echo
|
||||
echo "foo"
|
||||
foo
|
||||
```
|
||||
|
||||
你还可以在任意位置(不仅是开头)搜索包含该字符串的命令。为此,请像之前一样使用 `!` 加上要搜索的字符串,但在字符串的两端都用问号(`?`)围绕起来。如果你知道该字符串后紧跟一个换行符,那么可以省略最后的问号(就是在按*回车*之前输入的最后字符):
|
||||
|
||||
```
|
||||
$ echo "foo"
|
||||
$ true
|
||||
$ false
|
||||
$ !?foo?
|
||||
echo "foo"
|
||||
foo
|
||||
```
|
||||
|
||||
### 字符串替换
|
||||
|
||||
类似于在行首搜索字符串,你可以搜索字符串并用新字符串替换它,以更改命令:
|
||||
|
||||
```
|
||||
$ echo "hello"
|
||||
hello
|
||||
$ echo "world"
|
||||
world
|
||||
$ ^hello^foo
|
||||
echo "foo"
|
||||
foo
|
||||
```
|
||||
|
||||
### 让 history 有用
|
||||
|
||||
在 Bash 中,`history` 命令的功能远远超过此处介绍的内容,但这是一个很好的开始, 可以让你习惯使用你的历史记录, 而不是仅仅把它当作一个参考。经常使用 `history` 命令,并试试无需输入命令即可执行的操作。你可能会感到惊讶!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/6/bash-history-commands
|
||||
|
||||
作者:[Seth Kenlon][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/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/1980s-computer-yearbook.png?itok=eGOYEKK- (Person typing on a 1980's computer)
|
||||
[2]: https://opensource.com/resources/what-bash
|
@ -0,0 +1,81 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (GNU Health expands Raspberry Pi support, Megadeth's guitarist uses open source principles, and more open source news.)
|
||||
[#]: via: (https://opensource.com/article/20/6/news-june-23)
|
||||
[#]: author: (Lauren Maffeo https://opensource.com/users/lmaffeo)
|
||||
|
||||
GNU Health expands Raspberry Pi support, Megadeth's guitarist uses open source principles, and more open source news.
|
||||
======
|
||||
Catch up on the biggest open source headlines from the past two weeks.
|
||||
![][1]
|
||||
|
||||
In this week’s edition of our open source news roundup, GNU Health expands to Raspberry Pis, how Megadeth's guitarist uses open source principles, and more open source news.
|
||||
|
||||
### GNU Health expands its support for Raspberry Pi
|
||||
|
||||
The GNU Health project, designed to help hospitals run on low-cost software and hardware, expanded its support for Rapsberry Pi models in its recent release [according to CNX][2]. The GNU Health Embedded version that runs on Raspberry Pis is "especially suited for remote areas without internet, academic Institutions, domiciliary units, home nursing, and laboratory stations."
|
||||
|
||||
> *"GNU Health (GH) is a free and open-source Health and Hospital Information System (HIS) that can manage the internal processes of a health institution, such as financial management, electronic medical records (EMR), stock & pharmacies or laboratories (LIMS)." *
|
||||
|
||||
GNU Health is a free and open source health and hospital information system (HIS) to help healthcare systems manage finances, pharmacies, electronic medical records (EMRs), and more. The Raspberry Pi solution supports real-time monitoring of vital signs in hospitals, and retrieve information from labs.
|
||||
|
||||
More details may be found on [the official website][3].
|
||||
|
||||
### Megadeth's guitarist brings OSS approaches to music
|
||||
|
||||
Heavy metal fans likely know Kiko Loureiro as Megadeth's guitarist. Loureiro is less known in the OSS world, but that might change soon: His new solo album is called _Open Source_.
|
||||
|
||||
"By definition, 'open source' is related to softwares [in] which the original source code is made freely available and may be redistributed and modified," Loureiro shared [in a recent interview.][4] "It brings us a higher sense of community, enhances our creativity and creates new possibilities."
|
||||
|
||||
In true open source fashion, Loureiro is running an Indiegogo fundraiser to [keep his album][5] independent. His fundraiser emphasizes the "Open Source Mentality," which includes making his song's stems available for listeners to remix.
|
||||
|
||||
### The Linux Foundation partners with Harvard for a FOSS contributor security survey
|
||||
|
||||
The Linux Foundation's Core Infrastructure Initiative (CII) launched [a survey for FOSS contributors][6] addressing security concerns in open source. CII developed the survey in partnership with the Laboratory for Innovation Science at Harvard (LISH). FOSS contributors can [take the survey][7] through early August.
|
||||
|
||||
This new survey follows [the Census II analysis and report][8], which assessed popular FOSS components for vulnerabilities. David A. Wheeler, The Linux Foundation's director of open source supply chain security, said the survey is essential since open source solutions are used so widely now.
|
||||
|
||||
Along with its reports and surveys, CII built a [Best Practices badge program][9] that encourages developers to audit their solutions for security threats.
|
||||
|
||||
### In other news
|
||||
|
||||
* [OpenStack adds the StarlingX edge computing stack to its top-level projects][10]
|
||||
|
||||
* [OpenSAFELY is a new secure analytics platform for electronic health records in the NHS][11]
|
||||
|
||||
* [Linux Kernel 5.6 Reached End of Life, Upgrade to Linux Kernel 5.7 Now][12]
|
||||
|
||||
|
||||
|
||||
|
||||
Thanks, as always, to Opensource.com staff members and [Correspondents][13] for their help this week.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/6/news-june-23
|
||||
|
||||
作者:[Lauren Maffeo][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/lmaffeo
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/weekly_news_roundup_tv.png?itok=tibLvjBd
|
||||
[2]: https://www.cnx-software.com/2020/06/15/gnu-health-embedded-open-source-health-platform-works-on-raspberry-pi-3-4-and-soon-olimex-sbcs
|
||||
[3]: https://www.gnuhealth.org/#/embedded
|
||||
[4]: https://www.blabbermouth.net/news/megadeths-kiko-loureiro-unveils-cover-art-for-open-source-solo-album/
|
||||
[5]: https://www.indiegogo.com/projects/kiko-loureiro-new-open-source-album#/
|
||||
[6]: https://www.linuxfoundation.org/blog/2020/06/linux-foundation-harvard-announce-free-libre-and-open-source-software-foss-contributor-survey/?SSAID=389818&sscid=61k4_isd0j
|
||||
[7]: https://hbs.qualtrics.com/jfe/form/SV_enfu6tjRM0QzwQB
|
||||
[8]: https://www.coreinfrastructure.org/programs/census-program-ii/
|
||||
[9]: https://www.linuxfoundation.org/blog/2020/06/why-cii-best-practices-gold-badges-are-important/?SSAID=389818&sscid=61k4_isyv5
|
||||
[10]: https://techcrunch.com/2020/06/11/openstack-adds-the-starlinkx-edge-computing-stack-to-its-top-level-projects/
|
||||
[11]: https://opensafely.org/
|
||||
[12]: https://9to5linux.com/linux-kernel-5-6-reached-end-of-life-upgrade-to-linux-kernel-5-7-now
|
||||
[13]: https://opensource.com/correspondent-program
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,158 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to use Bash history commands)
|
||||
[#]: via: (https://opensource.com/article/20/6/bash-history-commands)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
如何使用 Bash history 命令
|
||||
======
|
||||
Bash 的 history 命令超过了所有其他 Linux Shell history 接口提供的功能数量。
|
||||
![Person typing on a 1980's computer][1]
|
||||
|
||||
Bash 有丰富的历史。 也就是说,它是一个久远的 shell(Bourne shell),但是它还有一个很棒的 `history` 命令,它的功能数量超过了所有其他 shell 的 history 接口。 [Bash][2]版本的 `history` 可进行反向搜索、快速调用、重写历史记录等。
|
||||
|
||||
`history` 命令与许多其他命令不同。 你可能习惯于将命令作为可执行文件放在常见的系统级位置,例如 `/usr/bin`、`/usr/local/bin` 或者 `~/bin`。 内置的 `history` 命令不在你的 `PATH` 中并且没有物理位置:
|
||||
|
||||
|
||||
```
|
||||
$ which history
|
||||
|
||||
which: no history in [PATH]
|
||||
```
|
||||
|
||||
相反,`history` 是 shell 本身的内置函数:
|
||||
|
||||
|
||||
```
|
||||
$ type history
|
||||
history is a shell builtin
|
||||
$ help history
|
||||
history: history [-c] [-d offset] [n] or
|
||||
history -anrw [filename] or
|
||||
history -ps arg [arg...]
|
||||
|
||||
Display or manipulate the history list.
|
||||
[...]
|
||||
```
|
||||
|
||||
因此,每个 shell 中的历史功能都是唯一的,因此你在 Bash 中使用的内容可能无法在 Tcsh 或 Fish 或 Dash 中使用,而在这些 shell 中使用的内容可能也无法在 Bash 中使用。在某些情况下,了解 Bash 可以做什么可能会激发其他 shell 的用户创建有趣的改造来复制 Bash 行为,并且可能会解锁你从未知道的 Bash 功能。
|
||||
|
||||
### 查看你的 Bash 历史
|
||||
|
||||
`history` 命令最基本,最频繁的用法是查看 shell 会话的历史记录:
|
||||
|
||||
|
||||
```
|
||||
$ echo "hello"
|
||||
hello
|
||||
$ echo "world"
|
||||
world
|
||||
$ history
|
||||
1 echo "hello"
|
||||
2 echo "world"
|
||||
3 history
|
||||
```
|
||||
|
||||
### 事件指示器
|
||||
|
||||
事件指示器 (Event designator) 按事件搜索你的历史记录。在这里,_事件_ (enent) 是记录在历史中的命令,以换行符表示。换句话说,它是一行,以索引号来标记。
|
||||
|
||||
事件指示器大多以感叹号开头,有时也称为 _bang_(`!`)。
|
||||
|
||||
要从你的历史记录中重新运行命令,请使用感叹号,之后紧跟(无空格)所需命令的索引号。例如,假设第 1 行包含命令 `echo "hello"`,你想要想再次运行它:
|
||||
|
||||
|
||||
```
|
||||
$ !1
|
||||
echo "hello"
|
||||
hello
|
||||
```
|
||||
|
||||
你可以在 history 中使用基于你当前位置的负数行号进行相对定位。例如,返回到倒数第三个条目:
|
||||
|
||||
|
||||
```
|
||||
$ echo "foo"
|
||||
foo
|
||||
$ echo "bar"
|
||||
bar
|
||||
$ echo "baz"
|
||||
baz
|
||||
$ !-3
|
||||
echo "foo"
|
||||
foo
|
||||
```
|
||||
|
||||
如果只想回去一行,那么可以使用速记 `!!` 代替 `!-1`。这节省了按键时间!
|
||||
|
||||
|
||||
```
|
||||
$ echo "foo"
|
||||
$ !!
|
||||
echo "foo"
|
||||
foo
|
||||
```
|
||||
|
||||
### 字符串搜索
|
||||
|
||||
你也可以反过来通过条目搜索特定的字符串来运行命令。要搜索以指定字符串_开始_的命令,请使用感叹号,之后紧跟(无空格)要搜索的字符串:
|
||||
|
||||
|
||||
```
|
||||
$ echo "foo"
|
||||
$ true
|
||||
$ false
|
||||
$ !echo
|
||||
echo "foo"
|
||||
foo
|
||||
```
|
||||
|
||||
你还可以搜索在任意位置(不仅是开头)包含该字符串的命令。为此,请像之前一样使用 `!` 加上要搜索的字符串,但在字符串的两端都用问号围绕起来。如果你知道该字符串后紧跟一个换行符,那么可以省略最后的问号(就是在按**回车**之前输入的最后字符):
|
||||
|
||||
|
||||
```
|
||||
$ echo "foo"
|
||||
$ true
|
||||
$ false
|
||||
$ !?foo?
|
||||
echo "foo"
|
||||
foo
|
||||
```
|
||||
|
||||
### 字符串替换
|
||||
|
||||
类似于在行首搜索字符串,你可以搜索字符串并用新字符串替换它,更改命令:
|
||||
|
||||
|
||||
```
|
||||
$ echo "hello"
|
||||
hello
|
||||
$ echo "world"
|
||||
world
|
||||
$ ^hello^foo
|
||||
echo "foo"
|
||||
foo
|
||||
```
|
||||
|
||||
### 让 history 有用
|
||||
|
||||
在 Bash 中,history 命令的功能远远超过此处介绍的内容,但这是让你习惯_使用_ history 而不仅仅是作为参考的良好起点。 经常使用 `history` 命令,并试试无需输入命令即可执行的操作。 你可能会感到惊讶!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/6/bash-history-commands
|
||||
|
||||
作者:[Seth Kenlon][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/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/1980s-computer-yearbook.png?itok=eGOYEKK- (Person typing on a 1980's computer)
|
||||
[2]: https://opensource.com/resources/what-bash
|
Loading…
Reference in New Issue
Block a user