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
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
firstis not specified, it will be set to-1(the most recent event), or to-16if the-lflag 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.
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.
- it returned this /Users/serax/.zsh_sessions/BDA4CA4B-F7E8-471F-84AB-47881887034D.historynew . So i open the directory in terminal and did
lsmany files appeared. I found 1 file with.historynewas extension, 1_expiration_check_timestampfile, and then half of the rest had random characters folowed by.historyand the other half random characters followed by.session. Now, which of these files is the history? If i open the one ending withhistorynewi see just one command that i used some time ago.serax– serax2021-07-11 14:52:51 +00:00Commented Jul 11, 2021 at 14:52 - This depends on how your shell is configured. Take a look at the
zshconfiguration files, like~/.zshrcand those in/etc/zsh/Panki– Panki2021-07-11 15:01:50 +00:00Commented 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 settingsserax– serax2021-07-11 15:07:30 +00:00Commented Jul 11, 2021 at 15:07
- 1Try 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...)C. M.– C. M.2021-07-11 19:24:17 +00:00Commented Jul 11, 2021 at 19:24