Linux starts from the shell

Source: Internet
Author: User
Tags egrep

1:shell Basics:

Learning about Linux is known to have a shell concept, the shell is between the user and kernel, the user's operation or instruction through the shell interpretation passed to Kernel,kernel can understand and perform the corresponding operation, why should we learn the shell? Because the shell is important, and someone has said that everything on Linux can be manipulated using the command line, what is the command line you are using? The shell not only includes command line Operation command, also includes the GUI software, and in my opinion, as long as you are dry Linux related, will require to write a certain script, of course, you say I can use Python, I can only hehe.

View the shell and the shell that the system can use: We can view the/etc/shells file, the general operating system is the default is/bin/bash, you can directly echo $SHELL, since the use of bash that means it must have merit Bai, What is the advantage of it: 1:history,2:tab,3:alias,4:shell Script,5:jobs,bg,fg,&,6:wildcard. So many of our previous Linux conmands are shell-built, of course not, we can look at the type of command by type, it could be alias, possibly an external command, and then it could be from the shell built-in, We can view it through type, such as Type–a ls.

Variable, is the amount can be changed, is to use a string of characters instead of some settings or data, we are more common path, SHELL, home, and so on, variable display and settings: Echo,unset, the former output, the latter cancellation, another point to pay attention to is the use of export, Set the variable to an environment variable, the variable is generally used in uppercase letters, and a child process, after we use bash, it is equivalent to open a new process, the parent process's variables can not be used in the child process, unless you use export settings, single and double quotes, env view environment variables, Set view all variables, $?, language variables Locale,read (-p), Array,declare, delete of variables, replace, alias,history.

Command execution: 1: Execute command with relative or absolute path 2: via Alias,3:bash built-in command 4:/etc/motd,bash environment profile via $path,bash Login Welcome interface, login shell, get bash with full login process, Non-login shell, which is typically a graphical interface login, does not require a full login when bash is obtained. Login shell, each user login to bash will execute/etc/profile, then/ETC/INPUTRC, and/etc/profile.d/*.sh will be executed, here lang.sh will call/etc/sysconfig /i18n, then to the user ~/.BASH_PROFILEÀ~/.BASHRC->/ETC/BASHRC, if it is non-login the words will use ~/.BASHRC directly.

wildcard characters and special symbols (it is important to strictly distinguish between wildcards and regular expressions without a full edge). Data flow redirection <,<< >,>>, 2>,2>>; command execution based on;&& | |,

Ls/tmp/sun && echo "Exist" | | echo "not exist", the pipe command will handle the standard output, ignore the error output, in addition, he used the output as standard input, keyword search grep, column-based processing Cut:last | grep "Root" | Cut–d "" –f 1

Text statistics WC, text sort sort, text compare Diff:last | Cut–d "" –f 1 | sore | uniq–c;tee bidirectional redirection ls/| Tee Sun.txt | More, Character conversion command: Tr,col,join,paste,expand. Cut file split.

2: Regular expression:

Through the arrangement of some special characters, to find, replace, delete one or more lines of text string, is a string processing basis, a notation, as long as the tool program supports this notation, then the tool can be used as a regular expression string processing, re divided into the basic regular expression, the extension of regular expression , the first direct indication of the language family, the special symbol [: Alnum:], [: alpha:],^,., [-], [^], use of sed, A,C,D,I,P,NL/ETC/PASSWD | Sed "2,5p", extended regular expression, egrep,

Grep–v "^$" file | Grep–v "^#", egrep–v "^$|^#" file, Last–n 5 | awk ' {print ' \ t ' $ $} '. awk divides a line into several fields.

3:shell script:

Shell script is to use the Shell function to write "program", this program mainly using shell commands, regular expressions, redirects, pipelines and other functions to achieve our purpose, a bit like the bat file we wrote earlier, learning the shell The meaning of script is that you can automate management, configure firewalls and the like, simple data processing, cross-platform, and many other features. Shell writing and execution: from top to bottom from left to right, ignoring spaces, encountering enter to execute, "#" begins with a comment; execution depends on the relative path and absolute path, or the process directly through bash, to write the first shell:

Declare the shell you are using, tell the purpose of the script, the history, the declaration part, the execution section, and then your own practice.

Linux starts from 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.