Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux high-level commands use the

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Awk [root@mysql nginx] # cat access.log | awk 'substr ($9Magazine 3) > 200records # View the access log and filter log requests with non-200status codes # substr ($4pime20): start from the 20th character in the fourth field to the end of the set delimiter # substr ($4c1p3): start with the first character in the fourth field Intercept 3 characters to end # substr ($4Jing 3jue 6): start with the third character in the fourth field and intercept 6 characters to end 2. Getopts

Getopts specifies the parameter and gets the value. There is also a similar option getopt, which can be viewed by Baidu on its own.

[root@mysql nginx] # vim test.sh # script content is as follows #! / bin/bashwhile getopts ": HVRP:" optname;do case "$optname" in "h") host_ip=$OPTARG;; "p") host_port=$OPTARG;; "?") echo "does not know this option" ":") echo "this option has no value";; "*") echo "error message" Esacdoneecho "IP is ${host_ip}, port is ${host_port}" # execution effect is as follows: [root@mysql nginx] # sh test.sh-h 192.168.20.2-p 3306IP is 192.168.20.2, port is 3306 [root@mysql nginx] # sh a.sh-p 22-h 192.168.20.3IP is 192.168.20.3, port is 22

In the above script, the getopts keyword after while is required, the h and p in quotation marks are optional and custom, corresponding to the options specified by the command line-h,-p, etc., and optname is also custom, as long as it corresponds to the variable name referenced after the case statement. Under the case statement, you can write as many options as you need to assign values to, which generally corresponds to the options specified after getopts.

3. Fgrep command [root@mysql ~] # fgrep-c "hello" test.txt # displays the number of hello characters matching lines in the test.txt file [root@mysql ~] # fgrep-l "hello" test.txt # shows the file name that matches hello 4, pkill [root@mysql ~] # pkill-kill-t pts/1 # disconnects the user of the current terminal 5. Script execution, get the path where the script is located

Most of the time, the script is executed in the same directory as the script, and the path can be obtained by using the pwd instruction in the script. The following syntax is to get the syntax of the path where the script is located when the script is not executed in the same path.

Cur_dir=$ (cd $(dirname ${BASH_SOURCE [0]}) Pwd) 6. Echo output color # background color range: 30m black words\ 033 [0m "echo-e"\ 033 [31m red words\ 0m "echo-e"\ 033 [32m green words\ 0m "echo-e"\ 033 [33m yellow words\ 033 [0m "echo-e"\ 033 [34m blue words\ 033 [0m "echo-e"\ 033] \ 033 [35m purple words\ 0m "echo-e"\ 033 [36m sky blue words\ 0m "echo-e"\ 033 [37m white words\ 033 [0m "# words background color range: 40UV 47 echo-e"\ 033 [40 37m White character on Black background\ 033 [0m "echo-e"\ 033 [41X 37m White character on Red background\ 033 [0m "echo-e"\ 033] [42X 37m White character on Green background\ 033 [0m "echo-e"\ 033 [43it37m White character on Yellow background\ 033 [0m "echo-e"\ 033 [44trans37m "echo-e"\ 033 [0m "echo-e"\ 033] [45x 37m White character on Purple background\ 033 [0m "echo-e"\ 033] 37m White words on Blue background\ 033 [0m "echo-e"\ 033 [47] 30m black word on white background\ 033 [0m "# final control option\ 33 [0m close all properties\ 33 [1m set high brightness\ 33 [4m underline\ 33 [5m flicker\ 33 [7m flicker\ 33 [8m hidden\ 33 [30m -\ 33 [37m set foreground color\ 33 [40m -\ 33 [47m set background color\ 33] [nA cursor up n] Line\ 33 [nB cursor move down n line\ 33 [nC cursor move right n line\ 33 [nD cursor move left n line\ 33 [y XH set cursor position\ 33 [2J clear screen\ 33 [K clear content from cursor to end of line\ 33 [s Save cursor position\ 33 [u restore cursor location\ 33 [? 25l Hidden cursor\ 33 [? 25h display cursor 7, sed get the ip address of domain name resolution nslookup www.baidu.com | sed-n-e'4m address nslookup www.baidu.com | awk'/ Address/ {print $2}'8, tr separator teinfo = "python,java" Php "for i in $testinfo Do echo $testinfo | tr','\ n' # separate commas,\ nwrap done# result output: pythonjavaphp# use-stitching testinfo= "python,java,php"; for i in $testinfo;do echo $testinfo | tr',''-' Donepython-java-php9, check the number of connections in timewait ss-tan state time-wait | wc-L10, get the current time of the system [root@mysql ~] # date +% Y.%m.%d-%H:%M:%S2020.01.03-22:47:46 [root@mysql ~] # date'+% F% Tunable 2020-01-03 22 22 ss 5011, Get the system time [root@mysql ~] # date-d'- 30 minutes' "+% F% T" # get the time before 30 minutes 2020-01-03 22:20:56 [root@mysql ~] # date-d yesterday "+% F% T" # the time of the day before acquisition 2020-01-02 2251 minutes' 4512, Get the local private network IPip addr | grep inet | egrep-v'(127.0.0.1 | inet6 | docker)'| awk'{print $2}'| tr-d "addr:" | head-n 1 | cut-d /-f113, showing permissions at all levels of the directory structure namei-om / var/log/messages

-this is the end of this article. Thank you for reading-

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report