As an iOS developer, it is often necessary to use command lines. Sometimes a long string of commands is really annoying, especially some common commands. We need to repeat the keyboard over and over again. However, laruence is generally not so stupid, because there is alias, through alias we can give frequently used variables an alias.
For example, in terminal:
Alias LA = "ls-"
Then, repeat:
La
What have you found? Now we can use La to replace LS-A. For example, we can also:
Alias GS = "Git status"
In this way, you can replace the git status Command with Gs.
Is it especially convenient?
Now restart terminal and try the alias command, Oh, oops! The commands just passed by alias are all gone. Are we never using terminal? Obviously, these alias can be permanently saved. Follow me below:
Open terminal, Cd ~ Switch to the current user's home directory;
Ls-A: Check all the files and see if there is a file named. bash_profile. If not, create one:
1) Enter Vim. bash_profile
2) Press ESC to enter Normal Mode
3) Press ":" To Enter command mode, enter WQ, and press Enter.
Once again, you will find that the file has been created.
Of course, you can also use touch. bash_profile to create this file, but we will use Vim to edit this file later. So here we will use Vim to create this file.
If this file already exists, proceed to the next step;
Run the "Vim. bash_profile" command to open. bash_profile,
Then press I to enter the input mode and enter the alias command, for example:
Alias LA = "ls-"
Alias LL = "ls-l"
Alias CLS = "clear"
Alias c = "clear"
Alias P = "PWD"
Alias Pb = "Ping www.baidu.com"
Alias IP = "ifconfig"
Alias HH = "CD ~ "
Alias Cr = "CD /"
Alias dd = "CD ~ /Desktop"
Press ESC to enter normal mode, press: To Enter command mode, enter WQ, and press Enter.
In this way, we will save these alias commands permanently. Of course, to make these commands take effect, we need to do another thing to run "Source ~ /. Bash_profile ". Try again and you will find that it has taken effect. Of course, restarting terminal will also take effect, because this file will be automatically run every time the terminal launch is restarted.
Principle:
Every time terminal is started, it will be automatically executed ~ /. Bash_profile automatically runs the command.
Therefore, we can extract these commands and write them into an independent file ~ /. Alias_profile, and then in ~ /. Just write a sentence in bash_profile:
#. Bash_profile
Source ~ /. Alias_profile
In this way, we can also use git to manage this ~ /. Alias_profile file, so that you can freely synchronize between multiple computers.