[Reading Notes] Linux commands, editors, and shell programming

Source: Internet
Author: User
[Reading Notes] Linux commands, editors, and shell programming-general Linux technology-Linux programming and kernel information. Read the following for details. Author: Hong haihui
Mark G. Sobell of Linux Command, editor and shell programming translated by Yang Mingjun Wang Fengqin to Tsinghua University Press

2007-12-24
Terminal handling characters:
Ctrl + z suspended. You can use fg to switch to the foreground. jobs can view background tasks;
Ctrl + w delete words;
Ctrl + u deleting rows ctrl + x seems ineffective;

Positioning tool:
Which only searches for the specified path and only reports the first found path;
Whereis in the standard path, show all;
Type determines whether the file is a built-in command;
Apropos keywords
Whatis completely matches the keyword;

Symbolic Link:
The built-in command pwd displays the Link name;
Tool (/bin/pwd) display path;
Info bash builtin list built-in commands;

2007-12-25
Use of vim:
Ctrl + w delete words;
Ctrl + h Delete row ctrl + u;
: Redo ctrl + r undo;
Ctrl + l refresh;
Vim-r check the swap file;

Move the cursor in command mode
Move spaces h and l; Ff
Move the word Ww W to separate characters by Spaces
Move row j k
Sentence ()
Segment {}
Screen H M L

Delete
Delete dG to the end;
D1G is deleted from the beginning;
D0 starts from the row;
~ Modify the case sensitivity;

Replace
1 ,. Starting to the current row;
., $ From current to end;
1, $ or % All;
: 1, $ s/ten/te/g replace all 10 of all rows with te;

