Thursday, October 29, 2009

Command History








 

 










Command History



As we said before, the shell keeps a history of previously entered commands. Each time you press the Enter key to execute a command, that command gets added to the end of this history list. This command list is actually stored inside a file, which means that you can access previously entered commands across login sessions. By default, the history list is kept in a file in your home directory under the name .sh_history (.bash_history for Bash, unless it is started with the --posix option). You can change this filename to anything you want by setting the variable HISTFILE to the name of your history file. This variable can be set and exported in your .profile file.



Naturally, there is a limit to the number of commands the shell records. The default value of this limit varies by implementation, but the POSIX standard requires it to be at least 128; the default value for the Korn shell is 128; the default value for Bash is 500. Each time you log in, the shell automatically truncates your history file to this length.



You can control the size of your history file through the HISTFILE variable. You may find that the default size isn't adequate for your needs, in which case you may want to set the HISTFILE variable to a larger value, such as 500 or 1000. The value you assign to HISTSIZE can be set and exported in your .profile file:





$ cat .profile

...

HISTSIZE=500

export HISTSIZE

...

$



Be reasonable about the values that you assign to HISTSIZE. The larger the value, the more disk space you will need to store the history file, and the longer it will take the shell to search through the entire history file.












     

     


    No comments:

    Post a Comment