1833341 Members
3380 Online
110051 Solutions
New Discussion

command history

 
SOLVED
Go to solution
mario_43
Occasional Contributor

command history

Hi,
in .sh_history there is a list of the last command type by user.
I wonder if there is a command in HpUx to recall the last command, for example:
>history_command 45
and I want the system reply with the 45th command type by user.
exist this command?
8 REPLIES 8
Pete Randall
Outstanding Contributor

Re: command history

Do this:

set -o vi

Then, use the "k" key sequence to recall your last command. You can continue back through previous commands by continuing to press "k", go forward with "j", and even edit the commands using vi.


Pete


Pete
Tim Adamson_1
Honored Contributor

Re: command history

Hi Mario,

To setup commandline recall put the following in .profile.

export HISTFILE=$HOME/.sh_history
export HISTSIZE=8192

The HISTSIZE will give a decent amount of history.

Logout and login again (or . .profile).

Press Esc k to bring back the last command. You can also type / (after pressing ESC k) to search through the command history for the command you are after.


Cheers!!
Yesterday is history, tomorrow is a mystery, today is a gift. That's why it's called the present.
Massimo Bianchi
Honored Contributor

Re: command history

Adding my little bit.


If you use csh,
the command history will show you the list of command,
ad a !##, where ## is the number of the command,
will execute it again.
!! will execute last command

see man csh

Massimo

Joseph C. Denman
Honored Contributor
Solution

Re: command history

Adding a little more for ksh?!#$%^

set -o vi

" k" #Give you last command and you can you the standard vi up and down keys to move through the command history. You can also edit the commands with standard vi commands.

"history" #Gives you a numbered list of used commands. You can run any of the commands with "r ##". The ## is the number of the command.

...jcd...
If I had only read the instructions first??
Dario_1
Trusted Contributor

Re: command history

Hi!

Use ESC k and that will bring the last command. Keep pressing k to go back and j to go forward.

Regards,

Dario

Make sure you have the following in your .profile:

set -o vi
Steve Post
Trusted Contributor

Re: command history

45th command eh? That's the 45th command since the user logged in? The commands are store in the filename listed in variable $HISTFILE.

The 45th line in HISTFILE will probably NOT be the 45th command they typed since login. You see that file doesn't track commands based on the login session. It's the list of their commands. In fact if two people are using the same userid, their commmands will both drop into this file.

But what can you do????
cp $HISTFILE $HOME/mylasthistory
Now you have file mylasthistory. You can edit the file to get the line(s) you want.

Another option: the script command. Let's say you are typing in a series of commands and want to log the commands and results.
Run "script mylogfile".
This gives you a new shell with all output going to file mylogfile. When done, exit that shell, then you can edit the file "mylogfile."
(first thing to do when editing it: use :%s/\^v^M//g to remove all control-M's from the end of line. But that's a different story.)

steve
Tim D Fulford
Honored Contributor

Re: command history

here is my what is in my .profile

# Do some housekeeping & deletie any XtermLogs and hist_ files over 7 days old:
find "$HOME" -name XtermLog\* -xdev -follow -mtime +7 -exec rm {} \;
find "$HOME" -name .hist_\* -xdev -follow -mtime +7 -exec rm {} \;

# Set up unique histfile per session
export HISTFILE=$HOME/.hist_$(tty| awk -F"/" '{print $NF}')


Works fine for me

Tim
-
Caesar_3
Esteemed Contributor

Re: command history

Hello!

First do
set -o vi

Then exec the commands
r

Caesar