5

I am using zsh on MacOS BigSur. If I write history, I get the last 15 commands. How can I view the complete history?

2 Answers 2

9

You can use history 0 or, equivalently, fc -l 0.

history in zsh is the same as fc -l. fc -l is defined as

fc -l [ -LI ] [ -nrdfEiD ] [ -t timefmt ] [ -m match ] [ old=new ... ] [ first [ last ] ] 

[...]

If first is not specified, it will be set to -1 (the most recent event), or to -16 if the -l flag is given.

(cf. the docs). This clears up why you only get 15 entries: history without any arguments is the same as fc -l -16 -1.

1

You can find out where your history file is located like this:

$ echo $HISTFILE 

If this does not return anything, you do not have a HISTFILE configured.

If it does, you can take a look at its contents with a pager or code editor of your choice.

4
  • it returned this /Users/serax/.zsh_sessions/BDA4CA4B-F7E8-471F-84AB-47881887034D.historynew . So i open the directory in terminal and did ls many files appeared. I found 1 file with.historynew as extension, 1 _expiration_check_timestamp file, and then half of the rest had random characters folowed by.history and the other half random characters followed by .session. Now, which of these files is the history? If i open the one ending with historynew i see just one command that i used some time ago. Commented Jul 11, 2021 at 14:52
  • This depends on how your shell is configured. Take a look at the zsh configuration files, like ~/.zshrc and those in /etc/zsh/ Commented Jul 11, 2021 at 15:01
  • and what should I look at in those files? what should i change?The values must be default as i have never changed such settings Commented Jul 11, 2021 at 15:07
  • 1
    Try seeing what files have a command you know should be in it (but not a common one hat would be in many files)? For example, I use host aliases for machines on my home network, and I know I rarely remote access the machine aliased "jupiter", so I could grep "ssh jupiter" .*hist* *hist*. This will only help narrow down where to look, though. You may also want to read the zsh's documentation on how it's history mechanism works, and how you can customize it. (I personally am unfamiliar with it...) Commented Jul 11, 2021 at 19:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.