Home  >  Article  >  Operation and Maintenance  >  Tutorial on the use of aliases and binaries in Linux

Tutorial on the use of aliases and binaries in Linux

黄舟
黄舟Original
2017-05-28 11:48:121372browse

This article mainly introduces you to the use of aliases and binaries in Linux. The introduction in the article is very detailed and has certain reference and learning value for everyone. Friends who need it can read it together. Take a look.

This article introduces the relevant content about the use of aliases and binaries in Linux. It is shared for your reference. Let’s take a look at the detailed introduction:

Binary

Generally, the term binary sounds mysterious, but when you understand it, it is actually not complicated. Data processing in computers is generally done in binary.

We usually count in base 10. For example, we usually count: 1, 2, 3, 4, 5, 6, 7, 8, 9. When we count to 10, the ones digit will change. becomes 0, and the tens digit becomes 1, because 9+1 needs to advance one to the tens digit. The decimal system means that the minimum digit of each digit of the number is 0 and the maximum is 9. In the same way, binary means that each digit of a number has a minimum of 0 and a maximum of 1. How is the decimal 2 represented in binary? 1+1 means adding one digit. For binary, 1+1=10, pay attention! The 10 here is not the decimal ten. Of course, the principle of binary subtraction is the same as that of decimal subtraction, 10-1=1. Because 0 is subtracted from 1, a bit must be borrowed to complete this operation. We all know that 0 and 1 have two states if they occupy one digit. If they have two digits, they are 00, 01, 10, 11, 4 states. Then the relationship between how many numbers it has and how many states it has is the power of 2 (2^n), for example:

2 raised to the 0th power is 1 (the 0th power of any number is 1, 0 The 0th power is meaningless)

2 raised to the 1st power is 2

2 raised to the 2nd power is 4

2 raised to the 3rd power is 8

2 raised to the 4th power is 16

2 raised to the 5th power is 32

2 raised to the 6th power is 64

2 raised to the 7th power is 128

2 to the 8th power is 256

2 to the 9th power is 512

2 to the 10th power is 1024

N represents the number of binary digits

2^N combinations

The maximum value is: 2^N-1.

Of course, if you really don’t know how to calculate, you can also use bc, a calculator under Linux. Can support hexadecimal conversion.

Linux alias

1. Definition

alias, English alias. It means just like our nickname, it is also a nickname for a command. Of course, there is also a tool called alias in the Linux system, which allows us to give a nickname, that is, an alias, to a frequently used command that is complex, has a long command length, so that if we want to enter those more complex or long commands in the future, When executing the command, you can use its alias to operate, and the same effect can be achieved.

For example: a file we often use, the cd /etc/sysconfig/network-scripts/ command is very long. If you have to enter such a long command every time you want to enter this file, is it a waste of time? Then we can define an alias for it, such as cdnet (of course you can choose this yourself and think it is easy to remember). Of course, we can first check whether the alias or command of "cdnet" is repeated. It is best not to use the alias we define with the system. The defined alias conflicts with some commands of the system. We can enter the name you want to set. Now I want to set up cdnet. You can enter cdnet and press Enter to see if there is such a command. If it prompts that the command cannot be found, then You can use cdnet to define this alias. Of course, we can also enter the command "alias" to see which aliases we have defined. The permanent aliases we add in the future will also be saved here. Now we are prompted that there is no cdnet command or alias. We can use this and use alias cdnet='cd /etc/sysconfig/network-scripts/' to create an alias for it. Then when you enter cdnet, enter cd /etc/ sysconfig/network-scripts/ is the exact same command. Isn’t this more convenient?

As shown in the picture:

2. Save

Of course it is possible now, but if you Exit, it will be gone. If you want to save it permanently, you need to write this command into the text. It is usually defined in your own home directory, because everyone's personal habits are different. The defined alias They are also different, so just create your own alias. Use ls -a to see a directory, the .bashrc directory. We need to enter the alias command we just created into the .bashrc directory. Here, enter the command nano .bashrc to enter this text, copy the newly created command in its order or enter it again, CTRL+o to save, and then exit CTRL+x. Generally, the alias you have just defined is not It will take effect immediately. Generally, it will take effect immediately by exiting directly. You can also use . to take effect immediately. Enter . .bashrc and it will take effect. Then you can use alias to view the newly created alias.

as the picture shows:

3. Cancel

And if you need to cancel an alias, or you don’t want the alias anymore, you can use unalias This command is used to delete. For example, if I don’t want the alias we just created, I can enter unalias and add the alias you want to delete, unalias cdnetThen make sure that the alias you just created is gone. You can check it by typing alias. There is also a command to delete all aliases. unalias -aThis command is Remove all aliases. Of course, this deletion is definitely only temporary deletion. If you exit, it will be restored. If you really want to delete it, just like when you just created it, enter the nano.bashrc directory and delete what you don’t want. Delete the alias directly, then save it, and it will be gone when you exit.

As shown in the picture:


##Use the command

alias View all aliases

unalias Delete alias

alias + name=the command you want to change the alias Modify alias

unalias -a Delete all aliases

nano                                                                                                                                                                                                    View the file name in the directory. Exit

bc Calculator

scale=3 Decimal point

ibase=10 Represents the base in which you input numbers

obase=2 Represents the base in which you output numbers System

Summary

The above is the detailed content of Tutorial on the use of aliases and binaries in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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