Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash history without line numbers [closed]

Tags:

linux

bash

Try this:

$ history | cut -c 8-

awk can help:

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

This answer can fail if you have a long history.


If you were willing to switch to zsh isntead of bash, then zsh supports this natively (as well as other options for history formatting)

zsh> fc -ln 0

(See https://serverfault.com/questions/114988/removing-history-or-line-numbers-from-zsh-history-file)


history -w /dev/stdout

From output of history --help:

-w write the current history to the history file

It writes current history to specified file - /dev/stdout in this case.


I'm late on this one, but the shorter method would be to add the following in your ~/.bashrc or ~/.profile file:

HISTTIMEFORMAT="$(echo -e '\r\e[K')"

From bash manpage:

       HISTTIMEFORMAT
              If this variable is set and not null, its value is used as a
              format string for strftime(3) to print the time stamp associated
              with each history entry displayed by the history builtin.  If
              this variable is set, time stamps are written to the history
              file so they may be preserved across shell sessions.  This uses
              the history comment character to distinguish timestamps from
              other history lines.

Using this capability, a smart hack consist in making the variable "print" a carriage return (\r) and clear the line (ANSI code K) instead of an actual timestamp.


Alternatively, you could use sed:

history | sed 's/^[ ]*[0-9]\+[ ]*//'

Using alias, you can set this as your standard (stick it in your bash_profile):

alias history="history | sed 's/^[ ]*[0-9]\+[ ]*//'"