• About
  • Advertise
  • Careers
  • Contact
Thursday, February 19, 2026
  • Login
No Result
View All Result
NEWSLETTER
Blacklight News
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
  • World
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
  • World
No Result
View All Result
Blacklight News
No Result
View All Result
ADVERTISEMENT

All About Aliases Part 2

by Ezekiel
November 2, 2022
in Uncategorized
0
All About Aliases Part 2
0
SHARES
50
VIEWS
Share on FacebookShare on Twitter

Just like you, we love a good sequel! “The Matrix Reloaded”, “The Godfather II”, and “Die Hard 2” are some of our all-time favorite movie sequels. In the same way, this article is a sequel to our previous article “All About Aliases”. Again, we will explore the topic of aliases; however, this time delving deeper into what was left uncovered before.

We only scratched the surface in our last article deliberately so that we could cover more ground in this one. This article will continue by discussing the topic of creating a separate alias file for Bash and Zsh. If you’re unsure of what an alias is, take another look at our last article for some clarification. Now that we’ve gotten that out of the way, here is the continuation to our previous article on aliases: “All About Aliases Part 2”.

As we left off, we were creating aliases in our ~/.bashrc file. While this method works just fine, it isn’t the most efficient way to do things. While it’s perfectly fine to add aliases directly to your ~/.bashrc or ~/.zshrc files, doing so can make those files quite large and difficult to manage over time. A cleaner solution would be to create a separate file that only contains your aliases and then load it from your ~/.bashrc or ~/.zshrc file. This method has the added benefit of being able to easily share your aliases with others by simply sharing the alias file.

While Bash and Zsh are two very similar shells, they are not the same and can cause issues if you use the same configuration file for both. To avoid this, follow along with what applies to either Bash or Zsh in this article. If you are using a Unix-based shell, your default shell is probably Bash. For Mac users, Zsh is likely your default shell. You can check which type of shell you are using by entering the following into your terminal:

echo $0

If the output is -bash, then you are using Bash. If the output is something else, such as -zsh, then you are using Zsh.

Alias File Location

The following sections will depend on which shell you are running. We will show you how to create a file called ~/.bash_aliases for storing Bash aliases, or a file called ~/.zsh_aliases for storing Zsh aliases. Although it is optimal to add your aliases to ~/.profile for bash and ~/.zprofile for Zsh, you can also create a ~/.bash_aliases or ~/.zsh_aliases file and then source these files from your main configuration file.

Create a Separate Alias for Bash (this only applies if you are using the Bash shell)

Let’s start by creating a ~/.bash_aliases file in our home directory:

To set this up, first create a new file called ~/.bash_aliases using the following syntax:

touch ~/.bash_aliases

This will create an empty file called ~/.bash_aliases in your home directory. To get bash to load this file, you need to add the following line to your ~/.bashrc file:

if [[ -f ~/.bash_aliases ]]; then
.  ~/.bash_aliases
fi

This will check if the file exists before trying to load it and prevent any errors if it doesn’t exist. Once you have this in place, any aliases you add to your ~/.bash_aliases file will be available the next time you open a new bash session. Add your aliases to the ~/.bash_aliases file we created earlier :

alias a='alias | grep $1'
alias ea='vim $HOME/.bash_aliases'
alias h='history | grep $1'
alias hf='find $HOME -type f -size +200M 2>&1 -exec du -hs {} + | sort -rh | head -n 5'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias sb='source $HOME/.bashrc'
alias mv='mv -iv'
alias rm='rm -iv'

Save and close the file when you are finished. Don’t forget to source your ~/.bashrc file or open a new terminal session for the changes to take effect.

source ~/.bashrc

Create a Separate Alias for Zsh (this only applies if you are using the Zsh shell)

The process for setting up a separate alias file for Zsh is similar to bash. First, create a new file called ~/.zshrc_aliases using the following syntax:

touch ~/.zshrc_aliases

To get Zsh to load this file, you need to add the following line to your ~/.zshrc file:

if [[ -f ~/.zshrc_aliases ]]; then
. ~/.zshrc_aliases
fi

