# What is .history file?



## unique name (Aug 20, 2021)

In my user home dir, there are numerous .history. files and new ones are popping up. Is this normal?


----------



## Tieks (Aug 20, 2021)

Login shells like csh and tcsh use these files to store commands that you entered, so you can reuse 'em. Yes, is normal.


----------



## grahamperrin@ (Aug 22, 2021)

unique name said:


> … numerous .history. files and new ones are popping up. Is this normal?



Probably not.

I'm not sure what causes the dregs but as far as I know, there should be just one ~/.history file (no dregs). See for example <https://forums.FreeBSD.org/threads/81237/post-523049>

I recently removed some dregs from my home directory.


```
root@mowa219-gjp4-8570p-freebsd:~ # ls -hl /usr/home/grahamperrin/.histor*
-rw-------  1 grahamperrin  grahamperrin    67K Aug 22 04:37 /usr/home/grahamperrin/.history
root@mowa219-gjp4-8570p-freebsd:~ # ls -hl /usr/home/bbsadmin/.histor*
ls: No match.
root@mowa219-gjp4-8570p-freebsd:~ # ls -hl /root/.histor*
-rw-------  1 root  wheel    73K Aug 22 09:48 /root/.history
-rw-------  1 root  wheel    37B Jan  2  2021 /root/.history.16593052
-rw-------  1 root  wheel   656B Feb 11  2021 /root/.history.3126201
root@mowa219-gjp4-8570p-freebsd:~ #
```


----------



## Phishfry (Aug 22, 2021)

I am seeing the same thing. Numerous history files with a number attached.
Example from users home directory:
.history.879329
.history.884368
.history.884856
.history.895317
.history.906169
.history.934475
.history.93622
.history.939921
.history.948512
.history.948584
.history.972109
.history.975053
.history.975309
.history.998851
.history.998894

What I have found is that when I open an Xfce4 Terminal window the history for that goes into a new file.
As seen above.

It is a new mis-behavior for a while now. I don't know if there is a setting or sysctl to funnel them to one history file.
That would be nice... It used to work that way.

There is a way to lose history by logging into the same user twice.
File locking probably blocking one terminals history saves.

I increase users tcsh shell config file to 10000 to keep alot. I find history a great way to write scripts.

set history = 10000
set savehist = (10000 merge)

I have often thought of a .history 'server' so that all my local network .history is collected in central reserve.


----------



## grahamperrin@ (Aug 22, 2021)

grahamperrin said:


> … I'm not sure what causes the dregs …



I wondered whether they're left following an ungraceful interruption to something. 

I killed Konsole whilst two or three tabs were open, no dregs were found.



Phishfry said:


> … when I open an Xfce4 Terminal window the history for that goes into a new file. …



I get no more than one file when I open an Xfce4 Terminal window.


----------



## Phishfry (Aug 22, 2021)

I have found the opposite. When I had a crashing machine that was shutting down the .history file got wiped out.

My dregs are caused by the xfce4 terminal app. For absolute sure.
I will look at the .config files and investigate.

When I switched to FreeBSD 12 the xfce4 terminal was broke. I had to learn xterm.
A subsequent update fixed the terminal for me.
It was around then that these dregs started occuring. I have 169 dreg .history files right now. How do you merge them?


----------



## Phishfry (Aug 22, 2021)

Nothing related in /.config/xfce/terminal/rcterminal

But what I noticed is that Xfce terminal is expecting bash_history so maybe that is what I am getting.
Separate history for each bash shell, when using tcsh as default user shell.



			how does Terminal 4.4.3 handle history saving? / General discussion / Xfce Forums
		



> when there are 2 or more terminals running, history command outputs differ, so each instance of terminal
> seemingly has its own storage


----------



## Phishfry (Aug 22, 2021)

Well for me it was related to xfce/terminal. The dregs are gone.
/.config/xfce/terminal/rcterminal
CommandLoginShell=TRUE

Also found in the Xfce Terminal Menu >>Edit>>Prefrences>> Check "Run Command As Login Shell"


----------



## grahamperrin@ (Aug 23, 2021)

Thanks, do you know whether changing the preference resulted in a merge of the files? Or were the files discarded?


----------



## Deleted member 67862 (Apr 4, 2022)

Is it possible to have tcsh put the history into a single file? My home directory gets crowded anytime I show hidden files.

I tried the following from here but it still generates more than one file.


----------



## grahamperrin@ (Apr 4, 2022)

hunter0one said:


> … have tcsh put the history into a single file? …



Take care to `exit` or key Control-D. 

(Don't simply close terminal tabs/windows, if the terminal application does not do what's required when closing.)

I have just one stray file, which might have been from a crash a few months ago: 


```
% echo $0
/bin/tcsh
% ls -hl ~/.history*
-rw-------  1 grahamperrin  grahamperrin    69K  4 Apr 12:46 /home/grahamperrin/.history
-rw-------  1 grahamperrin  grahamperrin     0B 29 Nov 07:37 /home/grahamperrin/.history.10857158
%
```


----------



## Deleted member 67862 (Apr 4, 2022)

grahamperrin said:


> Take care to `exit` or key Control-D.
> 
> (Don't simply close terminal tabs/windows, if the terminal application does not do what's required when closing.)
> 
> ...


I need to take back what I said. It did work, I just had history files from before still.
I didn't want to have to type exit every time I close a terminal, so this is much better.


----------

