0

I found this answer about time-stamping history for Bash.

Is there any way to permute the output? In particular

Number command time-stamp

rather than

Number time-stamp command
1

You can process the output of history builtin. First prepare your HISTTIMEFORMAT according to the answer you linked to:

export HISTTIMEFORMAT="%d.%m.%y %T "

To get the desired output, invoke:

history | awk '{ printf "%s\t",$1; for(i=4; i<=NF; i++) printf "%s",$i OFS; printf "\t%s %s\n",$2,$3 }'

If you overwrite history builtin with a function:

history() { builtin history | awk '{ printf "%s\t",$1; for(i=4; i<=NF; i++) printf "%s",$i OFS; printf "\t%s %s\n",$2,$3 }'; }

then it is enough to write history to get what you want.

Note: leading spaces and column formatting from bare history output are lost. Since the command field has no fixed length, having it in a middle is not a best idea. I deliberately separated the fields with tabs (instead of spaces) to make the output more readable. If you prefer spaces then replace \t in my code with (space).

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.