7

How can we preserve or maintain the same history across multiple terminals?

The same question, but for bash shell , were discussed in the below link

Preserve bash history in multiple terminal windows

let me know the corresponding settings for tcsh shell ?

  • For more information on tcsh's history, see man tcsh. Searching for history -S should jump you to the most relevant part. – Randall Dec 28 '17 at 21:05
6

These variables set the history to merge itself instead of overwrite, and not save duplicates:

set history=1000
set histdup=erase
set savehist=(1000 merge)

the secret sauce is this line:

alias precmd 'history -S; history -M'

which will save and merge your history prior to printing the prompt - i.e. after each command you type.

all of the above should be added to your .tcshrc file.

  • When I added this alias precmd 'history -S; history -M' nothing occurred when I wrote any command. Is there something else that should be done? – Ayman Salah Mar 14 '17 at 11:53
  • @AymanSalah what occurs is not obvious - it's the .history file (or histfile shell variable value, if set) getting written to disk. Without the precmd alias set, ls -l .history will show the .history file as a untouched. With precmd set as above, ls -l .history will show the updated timestamp and size, as it gets written with each command. – Randall Dec 28 '17 at 20:21
  • @Randall Thank you for pointing that out. I had problems then with the shell session. What you're saying is 100% correct. – Ayman Salah Jan 1 '18 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.