Home > Technology peripherals > It Industry > 75 Zsh Commands, Plugins, Aliases and Tools

75 Zsh Commands, Plugins, Aliases and Tools

Christopher Nolan
Release: 2025-02-15 10:08:13
Original
700 people have browsed it

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 enter sudo !!.
  • 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 typing echo $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, or history | 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>
Copy after login
Copy after login

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 a alias distro='cat /etc/*-release' alias that outputs information about your Linux distribution:

    .
  • reloadA alias reload='source ~/.zshrc' a

    alias, because I always can't seem to remember how to reload my terminal:
  • .
  • undo-git-reset alias undo-git-reset-head="git reset 'HEAD@{1}'"A git reset HEAD~Alias:

    . This will restore the effect of running
  • .
  • alias sapu='sudo apt-get update'

    A alias for an update package list:
  • .
  • alias ffs='sudo !!'

    A alias that reruns the previous command using sudo:
  • .
  • y yarnBecause I'm lazy, I'll use alias y='yarn' as an alias for the <kbd>y</kbd> command:

    . This means I can clone a repository and then just type
  • to introduce all the dependencies. I learned this from Scott Tolinski on Syntax.
  • node_modules package-lock.jsonI don't use it often, but this alias clears the alias 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

    O
  • nce.
  • .zshrc alias zshconfig='subl $HOME/.zshrc'A alias that opens my

    file for editing:
  • .
  • alias update-available-rubies='cd ~/.rbenv/plugins/ruby-build && git pull'

    A alias for an updated list of Ruby versions that rbenv can install:
  • alias server='python -m SimpleHTTPServer 8000'

    A alias to start the server in your current directory (no npm package required):
  • .
  • alias npmhelp='firefox https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/npm'

    You can also create an alias to open the document in your browser:
  • .
  • alias -g L='| less' cat production.log LA global alias for pipes the output of the command to less:

    . You can use it like this:
  • .
  • alias -g G='| grep' history G sshA global alias for pipes the output of the command to grep:

    . You can use it like this:
  • .
  • You can also use functions to create alias. The following (taken from here) creates an alias to add, commit and push code to GitHub:
    <code>alias [alias-name]='[command]'</code>
    Copy after login
    Copy 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 Replace mkdir 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 for cd ....
  • 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 for rmdir and md is an alias for mkdir -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 to cap, rake, ssh and kill.
  • 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.

  1. g is a convenient alias for git. This means you can type something like g clone <whatever></whatever> instead of git clone <whatever></whatever>. There may be only two keys, but they will accumulate soon.
  2. gaa is an alias for git add all. I've been using this all the time.
  3. gb is an alias for git branch that will list all branches in the current repository and show which branch you are currently in.
  4. gcb is an alias for git checkout -b, which allows you to create a new branch.
  5. gcm is an alias for git checkout master. This returns you to the main branch.
  6. gdca is an alias for git diff --cached. This allows you to make a differential comparison of any files that have been staging for submission.
  7. gf is an alias for git fetch.
  8. gm is an alias for git merge.
  9. gp is an alias for git push. To synchronize the branches of the repository, you can do: gf upstream, gm upstream/master, and then gp.
  10. glog is an alias for git log --oneline --decorate --graph, which will give you a beautiful git branch graph.

10 convenient npm alias

The

npm plugin provides completion and many useful aliases.

  • npmg is an alias for npm install --global that you can use to install dependencies globally on your system. For example, npmg nodemon.
  • npmS is an alias for npm install --save that you can use to install dependencies and add them to your package.json section of dependencies. Note that starting with npm 5.0.0, this is the default when running npm i <package></package>.
  • npmD is an alias for npm install --save-dev that you can use to install dependencies and add them to your package.json section of devDependencies.
  • npmO is an alias for npm outdated that will check the registry to see if any (or specific) installed packages are currently expired.
  • npmL is an alias for npm list that will list installed packages.
  • npmL0 is an alias for npm 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 for npm run start, a npm script commonly used to start applications.
  • npmt is an alias for npm run test , and as you might guess, it is used to run your tests.
  • npmR is an alias for npm 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 for npm init. This will ask you some questions and then create a package.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 for rails console that allows you to interact with your Rails application from the CLI.
  • rdc is an alias for rake db:create, which (unless RAILS_ENV is set) will create a development and test database for your application.
  • rdd is an alias for rake db:drop that will delete the development and testing database of your application.
  • rdm is an alias for rake db:migrate that will run any pending database migrations.
  • rds is an alias for rake db:seed that runs the db/seeds.rb file to populate your development database with data.
  • rgen is an alias for rails generate that will generate boilerplate code. For example: rgen scaffold item name:string description:text.
  • rgm is an alias for rails generate migration that will generate a database migration. For example: rgm add_description_to_products description:string.
  • rr is an alias for rake routes that lists all defined routes for the application.
  • rrg is an alias for rake routes | grep that allows you to list and filter defined routes. For example, rrg user.
  • rs is an alias for rails 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
Don't forget that if you spend a lot of time on the terminal, it's worth it to make it more visually appealing. Fortunately, Oh My Zsh comes with a lot of themes for you to choose from. My favorite topic is Agnoster.

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?

The

Zsh 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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template