Shell_01 basic operations

Source: Internet
Author: User

Shell_01 what is the basic operation of Shell shell? shell is a command interpreter echo $ SHELL -- through the Environment Variable cat/etc/shells -- view the switch of the currently registered shellshell to the system 1. Temporary switch #/bin/ksh 2. Fixed switch # vim/etc/passwd -- the last field in the file # chsh-s/sbin/nologin username # usermod-s/bin/bash username close the sub-shell. #/bin/bash # bin/kshforks -- Copy process information, inherit the definition exec of the parent shell-use exec to enable the Sub-shell. Why does it save time to use the shell to solve repeated operations and improve work efficiency? Powerful basic elements that do not need to compile shell scripts #! <Command interpreter> # -- for shell Command Flow Control (if/for/while/utile/case/function) man BASH_BUILTINS • shell history • Common Shell • one of the earliest Shell appearance of the Bourne Shell, the default Shell of most Unix systems, the rough cut lacks task control • nash --> initrd. img (init) • not a shell, which is not a SHELL and is a simple command interpreter designed as small as possible. It is mainly used to explain linuxrc or init in the initialization of ram disk. • csh • University of California Berkeley developed as part of its Unix implementation, currently, the most popular interactive Shell. It has many features, such as task control and history, but CShell is not suitable for writing scripts, there are also many potential defects • notorious errors • users cannot process file descriptors • users cannot put internal commands together in any proper way, you cannot use pipelines. • you cannot put Stream Control and commands together. • some commands seem reasonable, but they cannot run the extension version of tcsh • C shell, remove the notorious error • ksh • Korn shell in C shell, which is compatible with the Bourne shell and has most of the features of C shell, as well as the ability to edit history, reuse old commands, and edit these commands before execution. It is more reliable than csh in terms of programming stability. • Bash • Bourne-again shell, developed by the Free Software Foundation and absorbing all of the above Shell features, widely used in open-source operating systems • Internal and External commands • Shell does not need to start a separate process to run Internal commands • Shell needs to create (fork) and execute (exec) A new sub-process to run external commands • try to use internal commands to improve performance bash --> cd -- Process for parsing Internal commands bash --> forks --> bash (sub-process) --> ls -- Process for parsing External commands # type ls -- external command ls is aliased to 'ls -- color = tty '# type cd -- Internal Command cd is a shell builtin file name • you you can name a file or directory with any visible or invisible characters that you think are appropriate, but don't worry about yourself. • Security and convenience • case-sensitive characters • underscores • Dots • comma • do not appear" Space "• Extension • Easy to classify, not required • the command uses the file structure to determine its type (File)-type c file is of type c: B block (buffered) special c character (unbuffered) special d directory p named pipe (FIFO) f regular file l symbolic link; this is never true if the-L option or the-fol-low option is in effect, unless the symbolic link is broken. if you want to search for symbolic links when-L is in effect, use-xtype. s socket D door (Solari S) wildcard •? Any single character cannot match null • * any zero or multiple character groups (Files starting with a vertex cannot be matched) • Any character between [AB] a or B • [a-z] a and z, including the endpoint • It is a Shell, not a wildcard processed by the command itself, the wildcard character after the command is replaced before the command is executed. • if you need to process the wildcard character with a command instead of a Shell, use "\" to escape the wildcard character, escape Character # ll/dev/sd? Brw-r ----- 1 root disk 8, 0 03-14/dev/sda # ll/dev/sd *-rw-r -- 1 root 0 03-14/dev/sdbrw-r ----- 1 root disk 8, 0 03-14/dev/sdabrw-r ----- 1 root disk 8, 1 03-14/dev/sda1brw-r ----- 1 root disk 8, 2 03-14 09:03/dev/sda2brw-r ----- 1 root disk 8, 3 03-14 09:03/dev/sda3brw-r ----- 1 root disk 8, 4 03-14/dev/sda4brw-r ----- 1 root disk 8, 5 03-14/dev/sda5 # Ll/dev/sd? [1-5] brw-r ----- 1 root disk 8, 1 03-14/dev/sda1brw-r ----- 1 root disk 8, 2 03-14 09:03/dev/sda2brw-r ----- 1 root disk 8, 3 03-14 09:03/dev/sda3brw-r ----- 1 root disk 8, 4 03-14/dev/sda4brw-r ----- 1 root disk 8, 5 03-14 09:03/dev/sda5 # ll/dev/tty [1-5] [0-9] # ll/dev/sda [13] brw-r ----- 1 root disk 8, 1 03-14 09:03/dev/sda1brw-r ----- 1 root disk 8, 3 03-14 09:03/dev/sda3 # ll/dev/ Sda [1-3] brw-r ----- 1 root disk 8, 1 03-14 09:03/dev/sda1brw-r ----- 1 root disk 8, 2 03-14/dev/sda2brw-r ----- 1 root disk 8, 3 03-14/dev/sda3 escape # touch test \*\? \ [\]. Sh Escape Character # ls \>/root \> a \>/B bash quotes: Double quotation marks "": other variable values can be referenced using the $ symbol, the content of quotation marks is treated as a whole. single quotation marks '': other variable values cannot be referenced. special symbols in shell are considered as common characters, the quotation marks are used as a whole to view the anti-apostrophes '': $ () will be preferentially executed during command execution. One line of command can be separated, during the execution, whether the last command is correctly executed is not considered. & you can separate a line of commands. During the execution, check whether the last command is correctly executed. |! Command history # echo "This system is" HOSTNAME "" This is system is HOSTNAME # echo "This system is" $ HISTNAME "" This is system is # echo "This system is" $ HOSTNAME "" This is system is your top8.example.com # echo 'this system is "$ HOSTNAME" 'This is system is "$ HOSTNAME" [root @ override top8 ~] # Echo $5.00.00 [root @ topics top8 ~] # Echo \ $5.00 $5.00 # host = 'ifconfig eth0 | grep 'inet addr '| cut-d: -f2 | cut-d ''-f1 '# host2 = $ (ifconfig eth0 | grep 'inet addr' | cut-d:-f2 | cut-d'-f1) $ (): Operator $ [] # a = $(1 + 10 )) # echo $ a # a = $[1 + 100] # echo $ a • shell configuration file (software + configuration file) • csh • $ HOME /. run $ HOME /. run $ HOME /. logout • bash: # user01 --> login --> bash -->/etc/profile --> $ HOME /. bash_profile --> $ HOME /. bashrc -->/ Etc/bashrc global configuration file:/etc/profile -- bash working environment configuration (environment variable)/etc/profile. d /*. sh --/etc/profile extension configuration file/etc/bashrc -- bash configuration file for each user: $ HOME /. bash_history -- store command history $ HOME /. bash_logout -- the script $ HOME/executed when the shell is logged out/exited /. bash_profile $ HOME /. edit the bashrc command ctrl + u -- delete the current cursor to the beginning of the Line Content ctrl + k -- delete the current cursor to the end of the line content ctrl + c -- interrupt ctrl + l -- clear screen ctrl + -- jump to HOMEcrtl + e at the beginning of the line -- navigate to the end of the line ENDctrl + r -- quickly search for history command ctrl + z -- go to the background and run fg bgCtrl + d -- exit Shell, logout partition (Ctrl + p) display the previous command partition (Ctrl + n) display the next command alias -- Query System all existing aliases alias = 'real name' unalias -- cancel the system alias unalias-a to delete all aliases temporarily: alias la = 'LS-a' fixed: you can write it to the following files. You need to use source to refresh the definition, or log out and log on to the user again:/etc/profile $ HOME /. bash_profile $ HOME /. bashrc/etc/profile. d /*. sh command history: HISTSIZE = 1000 set the number of command history records history to query the history of all commands used by the current user (memory) cat $/HOME /. bash_history | grep xx (hard disk) history-w synchronize the commands in the memory to the hard disk ($/HOME /. bash_histo Ry) automatic synchronization: exit/log out of history-cecho ""> $ HOME/bash_history -- clear command history #:> $ HOME/bash_history call command history :! 101 pass ID !! History of calling the last command! Vim calls the history of the latest command starting with vim! $ Call the parameter command word in the last command history + [Option] + parameter ls-l/ctrl + r to find the special symbol of the bash command history: <>>>>&> | standard input 0 standard output (screen) 1 error output (screen) 2 # ls-l/dev/std * lrwxrwxrwx. 1 root 15 Aug 3 09:34/dev/stderr->/proc/self/fd/2lrwxrwxrwx. 1 root 15 Aug 3 09:34/dev/stdin->/proc/self/fd/0lrwxrwxrwx. 1 root 15 Aug 3/dev/stdout->/proc/self/fd/1

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.