Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell Zsh to write the current shell's history to my history file?

Tags:

I work in a place that has gazillions of tools which require tons of options, so I rely on my shell's history significantly. I even back it up every now and then just to make sure I don't lose useful, lengthy commands.

I just typed one of these commands and I want to make sure it's flushed to the history file, but I have a long-running job in the background and I can't type exec zsh. Is there something else I can do in this situation?

(Sure, I could copy and paste it into a file, but it would be more logical for there to exist a flush-history command.)

like image 402
a paid nerd Avatar asked May 09 '09 00:05

a paid nerd


People also ask

How do you use ZSH history?

To use it, press CTRL + R in your terminal session. This will change your terminal session to search mode, and you can type for previous commands. As you type, the shell will search for a matching command in the history and suggest it. To search for the next matching suggestion, press CTRL + R.

How do I enable terminal history?

To enable history logging, use the terminal history command, which takes the last-used size as the buffer size. To change the size of the current history buffer, use the size keyword followed by the number of lines you want to save in the buffer. The buffer's size can be from 1 to 256 lines.

How long is ZSH history?

Increasing the History File Size Unfortunately, zsh's default history file size is limited to 10000 lines by default and will truncate the history to this length by deduplicating entries and removing old data. Adding the following lines to . zshrc will remove the limits and deduplication of the history file.

How do I see entire bash history?

The command is simply called history, but can also be accessed by looking at your . bash_history in your home folder. By default, the history command will show you the last five hundred commands you have entered.


1 Answers

To write the shell history to the history file, do

fc -W 

fc has some useful flags, see them all in man zshbuiltins.

You can also fully automate reading and writing the history file after each command (thus sharing your history file automatically with each running zsh) by saying setopt -o sharehistory. Read more history-related options in man zshoptions.

like image 87
pts Avatar answered Oct 24 '22 10:10

pts