Method to Make the Alias Command Permanent Storage in Linux

Source: Internet
Author: User
Keywords alias storage linux alias command permanent alias linux command
Background
I recently came into contact with the Linux system. In the process of learning, there is a command alias that I feel particularly interesting. So I wrote my own command alias zzm='echo "wlz, I love u"' according to the tutorial, and then immediately showed it to my girlfriend. She first looked at those lines of code attentively, and then understood After that, we smiled shyly, with our eyes facing each other, we were all very excited.
Simple Application Server
USD1.00 New User Coupon
* Only 3,000 coupons available.
* Each new user can only get one coupon(except users from distributors).
* The coupon is valid for 30 days from the date of receipt.

But when I continued to learn Linux the next day, I first typed zzm on the command line, but found that I didn’t have this command anymore. It turned out that love would disappear, right? .

No, how could I let love disappear so unclearly! I'm not convinced!

So, I started to look up information and think about how to make the custom alias command permanent. There are some methods on the Internet, but there are some differences between different Linux distributions, and some methods are not applicable. My virtual machine is Ubuntu 18.04TLS.

I wanted to read a few chapters of the Linux book today, but I spent a long time studying this. But I don't regret at all for spending the time to delve into a small problem. Because this is the guardian of love, and at the same time, learning/research is actually a process of discovering various small problems and then self-exploring.

Not much nonsense, let me talk about how I solved it on Ubuntu 18.04TLS.

Solution
First adjust the current working directory to /home/own user/
cd /home/zzmine
Then, search for the .bashrc file (because it is a file starting with ., you need to use the -a option to display)
ls -a -l | grep .bashrc

After confirming that there is this file, open it!
less .bashrc

Scroll down and you will see a sentence

You may want to put all your additions into a separate file like
~/.bash_aliases, instead of adding them here directly.

This means that you can define a separate file .bash_aliases to store your own defined commands instead of adding them directly to the .bashrc file. Then let's write a .bash_aliases file in the current working directory /home/zzmine.
vim .bash_aliases
alias zzm='echo "wlz,I love u"'

Then save, exit, and finally re-execute the .bashrc file to make it effective
source .bashrc

Then, restart, directly enter the previously defined command, and find that it is all right!

Extension
In fact, the usefulness of custom commands is much more than simply showing affection. You can combine multiple commands and assign aliases to simplify future work. For example, you can set the first push to github command as:
alias gpush ='git add .; git commit -m "first commit"; git push -u origin master'
Finally, if readers have questions or other ideas about the article, welcome to share!
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.