The basic features of bash in operation and Maintenance Foundation--linux

Source: Internet
Author: User
Tags call shell clear screen

The basic features of bash are as follows:

First, the alias of the command--alias command

The alias used to define and display the command, UNALIAS to revoke the defined alias, but note the following:

The effect of 1.alias is limited to the lifetime of the current shell;

2. If you modify the. BASHRC configuration file, the saved alias will not take effect immediately and will only take effect after reloading the contents of the file.

3. In order to ensure that the alias is valid, both operations are usually done;

Ii. History of the order

The shell process saves previously executed commands from the user's session, and history is the shell's built-in command

1. Command syntax format:

History [-c] [-D OFFSET] [n]

HISTORY-ANRW [FILENAME]

History-ps value [value ...]

-C: Clears the command history;

-D offset (Offset Amount): Delete the specified command history,Offsetto be Historynumber of commands displayed

-R: Reads the command history from the file to the history list;

-W: Appends the commands in the history list to the history file;

History #: Displays the most recent # command;

  

Reusing commands in the command buffer

!#: Once again execute the # command in the history list;

!-#: Execution of the penultimate order;

! : To execute the last command once more;

! String: Executes the most recent command in the command history list that starts with a string;


part of the Reuse History command:

!$: Represents the last parameter in the last command;

ESC,. The last parameter in the last command;

ALT +. This usage can only be used on a real terminal;

!^: parameter of First position

!:num A parameter that represents the first NUM position in the last command;

! Sequence:num represents the NUM parameter of the first SE command;

! string:^|$|*| NUM;

2. History-related bash variables

The number of commands history that the Histsize:shell process can retain;

Histfile: A file that persists the history of the command, the default is. bash_history

Histfilesize: The number of storage history commands for the command history file;

Histcontrol: How to control command history

Ignoredups: Ignore duplicate commands;

Ignorespace: Ignores commands that begin with whitespace characters;

Ignoreboth: Both are effective at the same time;

Third, shortcut keys:

The key combination maps to a command that bash can recognize;

CTRL + A: Jump to the beginning of the command line

Ctrl+e: Jump to the end of the command line

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

Ctrl+k: Removes all characters from the cursor to the end of the line;

Ctrl+l: Clear screen, equivalent to clear


Iv. Command Completion mechanism:

The execution process of the% shell command:

1.SHELL will be based on the user type "enter" to determine the user's input end;

2.SHELL will collect the command information, according to the whitespace character segmentation: The first fragment is understood as the command field;

3. Determine whether the first field is an internal or external command: if it is an internal command, run directly, if it is an external command, through the path information indicated by the path variable, to find the relevant location, to determine if there is a file of the same name, if any, execute, otherwise error;

4. Determine whether the options and parameters are correct; %

Two aspects of understanding:

The string complement of the command itself && the completion of the parameters;


Use the TAB key to complete the command or path completion:

Note: If the given string is not uniquely identified, bash is not complete, and the TAB key again, Bash gives a reference list, and if there is too much content in the reference list, Bash asks if the list is displayed;


It can also be complete according to the parameter path provided, if the parameter does not have any hint string information, the default is to find from the working directory;

v. Shell command-line expansion (complex information that bash can identify with simple characters)


~

~ Bash will automatically expand it to the home directory of the currently logged-in user;

~str:bash will automatically expand it to a home directory with the username of STR;

~+: Call the value of the shell variable "PWD";

~-: Call Shell variable "oldpwd"


{}: In which a list of paths separated by "," can be populated, bash expands it into multiple independent paths;

For example: MkDir/{a,b}_{c,d} created four directories: A_c,a_d, B_c, B_d.


Vi. execution results of the command

1.bash output result by Status return value: Success: 0 failed: 1-255

0: Command execution succeeded; 1,2,127:bash built-in Status return value, 1 for small problem, 2 for serious problem, 127 for command itself, 3-126 and 128-255: User-defined status information;

2. The status return value is saved in Bash's special variable: $?

3. Execution result of the reference command: $ (command) or ' command '


There are two kinds of execution results for any one command:

One: The normal output result of the command;

Return content related to user requirements

Reference method:

": Inverted single quote-anti-quote;

$ (): standard command reference format;

Supplemental Command:

WC: Counts the number of rows, words, and bytes of a file;

-C: Show only the number of bytes

-L: Show only the number of rows

-W: Displays only the number of words;

Second: The execution state return value of the command;

The return content that is related to the success of the command execution is saved in a special variable in bash: $?;


Vii. Citation characteristics

": Strong references, all of which are quoted in quotation marks, bash treats them as ordinary characters, even if they have special functions and assignments, but the single quotation mark itself is an exception;

"": weak reference, the content quoted by double quotation marks, some special characters will still retain their special meaning, such as: $, \, "


Eight, Escape function:

The escape character defined by \:bash can only cause the subsequent character to lose its special meaning;


Nine, Globbing, the filename of the wildcard, referred to as glob;

Match pattern: metacharacters (a set of characters instead of one or more characters)

A special-purpose character that can be used to specify the occurrence mode of its leading character in the target object

*: matches any character of any length, including null characters

?: matches any single character

[]: matches any single character within the specified range

For example [ABC], [A-z], [A-z], [a-za-z], [A-z], [0-9], [a-z0-9]

Special format:

[[: Upper:]]: All uppercase letters

[[: Lower:]]: All lowercase letters

[[: Alpha:]]: All letters

[[:d Igit:]]: All numbers

[[: Alnum:]]: All letters and numbers

[[: Space:]]: all whitespace characters

[[:p UNCT:]]: All punctuation

[^]: matches any single character outside the specified range

X. input and output redirection;

The body that implements a function when using a computer is: program (= instruction + data;)

The data is the object of the instruction operation, in the Linux embodiment is the document;

A device that can be used for input is also a file;

such as keyboard equipment, file system of the regular files, network card sound card device;

Devices that can be used for output: Files

Monitor, file system general files, Nic sound card ...


Each of these programs has three forms of data flow:

a). Input data flow: The data stream for the program; the default input data stream is the keyboard;

b). Output data flow: The data stream that the program processes is presented to the user, and the end point of the default output data stream is the display;

c). Bad data flow: shows the data flow to the user of the results of problems that cannot be processed or handled by the program; the end point of the default error data stream is the display;


Input data streams implemented from the keyboard become standard inputs;

The output data stream to the monitor is called standard output;

Error data flow to the monitor is called standard error output, or standard error;


FileName Descriptor: File DESCRIPTOR,FD.

0: Standard input, stdin

1: Standard output, stdout

2: standard error, stderr



IO redirection: IO operations implemented with non-standard device files;


In simple terms,

Data flow input that is not done from a keyboard device can be called input redirection or redirect input;

Not the correct output of the data stream to the display device is called output redirection, or redirect output



Output redirection:

Overwrite output redirection

Set–c//Turn on the anti-false override switch, after which the switch can be used ">|" The symbol continues to overwrite the redirect;

Set +c//off error-proof coverage

>>: Append output redirection



Error redirection:

2>: Overwrite error redirect

2>>: Append error redirect


The basic features of bash in operation and Maintenance Foundation--linux

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.