2008-01-05
Array variables:
Assignment
NAMES = (max helen sam zach)
NAMES [1] = fly
Reference Value
# Echo $ {NAMES [2]}
Sam
------------------------------
Subscript
  • Difference from:
    The function is to extract the entire array, but the working mechanism of double quotation marks is different:
    @ Copy the original array to the new array, which is the same as the old one;
    * Copy the original array as an element to the new array.
    Example:
    A = ("$ {NAMES
  • }")
    B = ("$ {NAMES [@]}")
    Use declare-a to display the array content
    [Root @ Test ~] # Declare-
    Declare-a NAMES = '([0] = "max" [1] = "helen" [2] = "sam" [3] = "zach ")'
    Declare-a A = '([0] = "max helen sam zach ")'
    Declare-a B = '([0] = "max" [1] = "helen" [2] = "sam" [3] = "zach ")'

    Echo $ {# NAMES
  • } Number of elements
    [Root @ Test ~] # Echo $ {# NAMES
  • }
    4
    Echo $ {# NAMES [0]} element length
    [Root @ Test ~] # Echo $ {# NAMES [0]}
    3
    ---------------------------------
    (Count = count-1). Make sure that the shell is regarded as an arithmetic expression and the variable does not need to be $
    $ Process ID to create a unique file name;
    $0 command itself;
    $! Background process PID;
    $? Exit status;
    $ # Number of parameters except the command itself;
    $ * And $:
    $ * Treat all parameters as a whole (one parameter );
    $ @ Is the same as the original one;
    Subscript
  • [@] Same
    ----------------------------------
    Shift left shift command to get any parameter, cyclically scan command line;
    Set the initial command line parameter value;
    Set $ (date)
    Set date
    -----------------------------------
    :-Use the default value $ {name:-default}
    : = Default value $ {name: = default}
    : Built-in command assignment is not executed: $ {name: = default}
    :? The error message is displayed, and status 1 is returned. shell does not exit; $ {name :? Message}
    ------------------------------------
    Path Operators
    # Remove the minimum prefix;
    # Remove the maximum prefix;
    % Minimum removal prefix;
    % Remove the maximum prefix;
    Example:
    [Root @ Test ~] # Test =/usr/local/src/proftpd-1.2.10.tar.gz
    [Root @ Test ~] # Echo $ {test}
    /Usr/local/src/proftpd-1.2.10.tar.gz
    [Root @ Test ~] # Echo $ {test #/*}
    Usr/local/src/proftpd-1.2.10.tar.gz
    [Root @ Test ~] # Echo $ {test ##/*}
    [Root @ Test ~] # Echo $ {test % /*}
    /Usr/local/src
    [Root @ Test ~] # Echo $ {test % /*}

    [Root @ Test ~] # Echo $ {# test}: number of characters displayed
    36
    -------------------------------------
    Sed usage:
    Parameters:
    -N: in addition to the p command;
    -I save the changes to the file;
    Command:
    D. Delete the entire row;
    N displays the current row and reads the next row from the input;
    A. append the file after each line and use \ line feed;
    Append before line I;
    C replacement file (entire line );
    S replacement address;
    W. Redirect to the new file;
    R: after appending rows;
    Q: exit;
    Control Structure:
    ! NOT $! D except the last line;
    {} Command Group; separated
    Pattern and Hold:
    Pattern: Work Platform (Save the row you just read );
    Hold: Temporary Workspace
    H p-> H: append a line break and content to H
    H P-> H replace P zone with H
    G h-> P append a line break and content to G
    G H-> P replace H zone with P
    Example:
    Sed '5 Q' filename displays the first five rows;
    Sed '2 a test' insert a linefeed and test after row 2nd of filename;
    Sed '/the/n; P' file all match the not displayed;
    Sed's/^./\ t &/'the first line of filename is not a space to insert a tab;
    (^.) The beginning of the line is not a space;
    S/^/\ t/Insert a tab at the beginning of the line;
    S/* $ // delete all spaces at the end of the row;
    Sed 'G' filename insert an empty row after each row;
    Reverse Order:
    2, $ G
    H
    $! G
    ------------------------------
    Cat
    -A (-vET)
    -B Numbers non-empty rows;
    -N: numbers all rows;
    -S removes unnecessary blank rows;
    Cut
    -C
    -D separator;
    -F
    Example:
    [Root @ Test sh] # ll | tr-s ''' | cut-f 5, 9-d''
    2.3 K
    2.2 K B
    4.0 k bk/
    436 ip.1
    452 ip.2
    264 ip.
    85 K ip. list
    22 K ipList. temp
    486 sample. sh *
    9.9 K selectInfo. sh *
    4.0 K temp/
    Tr-s converts multiple spaces into a single space;

    [Root @ Test 20080114] # grep-n' ^ 'test
    1:
    2: B
    3: c
    4: d
    '^' Matches all rows;
    -N: numbers all rows.

    [Root @ Test 20080114] # grep-h a * | sort | uniq-c
    2
    -H: the file name is not displayed;
    Uniq-c displays duplicate rows only once and counts the number of repeated rows;

    [Root @ Test 20080114] # vi $ (grep-l 'A '*)
    2 files to edit
    Edit multiple matching files;
    -L name of the matched file;

    # Kill-9 0
    For common users, it is equivalent to logging out;
    Please use it with caution if root is equal to shutdown;
    --------------------------------
    Ls parameters:
    -A: All files except... are displayed;
    -F displays file features;
    -R inverse direction;
    -T: Based on the modification time;
    -X rows are displayed;
    -A file is displayed in one row;
    --------------------------------
    Sort
    Parameters:
    -B. Exclude spaces and tabs before fields;
    -F converts lowercase letters into uppercase letters (in front of uppercase letters );
    -N arithmetic sorting. The negative number and decimal point make sense;
    -R inverse direction;
    -T x separator x;
    -U duplicate rows are displayed only once;
    -K start [, stop]
    Note:
    Upper case before lower case;
    The blank space is before;
    The first query is not the same, and the second query is not performed;
    Example:
    # Sort -- key = 2 test 2nd field;

    # The sort-k 2-f test 2nd Field, which is in upper case;

    # Sort-k 2-B test 2nd Field. the blank spaces and tabs in front of the field are ignored;

    # Start with 3.4 characters in the sort-fb-k 3rd test 4th field;

    # Sort-B-k 3.4-k-2f test
    First time: 3rd characters of the 4th Field
    Second time: the 2nd field, which is in upper case;

    # Sort-k 1-k 5 test
    The first field, that is, the end field, and the fifth field;
    However, if the comparison for the first time is not the same, the comparison will not be performed for the second time;

    # Sort-k 1, 1-k 5 test
    The first field,-k (the first character of the first field to stop: the first field)
    Perform the fifth field;

    # Sort-u-k 1f-k 1 test
    Perform Two-time comparison. When fields with the same case are found;
    ------------------------------
    Regular Expression:
    Asterisk:
    /(. *)/The longest matching with parentheses;
    /([^)] *)/Minimum matching with parentheses;

    Empty regular expression:
    /\ (Test \)/is the same as/test;
    /A \ (B * \) c/is the same as/AB * c;

    Replacement string:
    & String matching of symbol and regular expression matching
    \ N escape number
    Example:
    : 1, $/\ ([^,] * \), \ (. * \)/\ 2 \ 1/
    1, $ all rows;
    \ ([^,] * \) Is the same as [^,] *, and matches any string except the comma;
    \ 2 represents the regular expression in 2nd parentheses;
    --------------------------------
    Extended Regular Expressions:
    + Match the first one or more characters;
    ? Match the first 0 or 1 Characters
    Example:
    /AB + c/abc abbc
    /AB? C/ac abc
    /(AB) + c/abc ababc
    /(AB )? C/c abc

    /AB | ac/AB ac abac
    /^ Exit | ^ Quit/start with Exit or Quit
    /(D | N) \. Jones/D. Jones N. JOnes

    Represented by \ | in vim |

    Special characters:
    . Single character;
    * And * The first 0 or multiple characters;
    \ <Start of the word;
    \> End of the word;
  • 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.