Features of bash in Linux

Source: Internet
Author: User
Tags aliases clear screen

The shell itself is an application, an interface program that completes interactive operations between the user and the operating system, providing simplified operations to the user.

Bourne Again shell, or bash, is the default shell program in a Linux system.


features of bash:     


The alias of a command (custom command)

Alias (inline command), defining or displaying aliases

using \command, the original command will be used instead of the custom command

Note: If the alias command does not have any options and parameters, it indicates that all alias settings that have been defined and are in effect are displayed


# alias alias= ' COMMAND [OPTION] ... [ARGUMENT] ... '

Unalias, remove a name from the alias definition list

-A, remove all alias definitions


Note: The function is immediately effective regardless of whether you use alias or Unalias, but the life cycle of these two commands is equal to the life cycle of the current shell, which is equivalent to shutting down bash once the login is logged off. Aliases that are defined with the alias command, or aliases that are deleted using the Unalias command, are immediately invalidated. Each user has a private bash file in the user's home directory, with a file name of. BASHRC, modified to restart the Bash program or the source command or "." will take effect,


Second, bash's shortcut keys:

C: Represents the CTRL key

M: Represents the ALT key

E: Represents the ESC key

DEL: Represents the BACKSPACE key

Common:

C-l: Clear Screen

C-A: Jumps the cursor to the beginning of the line

C-E: Jumps the cursor to the end of the line

C-k: Delete the contents of the cursor to the end of the line

C-u: Delete content from the cursor position to the beginning of the line

C-C: End foreground process

M.: Referencing the last parameter in the previous command (not available in Xshell)

E,.: function with M-.


Iii. Command history:

The bash process saves the commands that the user has executed in their painting to make it easier for the user to repeat an action;

The command history consists of two aspects:

1. Commands that have been executed by the user

2. Path of the command that the user has executed


In bash there is a built-in variable with the value of the--path,path variable that is the collection of paths to the file where all the commands in the current system are located


How is the command executed by the shell?

Bash slices the contents of the command line according to white space characters, determines whether the content of the first slice is an internal or external command, and if it is an internal command, it runs directly, if it is an external command, find the path cache in the hash table, and if so, execute it directly, otherwise you will need to find a file containing the corresponding name in path


Use the hash command to view the path of a remembered command file

-R, empty hash table


Use the history command to view command-line arguments for remembered commands;

-C, emptying the history buffer's command history

-D OFFSET, delete the specified line command


Commands for reusing historical buffers

! OFFSET, directly calling the corresponding row in the history command

! String, the last command beginning with string

!? String that contains the last command of string

!-number, the order of the countdown number.


C-r, finding commands

!$, the last parameter of the last command is called in the history buffer

!^, the first parameter of the last command

!:number, a parameter that invokes the number position of the last command in the history buffer

! Sequence:number, the parameter of the number position of the command that invokes the SEQUENCE line


Built-in variables related to command history in bash

Histsize, the maximum number of entries that the history buffer can hold, the default is 1000

The maximum number of command history entries that can be saved in the Histfilesize,~/.bash_history file, by default 1000

Histtimeformat, when a command is logged in the command history buffer and the timestamp of the command execution is recorded simultaneously, the format of the date command can be used to represent the time record, and the default value is NULL

Histcontrol, which controls how the command history is recorded, when the following values are

Ignoredups, ignoring consecutive and identical commands, as default values

Ignorespace, ignoring commands that start with whitespace characters

Ignoreboth, neither of these will be recorded.


Iv. Command Completion

1. Complete completion of the command string

Refer to the path in the path variable to complete the Command (Tab key). If the given string is unique within the path of the path variable, the command is directly complete, and if the given string does not have a unique path in the path variable, bash gives a hint (two tab key)

2. Completion of the string corresponding to the argument in the command

Complete completion based on the given path


V. Command line expansion

1.~,bash will automatically expand it to the home directory of the currently logged-in user

~string,bash automatically expands it to a home directory with a STRING user name


~+, call Bash's built-in variable "PWD" value

~-, call the value of Bash's built-in variable "OLDPWD"


2.{},

In ' {} ', you can populate a list populated with a "," Delimited path, and bash expands it into a separate command

1.txt{,.bak} = = 1.txt 1.txt.bak


Vi. execution results of the command

There are two types of command execution results in bash

1. Output of execution command


Command Reference or command substitution

"or $ (), the output of the reference command


2. Executing the status return value of a command

Indicates whether a previous command was executed successfully

Bash uses $? Variable to hold its contents in the range 0 to 255, where 0 indicates that the command executed successfully and 1-255 indicates that the command failed to execute

1,2,127 is a state return value for bash built-in command execution failed

1 Usually indicates some minor problems

2 indicates a serious problem

127 Indicates a problem with the command itself

Other digital users can customize error messages


Seven, reference function

Strong reference ", when bash is processing, the contents of the reference are all treated as ordinary characters, except for the single quotation mark itself

Weak reference "", some special characters will still retain special meanings, such as $, \, ""


Eight, Escape function

\,bash defines an escape character that can be escaped only after a word

\command, cancels the defined command alias, uses the original function


Nine, globbing--file name wildcard character, referred to as Glob

*, matches any character or string of any length, in some particular position. Characters do not match

?, matches any single character, in some special position. Characters do not match

[], matches any single character within the specified range and must match only one character

To specify a range of methods:

1. Enumeration method, listing all valid characters

2. Scope designation,

[0-9], representing all single decimal digits

[A-z],a,a,b,b,..., Y,y,z

[A-z],a,b,b,c,..., Y,z,z

3.bash built-in character set

[: Lower:], all lowercase letters

[: Upper:], all caps

[: Alpha:], all letters

[:d Igit:], all one digit

[: Alnum:], all alphanumeric

[:p UNCT:], all the symbols

[: Space:], representing white space characters, including spaces and tabs

4 . Reverse matching ^

Example: #ls a[^[:d ight:] "??


Ten, Pipeline

|, usually used to connect multiple commands, the command output preceding the pipe symbol as a parameter of the latter command


WC, the number of bytes, lines, and words of the statistic file or string

-C, show only the number of bytes in the file

-M to show only the number of valid characters in the file

-L, show only the number of rows in the file

-W to show only the number of words in the file



Xi. Input/Output redirection

When using a computer, the body that implements a function is a program

program = instruction + data

The data is critical


Entities that can complete input and output functions in a Linux system: file

Devices that can be used for input: Files

Keyboard equipment, file system of the regular files, network card equipment, sound card equipment, disk equipment, etc.;

Devices that can be used for output: Files

Monitor, regular file in file system, network card device, sound card device, disk device


The way to use a file in memory is to define a file descriptor that corresponds to a file

0, data flow for standard input, keyboard input

1, which represents the standard output, to the output data stream of the monitor

2, indicates a standard error, error data stream to the monitor


Input-output redirection (IO redirection): IO operations with non-standard device files

Input redirect

< Most of the time can be omitted


Output redirection

Overwrite output redirect

~]# set-c to prevent external overwrite of the source file switch, you can use ">|" The symbol finishes overwriting the redirected output without worrying about whether to turn on this switch

~]# Set +c off prevents overwriting of source file switches


>>, append output redirect


Error redirection

2>

2>>


Merging standard output and redirection of standard errors

1.COMMAND {>|>>}/path/to/somefile 2>&1

2.&>, &>>


Special device files

/dev/null bit Barrels

/dev/zero bubble machine, Spit 0 machine


Special symbols in Bash

<<, here document, end tag

<<<, here string, end tag


Features of bash in Linux

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.