Zsh Startup Files
Sources:
- **
Overview
There are five primary startup files for Z Shell (Zsh):
.zshenv
: Zsh Environment Configuration.zprofile
: Zsh Profile Configuration.zshrc
: Zsh Interactive Shell Configuration.zlogin
: Zsh Login Configuration.zlogout
: Zsh Logout Configuration
.zshenv
- Zsh Environment Configuration
.zshenv
is sources on all invocations of the shell, unless the -f
option flag is set.
What to Include:
- Command Search Path
- Environment Variable Exports
- Commands for setting up aliases and functions that are needed for other scripts
What to Exclude:
- Commands the product output
- Anything that assumes the shell is attached to a TTY
.zprofile
- Zsh Profile Configuration
.zprofile
is sourced in all login shells. It is meant to serve as an alternative to zlogin
for ksh
.
What to Include:
- Commands that should be executed only in login shells
- As a general rule, it should not change the shell environment at all.
- As a general rule, set the terminal type then run a series of external commands e.g. fortune, msgs, etc.
What to Exclude:
- Alias Definitions
- Function Definitions
- Options
- Environment Variable Settings
.zshrc
- Zsh Interactive Shell Configuration
zshrc
is sourced in interactive shells.
What to Include:
- Commands to setup aliases, functions, options, key bindings, etc.
.zlogin
- Zsh Login Configuration
.zlogin
is similar to .zprofile
, except sourced after .zshrc
.
.zlogout
- Zsh Logout Configuration
.zlogout
is sourced when a login shell exits.
Extras
.zsh-update
.zshrc-e
File Paths
Default System Files:
Default User Files:
When using XDG:
When using ZDOTDIR
:
Zsh System Directory Paths:
Zsh User Directory Paths: