NOTE: this “trick” works exactly the same on Linux. But I’m assuming that, if you’re using Linux, you already know about aliases.
For example, if you use macOS and Homebrew every once in a while you need to update homebrew and upgrade your formulas. So you will need to type
brew update && brew upgrade && brew cask upgrade. That takes time. But you can create an alias, a “shortcut” command that can consist of just one letter or word that will perform the same commands.
Makes sense? Let’s say you will set
brew as an alias for
brew update && brew upgrade && brew cask upgrade. Now when you want to update and upgrade homebrew, instead of executing that long line of multiple commands ( or executing them one by one ) all you have to do is execute
Ok so how do you create an alias? You will need to edit your
zshrc file. If you don’t know which one you need to edit, you’re using the default shell which is bash. But just to be sure, open up your terminal and type
echo "$SHELL" .
Now you can edit the bashrch file directly from the terminal with
nano ~/.bashrc or just open the file with a text editor. The file is located in your Home folder but it’s hidden. Here’s how to quickly toggle the visibility of hidden files in macOS.
Now just add your alias like this:
alias='your-long-command' and save the file. Example:
alias brew='brew update && brew upgrade && brew cask upgrade'
It’s that simple. Now, when you need to use the terminal, you can be so much faster and productive. Here’s a few aliases that I personally use (macOS) and you might find useful:
alias c='clear' - clear terminal output and clear screen alias r='reset' - reset terminal alias ls='ls -lG' - list files and directories with long listing and showing file type and permissions alias purge='sudo purge' - clear RAM alias dns='sudo killall -HUP mDNSResponder' - flush dns cache alias ip='curl ifconfig.co && curl ifconfig.co/country && curl ifconfig.co/country-iso && curl ifconfig.co/city && curl ifconfig.co/asn' - get IP