Day9-1 Shell Basics

Source: Internet
Author: User

The shell is a command interpreter that provides user and machine interaction before

  1. Command history
    Press UP ARROW key to appear before order history
    History View Previous commands

    The command history exists in the file. Bash_history

    The maximum number of rows in a file is determined by the variable histsize, default 1000

    Variable histsize can be modified in/etc/profile
    histtimeformat= "%y/%m/%d%h:%m:%s"
    Set time display, non-permanent, to remain valid, need to increase in/etc/profile

    Chattr +a ~/.bash_history Permanent Save command (chattr +a can only increase cannot be deleted)
    !! Previous command
    ! [Char] recent char start command
    !n previous nth Command

  2. Command completion
    When the command starts out a portion, such as ' MK ', tab completion command and file directory name, if the result is not unique, you need to press twice consecutively, will list all the commands starting with MK

  3. Wildcard characters

    • Any number of arbitrary characters
      ? 1 arbitrary characters
      [0-9] any one number [2345] 2345 either
      [A-z] A-Z any
      [A-z] A-Z any
      [0-9a-za-z] any number or letter
      {1,3,t,y,h} enum-Select one, separated by commas
  4. Input and output redirection
    [contents or cmd] > [file] redirects the left content (correct) to the right file, overwriting the original contents of the file
    [contents or cmd] >> [file] redirects the left content (correct) to the right file without overwriting the original contents of the file, appending
    [contents or cmd] 2> [file] redirects the left content (error) to the right file, overwriting the original contents of the file
    [contents or cmd] 2>> [file] redirects the left content (error) to the right file without overwriting the original contents of the file, appending
    [contents or cmd] &> [file] redirects all content on the left to the right file, overwriting the original contents of the file
    [contents or cmd] &>> [file] redirects everything on the left to the right file without overwriting the original contents of the file, appending
    [contents or cmd] > [file1] 2>[file2] Correct and error content output to different files separately

[cmd] < [file] Enter the contents of the document into the command (the left cannot be a file)

    1. Pipe character
      Pipe symbol: [cmd] | [cmd] outputs the left command result to the right
      Cut intercept characters
      -d ' [xx] ' with XX as delimiter
      -F N,m intercept the nth and M bits
      -c Specifies the number of characters

      Sort sorts
      -N is numerically sorted (other symbols are recognized as 0)
      -R Reverse Order

      WC statistic Character
      -L Number of rows
      -M character Count
      -W number of words (separated by spaces, not real words)

      Uniq (to be sorted so that the same row is adjacent to go Heavy)
      -C Count Repeats

      Tee is equivalent to, but add | pipe character, and it will be displayed
      -A Append

      TR Replacement Character

      Split cut
      -B Size (default unit byte)
      -L Number of rows

    2. Job Control
      CTRL + Z Pause task
      FG N Back (nth) Pause command
      Jobs view tasks that are stopped or run in the background
      BG puts tasks in the background (can be used after a pause)
      Command add ' & ' to run the command directly in the background

    3. Variable
      Env View System Variables

      Custom variable, c not defined, so no content

      unset [variable name] undo variable Definition
      Variable naming: Consists of numbers, letters, underscores, the first cannot be numbers
      When there are special symbols in the value of a variable, enclose them in single quotation marks

      The difference between single quotation marks, double quotes, and anti-quotes, seen in another piece of http://blog.csdn.net/iamlaosong/article/details/54728393

Bash enters child shell

Exit the shell after entering the child shell
Generally defined variables do not span the shell
Export [variable name]=[variable value] This definition can be used in the child shell of the current shell

environment variable configuration file
/etc/profile Loading after Login
/ETC/BASHRC Executing shell loading
Under the user directory are:
~/.bashrc
~/.bash_profile
~/.bash_history
~/.bash_logout defining what to do when a user exits
Variable PS1, defined in/etc/profile, representing the string format before the command

The case of W corresponds to the current path display complete or not

    1. Special symbols
      $ variable Prefix
      ; Multiple commands are written in one line separated by semicolons
      ~ User Home Directory
      & at the back of the command, which means to put the command in the background
      [] One of the specified characters
      || Between two commands, the first command fails to execute the following command
      && two commands, the first command executes successfully before executing the following command

Day9-1 Shell Basics

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.