In OSX's terminal, I run the history command to find my recent commands. Often I notice recent commands will not show up, seemingly randomly. For example, I will log on one-day and notice my commands from the previous day are not showing in history (though they did they day before) but rather last week's commands are there. How do you troubleshoot this? Is it an error or I am understanding something incorrectly?
history -a; history -n to:
- load commands from the history file that were added from other open shells
- append new commands from your current shell session to the history file
This effectively keeps any concurrenly open Termimal sessions "in sync". You can add this command to your
PROMPT_COMMAND shell variable to have it automated on every prompt (after every command is executed).
A bit about
PROMPT_COMMAND If this variable is set, and is an array, the value of each set element is executed as a command prior to issuing each primary prompt. If this is set but not an array variable, its value is used as a command to execute instead.
In other words, Terminal.app connects you to a certain shell, allowing you to access all sorts of them concurrently.
cat /etc/shells to see what shells are on your system.
I’m sure you’ve got Bash, ZSH, and a few others.
Then read up on configuring the history for your chosen shell, and try to make it a habit to always know which shell you’re using.
The fish shell, for instance, has an extensive and user friendly history browser, allowing you to see all commands you’ve run using fish.
With bash it’s a bit different.
Also Mac specific:
If you have apps that run maintenance and require administrative privileges, they likely run some of their tasks as simple shell scripts, and almost always using
Think: Catalina Cache Cleaner, Cocktail and Onyx, to name a few.