Boost Productivity with Z and Zsh on Ubuntu

  • Last Created On Dec 10, 2024
  • 7
0 0

Introduction

Working on Linux systems means that one is using the command line more often than not. Having to type long directory names over and over as well as guessing command names eats up valuable time. This can add up very quickly. Z is a tool that records every directory you browse and compiles a weighted list of the most frequent/recently used ones. Zsh is an alternative to bash (the default shell that come with most Linux distros) that adds subtle improvements like spelling correction of words/commands and better tab-completion.

Setup & Installation

Spin-up for AKLWEB Host Server or VPS with running Ubuntu (either version 12,14 or 16) and follow the steps below to add a new admin (sudo) user. We’re doing this because it is along the lines of best practices to create a new user and assign it admin rights to access the server, rather than use the root user.

  1. Connect to your Server ssh root@[akl-web-host-server-ip-address].
  2. Add a new user adduser <newuser> (you will need to answer some prompt questions after issuing this command).
  3. Make the new user an admin user adduser <newuser> sudo.
  4. Disconnect from the server exit.
  5. Reconnect to server, but this time as the new user ssh <newuser>@[akl-web-host-server-ip-address].

Installing and Using Z

You should be in your home directory after you logon as “newuser” (otherwise, run cd ~). Follow the next set of steps to install Z. Note that since Z is a script, what we do is download it to our home directory and tell our default shell to run Z anytime it starts.

  1. Download wget https://raw.githubusercontent.com/rupa/z/master/z.sh.
  2. Install printf "\n\n#initialize Z (https://github.com/rupa/z) \n. ~/z.sh \n\n" >> .bashrcThis command appends . ~/z.sh to your .bashrc file, which in turn tells it to run Z upon start-up.
  3. Reload shell source ~/.bashrc.

To test how Z works, browse to these directories:

cd /etc/systemd/system
cd /usr/share/nano
cd /etc/kernel/postinst.d
cd ~

Now, from your terminal, type in z sys and push the tab button, then enter. Next, type z nano and hit the tab button, then enter again. You will see in both cases that Z automatically knew to cd into the first and second directories where we initially browsed.

Installing and Using Zsh

  1. Install sudo apt-get update && sudo apt-get -y install zsh.
  2. Check version to verify installation zsh --version.
  3. Make Zsh your default shell chsh -s /bin/zsh. You will be prompted to enter your password.
  4. Logout exit.
  5. Log back into the system ssh <newuser>@[akl-web-host-server-ip-address].

If you are greeted with a Zsh shell configuration prompt, select “2” to accept default settings.

To test things out, type cd /emc and push the tab button. Zsh will auto-complete terminal to cd /etc because a /emc directory does not exist and /etc is the closest option as to what was intended. Next, type “kill ” and push the tab button (there is a space after kill). Zsh will automatically show you a list or processes to kill as oppose to doing nothing.

Zsh also shares your terminal history across multiple windows/sessions, and has tons of other useful features. There are also frameworks built on top of Zsh that even add more dazzling features to it, such as oh-my-zsh and prezto.

Using Z with Zsh

  1. Run printf "\n\n#initialize Z (https://github.com/rupa/z) \n. ~/z.sh \n\n" >> .zshrcThis command appends . ~/z.sh to .zshrc file, which tells it to run Z on start-up.
  2. Reload shell source ~/.zshrc.

Note: If you do not like the default settings, you can update the Zsh shell configuration by editing the .zshrc file (in your home directory), or by running the following commands:

autoload -U zsh-newuser-install
zsh-newuser-install -f

Conclusion

Z and Zsh are useful tools that may drastically help increase your productivity.

Other Versions

CentOS

Views: 7

Recent Articles

  • How to Install JAX with ROCm Acceleratio...
    96
  • Deploy a PyTorch Workspace on a Vultr Cl...
    71
  • Managing Backup Storage
    83
  • Automating FTP Backups in Windows Server
    71
  • Automating FTP Backups in Linux
    75

Popular Articles

  • Our General Terms & Conditions
    2633
  • Our Privacy Policy
    2478
  • Our Cookies Policy
    275
  • Our Terms of Use
    153
  • How to Install JAX with ROCm Acceleratio...
    96