Shell base script execution, command aliases and shortcut keys, etc.

Source: Internet
Author: User
Tags clear screen save file

How scripts are executed

For example, we wrote a script under/root/, named Hello.sh. So how does the call execute it? There are two ways to do this:

(1) Directly through bash, as follows:

Bash hello.sh

Note: Execute scripts with bash and do not need to give execute permissions. But this does not conform to the habit, generally not recommended to use.

(2) Give permission first, then call directly:

chmod 755 hello.sh

/root/hello.sh

Note: The first sentence above is to give the script permission, the second sentence is to execute the command. This type of execution is generally recommended.

===============================================================================================================

Alias

Sometimes the command is long in the shell, and when we want to overwrite the original command with a new command, we use the command alias. The following is a systematic talk about

This is some knowledge about aliases.

(1) Viewing aliases present in the system

It's simple, a command is done: alias

For example, the command aliases in my system have the following:

For example, LL is an alias for the command "Ls-l--color=auto."

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++

(2) Edit your own aliases

Also very simple, the syntax is:

Alias Command aliases = ' Original command name '

Note: This is a single quotation mark. and the General Command alias is not the same as the original command name. But if you want to overwrite the original command, you can order the same.

For example, I would like to add a new command alias, so that when you enter the command VI, you actually perform the VIM command. You can do the following:

By the above, when you use alias to see the command alias that exists in the system, more VI. Later we call the command VI, the actual implementation is the VIM command.

However, note that aliases generated using alias are only temporary, which means that the system exits and then enters is not valid.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

So how do you create a permanent alias?

In fact, it is very simple, such as our current position in the/root/, then only need to edit the file/ROOT/.BASHRC.

First, let's take a look at this file, using the Vim/root/.bash.rc command, as follows:

The above is all the command aliases that exist in the current system, and now we just need to add our own command aliases. such as the following:

As you can see, I added the vi= ' vim ' to this command alias.

The SOURCE/ROOT/.BASHRC command can then be generated immediately, and if you do not want to take effect immediately, the restart will take effect. In short, this

The way to add aliases is permanent.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

(3) Deleting aliases

Deleting aliases is also simple, as follows:

Unalias command Aliases

Note: This deletion method is also temporary, that is, the alias in the current system is invalid. This alias is still valid if restarted. The reason is

The aliases in/ROOT/.BASHRC are not really deleted (if you edit this alias in this file). You can run alias to see and find

Aliases have been deleted, but run VIM/ROOT/.BASHRC found. Aliases in BASHRC are also present. So only the aliases in the. BASHRC are removed.

To actually delete the alias (if you don't edit the alias in. bashrc)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

(4) Order in which the order takes effect

When the command is overwritten (that is, the alias is the same as the original command name), for example, in our example, vi= ' vim ' overwrites the system's original command VI, you must have doubts

Why not call the original command again? It's all the same name, obviously. This is actually the order in which the commands in Linux are enforced. The following describes the Linux

The order in which the commands are valid.

The order of precedence is as follows:

First-bit execution of commands executed with absolute or relative paths

Second cis-execute alias

Third-level execution command inside bash

The first command found in the directory lookup order defined by the $PATH environment variable is executed in the second position.

We found that the execution level of the alias is still very high, ha. Well, the knowledge about aliases is here.

===============================================================================================================

Shortcut keys

We remember the following common shortcut keys can be, there is nothing to say. As follows:

CTRL + C forces the current command to terminate

Ctrl+l Clear Screen

CTRL + A cursor moves to the beginning of the command

Ctrl+e cursor moves to the end of the command line

Ctrl+u deleted from the cursor position to the beginning of the line

CTRL + Z put commands into the background

Ctrl+r Search in the history command

===============================================================================================

Historical command

History [Options] [Historical command Save file]

Options:

-C Empty History command

-W writes the history command in the cache to the history command to save the file "~/.bash_history"

If you enter the command line only for history, you can see all the current historical commands (including the one you logged in and the current login)

If you enter only command history-c on the command line, all history commands that are currently logged in are deleted.

If you enter the command history-w, the current History command is written to the ~/.bash_history file.

Note:. bash_history This file will only save the history command that was previously logged in, and the current login will only leave the history command

Write this file. So using the option-W can be written immediately.

=======================================================================================================

Auto-complete

Automatic completion in the shell as long as you press the TAB key. If you press down without auto-completion, there are several ways to complete, you can press the TAB key, you will

Show a variety of complementary ways, so you can choose the right complement.

Shell base script execution, command aliases and shortcut keys, etc.

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.