This will check if the file exists before trying to load it and prevent any errors if it doesn’t exist. Once you have this in place, any aliases you add to your ~/.zshrc_aliases file will be available the next time you open a new Zsh session. Add your aliases to the ~/.zshrc_aliases file we created earlier:

alias a='alias | grep $1'
alias ea='vim $HOME/.zsh_aliases'
alias h='history | grep $1'
alias hf='find $HOME -type f -size +200M 2>&1 -exec du -hs {} + | sort -rh | head -n 5'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias sz='source $HOME/.zshrc'
alias mv='mv -iv'
alias rm='rm -iv'

Save and close the file when you are finished. Don’t forget to source your ~/.zshrc file or open a new terminal session for the changes to take effect.

source ~/.zshrc

Zsh Suffix Aliases

Suffix aliases help you choose which tool to use when opening a file with a specific extension. We can create them by using the -s flag, which follows this syntax: alias -s <suffix>=<program>.

For example, we can create a suffix alias to open all .txt files in vim by running the following command:

alias -s txt=vim

Now, whenever we type the name of a file ending with the .txt extension at the command line, it will open the file in vim. This is extremely helpful when you are working with a lot of different file types and don’t want to have to remember which program to use for each one.

Zsh Global Aliases

Global aliases are similar to suffix aliases, but they are not tied to a specific file extension. We can create them by using the -g flag, which follows this syntax: alias -g <name>=<command>.

For example, we can create a global alias called L that will pipe the output of any command to less by default. This is useful for commands that return a lot of data. To create and use this alias, we would run the following commands:

alias -g L='| less'

To use this alias try running a command like this:

ps auxL

This will show all the processes running on your system, one page at a time.

Where you would normally type “ps aux | less” you can now just type “ps auxL”

Some other common global aliases to use for Zsh are:

alias -g H='| head'
alias -g T='| tail'
alias -g G='| grep'
alias -g C='| wc -l'

Conclusion

Creating aliases, or shortcuts is a great way to both personalize and optimize your shell. In this article, we went over how to create an alias file for both bash and Zsh users as well as global aliases. We even left you some great examples to get your alias file started with some basic, but extremely useful aliases. Give them a try and see how they can help you work more efficiently at the command line.

Whenever you make changes to your alias file, don’t forget to either source your file or open a new terminal session for the changes to take effect. Now that you understand what aliases are, attempt creating some yourself so that you can save time while working in the terminal.

Our next technology article will cover how to manage your command line history file, so stay tuned!

If you enjoyed this article, please share it with your friends or leave a comment below letting us know which alias or action movie sequel is your favorite.

Thanks for reading!

Tags: LinuxTech
Ezekiel

Ezekiel

Next Post

Bash to the Future: A Guide to Setting Up and Using Bash History

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended

A New Dangerous TikTok Trend Risking The Health of Young Women

A New Dangerous TikTok Trend Risking The Health of Young Women

3 years ago
Biden Announces Proposal to End the Student Loan Debt

Biden Announces Proposal to End the Student Loan Debt

3 years ago

Popular News

  • Are Automated Journalism Tools Destroying The News Industry?

    Are Automated Journalism Tools Destroying The News Industry?

    0 shares
    Share 0 Tweet 0
  • Biden Announces Proposal to End the Student Loan Debt

    0 shares
    Share 0 Tweet 0
  • North Carolina Teen Earns Title Of Fastest Runner In America 

    0 shares
    Share 0 Tweet 0
  • Florida Man Shoots Student Over $1

    0 shares
    Share 0 Tweet 0
  • The Science Behind Why Janet Jackson’s Rhythm Nation Can Cause Laptops To Crash

    0 shares
    Share 0 Tweet 0

Connect with us

Facebook Twitter Youtube RSS

Category

  • National

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
No Result
View All Result
  • Home
  • World
  • National
  • Gaming
  • Movie

If you're looking for a way to stay up-to-date on the latest news, events, and happenings, then subscribing to our newsletter is the perfect solution! Not only will you receive regular updates, but you'll also get exclusive access to articles, tips, and advice that you won't find anywhere else. So what are you waiting for? Subscribe today!