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

Executed bash commands are stored in a file named .bash_history.  This file is located every users 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.

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. We will remove the command history line numbers with a expression which will get only commands from history command output.

Using Awk
Using Awk

Using Sed

sed is alternative to the awk.  We will use similar tactic where we will remove line numbers. 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.
LEARN MORE  Linux VMware Workstation Not Enough Physical Memory Is Available Error and Solution

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

Using Cut
Using Cut

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