Configure shells Bash, Zsh, PowerShell
The default interactive shell for operating systems is typically:
- Linux: Bash
- macOS: Zsh
- Windows: PowerShell
Note that the non-interactive shell may default to a simpler POSIX shell like Dash, so ensure that script shebang line specifies the intended shell for running scripts.
Each shell vendor has configuration files to change the default shell parameters. Shells typically have a persistent command history file that stores the commands that have been executed. This allows users to recall and reuse previous commands. A very long history may retain mistyped commands or commands that are no longer relevant.
Bash
Get the location of the Bash command history file:
echo "${HISTFILE:-$HOME/.bash_history}"Edit the ~/.bashrc file to include the following settings:
# Number of commands remembered in the current session (in memory)
export HISTSIZE=500
# Number of commands saved to the history file on disk
# Keep at least a little bigger than HISTSIZE to handle duplicates
export HISTFILESIZE=1000
# Ignore both duplicate and empty commands
export HISTCONTROL=ignoredups:ignorespaceZsh
Get the location of the Zsh command history file:
echo "${HISTFILE:-${ZDOTDIR:-$HOME}/.zsh_history}"Edit the ~/.zshrc file to include the following settings:
# Number of commands remembered in the current session (in memory)
export HISTSIZE=500
# Number of commands saved to the history file on disk
# Keep at least a little bigger than HISTSIZE to handle duplicates
export HISTFILESIZE=1000
setopt hist_ignore_dups
setopt hist_ignore_spacePowerShell
Get the location of the PowerShell command history file:
(Get-PSReadLineOption).HistorySavePathEdit the “$profile” file to include the following settings: ignore duplicates and limit the number of commands in the history.
Set-PSReadLineOption -MaximumHistoryCount 500 `
-HistoryNoDuplicates