1

How can I get the Ubuntu terminal history without the line number?

history

history command returns the previous commands with line number. I am looking for something like:

 cd tizen-sdk\tools          
 ls

instead of

924  cd tizen-sdk\tools      
925  ls
6

You can use the fc command instead. From help fc:

fc: fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command]
    Display or execute commands from the history list.

    fc is used to list or edit and re-execute commands from the history list.
    FIRST and LAST can be numbers specifying the range, or FIRST can be a
    string, which means the most recent command beginning with that
    string.

    Options:
      -e ENAME  select which editor to use.  Default is FCEDIT, then EDITOR,
            then vi
      -l    list lines instead of editing
      -n    omit line numbers when listing
      -r    reverse the order of the lines (newest listed first)

Therefore:

fc -ln

You can also look at the history file directly, but it might not be updated:

cat "$HISTFILE"
  • + OP's question, is there a way to tell to do not record line number in history file? – αғsнιη Oct 20 '16 at 14:22
  • 1
    @KasiyA the history file does not record line numbers (it only records commands, and if HISTTIMEFORMAT is set, timestamps). – muru Oct 20 '16 at 14:23
  • Will it display all history? – Anwar Oct 20 '16 at 16:32
2

Use this command:

history | cut -c 8-
1

Using awk.

history | awk '{$1=""; print}'
  • 1
    You can use awk '{$1=""}1' – muru Oct 24 '16 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.