Some features of the Linux bash

Source: Internet
Author: User

Features of the 1.bash

Shell programming in Linux is a common task, and it is necessary to familiarize yourself with the features of bash.

Yesterday spent a day, on the characteristics of the Bash learning Summary, found that the past self, on the Linux bash features little knowledge, a lot of harvest.


2.BASH support for command line editing

All along, with the command line of Linux, only know clear clear screen, with the backspace bar to delete. In fact, Bash supports the command line for efficient, fast editing. Some of the commonly used, summarized as follows:

Serial number Command shortcut keys Description
1 CTRL + A To jump to the beginning of a command
2 Ctrl+e To skip to the end of the command line
3 Ctrl+u Clears the character from the beginning of the cursor to the beginning of the line
4 Ctrl+k Clears the character from the beginning of the cursor to the end of the line
5 Ctrl+d The next character that clears the cursor
6 Ctrl+l Equivalent to clear


3.BASH Support Command Line history

It's really about the use of history.

Tips on how to use history:

Serial number Skills Description
1 ! Number Exactly which command to execute. There is also a!-number usage (the number here indicates the first few commands from the countdown, not commonly used)
2 ! Str Match from the countdown to find the first command to start with STR
3 !! Executes the last command. It might be easier to use the up and down arrows, but what if we want to do it in a shell script?
4 !$

A quick reference is made to the last parameter of the previous command.

This is useful because it is often done by looking at a file and then editing it, and if you use this technique, you can avoid repeating the input. There is, of course, a much faster way of esc+.


4.BASH Full complement support

The techniques we use often, such as when we knock on a part of a command, or part of a path, can be done quickly using this technique.

Mechanism of command completion: Search by PATH environment variable

Mechanism of PATH completion: path matching


Sometimes, if we press the TAB key 2 times, we will list all the matches, if too many, will prompt.


5.BASH Support Command aliases

Under Windows DOS, the Clear command is CLS, and you can define aliases under Linux.

[email protected] test]# alias Cls=clear[[email protected] test]# aliasalias cls= ' Clear ' Alias cp= ' cp-i ' Alias l.= ' ls-d. *--color=tty ' Alias ll= ' Ls-l--color=tty ' Alias ls= ' ls--color=tty ' alias mv= ' mv-i ' Alias rm= ' rm-i ' Alias Which= ' Alias | /usr/bin/which--tty-only--read-alias--show-dot--show-tilde ' [[email protected] test]#

To revoke an alias, unalias the CLS directly.

It is important to note that:

Alias is defined by the alias command, which is valid at the current shell, even if you log in with the same ID.

And the command defines the alias, which fails after the restart.


6.BASH Support Command Replacement

What is command substitution, that is, a subcommand in a command is replaced with the result of a quilt command.

This is very important.

Look at an example:

[[email protected] test]# echo ' The Dir is $ (pwd) ' The Dir was $ (pwd) [[email protected] test]# echo "The Dir is $ (pwd)" The D IR is/root/test[[email protected] test]# echo "The dir is ' pwd '" The dir is/root/test

Important manifestations of command substitution: $ (), "", ""

Add: The types of quotes supported by bash

Single quotation marks Weak references, that is, no substitution is made, plainly, what you see is what
Double quotes A strong reference, the replacement operation is performed.
Anti-Quote ' Command ' equals $ (command)


7.BASH Support file name wildcard

Refer to my blog: http://zhangfengzhe.blog.51cto.com/8855103/1409363















This article is from the "I want to surpass myself" blog, please be sure to keep this source http://zhangfengzhe.blog.51cto.com/8855103/1409381

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.