Is there a way to save all bash commands from all terminals to a single file? By default, different terminals have different history and that gets confusing. I'd like to save all history to a single file and optionally look up those commands instead? Perhaps shift+uparrow could look up in the history in the central file?
1 Answer
First, you must tell the shell to add the time and the username to each user's history and expand the size of each history file from its default of 500 lines with something like this command (set the value as you wish) entered at a shell prompt, with
echo 'HISTTIMEFORMAT="%F %T $USER"' >> ~/.bashrc && HISTSIZE=10000 and reboot after that so the change is activated. Why? Well, history without a date and time, and does not identify who entered a command may not be very useful.
Then, periodically copy the contents of ~/.bash_history for each user into a joint history file, and sort it, so the consolidated history will sort out in order of date, time, and user.
After you have done that, delete the source files in each user directory by an admin level script looping through
cd /home/userx && rm ~/.bash_history && history -c changing x so as to perform that line for every user.
- 1Why is timestamping necessary?Jim L.– Jim L.2019-05-31 21:34:51 +00:00Commented May 31, 2019 at 21:34