Basic usage of the shell

Source: Internet
Author: User
Tags clear screen

SHELL:
An interface program that completes the interactive operation between the user and the operating system, providing the user with simplified operation;

In the middle of the 70 's, Bell Lab, Bourne;bourne Shell, abbreviated Sh;bill JOY:C Shell, referred to as CSH;TCSH for its derivative version; David korn:korn Shell, abbreviated Ksh;gnu:bourne Again Shell, referred to as the default shell program in the Bash;linux system; ZSH: The final shell is very powerful, all the security shells in the current system can be supported:/etc/shells Note: 1. In addition to/sbin/nologin,    Other shells can be used for testing; 2. When replacing the shell, it is best to replace the other shell in bash, and if you have replaced the other shell, use the exit command to return to bash, and then toggle; Bash features: First, command alias-(custom command)        Alias alias-defines or displays aliases.        Format: Alias [-P] [Name [= value] ...]        Note: If the alias command does not have any options and parameters, it shows all alias settings that have been defined and are in effect; Unalias Unalias-Removes each "name" from the alias definition list.    Format: Unalias [-A] name [name ...] Note: The function of the alias command or the Unalias command takes effect immediately; the lifetime of this second command is only the life of the current shell; Once you log off, it's the equivalent of shutting down bash, Aliases defined with the alias command or alias operations deleted using the Unalias command are immediately invalidated; For each user, there is a private bash profile, a hidden file in the user's home directory, with the file name ". BASHRC",                Its main function is to save the definition of the alias of the command; Note: After you edit and save the command alias in this file, it does not take effect immediately in the currently running bash and requires reloading the file for the configuration to take effect, the following two actions are possible:                1. Restart bash: Log in again after logging out, 2. Execute the command defined in the file: using the source command, or. command; source/. Source-Executes a file in the current shellThe command:                -Executes a command in a file in the current shell. Format: source/. filename [parameter] Two, bash shortcut key: C:ctrl key M:alt key E:esc key Del:backspace key c-l: Clear screen, equivalent to clear command; C-A: Jumps the cursor to the beginning of the command line edit mode; c-e : Jumps the cursor to the end of the line in the command line edit mode; C-k: Deletes the contents of the command line edit mode at the end of the line; C-u: Removes the command line edit mode cursor position to the beginning of the content; C-c: End foreground process; M.: References the last parameter in the previous command;            Not available in the shell) E,.: function with M. Iii.. Command history: The bash process saves commands that users in their sessions have executed to facilitate repeated execution of a command operation; the command history consists of two aspects: 1. The user has executed the command;        2. The 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 set of the path to the file where all the commands in the current system are located; How are commands executed by the shell? Bash slices the contents of the command line according to whitespace characters, analyzing the contents of the first slice: 1. Determine whether the contents of the first slice are internal or external, and if it is an internal command, run directly; First find the hash table in the path cache, if any, then directly execute; otherwise, by looking up the path variable contains the paths, whether there is a corresponding name of the file; Use the hash command to see the path of the remembered command file;-r: Empty the hash table                    ; Use the history command to view command-line arguments for a remembered command; historical-Displays or manipulates a list of histories.                        Format: History [-c] [-D offset] [n] or HISTORY-ANRW [filename] or history-ps parameter [parameter ...] OftenUse option:-C: Clears the history of the command history buffer;-D OFFSET: Deletes the specified history command entry; Repeat Calendar The command in the history buffer:! Number: Repeats the command numbered "numbers" in the history buffer;! String: Repeats the last command executed in the history buffer that begins with "STRING";!? String: Repeats the last executed command that contains "STRING" in the history buffer;!-number: Repeats the countdown number in the historical buffer; use up, down arr                    OW can invoke the command from the historical buffer, execute it after the carriage return, C-r: Implement the search in the history buffer, execute after carriage return,!$: invokes the last parameter of the last command in the history buffer; !^: A parameter that invokes the first position of the last command in the history buffer;!:number: Invokes the "number" positional parameter of the last command in the history buffer! Sequence:number: The "number" positional parameter of the "SEQUENCE" command is called in the history buffer in bash built-in variables related to the command history: Histsize: In the history buffer                    The maximum number of entries that can be saved in the history of a command, the default value is 1000, the maximum number of entries in the Histfilesize:~/.bash_history file that can be saved in the command history; Histtimeformat: When a History command is recorded in the command history buffer, the timestamp token of the execution of the command is also recorded; the format of the date command can be used to represent the time record; The default value is null; Histcontrol: Control command history Recording method:                       Ignoredups: Consecutive and identical commands are not recorded to the historical buffer; this is the default; Ignorespace: Commands that begin with a blank character are not recorded in the history buffer; Ignoreboth: Neither of the above is recorded in the historical buffer; Iv. Command Completion-(use of the TAB key) includes two aspects: 1. The completion of the command string; reference P        The path in the ATH variable that complements the command: if the given string is unique within the PATH variable, the command is directly complete, and if the given string is not unique in the path corresponding to a path variable, bash gives a hint; 2. The string complement of the arguments in the command, and the completion according to the given path: if the given string is unique in the given path, the parameters are directly complement; Not unique in the path, Bash gives a hint; five, command line expansion (A+B+C) (d+e+f) =ad+ae+af+bd+be+bf+cd+ce+cf 1.~ Expand: ~:bash will automatically expand it as the home directory of the currently logged-in user; ~s Tring:bash automatically expands it to a user's home directory with a "STRING" user name; ~+: Call Bash's built-in variable "PWD" value; ~-: Call Bash's built-in variable "oldpwd" value; 2. {} Expand: In ' {} ', you can populate a list of paths separated by "," and bash expands it into multiple independent paths; Example: ~]# Mkdir-pv/china/{hb,hn,jl,hlj,ln}/{lin K,LINKA,LINKB}/CLASS18 ~]# CP 1.txt{,.bak} 1.txt{,.bak} = = 1.txt 1.txt.bak vi. command execution results in bash, command         There are two kinds of execution results: 1. Output of the execution command:   The normal output result of command execution according to the user's requirement; command reference or command substitution: ' equivalent to $ () ': Inverted single quotation mark, back quote; Example: Create a file with the file name test-system time; ~]# Touch test-' Date +%f-%h-%m-%s ' 2. Executes the status return value of the command: whether the previous command succeeded                Row-related return content; Bash uses a special built-in variable to save its contents: $?                        $? Actually holds a numeric value, the range of values: 0-255 Where: 0: Indicates that the command executed successfully; 1-255: Indicates that the command execution failed;                            1,2,127:bash the status return value of the built-in command execution failed; 1: small problem; 2: Indicates a serious problem;        127: Indicates a problem with the command itself; the remaining number (3-126,128-255): The user can customize the return value of the failed state; Reference function: ": Strong reference  All the quoted contents of the quotation mark, bash is treated as ordinary characters, even if it is a bash defined with special functions and function characters, but the single quotation mark itself; "": Weak references are quoted in double quotes, and some special characters still retain their special meanings, such as: $,     \, ""; eight, Escape function: \:bash defines the escape character; In most cases, "/" can only be escaped after a word; \command: cancels the defined command alias and uses the function of the command itself; nine, globbing--filename wildcard, referred to as glob; *: matches any character or string of any length, ("." In some special places) characters do not match;): matches any single character; ("." In some special places) character does not match;) []: match refers toAny single character within the specified range must match and match only one character; method of specifying a range: 1. Enumeration method: List all valid characters; 2. Range designation: [0-9]: denotes all individual decimal digits                ; [A-z]:a,a,b,b,c,c,..., x,x,y,y,z [a-z]:a,b,b,c,c,..., x,x,y,y,z,z 3.bash built-in character set: [: Lower:]: All lowercase letters [: Upper:]: All caps [: Alpha:]: All letters, including case; [:d IGI T:]: all single decimal digits; [: Alnum:]: All letters and decimal digits; [:p UNCT:]: all symbols; [: space:]: denotes whitespace characters, including spaces  and tabs; 4. Reverse matching: ^ Example: #ls a[^[:d igit:] "?? The second character representing the file name cannot be a decimal number; Note: in parentheses, "^" indicates the use of "*" when the character set is reversed, because the "*" wildcard range may cause the reverse match to fail; This kind of failure is because Bash's globbing is matched in greedy mode;    Ten, Pipeline |  Pipelines are usually used to connect multiple commands, and the output of the command that precedes the pipe symbol is passed through the pipeline to the command following the pipe symbol, so that the following command uses the output of the preceding command as a parameter; Wc:wc-print newline, Word, and byte Counts for each file format: WC [OPTION] ...            [FILE] ... Common options:-C,--bytes: Displays only the number of bytes in the file;-M,--chars: Displays only the number of valid characters in the file;-L,--lines: Displays only the number of lines of the file;-W,--words: Displays only the number of words in the file; Note: 1. In general, any command that is connected to a pipe should be able to execute after successful execution    Complete the output of the command result, otherwise the pipeline is meaningless; 2. Pipelines are not omnipotent, some occasions can not use the pipeline; xi. input and output redirection when using a computer, the body that implements a function is a program!    program = instruction + data data is critical! Files, io--input/output entities that are capable of completing input and output functions in a Linux system: files, devices that can be used for input: File keyboard devices, general files in file systems, network card devices, sound card devices, disk devices, etc. devices that can be used for output: text Device, general files in the file system, network card devices, sound card devices, disk devices, and so on; the use of files in memory is defined by a file descriptor, a file descriptor corresponding to a file, 0: input data stream for standard input, stdin, from the keyboard; 1            : Indicates standard output, stdout, output data stream to monitor, 2: Error data stream for standard error, stderr, to monitor, input/output redirection (IO redirection) IO operation with non-standard device file; input redirection: < output redirect:: Overwrite output redirect, ~]# Set-c//Turn on prevent accidental overwrite of source file switch, you can use ">|"            The symbol finishes overwriting the redirected output without caring whether to turn on this switch; ~]# set +c//off Prevent accidental overwrite of source file switch >>: Append output redirection; Error redirection: 2&gt: Overwrite error redirect, 2>>: Append error redirect, merge standard output and redirect to standard error: 1.COMMAND {>|>>}/path/to/som Efile 2>&1 2.&>, &>> Special Equipment Files:/dev/null:blackhole,bitbucket (bit barrels)/dev/zero: Bubble machine, spit 0 machine; Other special symbols in bash: <<:here document, here documentation, end tag;

Basic usage of the shell

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.