linux命令查看行号_没有行号Linux打印历史命令

linux命令查看行号

linux命令查看行号

Linux history command is used to get previously used commands by the current user. The default size for the history command is 1000 which means that last 1000 command will be stored in history. While listing history of bash line numbers are provided too. This is not expected in some situations. To get history without line numbers following commands can be used.

Linux history命令用于获取当前用户先前使用的命令。 history命令的默认大小为1000,这意味着最后1000条命令将存储在历史记录中。 同时提供bash行号的列表历史记录。 在某些情况下,这是不期望的。 要获取没有行号的历史记录,可以使用以下命令。

带数字的打印历史文件 (Print History File with Numbers)

By default history command is used to print Linux bash history where the commands with the index numbers are printed to the screen. By deafult, only the last 1000 commands are printed.

默认情况下, history命令用于打印Linux bash历史记录,其中带有索引号的命令被打印到屏幕上。 按默认,仅打印最后1000个命令。

$ history
Print History File with Numbers
Print History File with Numbers
带数字的打印历史文件

We can see that before the command the number of the file is printed to the screen.

我们可以看到,在执行该命令之前,文件号已显示在屏幕上。

打印不带行号的.bash_history文件 (Printing .bash_history File Without Line Numbers)

Executed bash commands are stored in a file named .bash_history.  This file is located in every user’s home directory. For example for user ismail is will be located at /home/ismail/.bash_history. The simplest and easiest way is printing .bash_history file. History file stored commands in a plain format.

执行的bash命令存储在名为.bash_history的文件中。 该文件位于每个用户的主目录中。 例如,对于用户ismail将位于/home/ismail/.bash_history 。 最简单,最简单的方法是打印.bash_history文件。 历史记录文件以纯格式存储命令。

$ cat ~/.bash_history
Printing .bash_history File
Printing .bash_history File
打印.bash_history文件

From the output, we can see that only commands are printed from the .bash_history.

从输出中,我们可以看到从.bash_history中仅打印命令。

使用Awk (Using Awk)

awk is a very useful tool used to read strings and filter them according to the given expression. With awk following command can be used to filter with substring. We will remove the command history line numbers with an expression which will get only commands from history command output.

awk是一个非常有用的工具,用于读取字符串并根据给定的表达式过滤它们。 使用awk,可以使用以下命令来过滤子字符串。 我们将使用一个表达式删除命令历史记录行号,该表达式将仅从history命令输出中获取命令。

$ history | awk '{$1="";print substr($0,2)}'

Using Awk
Using Awk
使用Awk

使用Sed (Using Sed)

sed is an alternative to the awk.  We will use a similar tactic where we will remove line numbers. We can use sed streamline editor to filter line numbers we will remove all numbers from the start of each line up to space in this example.

sedawk的替代方法。 我们将使用类似的策略来删除行号。 我们可以使用sed流线编辑器来过滤行号,在此示例中,我们将从所有行的开头删除所有数字,直到空格为止。

  • /s used to search

    /s用于搜索

  • ^ used to start of the line

    ^用于开始行

  • [ ]* used to spaces from start

    [ ]*从一开始就用于空格

  • [0-9]\+ used for numbers

    [0-9]\+用于数字

  • // is used to remove previously given regex which is numbers and spaces from the start of the line.

    //用于删除先前给定的正则表达式,该正则表达式是从行首开始的数字和空格。

$ history | sed 's/^[ ]*[0-9]\+[ ]*//'
Using Sed
Using Sed
使用Sed

使用切割 (Using Cut)

The cut is the simplest example of removing history line numbers. We will delimit output according to space and print columns start with 2 and others.

剪切是删除历史记录行号的最简单示例。 我们将根据空间来分隔输出,并且打印列以2和其他开头。

  • -d is used to specify the delimiter which is space.

    -d用于指定分隔符,即空格。

  • -f is used to column number which is from 4 to the end

    -f用于从4到末尾的列号

$ history | cut -d ' ' -f 4-
Using Cut
Using Cut
使用切割

没有行号信息图Linux打印历史命令(Linux Print History Command Without Line Numbers Infographic)

Linux Print History Command Without Line Numbers Infographic
Linux Print History Command Without Line Numbers Infographic
没有行号信息图Linux打印历史命令
LEARN MORE  How To Create Case Insensitive Regex?
了解更多如何创建不区分大小写的正则表达式?

翻译自: https://www.poftut.com/linux-history-command-without-line-numbers/

linux命令查看行号

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值