Linux Command Small note

Source: Internet
Author: User

  1. awk command
    Delete duplicate, non-contiguous rows

    'awk'! a[$0]++'

    awk separates columns with special separators

    Echo " 192.168.102.134 " awk ' {print $4} '
  2. SED command
    Intercepting text in a time range in the program log

    sed ' /^2015-05-14 15:32:30/,/^2015-05-14 16:12:09/p ' access_log > Log.txt

    Sed to remove blank lines

    secret= 'sed'/^$/d'filehead -1'

    Replace word special characters with SED

    Echo " 12,34,56 " sed ' s/,//g '

    Replace the string contents between the two by SED
    File contents

    <id= "Film-web"  address= "127.0.0.1"  port= "6881"  ></server>
    [Email protected]/]#CatTest.txt<serverID="Film-web"address="127.0.0.1"port="6881"> </server>[[Email protected]/]#sed-N"s/\ (*server.*port=\ "\). *\ (\". *\)/\1abc\2/p"Test.txt<serverID="Film-web"address="127.0.0.1"port="ABC"> </server>[[Email protected]/]#sed-N"s/\ (*server.*address=\ "\). *\ (\" *port\)/\1abc\2/p"Test.txt<serverID="Film-web"address="ABC"port="6881"> </server>

    Note: in sed, content enclosed in parentheses can be seen as a variable. Output using \ 1 and \.
    See also: http://coolshell.cn/articles/9104.html parenthesis Matching
    Sed "s/abc/123/g" test.txt to replace ABC with 123

  3. grep command
    Find text content, exclude. jar,. log files

    grep -i-r--exclude=*.jar--exclude=*.log abc/home/

    View Tomcat Log specific content

    Cat grep grep awk ' {if ($ >) print $} '

    View Tomcat logs for one day

    Tail -800000grep-05 -. Log

    grep or action

    grep " pattern1|pattern2 " file . txt Egrep " pattern1|pattern2 " file. txt

    grep Non-operational

    grep ' pattern1 ' file. txt
  4. PS Command
    CPU/memory usage sort

     ps  auxw-- Sort  =%cpu  ps  auxw "--sort  =%mem 

    View End share population with

     lsof-i:8080  ps -aux | grep   Java  ps -aux | grep  pid 
  5. Kill command
    Bulk Shutdown process

    Kill -9 'PSgrep grep'grep'awk { ' Print $ '} `
  6. Vim command
    Vim Show/Hide line numbers

    : Set Nu or: Set Number:set Nonu or: Set Nonumber

    Vim replaces specified area matching text

    Ten, s/10.13. 92.1/10.13. 92.2/g
  7. Date command
    Print Time

    echo 'date'+%y-%m-%d%h:%m:%s'

    Time display

    Date Date ' +%y-%m-%d%h:%m:%s '
  8. Tar command
    Tar package file, exclude option to exclude specified file or directory

    # # Package The current catalog file as a Pak. Tar . GZ, excluding the logs folder tar zcvf. /pkg.tar. GZ *  --exclude=*.txt--exclude=logs
  9. The difference between BASHRC and profile
    Https://wido.me/sunteya/understand-bashrc-and-profile

Linux Command Small note

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.