Linux primary study notes 4: Detailed explanation of bash features! (Video serial number: 03_2, 3)

Commands learned in this section: history, alias, ualias, \CMD

Skills learned in this section:

         Features of bash
      Cursor jumps
      Viewing command history
      Command history tricks
      Aliasing
      commands Command substitution
      Filename wildcards

shell : shell

  GUI : Gnome, KDE, Xfce

  CLI: sh, csh, ksh, bash, tcsh, zsh

  Process: From the perspective of each process, only the kernel and the current process exist on the current host

  A process is a copy of a program, a process is an instance of program execution

User working environment :

bash:

    #: Administrator Command Prompt

    $: normal user command prompt

Features of bash:

  1. Command history, command completion

  2, pipeline, redirection

  3. Command alias

  4. Command line editing

  5. Command line expansion

  6. File name wildcard

  7. Variables

  8. Programming

 

Command line editing :

Cursor jump :

    Ctrl+a : Jump to the beginning of the command line

    Ctrl+e : Jump to the end of the command line

    Ctrl+u : delete the content from the cursor to the beginning of the command line

    Ctrl+k : delete the content from the cursor to the end of the command line

    Ctrl+l : clear screen

 

Command History :

  history : View command history

      -c: clear command history

      -d OFFSET [n]: delete the command at the specified position

      -w: save command history to history file

 

environment variable

  PATH: command search path

  HISTSIZE: command history buffer size (can be viewed with ' echo $HISTSIZE ')

 

Tips for using command history :

  !n: execute the nth command in the command history;

  !-n: Execute the nth last command in the command history;

  !!: Execute the previous command;

  !string: Execute the most recent command in the command history that begins with the specified string

  !$: refer to the last parameter of the previous command, or use "Esc + .";

 

text related commands

  查看:cat, tac, more, less, head, tail

  Statistics: wc

  Processing: tr, cut, join

  Sort: sort

  Uniq

 

command completion, path completion

  Command completion: Search for executable files starting with the string we give in each path specified by the PATH environment variable. If there is more than one, tab twice to give a list; otherwise, it will be directly completed;

  Path completion: search for each file name under the starting path we give, and try to complete it;

 

command alias

  alias CMDALIAS='COMMAND [options] [arguments]'

  Aliases defined in the shell are only valid in the current shell life cycle; aliases are only valid for the current shell process;

  alias : Displays all currently aliased commands

  ualias CMDALIAS : undo command alias

  type COMMAND : see if the command is bound with additional parameters

  \CMD : use the original properties of the parameterized command

 

Command substitution : $(COMMAND), backticks: `COMMAND`

  The process of replacing a subcommand in a command with its execution result

 

Quotes supported by bash :

  ``: command substitution

  "": Weak reference, which can implement variable substitution

  '': strong reference, does not complete variable substitution

 

filename globbing, globbing

  *: any character of any length

  ?: any single character

  []: matches any single character within the specified range

    [abc], [am], [az], [AZ], [0-9], [a-zA-Z], [0-9a-zA-Z]

      [:space:]: whitespace character

      [:punct:]: punctuation mark

      [:lower:]: lowercase letters

      [:upper:]: uppercase letters

      [:alpha:]: upper and lower case letters

      [:digit:]: digit

      [:alnum:]: numbers and uppercase and lowercase letters

      How to get these lists: man 7 glob (I didn't succeed)

  [^]: matches any single character outside the specified range

  [[:alpha:]]*[[:space:]]*[[:alpha:]]: Get files that start with a letter, end with a letter, and have spaces in between

  [[:alpha:]]*[[:space:]]*[^[:alpha:]]: Get files that start with letters, end with non-letters, and have spaces in between

 

practise:

1. Create a123, cd6, c78m, c1 my, mz, k 67, 8yu, 789 and other files; note that the above files are separated by commas, and other symbols are part of the file name;

2. Display all files starting with a or m;

  ls [am]*

3. Display all files that contain numbers in their file names;

  ls * [0-9] *

  ls * [[: digit:]] *

4. Display all files that end with numbers and do not contain blanks in the file name;

  ls *[^[:space:]]*[0-9]   ?????????

5. Display files whose file names contain special symbols other than letters or numbers;

  ls * [^ [: alnum:]] *

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324860801&siteId=291194637