cancel
Showing results for 
Search instead for 
Did you mean: 

History command

 
SOLVED
Go to solution
DKC
Advisor

History command

Hi Flock,

I am working in HPVM machine, OS 11.31 and I want to see previous command for that i am given history command but i got error.
# history
sh: fc: Cannot access or open the history file.

Anyone can assist me why history command are not working.

Thanks & Regards,
Dev
22 REPLIES
R.O.
Esteemed Contributor

Re: History command

Hi,

Put these variables in your .profile:

export HISTFILE=$HOME/sh_history
export HISTSIZE=5000

Then, logout and login again and you will have the command history enabled.

Regards,
"When you look into an abyss, the abyss also looks into you"
R.O.
Esteemed Contributor

Re: History command

Sorry, missed a dot in front of sh_history:

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

Regards,
"When you look into an abyss, the abyss also looks into you"
DKC
Advisor

Re: History command

Hi R.O.

I have done all the task but still a getting error
Value of TERM has been set to "xterm".
WARNING: YOU ARE SUPERUSER !!

#
#
# history
sh: fc: Cannot access or open the history file.

after exporting histsize and histfile i have logout and than login but same error.

Regards,
Dev
Pete Randall
Outstanding Contributor

Re: History command

Is $HOME set? "echo $HOME" will tell you.

Try setting HISTFILE to a explicit full path name wherever root's home really is, like "HISTFILE=/.sh_history" or "HISTFILE=/root/.sh_history".


Pete

Pete
DKC
Advisor

Re: History command

Hi Pete,

echo $ HOME
/

After that i have given HISTFILE=/root/.sh_history

but still i am facing error.

# history
sh: fc: Cannot access or open the history file.

Regards,
Dev
R.O.
Esteemed Contributor

Re: History command

Hi,

Are you setting HISTFILE & HISTSIZE in the user's .profile ?

Regards,
"When you look into an abyss, the abyss also looks into you"
Torsten.
Acclaimed Contributor

Re: History command

If you set

HISTFILE=/root/.sh_history


do you have

/root ???

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Pete Randall
Outstanding Contributor

Re: History command

If "echo $HOME" tells you /, as you say, then you should not be setting HISTFILE to /root/.sh_history. Set it to /.sh_history and try again.


Pete

Pete
DKC
Advisor

Re: History command

Hi,

No, I haven't set in users profile.

I am root user and want to previous command with the help of history command. For that i done export HISTFILE=/root/.sh_history
HISTFILE=500
Than logout than again login with root use but after giveing history command same error.

Regards,
Dev


Torsten.
Acclaimed Contributor

Re: History command

Again, if you set it to be in directory /root


this directory

/root

must exist!



Does it???

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
R.O.
Esteemed Contributor

Re: History command

...apart from the fact that directory "/root" must exist, if you don't set the variables in your ".profile", when you logout you lost the changes in the variables. Put these lines in your .profile:

export HISTFILE=/.sh_history (if your home is "/"; is it is /root and it exists, put /root/.sh_history)
export HISTFILE=5000

Then, try again by logout/login.

Regards,
"When you look into an abyss, the abyss also looks into you"
Pete Randall
Outstanding Contributor

Re: History command

What shell are you using?


Pete

Pete
Bill Hassell
Honored Contributor
Solution

Re: History command

There is a dumb bug in root's shell that will not create the history file automatically. Ordinary users are fine but just in case, the commands (which I put in /etc/profile so everyone gets a history file) are:

umask 022
touch $HOME/.sh_history
export HISTORY=$HOME/.sh_history
export HISTFILE=5000




>> $HOME=/

A very bad default location for root's $HOME. Create a separate /root directory and move all of root's files to /root, then change /etc/passwd so the $HOME directory is /root and not /, like this:

root:*:0:3:root user:/root:/sbin/sh

If you move root's $HOME on every Unix platform you have, you may avoid a total disaster in joining the rm -r * club.


Bill Hassell, sysadmin
Torsten.
Acclaimed Contributor

Re: History command

I agree, it is IMHO a good practice to change root's home from / to something like /root.

If you simply export these variables and then logout, the change is gone. You need to write it to .profile to make it permanent and working.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
DKC
Advisor

Re: History command

Hi,

# history
sh: fc: Cannot access or open the history file.
# pwd
/
#
#

after exporting HISTFILE AND HISTSIZE logout than login same problem. You tell me from my side what infomation required, so history command work.

Dev
Torsten.
Acclaimed Contributor

Re: History command

Meanwhile many people wrote the very same several times - just follow the advises.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
DKC
Advisor

Re: History command

Hi,

# echo $SHELL
/sbin/sh
m using shell.

Regards,
Dev
R.O.
Esteemed Contributor

Re: History command

"after exporting HISTFILE AND HISTSIZE logout than login same problem"

If you do not put these in root's ".profile" you will lose the variables each time you log out of the system......

Regards,
"When you look into an abyss, the abyss also looks into you"
Torsten.
Acclaimed Contributor

Re: History command

As said, add

export HISTFILE=/root/.sh_history
export HISTSIZE=5000

to your .profile and do

# mkdir /root

logout and back in.


To change root's home, modify /etc/passwd.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Pete Randall
Outstanding Contributor

Re: History command

See Bill Hassell's post above. Follow his suggestions. It will work. Report back only when it has worked, not when you've done the same wrong thing over again.


Pete

Pete
Bill Hassell
Honored Contributor

Re: History command

>> # history
>> sh: fc: Cannot access or open the history file.

Did you create the .sh_history file?


Bill Hassell, sysadmin
SoorajCleris
Honored Contributor

Re: History command

Hi Devkant,

If you don't mind, Could you please provide below information?

1. /.profile
2. /etc/profile
3. ls -la / |grep -i history
4. cat /etc/passwd |grep root

Regards,
Sooraj
"UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity" - Dennis Ritchie