0

I am fairly new to Linux and I need to find a way to show the contents of my Bash History via the command line, and unfortunately I can't seem to find anything that works, or that I can understand. I am using Linux Ubuntu 11.10, and when I open the Bash History manually by finding the file, it opens with something known as gedit. How will I be able to view the contents of my Bash History via the command line? Many Thanks! ~ShadedVeil

  • sudo nano ~/.bash_history this will allow you to open up your bash_history and go through it – Alex Lowe Feb 11 '16 at 21:56
  • Thank you for your answer! Although, I believe our sudo is passworded as we use Linux on the school system, and the teacher is still finding a way around this. Is there an alternative to using the sudo command? – ShadedVeil Feb 11 '16 at 22:02
  • Just take off the sudo from the command so it would look like this nano ~/.bash_history – Alex Lowe Feb 11 '16 at 22:06
  • You can also search through your history file to find a certain command like this history | grep ls which will find all of the times that you have run the command ls – Alex Lowe Feb 11 '16 at 22:08
  • BTW, Why are you using 11.10? The end-of-life of that version was May 9, 2013. You really should upgrade to 14.04 or 15.10. – QwertyChouskie Feb 11 '16 at 22:39
0
$history

and it will show the history

 1999  exit
 2000  cd /opt
 2001  sudo apt-get install p7zip-full
 2002  sudo apt-get install p7zip-rar
 2003  mkdir CS-RT-code
 2004  cd CS-RT-code/
 2005  ls -lrt
 2006  history

$ !<history #> to execute the previous history command
0

less is a pretty useful command evolved from more. You can use it to browse through large text files. Run:

less $HOME/.bash_history

Use the Up/Down arrow keys to go up and down in the file. Press q to exit.

For more information/keyboard shortcuts in less, run man less. It will show its manual pages.

For instance, you could also use other utilities, such as cat (cat $HOME/.bash_history), more (more $HOME/.bash_history), nano (nano $HOME/.bash_history) and Vim (vim $HOME/.bash_history).

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