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
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
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)}'
使用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.
sed
是awk
的替代方法。 我们将使用类似的策略来删除行号。 我们可以使用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 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-
没有行号信息图Linux打印历史命令(Linux Print History Command Without Line Numbers Infographic)
翻译自: https://www.poftut.com/linux-history-command-without-line-numbers/
linux命令查看行号