I want to view the contents of my
.bash_history file but don't know how to get there via the command line.
If you want to access the actual file itself, just use your favorite text editor (I use
That is the default location if your history file. If you don't find anything there, you may have changed he history file name. This is stored in the
If, instead of the file, you just want to see your history, you can run
If you actually need the output of the
If you actually want the commands without numbers in front, use this command instead of
otherwise, there will be no difference (except if you're using a different shell).
Last 15 commands
You can use
to get only the last 15 lines of your history with the last executed printed last (at the bottom).
Searching for a command
to get the last 15 commands which contained
Scrolling through history
You can use
to scroll through all the commands executed starting with the most recent at the top. Press q to exit.
to scroll through all the commands executed with "
In addition to minerz029's excellent answer.
To reiterate - the 'history' command prints the history along with a number next to it.
You can pipe the output of history into grep, less etc.
The ouput of history also shows a number on the left next to the output. e.g.
With this number you can re-run the command.
e.g. to re-run 473 I would type into the terminal
followed by the enter key to repeat the command next to 473 in the history output.
You can also search interactively backwards in the command history by typing
Of course, those last two options work in the bash shell. I'm not sure if these features work in other shells. But since bash is the Ubuntu default shell you should find them there.
You may wan to try "suggest box"-like history https://github.com/dvorka/hstr - it reads Bash history and allows for quick navigation.
protected by Rinzwind Jun 8 at 8:52
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?