75 Zsh Commands, Plugins, Aliases and Tools
Zsh: 75 commands, plugins, alias and tools to help you improve terminal efficiency
I work most of my time every day at the terminal, and the shell I chose is Zsh – a highly customizable Unix shell with many powerful features. As a lazy developer™, I've been looking for ways to reduce the amount of input and automate all tasks. Fortunately, Zsh was born for this.
In this article, I will share 75 commands, plugins, alias and tools, hoping to help you save some key presses and improve your daily work efficiency.
If you haven't installed Zsh on your machine, check out this article and I'll show you how to get started quickly.
Key Points
- Zsh is a highly customizable Unix shell that is ideal for developers looking to automate tasks and increase productivity by reducing the number of key presses.
- This article provides a comprehensive guide to 75 Zsh commands, plugins, alias, and tools, including practical applications and customization tips.
- Zsh's key features include powerful command-line navigation, conditional execution, and the ability to efficiently link multiple commands.
- Oh My Zsh, a community-driven framework that simplifies your workflow by providing thousands of useful functions, plugins, and themes.
- This article also highlights the use of aliases and plugins that can significantly speed up common tasks and simplify complex commands in Zsh.
Zsh's 15 out-of-the-box features
Zsh shares many convenient features with Bash. The following features are not unique to Zsh, but are still worth knowing. I encourage you to start using the command line to do the actions listed below. At first it may seem like it's more laborious than using a GUI, but once you get the trick, you'll never regret it.
- Enter
cd
from anywhere in the file system will take you back to your home directory directly. - Enter
!!
will call up the last command. This will be very convenient if the command fails because administrator privileges are required. In this case, you can entersudo !!
. - You can use
&&
to link multiple commands. For example,mkdir project && cd project && npm init -y
. - Use
||
to perform conditional execution. For example,git commit -m "whatever..." || echo "Commit failed"
. - Using the
mkdir
command's-p
switch will allow you to create a parent directory as needed. Use curly braces to expand to reduce duplication. For example,mkdir -p articles/jim/sitepoint/article{1,2,3}
. - Set environment variables based on each command, for example:
NODE_DEBUG=myapp node index.js
. Or, set on a per-session basis:export NODE_DEBUG=myapp
. You can check if it is set by typingecho $variable-name
. - Transfer the output of one command to the second command. For example,
cat /var/log/kern.log | less
makes long logs easy to read, orhistory | grep ssh
searches for any history entry containing "ssh". - You can open files from the terminal in your editor. For example,
nano ~/.zshrc
(nano),subl ~/.zshrc
(Sublime Text),code ~/.zshrc
(VS Code). If the file does not exist, it will be created when you press "Save" in the editor. - Navigation is an important skill. Don't rely on your arrow keys just. For example,
<kbd>Ctrl</kbd> <kbd>a</kbd>
will take you to the beginning of a line. - And
<kbd>Ctrl</kbd> <kbd>e</kbd>
will take you to the end. - You can use
<kbd>Ctrl</kbd> <kbd>w</kbd>
to delete a word (backward). -
<kbd>Ctrl</kbd> <kbd>u</kbd>
will delete everything from the cursor to the beginning of the line. -
<kbd>Ctrl</kbd> <kbd>k</kbd>
Clears everything from the cursor to the end of the line. The last three can be undoed using<kbd>Ctrl</kbd> <kbd>y</kbd>
. - You can use
<kbd>Ctrl</kbd> <kbd>Shift</kbd> <kbd>c</kbd>
to copy text. This is much more elegant than right-clicking and selecting Copy. - Instead, you can use
<kbd>Ctrl</kbd> <kbd>shift</kbd> <kbd>v</kbd>
to paste copied text.
Try to remember these key combinations. You'll be surprised at how often they come in handy.
15 custom aliases to increase your productivity
Alias is a terminal shortcut for regular commands. You can add them to your ~/.zshrc
file and reload your terminal (using source ~/.zshrc
) to make them take effect.
The syntax for declaring (simple) alias is as follows:
<code>alias [alias-name]='[command]'</code>
Alias is perfect for common commands, long commands, or commands that are difficult to remember in syntax. Here are some aliases that I often use:
-
A
myip
alias that prints your current public IP address to the terminal:alias myip='curl http://ipecho.net/plain; echo'
. -
A
.distro
aalias distro='cat /etc/*-release'
alias that outputs information about your Linux distribution: -
reload
Aalias reload='source ~/.zshrc'
a . -
undo-git-reset
alias undo-git-reset-head="git reset 'HEAD@{1}'"
Agit reset HEAD~
Alias: . -
alias sapu='sudo apt-get update'
. -
alias ffs='sudo !!'
. -
y
yarn
Because I'm lazy, I'll usealias y='yarn'
as an alias for the<kbd>y</kbd>
command: to introduce all the dependencies. I learned this from Scott Tolinski on Syntax. -
node_modules
package-lock.json
I don't use it often, but this alias clears thealias yolo='rm -rf node_modules/ && rm package-lock.json && yarn install'
folder and deletes the file, and then reinstalls the project's dependencies: . As you may know, yolo stands for You Only Live nce. -
.zshrc
alias zshconfig='subl $HOME/.zshrc'
A alias that opens my . -
alias update-available-rubies='cd ~/.rbenv/plugins/ruby-build && git pull'
-
alias server='python -m SimpleHTTPServer 8000'
. -
alias npmhelp='firefox https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/npm'
. -
alias -g L='| less'
cat production.log L
A global alias for pipes the output of the command to less: . -
alias -g G='| grep'
history G ssh
A global alias for pipes the output of the command to grep: . -
<code>alias [alias-name]='[command]'</code>
Copy after loginCopy after login
There are many places to find more ideas about alias online. For example, this Hacker News discussion, or this article about using Zsh to improve command line productivity.
15 cool things you can do with (Oh My) Zsh
Oh My Zsh is a community-driven framework for managing your Zsh configuration and bundled with thousands of useful functions, assistants, plugins, and themes. If you are going to use the Z shell as your daily driver, you should really install Oh My Zsh.
Here are fifteen useful things Oh My Zsh can do for you:
-
The
-
take
command will create a new directory and enter the directory.take my-project
Replacemkdir my-project && cd my-project
. -
zsh_stats
will provide you with a list of the first 20 commands and their number of runs. - Oh My Zsh simplifies your file system navigation. For example,
..
is an alias forcd ...
. - Similarly,
...
moves you upwards two directories,....
moves three upwards, and.....
moves four upwards. - You can omit
cd
when navigating. For example, entering/
will take you directly to your file system root directory. - also supports partial matching. For example, enter
/h/j/De
and press<kbd>TAB</kbd>
and then<kbd>Return</kbd>
will take me to/home/jim/Desktop/
. -
rd
is an alias forrmdir
andmd
is an alias formkdir -p
. - You can enter
d
to list the last directory used in the terminal session. - You can then use
cd -n
to navigate to any of these directories, where n is the directory number. - Tab completion is another great feature. For example, entering
ls -
and pressing<kbd>TAB</kbd>
will list all command options, as well as a useful description of their functions. This also applies tocap
,rake
,ssh
andkill
. - Enter
alias
All your current aliases will be listed. - Using wildcards (Zsh function), you can list files with specific extensions. For example,
ls *.html
will list all HTML files in the current directory. To include subdirectories, change to:ls **/*.html
. - Wildcard qualifier allows you to use flags to select file types. For example,
ls -l **/*(.x)
will find all executables in the current directory and all subdirectories. - You can search for files by modification date. For example,
ls *(m-7)
will list all files modified in the past week. - You can search for files by size. For example,
ls *(Lm 1)
will look for all files with a size greater than 1MB.
Get fun and benefits with plug-ins
Oh My Zsh comes with a large number of plugins. You should browse these plugins and invest some time learning those that can help your workflow.
The following are three plugins I often use that provide a lot of handy shortcuts and aliases.
10 beautiful Git alias
git plugin provides many aliases and some useful functions. Why not browse these and try to remember the ten you use most often? Here are the ones I use most.
-
g
is a convenient alias forgit
. This means you can type something likeg clone <whatever></whatever>
instead ofgit clone <whatever></whatever>
. There may be only two keys, but they will accumulate soon. -
gaa
is an alias forgit add all
. I've been using this all the time. -
gb
is an alias forgit branch
that will list all branches in the current repository and show which branch you are currently in. -
gcb
is an alias forgit checkout -b
, which allows you to create a new branch. -
gcm
is an alias forgit checkout master
. This returns you to the main branch. -
gdca
is an alias forgit diff --cached
. This allows you to make a differential comparison of any files that have been staging for submission. -
gf
is an alias forgit fetch
. -
gm
is an alias forgit merge
. -
gp
is an alias forgit push
. To synchronize the branches of the repository, you can do:gf upstream
,gm upstream/master
, and thengp
. -
glog
is an alias forgit log --oneline --decorate --graph
, which will give you a beautiful git branch graph.
10 convenient npm alias
Thenpm plugin provides completion and many useful aliases.
-
npmg
is an alias fornpm install --global
that you can use to install dependencies globally on your system. For example,npmg nodemon
. -
npmS
is an alias fornpm install --save
that you can use to install dependencies and add them to yourpackage.json
section ofdependencies
. Note that starting with npm 5.0.0, this is the default when runningnpm i <package></package>
. -
npmD
is an alias fornpm install --save-dev
that you can use to install dependencies and add them to yourpackage.json
section ofdevDependencies
. -
npmO
is an alias fornpm outdated
that will check the registry to see if any (or specific) installed packages are currently expired. -
npmL
is an alias fornpm list
that will list installed packages. -
npmL0
is an alias fornpm list --depth=0
that lists top-level packages. This is especially useful for viewing which modules are installed globally without flooding your terminal with a huge dependency tree:npmL0 -g
. -
npmst
is an alias fornpm run start
, a npm script commonly used to start applications. -
npmt
is an alias fornpm run test
, and as you might guess, it is used to run your tests. -
npmR
is an alias fornpm run
. It itself will list all available npm scripts for the project, as well as a description of their functionality. When used with the script name, it will run the script, for example,npmR build
. -
npmI
is an alias fornpm init
. This will ask you some questions and then create apackage.json
based on your answer. Use the-y
flag to automate this process. For example,npmI -y
.
10 Time-saving Rails/Rake Alias
This plugin adds completion of the Ruby on Rails framework and Rake programs, as well as some aliases for logs and environment variables.
-
rc
is an alias forrails console
that allows you to interact with your Rails application from the CLI. -
rdc
is an alias forrake db:create
, which (unlessRAILS_ENV
is set) will create a development and test database for your application. -
rdd
is an alias forrake db:drop
that will delete the development and testing database of your application. -
rdm
is an alias forrake db:migrate
that will run any pending database migrations. -
rds
is an alias forrake db:seed
that runs thedb/seeds.rb
file to populate your development database with data. -
rgen
is an alias forrails generate
that will generate boilerplate code. For example:rgen scaffold item name:string description:text
. -
rgm
is an alias forrails generate migration
that will generate a database migration. For example:rgm add_description_to_products description:string
. -
rr
is an alias forrake routes
that lists all defined routes for the application. -
rrg
is an alias forrake routes | grep
that allows you to list and filter defined routes. For example,rrg user
. -
rs
is an alias forrails server
, which starts the Rails default web server.
Other Resources
The main job of the plug-in listed above is to provide alias for common commands. Note that there are many other plugins that can add additional features to your shell.
The following are four of my favorites:
-
sudo
allows you to easily prefix the current or previous command by pressing<kbd>ESC</kbd>
twice.sudo
- Suggest commands as you type based on history and complete content. If the suggestion is the command you are looking for, press the
autosuggestions
key to accept it. A real time-saving tool!<kbd>→</kbd>
- : If the command is not recognized in
command-not-found
, it will use the Ubuntu's$PATH
package to find it or suggest a misspelling.command-not-found
- is a handy plugin that builds your most commonly used and recent folder lists (it is called "frecent") and allows you to jump to them with a command.
z
You can learn more about the topic in my article 10 Zsh tips and tricks: Configuration, Customization, and Usage.
Conclusion
It's like this: 75 Zsh commands, plugins, alias, and tools. I hope you have learned a trick or two during the learning process and I encourage you to leave your GUI and go to the terminal. It's much easier than it seems and is a great way to increase productivity.
If I missed your favorite plugin or time-saving alias/command, please let me know on Twitter.
Want to get more from your toolkit? Check out Wiley's Visual Studio Code: End-to-end editing and debugging tools for web developers.
FAQs about Zsh commands, plugins, alias, and tools
What are the benefits of using Zsh than using other shells such as Bash?
Zsh, also known as Z shell, is a powerful shell that contains features from other shells such as Bash, tcsh, and ksh. It offers some advantages over these shells. First of all, Zsh has powerful autocomplete features that can suggest commands, file names, options, and even host names. This feature can significantly speed up your workflow. Second, Zsh supports sharing command history, which allows you to view commands typed in another terminal session. Third, Zsh allows you to use Emacs and vi editing modes at the same time, which makes it more flexible for different users. Finally, Zsh has a powerful scripting language with features such as associative arrays and floating point operations that are not available in Bash.
How to customize my Zsh prompt?
Zsh allows you to customize your prompt using the PROMPT
variable. You can set this variable in your .zshrc
file. For example, if you want to display the current directory in your prompt, you can use the %~
parameter. Therefore, your PROMPT
variable will look like this: PROMPT='%~%# '
. You can also add colors to your prompt using the %F{color}
parameter. For example, to make your prompt green, you can use: PROMPT='%F{green}%~%# %f'
. %f
Reset the color to the default color.
How to use alias in Zsh?
Aliases in Zsh can help you save time by allowing you to create shortcuts for long or common commands. You can create an alias by using the alias
command followed by the alias and the command you want to be quick. For example, to create an alias for the ls -l
command, you can use: alias ll='ls -l'
. You can add this line to your .zshrc
file to make the alias permanently effective.
What are Zsh plugins and how do you use them?
Zsh plugin is a script that adds additional features to your Zsh shell. They can help you automate tasks, add new features, or customize your shell. To use the Zsh plugin, you first need to install it. This usually involves cloning the plugin's repository into your .oh-my-zsh/plugins
directory and then adding the plugin to the .zshrc
array in your plugins
file. Once the plugin is installed, you can start using its features.
How to switch from Bash to Zsh?
Switching from Bash to Zsh is an easy process. First, you need to install Zsh using your package manager. For example, on Ubuntu, you can use: sudo apt install zsh
. After installing Zsh, you can set it as your default shell using the chsh
command: chsh -s $(which zsh)
. The next time you open the terminal, it will use Zsh.
How to use Zsh theme?
Zsh theme allows you to customize the appearance of the shell. You can change the color scheme, prompt layout, and even add elements such as the current time or git status. To use the Zsh theme, you first need to install it. This usually involves cloning the repository of the topic into your .oh-my-zsh/themes
directory and setting the .zshrc
variable in your ZSH_THEME
file to the name of the topic. After installing the theme, you can activate it by getting your .zshrc
file: source ~/.zshrc
.
What is Oh My Zsh and how to use it?
Oh My Zsh is a community-driven framework for managing your Zsh configuration. It comes with many useful functions, plugins, and themes. To use Oh My Zsh, you first need to install it. This usually involves downloading the installation script and running it in your terminal. After installing Oh My Zsh, you can start customizing your shell by editing your .zshrc
file.
How to use Zsh function?
TheZsh function allows you to group commands together and execute them as a single command. You can define a function using the function
keyword followed by the function name and command block. For example, to create a function that prints "Hello, world!", you can use: function hello { echo "Hello, world!"; }
. You can call this function by typing the function name: hello
.
How to use Zsh arrays?
Zsh supports indexed arrays and associative arrays. You can use the set
command followed by the array name and element to create an index array. For example, to create a color array, you can use: set -A colors red green blue
. You can access elements of an array using its index: echo $colors[1]
. To create an associative array, you can use the typeset
command: typeset -A colors; colors[red]=#FF0000; colors[green]=#00FF00; colors[blue]=#0000FF;
.
How to use Zsh loop?
Zsh supports several types of loops, including for, while, and until loops. The for loop allows you to execute command blocks repeatedly for each element in the list. For example, to print numbers from 1 to 5, you can use: for i in {1..5}; do echo $i; done
. The while loop allows you to repeat the command block when the condition is true. For example, to print numbers from 1 to 5, you can use: i=1; while (( i < 6 )); do echo $i; i=$((i 1)); done
. The until loop allows you to repeat the command block when the condition is false. For example, to print numbers from 1 to 5, you can use: i=1; until (( i > 5 )); do echo $i; i=$((i 1)); done
.
The above is the detailed content of 75 Zsh Commands, Plugins, Aliases and Tools. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











This pilot program, a collaboration between the CNCF (Cloud Native Computing Foundation), Ampere Computing, Equinix Metal, and Actuated, streamlines arm64 CI/CD for CNCF GitHub projects. The initiative addresses security concerns and performance lim

This tutorial guides you through building a serverless image processing pipeline using AWS services. We'll create a Next.js frontend deployed on an ECS Fargate cluster, interacting with an API Gateway, Lambda functions, S3 buckets, and DynamoDB. Th

Stay informed about the latest tech trends with these top developer newsletters! This curated list offers something for everyone, from AI enthusiasts to seasoned backend and frontend developers. Choose your favorites and save time searching for rel
