Shell shell history disappeared after reboot

Hi,

after reboot I can't access history by typing history

Please, help, event don't have ideas who stoled it and why
 
The sh(1) shell does have a history but it's not persistent, in other words, it's not saved when you exit the session.
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?
 
Hi,

after reboot I can't access history by typing history

Please, help, event don't have ideas who stoled it and why
If you reboot by typing 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.

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?
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 using sudo su to gain root privileges, you were retaining the shell and home directory of the user account which executed that command.

But, when you use 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.

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
 
(Minor detail, probably not important to the OP)

If you reboot by typing 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.
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.
 
(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.
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.

Edited to add: Please note that /bin/tcsh is a link to /bin/csh on FreeBSD systems.
 
If you reboot by typing 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.)

dbdemon has asked a very good question. When you were still using sudo su to gain root privileges, you were retaining the shell and home directory of the user account which executed that command.

But, when you use 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.

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
ihor:*:1001:1001:ihor:/home/ihor:/bin/sh
root:*:0:0:Charlie &:/root:/bin/sh
 
ihor:*:1001:1001:ihor:/home/ihor:/bin/sh
root:*:0:0:Charlie &:/root:/bin/sh
Since both accounts have the sh(1) shell, I can't explain how the history command ever worked for you before. 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

When I type history as root, with the csh(1) shell, it does display my history.

In the sh(1) shell, you can use the fc builtin(1) command to display your session history in the default text editor, but only for the current terminal session.
 
Run 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.
How does one go about installing ksh(1)? My 13.0-RELEASE system doesn't seem to have it installed. I ran 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.
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.
 
How does one go about installing ksh(1)? My 13.0-RELEASE system doesn't seem to have it installed. I ran 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).

$ grep ksh /etc/shells
empty?!
$ doas echo /usr/local/bin/ksh93 >> /etc/shells
$ doas chsh -s /usr/local/bin/ksh93 USERNAME

$HOME/.profile
Code:
set -o posix
 
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.
If you use ports you have an option between ksh or ksh93 name but with packages is ksh93.
 
Back
Top