Shell Basic Finishing

Source: Internet
Author: User
Tags aliases clear screen

the role of the shell is to convert a user-entered text command into an internal nuclear identification data instruction to the kernel for execution, and the kernel needs to be translated into binary to be executed by the CPU bottomthe user layer->shell-> calls the corresponding application->kernel-> hardware Layer----and the peripheral peripherals--pass to the kernal-> application->shell-> userthe shell is the underlying command interpreter, and the shell is the user interfaceThere are two kinds of syntax for the shell: Bourne and CThe Bourne family includes: sh, ksh, Bash, PSH, zshC family includes: CSH, tcsh (mainly for Unix)Bash is the standard shell for current Linux systemsEcho $SHELL can see where the shell corresponds: Bin/bashsupported shells under the/etc/shells filemultiple shells can be entered in a hierarchical call Output command:echo "Hello World" returns a command at the command lineecho-e "H\te\tl\nl\to"-e Specifies that the escape character is recognized, \ t tab \ n WrapOutput Color Printing:echo-e "\e[1;31m Hello World \e[0m"\e[1, and \e[0m is a fixed format that represents the turn color on and off color, if you do not close subsequent command line all is specified color, middle section specifies color and content30m black, 31m red, 32m Green, 33m yellow, 34m blue, 35m magenta, 36m cyan, 37m white The first shell script is written:build script: Vim hello.shInput:#!bin/bash# the first shell programecho-e "\e[1;34m Hello Shell \e[0m": Wq Save Scriptgive executable permission: chmod 755 hello.shexecution:./hello.sh (Common method)or call directly: Bash hello.sh Shello aliases are designed to simplify command executionalias View the default alias of the current shell, the system adds some common necessary parameters by defaultset aliases, such as: Alias ls= ' ls--color=never ' so that the default is to add the parameters of the alias, simplifying the command inputExample: Alias vi= ' vim 'aliases in order to facilitate user habitsalias set by the alias command is invalidated when the operating system is restartedde-alias settings without rebooting: Unalias vi= ' vim 'permanently modify, modify the environment variable that holds the alias: Vim ~/.BASHRCeffective immediately after saving: source ~/.BASHRC    command execution priority: absolute or relative path execution command > alias > Bash Internal Command > The Order of the environment variable definition the first command to findShell Common shortcut keys:Force Abort Program CTRL + CClear Screen Ctrl+lDelete the cursor to the beginning of the command: Ctrl+ucursor is positioned to the beginning of the line: Ctrl + acursor navigates to end of line: Ctrl+ePut the front desk command in the background: Ctrl + ZSearch in the history command: CTRL+R Press the shortcut key, enter the command, and follow the search results to perform View all historical input commands: HistoryClear History Input command: History-cHistorical Command storage location: ~/.bash_historyThe file contains fewer commands than history, because the file is not updated when the user exitsSynchronize current command to ~/.bash_history:history-w nowset up do not delete historical commands casually, facilitate troubleshooting and check intrusionThe history command holds up to 1000 records, and you can edit/etc/profile to modify the Histsize property values. Up and down arrows perform history commandsThe history query number uses!n to perform the order of the number n command,!! Execute the previous command! The string repeats the last command at the beginning of the string Tab key to execute command and directory and file completion, complete data dependent on environment variables and operation Path   Standard Input:/dev/stdin file Descriptor: 0 Device: KeyboardStandard output:/dev/stdout file Descriptor: 1 Device: Monitorstandard error Output:/dev/stderr file Descriptor: 2 Device: Monitorare actually soft links, linked to the real-time hardware memory directory/proc  Standard output redirection: commands > Files overwrite correct command input to file, command >> file content appendstandard Error Output redirection: command 2> file, command 2>> file function as above, note 2 do not add space after correct and error output to file simultaneously: command > File 2>&1 or command >> file 2>&1or use: Commands &> files and commands &>> filesseparate file write: command >> file 1 2>> file 2 put the correct result in file 1, error result put to file 2 Command &>/dev/null command does not output any kind of execution results,/dev/null equivalent to the black hole under Linux, the output will not exist input REDIRECT WCthen enter text to end by Ctrl+dthe shell returns the count of rows, the number of words, and the number of charactersWc-c only count characters including spaces and line breaksWc-w only count the number of wordswc-l count rows only WC < Success.log or WC server.log data in a statistical fileCommand < File submit the contents of the document to the command executionWC << DDDInput text input to DDD after input is over, return statistics, DDD is the custom end identifier sequential execution of multiple commands:Command 1, Command 2 Multiple command order execution, no logical relationship between commandsCommand 1 && command 2 logic is executed when command 1 executes the correct command 2Command 1 | | command 2 logic or when command 1 is executed incorrectly, command 2 executes; command 1 does not execute when command 2 is executed correctly To count the execution time of an action script: date, command, dateData +%s Displays the current UNIX timestamp for easy statisticsreturn simple correct or error prompt: Command && echo "Yes" | | echo "NO" pipe Break: Command 1 | command 2the output of command 1 is the operand of command 2, and if command 1 executes an error, command 2 will not be executed.For example: Ls-l/etc/| More realize split screen displayCommand 2 must be able to strictly operate the output of command 1, can not be used casuallyFor example: Netstat-an | grep established | WC-L processing the specified data in the command results, statistics some results, etc.  Wildcard: * Match one or more? Match 1 [ABC] match ABC 1 [a-z] [0-9] match any one in a-Z and 0-9 in any one of the numbers [^0-9] matches a character that is not a number Special Symbols:For example: aa=123 #定义变量echo $AA So you can output variable valuesecho ' $aa ' output is $AA this stringecho "$aa" output is the variable value of $AA"All special symbols in single quotes are output in double quotes, $ ' \ have special meaningsFor example: aa= ' ls ' is the result of the LS execution stored in the variable AA, using the anti-quote can execute system commandaa=$ (LS) is consistent with the above action, it is recommended to use\$ is purely representative of $ this character, for example: Echo \ $aa Output $AA This string, and single quote function consistent#代表注释

Shell Basic Finishing

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.