One: Shell Basics

Source: Internet
Author: User
Tags aliases clear screen garbage collection save file


1.shell Overview
The shell is a command-line interpreter that provides the user with an interface system-level program that sends a request to the Linux kernel to run the program, and the user can start with the shell, suspend, stop, or even write some programs;
The shell is also a powerful programming language, easy to write, easy to debug, flexible.

   shell is the scripting language for interpreting execution, The Linux system commands can be called directly in the shell,
  user input commands, The shell command is translated into the kernel by the ASCII code table, the kernel calls the computer hardware to handle it, and the computer hardware can pass the information to the kernel, and then the kernel tells the message to pass a Shell,shell   character, which is equivalent to the inverse process;
  windows have a shell? In fact, Windows is not called shell, graphical interface operation can also be called "shell", but not so called;
2.shell classification
  1. Bourne shell Basic Elimination, Bourne family mainly includes sh,ksh,bash,psh;
  2.c shell, mainly including: CSH,TCSH;

3. How scripts are executed

1. Echo output command and Script execution format: echo [options] [Output]

options:- E: Character conversion support for backslash control
Echo "Bols he cangls ni Xihuan nayige"
\a-output warning tone
\b-backspace
\ n-line break
\ r-return
\ t-tab, which is tab
\v-Vertical tab
\0NNN-output characters in octal ASCII code
\XHH-output characters by hexadecimal ASCII table
Echo-e bols He cangls ni\b Xihuan nayige
echo-e "Hell\bo"
Echo-e "h\te\tl\nl\to\t"
Echo-e "\x68\t\x65\t\x6c\n\x6c\t\x6f"
Echo-e "\e[1;31m Marry chicken Sister e[0m "
#输出颜色 \e[1;# #m-turns on the color display; \e[0m-turns the color display
#30m = black, 31m= red, 32m= Green, 33m= yellow
#34m = blue, 35m= magenta, 36m= cyan, 37m= white

2, Script execution:
Method 1: Give execute permission, run directly
   chmod 755 hello.sh
   ./hello.sh (or absolute path execution/root/ hello.sh)
Method 2: Execute script with bash call
    Bash hello.sh
3,
#! /bin/bash
  is not a comment, it is nominally the following content is the standard script for Linux
  If the script is completed with a pure shell statement, without adding #! /bin/bash, run no problem
  But the script calls the other languages, it will error

4. Aliases and shortcuts

1. You can set a new alias by alias ls= ' ls--color=never '

Alias view aliases, preceded by aliases, followed by full names

usually restart, after re-login, it expires!
If you want to work long-term, you need to configure the file

Vim is more powerful than VI and can be invoked by setting alias Vi= ' Vim ', but fails after restarting login

2. Write the alias to the configuration file:
VI ~/.BASHRC #写入配置文件 for permanent entry
~ refers to each user's directory, each user's directory is different, the configuration file is not the same, the resulting effect is not the same
After writing, source. BASHRC

Unalias aliases #删除别名

3. Order in which the order takes effect

First bit: a command executed with an absolute path or relative path.
Second straight bit: Execute alias command
Third level: Execute bash internal command
Four-bit: the order in which directories are found according to the $PATH environment variable first command

4. Shortcut keys
Ctrl C Forced termination
Ctrl L Clear Screen
Ctrl u Delete to beginning of line
Ctrl a cursor moves to the beginning of the line
Ctrl e moves to the end of the line
Ctrl Z put the command in the background (no termination, just into the background to execute)
Ctrl R Search History

5. Historical order

History command

History [Options] [Historical command Save file]

-C Empty History command
-W writes the history command in the cache to the history command to save the file ~/.bash_history
#默认保存1000条
histsize=1000
#vi/etc/profile environment variable configuration file modification Histsize

Basic call
Up and down arrows to repeat the call
!n to perform the nth historical command
!! Repeat the previous command
The string repeats after a command that starts with that string

TAB key
Making commands (Environment variables) and directory completion (action path)

6. Output redirection

Command &>/dev/null put command execution information into a black hole or can be understood as a garbage collection station

7. Pipe break

";" The connection command sequence executes
' | | ' Connect the command logic or perform the first execution of the second article do not perform the first error the second executes
Applications in scripts: Commands && echo yes | | echo no command correct yes error no
note && Echo Yes || Echo No order cannot be reversed, otherwise the command will output no Yes

when it goes wrong

"|" pipe character command 1| command 2 command 1 correct result as command 2 action object
such as Ls-l >/etc/| More "for pagination display command execution results"
Netstat-an | grep established | Wc-l "To view the clients currently connected to this machine and to count the number of clients"

8. Wildcard characters

One: Shell Basics

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.