9

Example history:

$ history
1  whoami
2  pwd
3  ls

To get a reversed history list, I do:

$ history|tac
3  ls
2  pwd
1  whoami

But are there any better ways to do this, perhaps that needn't invoke another program, for those without tac installed, for example?

0

2 Answers 2

8

Since the owner of a separate answer deleted it, I'll suggest:

history | sort -rn
6

To list history in reverse order add -rl to fc command:

fc -rl

Obviously fc -l list in standard order. You can also specify the number of entries you want to see e.g. fc -rl -10.

3
  • This works, but it removes my HISTTIMEFORMAT from every line. Commented Jun 19, 2017 at 10:51
  • @EmmaV - the -i or flag is what you need to display the time format. Like so: fc -rli. -E and -f are alternative flags to -i if you prefer a different time format. Commented Jan 1, 2021 at 16:05
  • had no clue fc existed this is how I found out after using bash for 7 years Commented May 4, 2024 at 7:04

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.