What is zsh? Features and getting started
Author: Domeny.ForSale editorial team Published
In brief: Zsh, or Z shell, is a system shell — a program that interprets the commands you enter and runs the tasks you specify. It makes terminal work easier through extensive command completion, history and configuration options. It is mainly useful for interactive work with your system, but you do not need to know it to start using a terminal.
Zsh and the terminal — what is the difference?
A terminal is an application that provides a place to enter commands and display results. The shell runs inside that application: it reads commands, parses their syntax and initiates the requested operations. You can run different shells in the same terminal, such as zsh or Bash.
When you enter cd Documents, zsh runs its built-in command to change directories. When you enter git status, it launches the external program Git, provided it is installed and available on the program search path. This distinction matters: installing zsh does not automatically install the tools you name in your commands.
Zsh is available on systems including Linux and macOS. Since Catalina, it has been the default shell for new user accounts on macOS, though an individual account may use a different setting. On Windows, you can use it in WSL, for example — an environment that lets you run Linux tools.
How does zsh help with everyday work?
The main benefit of zsh is that it reduces the need to type repetitive parts of commands manually. Its convenience depends on configuration, however: a fresh installation may not look or behave like the terminal shown in a tutorial.
Useful features include:
- Tab completion: can suggest command names, paths, options and arguments. The range of suggestions depends on the available completion definitions.
- Command history: lets you return to earlier commands. Saving history between sessions and sharing it across sessions require appropriate settings.
- Filename matching: patterns let you select groups of files without listing every name individually.
- A configurable prompt: the text before the cursor can show the directory, the status of the last command or information about a Git repository.
For example, if your current directory contains a folder called project-shop, you can enter cd proj and press Tab. The shell will try to complete the name; if several directories match, it may show the available choices. Other shells offer similar features too. For some users, zsh’s advantage lies in its range of configuration options and extensions, not simply in having completion.
Zsh or Bash — which should you choose?
Bash is another popular shell, commonly used on Linux and in administration scripts. Zsh and Bash support many similar commands, but their syntax is not fully compatible. Differences include how they handle arrays, variable expansion and filename matching.
A practical example: with its default settings, zsh will report a matching error for ls *.txt if the directory contains no files with the .txt extension. By default, Bash will instead pass the literal argument *.txt to ls, which will report that no such file exists. A seemingly identical command can therefore fail at a different stage.
For everyday work, choose the shell that makes your tasks easier. For scripts, choose the interpreter deliberately. A script starting with #!/bin/bash specifies Bash as its interpreter when run directly. Using zsh in your terminal does not mean you need to rewrite that script; running it with zsh script.sh, however, may cause compatibility errors.
How do you check for and run zsh?
First, check whether the program is available:
zsh --version
If you get a version number, you can try zsh by entering zsh. The exit command will end that session and return you to the previous shell. This does not change your account’s default settings.
If the system cannot find the program, install it on Linux using your distribution’s package manager. For example, on Debian and Ubuntu, use sudo apt install zsh. This command requires administrator privileges; for another distribution, check its official documentation for the correct procedure.
The often-recommended echo $SHELL usually shows the configured login shell, not necessarily the shell running in your current session. After starting zsh, you can check echo $ZSH_VERSION — in zsh, this variable contains its version number.
You can usually change your account’s default shell with chsh. Before doing so, confirm the program’s path and your system’s rules: the shell may need to be listed in /etc/shells, and workplace accounts may be subject to administrative restrictions.
Configuring zsh and the role of Oh My Zsh
The main configuration file for interactive sessions is usually ~/.zshrc, where ~ represents the user’s home directory. You can put aliases — command shortcuts — and completion settings in this file. A simple starting point looks like this:
alias ll='ls -lh'
autoload -Uz compinit
compinit
The alias lets you enter ll instead of ls -lh, while the following lines initialise the completion system. Before editing an existing file, make a copy and check whether it already contains similar settings. The easiest way to test changes is in a new zsh session.
Oh My Zsh is an optional collection of configurations, themes and plugins, not the shell itself. Coloured suggestions as you type and syntax highlighting often come from additional extensions. They are not automatically available after installing zsh.
To begin, run zsh without changing your default shell and carry out a few of your usual tasks. Add extensions only when you can identify the specific task they should make easier; before running an installer, check its source and the changes it will make.
See also: What is AGI?
