"Linxu Learning 004" Bash Shell related

Source: Internet
Author: User
Tags character classes clear screen glob

First, bash

1.bash is also a program, when is the program called?

User login, using the SU command to switch users, directly execute the BASH command will open a new bash, this shell called the child shell, the child shell can not be the same as the parent shell type, for example, the child shell can be Cshell, can be Kshell, That is, the type of the child shell is arbitrary.

2. How to view the current shell type

Echo $SHELL

3. How to view bash's specific usage

Mans Bash

More detailed information:http://pubs.opengroup.org/onlinepubs/9699919799/

Second, command-line editing in the bash environment

1. Cursor Jump

CTRL + A: Cursor jumps to the beginning of the command

Ctrl+e: Cursor jumps to command line tail

Ctrl+d: Delete the current cursor character

Ctrl+u: Deletes all characters from the current cursor to the beginning of the line

Ctrl+k: Deletes all characters from the current cursor to the end of the line

2. Clear Screen method

Use ctrl+l shortcut keys or use commands

Clear

3. Command completion and path completion

The use of the TAB key to achieve command completion or path completion, but the implementation of the principle is not the same: command completion is in the PATH environment variable to find the corresponding command, but the path is complete in the beginning of the path to search.

Iii. Command History-related

1. How to view command history

History

2.history related

(1). History is an internal command (Type command view) that needs to be viewed with help and cannot be viewed with man.

(2). Use

Echo $HISSIZE

View the number of history records that can be cached. The default is 1000 bars.

(3). History command Options

Histroy-           C            #清空历史记录-           D #删除第500条记录-           D     #删除第500条记录到之后的十条记录之间的所有记录-           w            # Writing to the configuration file ~/.bash_history

(4). If the user exits normally, the history will be saved to the ~/.bash_history, the next login can continue to use, otherwise not saved; You can use History-w to manually save the current history to the configuration file ~/.bash_history

3. Execute a command from a history record

!n: Execute nth command

!-n: Execute the countdown to the nth command

!! : Executes a recent command

!string: Executes the last command starting with string

!$: Referring to the last parameter used by the latter command, you can use ALT +. Shortcut keys or press the ESC key to press and hold.

Iv. command Aliases

Using aliases can make it more efficient for users to type commands, and the purpose of giving them aliases is to "simplify" and replace complex and frequently used commands with a simple command.

1. View all aliases

Alias

2. Aliases

Alias Cls=clear

3. Unbind aliases

Unalias CLS

4. How to invoke the command itself instead of the alias

You can use \command.

V. Command Reference

The purpose of a command reference is to use the result of one command as the execution parameter of another command.

The way the command is referenced is $ () or using '

1. Show current directory (custom)

[Email protected]:~$ echo "This is $ (pwd) dir"    #这里必须使用双引号this is/home/kdyzm dir

2. Displays a list of file types for all files in the current folder

[Email protected]:~$ file $ (LS) a.txt:            emptyb.txt:            ASCII textdatastructure:    directorydesktop:          Directorydocuments:        directorydownloads:        directoryexamples.desktop:utf-8 Unicode textmusic:            Directorypictures:         directoryprogramfiles:     directorypublic:           directorysoftware:         Directorytemplates:        directoryvideos:           Directory

3. Dynamically create a file with the current time name

[Email protected]:~$ Touch file-$ (date + '%y-%m-%d_%h:%m:%s '). txt "[email protected]:~$ ll file*-rw-rw-r--1 kdyzm kdyzm 0  January 17:27 File-2016-01-28_17:27:45.txt
VI. file name wildcard Glob

1. Wildcard characters

*: matches any character of any length

? : matches any character with a length of 1

[]: matches any single character within the established range

[^]: does not match any single character in the specified range

2. View special wildcard symbols in glob with the man 7 glob command

[: Alnum:]  [: Alpha:]  [: Blank:]  [: Cntrl:] [:d igit:]  [: Graph:]  [: Lower:]  [:p rint:] [:p UNCT:]  [: Space:]  [: Upper:]  [: Xdigit:]    So that one  can say "[[: Lower:]]" instead of "[A-Z]", and has thingswork in Denmark, too, where there is three Letters  past  ' z '  in  Thealphabet.  These character classes is defined by the Lc_ctype categoryin the current locale.

3. Example

(1). Displays all letters beginning with the letter ending with all the blanks in the middle of the file:

LS [[: Alpha:]]*[[:space:]]*[[:alpha:]]

(2). Displays all files that begin with any character, end with a number, with no spaces in the middle

The wrong wording:

LS *[^[:space:]]*[[:d igit:]]

In fact, the problem cannot be solved by using wildcards, and the problem needs to be resolved with regular expressions, and the archive is continued.




This article is from the "stolen A Plum blog" blog, please be sure to keep this source http://kdyzm.blog.51cto.com/8316029/1739606

"Linxu Learning 004" Bash Shell related

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.