Linux Print History Command Without Line Numbers

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-history-command-without-line-numbers/
PINTEREST
PINTEREST
INSTAGRAM

Linux history command is used to get previously used commands by the current user. Default size for the history command is 1000 which means that last 1000 command will be stored in the 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.

Printing .bash_history File

The simplest and easiest way is printing .bbash_history file. History file stored commands in a plain format.

Printing .bash_history File
Printing .bash_history File

Using Awk

awk is a very useful tool used to read strings and filter them according to given expression. With awk following command can be used to filter with substring.

Using Awk
Using Awk

Using Sed

We can use sed stream line editor to filter line numbers we will remove all numbers from start of the each line up to a space in this example.

  • /s used to search
  • ^ used to start of the line
  • [ ]* used to spaces from start
  • [0-9]\+ used for numbers
  • // is used to remove previously given regex which is numbers and spaces from start of the line.

Using Sed
Using Sed

Using Cut

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

  • -d is used to specify the delimiter which is space.
  • -f is used to column number which is from 4 to the end
LEARN MORE  Linux vs Unix

Using Cut
Using Cut

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-history-command-without-line-numbers/
PINTEREST
PINTEREST
INSTAGRAM