Bash history without line numbers [closed]

Solution 1:

Try this:

$ history | cut -c 8-

Solution 2:

awk can help:

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

This answer can fail if you have a long history.

Solution 3:

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)

Solution 4:

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.

Solution 5:

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.