Linux Bash历史

[rps-include post=6835]

[rps-include post = 6835]

Bash shell runs in terminals like gnome-terminal, konsole, getty, etc. To make things make easy bash provides some shortcuts and pragmatic operations. Here we will look details about them.

Bash shell运行在gnome-terminal,konsole,getty等终端中。为了使事情变得简单,bash提供了一些快捷方式和实用的操作。 在这里,我们将详细介绍它们。

历史 (History)

Busy system administrators writes a lot of bash commands. They have no time to write notes about the commands. But bash have a history to assist. Bash history holds commands written before. This is very helpful when you write long and rarely used command and needed right now.

繁忙的系统管理员编写了很多bash命令。 他们没有时间编写有关命令的注释。 但是bash有帮助的历史。 Bash历史记录包含之前编写的命令。 当您编写长时间且很少使用且现在需要使用的命令时,这非常有用。

上市历史 (Listing History)

$ history 
    1  npm run
    2  cd ..
    3  ls
    4  npm run
    5  cd react-15.3.0/

I have cut the history is long as by default 1000 line. As you see bash lists all command we have issued.

我已将历史记录默认为1000行。 如您所见,bash列出了我们发出的所有命令。

运行命令 (Rerunning command)

There is easy way to rerun previously issued command. As we see that history numbers commands. We will use these numbers to specify command like below.

有一种简单的方法可以重新运行先前发出的命令。 如我们所见,历史编号命令。 我们将使用这些数字来指定如下所示的命令。

$ !3
ls
Desktop  Documents  Downloads  workspace

We use !3 to rerun number 3 history command. As we see that rerunning command echoes issued command which is ls

我们使用!3重新运行3号历史记录命令。 如我们所见,重新运行的命令会回显发出的命令ls

搜索历史 (Searching History)

History provides a lot of commands. And finding a specific command in list may become hard. There is easy way to filter commands.

历史记录提供了许多命令。 在列表中查找特定命令可能会变得很困难。 有一种简单的方法来过滤命令。

$ history | grep ls
    3  ls
    6  ls
   57  ls

We get help from grep command. It filters commands that provides ls and list them.

我们从grep命令获得帮助。 它过滤提供ls的命令并列出它们。

清算记录 (Clearing History)

Some times we need to clear things we have done. For example if we provided a command with clear text password we may want to clear these commands.

有时我们需要清除已经完成的事情。 例如,如果我们为命令提供了明文密码,则可能需要清除这些命令。

$ history -c
$ history 
    1  history

获取历史记录大小 (Getting History Size)

History is very helpful but if we are hardworking system administrator the size of the is may become small for us. By default history size is 1000 which means the last 1000 commands will be hold.

历史记录非常有帮助,但是如果我们是一位努力的系统管理员,那么对于我们来说,这可能会变得很小。 默认情况下,历史记录大小为1000,这意味着将保留最后1000个命令。

$ echo $HISTSIZE
1000

History size is hold as bash environment variable. By changing HISTSIZE environment variable the size may increased.

历史记录大小作为bash环境变量保存。 通过改变 HISTSIZE环境变量的大小可能会增加。

LEARN MORE  Windows CMD.exe or Command Shell Tutorial with Examples
了解更多Windows CMD.exe或命令外壳程序教程和示例

设置历史记录大小(Setting History Size)

History is very helpful but if we are hardworking system administrator the size of the is may become small for us. By default history size is 1000 which means the last 1000 commands will be hold.

历史记录非常有帮助,但是如果我们是一位努力的系统管理员,那么对于我们来说,这可能会变得很小。 默认情况下,历史记录大小为1000,这意味着将保留最后1000个命令。

$ HISTSIZE=2000
$ echo $HISTSIZE
2000

History size is hold as a bash environment variable. By changing HISTSIZE  environment variable the size may increase.

历史记录大小作为bash环境变量保存。 通过改变 HISTSIZE环境变量的大小可能会增加。

[rps-include post=6835]

[rps-include post = 6835]

翻译自: https://www.poftut.com/linux-bash-history/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值