It never had persistent history. Not with that shell. The traditional csh(1) of root does have a persistent history.But it was around here before, as far as I remember.
You can't enable something that isn't there to begin with.Then, how to add this history in sh?
Maybe you were using a different shell? (I see in another thread you were asking about bash ...)But it was around here before, as far as I remember. 100% it was when I used sudo su to login.
If you reboot by typingHi,
after reboot I can't access history by typinghistory
Please, help, event don't have ideas who stoled it and why
reboot
or shutdown -r now
from a terminal session, you will always lose the history for that terminal session. To retain the history for that session, you must exit the session by either ( 1.) entering the exit
command, or by ( 2.) typing the [CTRL][D] key combination.What SirDice is saying is 100% correct. You cannot retain history for previous sessions if sh(1) is your shell. You can, however, retain session history if tcsh(1) or bash(1) is your shell. (I am not, however, recommending that you change your root login shell to bash(1) -- that is not a good practice.)But it was around here before, as far as I remember. 100% it was when I used sudo su to login.
Then, how to add this history in sh?
sudo su
to gain root privileges, you were retaining the shell and home directory of the user account which executed that command. sudo -i
, sudo su -
, or sudo su -l
to gain root privileges, you are simulating a root login session, and thereby acquiring the shell and home directory of the root account. getent passwd ihor
getent passwd root
Is that true for all shells? I vaguely remember that some shells update the history file much more frequently, long before the shell exits. Why do I say that? I often have 3 or 4 windows logged in to the same machine and the same user, with separate shell executables. And sometimes it seems to me that one shell can see commands in the history that another shall has executed recently, while that other shell is still alive. I don't see them with cursor-up command line editing, but when I search the history with control R.If you reboot by typingreboot
orshutdown -r now
from a terminal session, you will always lose the history for that terminal session. To retain the history for that session, you must exit the session by either ( 1.) entering theexit
command, or by ( 2.) typing the [CTRL][D] key combination.
Don't know. I have only tested this with csh(1) and not with multiple shell sessions. Have not used bash(1) in FreeBSD, only in Linux and Mac OS X, where it is was the default shell.(Minor detail, probably not important to the OP)
Is that true for all shells? I vaguely remember that some shells update the history file much more frequently, long before the shell exits. Why do I say that? I often have 3 or 4 windows logged in to the same machine and the same user, with separate shell executables. And sometimes it seems to me that one shell can see commands in the history that another shall has executed recently, while that other shell is still alive. I don't see them with cursor-up command line editing, but when I search the history with control R.
ihor:*:1001:1001:ihor:/home/ihor:/bin/shIf you reboot by typingreboot
orshutdown -r now
from a terminal session, you will always lose the history for that terminal session. To retain the history for that session, you must exit the session by either ( 1.) entering theexit
command, or by ( 2.) typing the [CTRL][D] key combination.
What SirDice is saying is 100% correct. You cannot retain history for previous sessions if sh(1) is your shell. You can, however, retain session history if tcsh(1) or bash(1) is your shell. (I am not, however, recommending that you change your root login shell to bash(1) -- that is not a good practice.)
dbdemon has asked a very good question. When you were still usingsudo su
to gain root privileges, you were retaining the shell and home directory of the user account which executed that command.
But, when you usesudo -i
,sudo su -
, orsudo su -l
to gain root privileges, you are simulating a root login session, and thereby acquiring the shell and home directory of the root account.
What was the shell of your user account then, and, what is the shell of your user account now? I'm assuming that your user account is still named ihor. Please enter the following two commands and post the output:
getent passwd ihor
getent passwd root
Since both accounts have the sh(1) shell, I can't explain how the history command ever worked for you before.ihor:*:1001:1001:ihor:/home/ihor:/bin/sh
root:*:0:0:Charlie &:/root:/bin/sh
history
is not a sh(1) builtin(1) command. When I type history
in my user account with the sh(1) shell, it outputs:sh: history: not found
history
as root, with the csh(1) shell, it does display my history. fc
builtin(1) command to display your session history in the default text editor, but only for the current terminal session.How does one go about installing ksh(1)? My 13.0-RELEASE system doesn't seem to have it installed. I ranRun ksh(1) with set -o posix option. Now, you have ksh in POSIX mode. Also a .sh_history.
Change the HISTFILE and HISTSIZE shell parameters to set it up, according to your preferences.
pkg install ksh93
but after running ksh93
it says my $SHELL is /bin/csh and typing set -o posix
outputs ksh93: set: posix: bad option(s)
.I think $SHELL shows your login shell, so not necessarily showing what is your current shell.How does one go about installing ksh(1)? My 13.0-RELEASE system doesn't seem to have it installed. I ranpkg install ksh93
but after runningksh93
it says my $SHELL is /bin/csh and typingset -o posix
outputsksh93: set: posix: bad option(s)
.
Yeah you're right, it's displaying my login shell. I've tried installing ksh93, ksh2020, and ast-ksh but in each case I can find only the file /usr/local/bin/ksh93 and no ksh.I think $SHELL shows your login shell, so not necessarily showing what is your current shell.
How does one go about installing ksh(1)? My 13.0-RELEASE system doesn't seem to have it installed. I ranpkg install ksh93
but after runningksh93
it says my $SHELL is /bin/csh and typingset -o posix
outputsksh93: set: posix: bad option(s)
.
$ grep ksh /etc/shells
$ doas echo /usr/local/bin/ksh93 >> /etc/shells
$ doas chsh -s /usr/local/bin/ksh93 USERNAME
set -o posix
If you use ports you have an option between ksh or ksh93 name but with packages is ksh93.Yeah you're right, it's displaying my login shell. I've tried installing ksh93, ksh2020, and ast-ksh but in each case I can find only the file /usr/local/bin/ksh93 and no ksh.
It's just something for me to play with. I prefer running /bin/sh for my day-to-day but, am curious about ksh because it was the default shell on AIX systems back in the '90s, and my favorite shell at that time.