LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Stored terminal commands? (https://www.linuxquestions.org/questions/linux-newbie-8/stored-terminal-commands-4175414821/)

Cinnamint 07-04-2012 03:11 AM

Stored terminal commands?
 
When using terminal, you can use up and down arrow keys to scroll through previous commands entered as the user. What file is this list stored in if I wished to print it?

Genocide_Hoax 07-04-2012 03:17 AM

use the command history to print them. And they are stored in the following location /<username>/.bash_history. So for the root user it'll be /root/.bash_history

okcomputer44 07-04-2012 03:22 AM

Hi,

It stored at /home/"username"/.bash_history

But this file is hidden, so you need to issue
Quote:

ls -al
to see it in your home directory.
And you can list it with the
Quote:

history
command too.

If you want to use any command again which previously used, you could use the !"number here" to rerun the command again.
e.g.:
Quote:

!25
will run the 25 command from the bash history.

Laz

rknichols 07-04-2012 06:40 AM

Note, though, that the shell (well, bash at least) updates that file only when the shell exits. As long as the shell is running, it just updates its internal copy of the command history.

chrism01 07-04-2012 07:00 PM

Incidentally, extending post#3, you can also use
Code:

!tail
to re-run the last cmd beginning with that string

okcomputer44 07-05-2012 12:03 AM

Quote:

Originally Posted by chrism01 (Post 4719450)
Incidentally, extending post#3, you can also use
Code:

!tail
to re-run the last cmd beginning with that string

Nice one!
I didn't know this one.

Cinnamint 07-06-2012 02:07 AM

ha, of course, .bash_history, it's been way too long since I worked with the shell :(
Thanks for the other tips too.


All times are GMT -5. The time now is 09:10 AM.