1836617 Members
1669 Online
110102 Solutions
New Discussion

Re: retyped commands

 
sam kim_1
Frequent Advisor

retyped commands

1)everytime i have to retype using commands again at the prompt
2)is there anyway i can setup to memorize or remember past commands or previous 10 commamnds that i typed already
3)so, i can use 'up arrow key' to bring past commands like dos or router

thanks!
4 REPLIES 4
Stefan Farrelly
Honored Contributor

Re: retyped commands


Yes, you can remember the last commands you have typed; Here is one way, in your .profile set the following variables;

HISTFILE=$HOME/.sh_history
HISTSIZE=
set -o vi

Next time you login your commands will be remembered but using this method you will need to press ESC then K to see your last command, and keep pressing K to scroll back through your commands, and J to go forward etc. And you can search for a command by press ESC then / then to search for. All the commands you use in vi you can use to find/modify previous commands before pressing Return to execute them.

Im from Palmerston North, New Zealand, but somehow ended up in London...
Rita C Workman
Honored Contributor

Re: retyped commands

First check and make sure your have .sh_history file. If your a user it should be in your /home directory...if your root it's at / .
If it's not there than do a touch .sh_history to first create it.
Now vi your .profile

If you have a line that says VISUAL ($when....) than rem this out.

Add the following lines:

VISUAL=vi;export VISUAL
HISTFILE=/.sh_history;export HISTFILE (this reflects for root .profile)
HISTSIZE=100;export HISTSIZE

This should give you the ability to do esc k and recall the last 100 commands keyed.

I'm not the best typist....hope this helps,
David McMullen
Occasional Advisor

Re: retyped commands

If you like the arrow keys, try using a bash shell.
John Palmer
Honored Contributor

Re: retyped commands

Another point to condider with command recall is that if you use the '.sh_history' file then it can be very annoying if there are several users logged in to the same account as their commands get interspersed with yours.

To get around this, set HISTFILE=/.hist.${$}

where is /tmp or /var/tmp which gets tidied regularly.

For full details of command recall, see man sh-posix. Most people prefer vi but for some reason, I always use 'emacs' mode (set -o emacs) even though I have never used the emacs editor. You can even use the arrows keys with emacs mode provided you remap your keyboard so that:-
uparrow = P
downarrow = N
leftarrow = B
rightarrow = F