{"id":3459,"date":"2014-08-21T01:08:08","date_gmt":"2014-08-20T17:08:08","guid":{"rendered":"http:\/\/rmohan.com\/?p=3459"},"modified":"2014-08-21T01:48:09","modified_gmt":"2014-08-20T17:48:09","slug":"linux-common-shell","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=3459","title":{"rendered":"Linux common SHELL"},"content":{"rendered":"<p>Linux common SHELL<br \/>\n1 delete 0 byte file<br \/>\nfind -type f -size 0 -exec rm -rf {} \\;<br \/>\n2. view the process<br \/>\nArranged in descending memory<br \/>\nps -e -o &#8220;% C:% p:% z:% a&#8221; | sort -k5 -nr<br \/>\nPress the cpu utilization in descending order<br \/>\nps -e -o &#8220;% C:% p:% z:% a&#8221; | sort -nr<br \/>\n4 print says in the URL cache<br \/>\ngrep -r -a jpg \/ data \/ cache \/ * | strings | grep &#8220;http:&#8221; | awk -F&#8217;http: &#8221; {print &#8220;http:&#8221; $ 2;} &#8216;<br \/>\n5 Check number of concurrent requests and TCP connection status http in:<br \/>\nnetstat -n | awk &#8216;\/ ^ tcp \/ {++ S [$ NF]} END {for (a in S) print a, S [a]}&#8217;<\/p>\n<p>6. sed -i &#8216;\/ Root \/ s \/ no \/ yes \/&#8217; \/ etc \/ ssh \/ sshd_config sed in this text in Root row, matching Root line, replace the no into a yes.<br \/>\n7.1 How to kill mysql process:<br \/>\nps aux | grep mysql | grep -v grep | awk &#8216;{print $ 2}&#8217; | xargs kill -9 (learned from the use awk)<br \/>\nkillall -TERM mysqld<br \/>\nkill -9 `cat \/ usr \/ local \/ apache2 \/ logs \/ httpd.pid` try killing the process PID<\/p>\n<p>The display runs three levels of open services:<br \/>\nls \/etc\/rc3.d\/S* | cut -c 15- (learned from the use of cut, intercept data)<br \/>\n9 How to display more information in the preparation of SHELL, with EOF<br \/>\ncat &lt;&lt; EOF<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;- +<br \/>\n| === Welcome to Tunoff services === |<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;- +<br \/>\nEOF<br \/>\n10. for the clever use (such as to build mysql soft link)<br \/>\ncd \/ usr \/ local \/ mysql \/ bin<br \/>\nfor i in *<br \/>\ndo ln \/ usr \/ local \/ mysql \/ bin \/ $ i \/ usr \/ bin \/ $ i<br \/>\ndone<br \/>\n11 take IP address:<br \/>\nifconfig eth0 | grep &#8220;inet addr:&#8221; | awk &#8216;{print $ 2}&#8217; | cut -c 6- or<br \/>\nifconfig | grep &#8216;inet addr:&#8217; | grep -v &#8216;127.0.0.1&#8217; | cut -d: -f2 | awk &#8216;{print $ 1}&#8217;<br \/>\n12 memory size:<br \/>\nfree -m | grep &#8220;Mem&#8221; | awk &#8216;{print $ 2}&#8217;<\/p>\n<p>13.<br \/>\nnetstat -an -t | grep &#8220;: 80&#8221; | grep ESTABLISHED | awk &#8216;{printf &#8220;% s% s \\ n&#8221;, $ 5, $ 6}&#8217; | sort<br \/>\n14 See Apache concurrent requests and TCP connection status:<br \/>\nnetstat -n | awk &#8216;\/ ^ tcp \/ {++ S [$ NF]} END {for (a in S) print a, S [a]}&#8217;<br \/>\n15. colleagues to statistics about the server because all of the following jpg file size, wrote a shell to him to count. Original use xargs to achieve, but he once treated a part, there are more than the sum of the &#8230;. out, the following command will be able to solve it.<br \/>\nfind \/ -name * .jpg -exec wc -c {} \\; | awk &#8216;{print $ 1}&#8217; | awk &#8216;{a + = $ 1} END {print a}&#8217;<\/p>\n<p>The number of CPU&#8217;s (multi-accounting multiple CPU, cat \/ proc \/ cpuinfo | grep -c processor), the more low system load, the number of requests per second can handle the more.<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n16 CPU load # cat \/ proc \/ loadavg<br \/>\nBefore checking whether the three output value exceeds four times the system logical CPU.<br \/>\n18 CPU load #mpstat 1 1<br \/>\nCheck% idle is too low (eg less than 5%)<br \/>\n19 memory space # free<br \/>\nCheck free value is too low can also use # cat \/ proc \/ meminfo<br \/>\n20 swap space # free<br \/>\nCheck swap used value is too high if the swap used value is too high, further examination swap action is frequent:<br \/>\n# Vmstat 1 5<br \/>\nSi and the observed values ??are so large<br \/>\n21 Disk Space # df -h<br \/>\nCheck for partition usage (Use%) is too high (eg over 90%) found a partition space close to exhaustion, you can enter the mount point of the partition, use the following command to find the most space-consuming file or directory:<br \/>\n# Du -cks * | sort -rn | head -n 10<br \/>\n22 disk I \/ O load # iostat -x 1 2<br \/>\nCheck the I \/ O utilization (% util) exceeds 100%<br \/>\n23 Network Load # sar -n DEV<br \/>\nCheck the network traffic (rxbyt \/ s, txbyt \/ s) is too high<br \/>\n24 Network Error # netstat -i<br \/>\nCheck whether there is a network error (drop fifo colls carrier) can also use the command: # cat \/ proc \/ net \/ dev<br \/>\nThe number 25 network connection # netstat -an | grep -E &#8220;^ (tcp)&#8221; | cut -c 68- | sort | uniq -c | sort -n<br \/>\n26 processes total # ps aux | wc -l<br \/>\nCheck whether the normal number of processes (eg more than 250)<br \/>\n27 The number of runnable processes # vmwtat 1 5<br \/>\nColumn gives the number of runnable processes, check whether it exceeds the system logical CPU 4 times<\/p>\n<p>28 Process # top -id 1<br \/>\nObserve whether there is an exception process occurs<br \/>\n29 Network status check DNS, gateway, etc. are properly connected<br \/>\n30 users # who | wc -l<br \/>\nCheck the login user is excessive (eg over 50) can also use the command: # uptime<br \/>\n31 system log # cat \/ var \/ log \/ rflogview \/ * errors<br \/>\nCheck for unusual error log can also search for some unusual keywords, for example:<br \/>\n# Grep -i error \/ var \/ log \/ messages<br \/>\n# Grep -i fail \/ var \/ log \/ messages<br \/>\n32 core logging # dmesg<br \/>\nCheck for unusual error logging<br \/>\n33 system time # date<br \/>\nCheck the system time is correct<br \/>\n34 the number of open files # lsof | wc -l<br \/>\nThe total number of checking whether too many open files<br \/>\n35 Log # logwatch -print configuration \/etc\/log.d\/logwatch.conf, the Mailto set their own email address, start mail service (sendmail or postfix), so that you can receive a daily log report.<br \/>\nThe default logwatch report only yesterday logs, you can use # logwatch -print -range all get all the log analysis results.<br \/>\nYou can use the # logwatch -print -detail high to obtain more detailed log analysis results (not just the error log).<br \/>\n36 killed 80 port-related processes<br \/>\nlsof -i: 80 | grep -v &#8220;PID&#8221; | awk &#8216;{print &#8220;kill -9&#8221;, $ 2}&#8217; | sh<br \/>\n37. clear zombie processes.<br \/>\nps -eal | awk &#8216;{if ($ 2 == &#8220;Z&#8221;) {print $ 4}}&#8217; | kill -9<br \/>\n38.tcpdump capture, data can be analyzed to prevent being attacked on port 80<br \/>\n# Tcpdump -c 10000 -i eth0 -n dst port 80&gt; \/ root \/ pkts<br \/>\n39. then check the IP number of repetitions and small to large order note &#8220;-t \\ +0&#8221; in the middle of two spaces<br \/>\n# Less pkts | awk {&#8216;printf $ 3 &#8220;\\ n&#8221;&#8216;} | cut -d -f 1-4 |. Sort | uniq -c | awk {&#8216;printf $ 1 &#8220;&#8221; $ 2 &#8220;\\ n&#8221;&#8216;} | sort -n -t \\ +0<br \/>\n40. have php-cgi process to see how many activities<br \/>\nnetstat -anp | grep php-cgi | grep ^ tcp | wc -l<br \/>\nchkconfig &#8211;list | awk &#8216;{if ($ 5 == &#8220;3: on&#8221;) print $ 1}&#8217;<br \/>\n41.kudzu view card model<br \/>\nkudzu &#8211;probe &#8211;class = network<br \/>\nMatching Chinese characters regex: [\\ u4e00- \\ u9fa5]<br \/>\nCommentary: Matching Chinese really is a troublesome thing, with this expression will be easier<br \/>\nMatching double-byte characters (including characters including): [^ \\ x00- \\ xff]<br \/>\nCommentary: can be used to calculate the length of the string (a double-byte character length gauge 2, ASCII character count 1)<br \/>\nBlank lines matching regular expression: \\ n \\ s * \\ r<br \/>\nCommentary: can be used to remove blank lines<br \/>\nHTML tags matching regular expression: &lt;(\\ S *?) [^&gt;] *&gt; * &lt;\/ \\ 1&gt; | &lt;* \/&gt;.?.?<br \/>\nCommentary: Too bad the version circulated on the Internet, this is only able to match the above section, for complex nested tags still powerless<br \/>\nAnd last match whitespace regex: ^ \\ s * | \\ s * $<br \/>\nCommentary: whitespace delete the line end of the line can be used (including spaces, tabs, page breaks, etc.), very useful expression<br \/>\nMatching Email address regex: \\ w + ([-. +] \\ W +) * @ \\ w + ([-.] \\ W +) * \\ \\ w + ([-.] \\ W +) *.<br \/>\nCommentary: When a very practical form validation<br \/>\nWebsite URL matching regular expression: [a-zA-z] +: \/\/ [^ \\ s] *<br \/>\nComment: The spread of the Internet version of the function is very limited, to meet the basic needs of the above<br \/>\nMatch the account is legitimate (letter beginning, allowing 5-16 bytes, allowing alphanumeric characters and underscores): ^ [a-zA-Z] [a-zA-Z0-9 _] {4,15} $<br \/>\nCommentary: When a very practical form validation<br \/>\nMatching domestic phone number: \\ d {3} &#8211; \\ d {8} | \\ d {4} &#8211; \\ d {7}<br \/>\nCommentary: matching forms such as 0511-4405222 or 021-87888822<br \/>\nMatching Tencent QQ number: [1-9] [0-9] {4}<br \/>\nCommentary: Tencent QQ number from 10,000 to start<br \/>\nMatching China Postal Code: [1-9] \\ d {5} (?! \\ D)<br \/>\nCommentary: China ZIP code for six figures<br \/>\nMatching ID: \\ d {15} | \\ d {18}<br \/>\nCommentary: China&#8217;s ID card for 15 or 18<br \/>\nMatch ip address:&#8230; \\ D + \\ \\ d + \\ \\ d + \\ \\ d +<br \/>\nCommentary: When extracting useful ip address<br \/>\nMatch a specific number:<br \/>\n^ [1-9] \\ d * $ \/\/ match the positive integers<br \/>\n^ &#8211; [1-9] \\ d * $ \/\/ match negative integers<br \/>\n^ -? [1-9] \\ d * $ \/\/ match integers<br \/>\n^ [1-9] \\ d * | 0 $ \/\/ match non-negative integer (positive integer + 0)<br \/>\n^ &#8211; [1-9] \\ d * | 0 $ \/\/ matching non-positive integers (negative integer + 0)<br \/>\n^ [1-9] \\ d * \\ \\ d * |.. 0 \\ \\ d * [1-9] \\ d * $ \/\/ match float<br \/>\n^ &#8211; (.. [1-9] \\ d * \\ \\ d * | 0 \\ \\ d * [1-9] \\ d *) $ \/\/ match negative float<br \/>\n? ^ &#8211; (..?. [1-9] \\ d * \\ \\ d * | 0 \\ \\ d * [1-9] \\ d * | 0 \\ 0+ | 0) $ \/\/ match float<br \/>\n^ [1-9] \\ d * \\ \\ d * |.. 0 \\ \\ d * [1-9] \\ d * | 0 \\ 0+ |?. 0 $ \/\/ match non-negative floating point (float + 0)<br \/>\n^ (-.. ([1-9] \\ d * \\ \\ d * | 0 \\ \\ d * [1-9] \\ d *)) | 0 \\ 0+ | 0 $ \/\/ matching non-upright?. points (negative float + 0)<br \/>\nCommentary: When handling large amounts of data useful to note that amendments to the specific application<br \/>\nMatch a specific string:<br \/>\n^ [A-Za-z] + $ \/\/ match a string of 26 English letters<br \/>\n^ [AZ] + $ \/\/ match by 26 uppercase letters of the alphabet composed of a string<br \/>\n^ [az] + $ \/\/ match a string of 26 lowercase letters of the alphabet consisting of<br \/>\n^ [A-Za-z0-9] + $ \/\/ match the string of numbers and 26 letters of the English<br \/>\n^ \\ w + $ \/\/ matching string by numbers, 26 English letters or underscores the<br \/>\nCommentary: some of the most basic and most common expressions<\/p>\n<p>1 build file links<br \/>\n(1) Fixed Link:<br \/>\nWhen you delete a file which is actually just deleted the link to the file, if a file has multiple files linked to really delete this file must remove all links to this file<br \/>\nExample: foo bar create a fixed file link for the file named<br \/>\nln foo bar<br \/>\nDisplay file link information<br \/>\nls -i foo bar<br \/>\n(2) a symbolic link: Similar to the windows shortcuts<br \/>\nln -s source file name destination file name<br \/>\n2 Find a file<br \/>\n(1) find: by file name to find the advantage is to find a flexible, the disadvantage is the search time is too long<br \/>\nFormat: find a path expression match<br \/>\nfind \/ -iname myfile *<br \/>\nDescription: iname for matching expression, which has more than 20 kinds of choice<br \/>\nExample: Find by size<br \/>\nfind \/ -size 53k<br \/>\n(2) locate: Find by file name, but according to the index to find, so the speed is faster than find<br \/>\nExample: locate * .ps<br \/>\n(3) whereis: the search results can be displayed while the file is a binary file, source code and documentation storage location of<br \/>\nExample: whereis find<br \/>\n(4) grep string filename parameter<br \/>\n3 archive command: Archive role is to package multiple files into one file, but it does not compress each file<br \/>\nFormat: tar &#8211; parameter target file name of the source file<br \/>\nParameter List:<br \/>\n-c establish archive<br \/>\n-f archive to a file instead of a tape drive<br \/>\n-v during replication, to join the file is displayed on the screen<br \/>\n-t display each file list<br \/>\n-x unlock an archive file to the appropriate directory, and contrary -c<br \/>\n-w in each filing \/ unlock the file for each file when confirmation, to prevent misuse overwrite files<br \/>\nBy filing reconciliation gzip file when filtering -z<br \/>\nArchive formats: tar -cvf list of files to be archived archive file name<br \/>\nExample: tar -cvf vnc.tar \/ root<br \/>\nXie file formats: tar -xvf archive file name<br \/>\n4 compression and decompression command<br \/>\ngzip &#8211; parameter file name<br \/>\nDescription: gzip with winzip software is different, it can only compress a file, so often used in conjunction with the tar command, gzip generally without any parameters, such as:<br \/>\ngzip mydoc.tar<br \/>\nWill produce mydoc.tar.gz compressed file in the current directory<br \/>\nNote: You can use tar -z file compression, for example, type the following command<br \/>\ntar -cvfz resarch.tar.gz \/ etc<br \/>\nThe above command will be on file in \/ etc archive for research.tar, then use gzip to compress files generated research.tar.gz<br \/>\nIn contrast, type the following command:<br \/>\ntar -xvfz research.tar.gz<br \/>\n5.RPM (Redhat Package Manager abbreviation). It is a powerful software package developed by Redhat management software<br \/>\n(1) installation package<br \/>\nrpm -i package name<br \/>\n(2) Uninstall one package<br \/>\nrpm -e package name<br \/>\n6. rights management file \/ directory<br \/>\n-rw-r-r &#8211; l<br \/>\nIn addition to the above file permissions first letter back nine groups of three letters each, followed by representatives of the file owner, file group, and other users all the permissions on the file, where r represents read<br \/>\nPermissions, w write permission on behalf of, x behalf of the Executive authority. Catalog, x permission for representatives of the search. File permissions shown above represent the file belongs to the user is concerned, it has read and write permissions<br \/>\n; For other users only read access. This is also the general file permissions allocation.<br \/>\nNote: The directory permissions greater than the file permissions<br \/>\n7 Change the file \/ directory permissions<br \/>\nchmod permissions for the file name + user categories<br \/>\nUser categories include the following:<br \/>\na representative of all users<br \/>\ng represents the file belongs to a user group<br \/>\no behalf of all the documents to other users outside the group<br \/>\nRights include: r, w, x<br \/>\nExample: myfile belongs to the group of users with write permissions:<br \/>\nchmod g + w myfile<br \/>\nExample: All users can execute mybatch file<br \/>\nchmod a + x mybatch<br \/>\nEstablishment (similar dos bat file) in 8.Linux script file<br \/>\nThe difference is that with dos in dos to distinguish whether the file extension to perform, but in linux by adding x to set the file executable permissions<br \/>\nExample: clear set as executable script file<br \/>\nchmod -u + x clear<br \/>\n9 change their user and group files<br \/>\nchown parameter user: group file name<br \/>\nExample: chown tlc: book destfile<br \/>\nThe respective user destfile set to tlc, user group is set to book<br \/>\n10. process management<br \/>\nWhen you enter a command in the command line, as long as the command plus an &amp; operator, you can make this program running in the background. For example, type updatedb &amp; can make this task performed in the background<br \/>\nctrl + z can put the programs into the background while suspended<br \/>\nbg so continue to be suspended<br \/>\nfg to keep it in the background<br \/>\nctrl + c to terminate a program run<br \/>\n11 View into the Program Status: ps<br \/>\nDetails ps -l display process<br \/>\nps -f display process tree to represent the superior-subordinate relationship between processes<br \/>\nps -r display running processes<br \/>\nps -m display memory usage<br \/>\nProgram processes the highest top 12 display system<br \/>\nk kill processes<br \/>\nq Exit<br \/>\n13. kill command to terminate the process<br \/>\n14. manage users and user groups<br \/>\nThe general command format to add users<br \/>\nuseradd username parameter<br \/>\nExample: useradd staff1 role is to build user staff1, this time not set a password, so then if this user is logged, no need to enter a password. The default user working directory is \/ home \/ username<br \/>\nCommon parameters:<br \/>\nThe minimum set user id id, this value should be greater than 99 and greater than the existing users: -u user id<br \/>\n-g user group name: The user should belong to the specified user group<br \/>\n-d working directory: Specifies the user&#8217;s working directory<br \/>\nuseradd -g guest -d \/ mydoc user<br \/>\nThis command creates a user-user, it belongs to the guest group (if not in this group, then create it). Its working directory is \/ mydoc (If you do not have this directory, then create it)<br \/>\nDelete user-friendly format:<br \/>\nuserdel username parameter<br \/>\nThis command is only one parameter -r, expressed delete users delete the user&#8217;s working directory<br \/>\n15. create and modify password<br \/>\nUnder linux system in addition to the root user must set a password, the other ordinary user&#8217;s password from a technical point of view is not set, but for safety reasons, are generally required to set a password. Set a password in Linux command passwd, it&#8217;s the general format is:<br \/>\npasswd -u username<br \/>\nExample: psswd wang1 will modify the user&#8217;s password wang1<br \/>\nAchieved with one shell statement: all updated more than 10 days under the current directory (including subdirectories) suffix to suffix .a file .b<br \/>\nfor i in $ (find -name &#8216;* .a&#8217; -a -mtime +10.); do mv $ i $ {i% *.} b;. done<br \/>\nfind -name &#8216;* .a&#8217; -a -mtime +10 |. xargs rename .a .b<br \/>\nLittle or insurance<br \/>\nfind -name &#8216;* .a&#8217; -a -mtime +10 |. xargs -n1 -i rename .a .b<br \/>\n. find -type f -name &#8220;* .b&#8221; | awk &#8216;{cmd = sprintf (&#8220;mv% s% sa \/&#8221;, $ 1, substr ($ 1,1, length ($ 1) -2)); system<br \/>\n(cmd)} &#8216;<br \/>\nfor i in $ (find -name &#8216;* .a&#8217; -a -mtime +10.); do mv $ i [color = red] $ b [\/ color] {i% *.};. done<\/p>\n<p>shell programming, to achieve the following functions:<br \/>\n\/ There are 800 files in tmp path, file name format is: filename_YYYYMMDD_ serial number (001 to 999) .dat, cases<br \/>\nSuch as: filename_20040108_089.dat<br \/>\nNow wants to rename these files, the new file name format is: filename_TODAY (current date) _ serial number (from 500 starts to reach<br \/>\nAfter 999 from 001) .dat,<br \/>\nFor example: the filename_20040108_089.dat to filename_20041222_589.dat, pay attention to the new file name order<br \/>\nNo need to order of the columns and the original agreement, namely to do the sorting process.<br \/>\n#! \/ usr \/ bin \/ bash<br \/>\nDEST_FILE_PART2 = &#8220;_` date &#8216;+% Y% m% d&#8217;`_&#8221;<br \/>\nEXT_NAME = &#8220;. Dat&#8221;<br \/>\nSRC_FILE_LIST = `find \/ tmp -name&#8221; * _ * _ * $ EXT_NAME &#8220;-print`<br \/>\nfor each in $ SRC_FILE_LIST; do<br \/>\nDEST_FILE_PART1 = `echo $ each | awk -F&#8221; _ &#8220;&#8216;{print $ 1}&#8217;`<br \/>\nOLD_NUM = `echo $ each | awk -F&#8221; _ &#8220;&#8216;{print $ 3}&#8217; |&#8221;. &#8220;Awk -F &#8216;{print $ 1}&#8217;`<br \/>\nDEST_FILE_PART3 = `expr $ OLD_NUM + 500`<br \/>\n[$ DEST_FILE_PART3 -gt 999] &amp;&amp; DEST_FILE_PART3 = `expr $ OLD_NUM &#8211; 499`<br \/>\n&amp;&amp; DEST_FILE_PART3 = `printf% 03d $ DEST_FILE_PART3`<br \/>\nDEST_FILE = $ DEST_FILE_PART1 $ DEST_FILE_PART2 $ DEST_FILE_PART3 $ EXT_NAME<br \/>\necho &#8220;mv $ each to $ DEST_FILE&#8221;<br \/>\nmv $ each $ DEST_FILE<br \/>\ndone<br \/>\n1 extracted from a.log file contains &#8220;WARNING&#8221; or &#8220;FATAL&#8221;, while not contain &#8220;IGNOR&#8221; line, and then extracted with &#8220;:&#8221; The first five split<br \/>\nField<br \/>\n2 write a script, just a simple subtraction, require prompt input variables<br \/>\n3. Shell script reading (interpretation functions performed below), please pick the following program or script errors, and explain what went wrong.<br \/>\n#! \/ bin \/ bash<br \/>\n# Monitoring cpuser the point port is normal<br \/>\nlogname = &#8220;\/ home \/ forum \/ log \/ lpointlog.wf&#8221;<br \/>\nflagfile = &#8220;\/ home \/ forum \/ log \/ lognum.txt&#8221;<br \/>\nlodnum = sed -n &#8220;1,1 p&#8221; $ flagfile<br \/>\nnewnum = wc -l $ {logname}<br \/>\necho $ newnum&gt; $ flagfile<br \/>\ntotalnum = expr $ newnum &#8211; $ oldnum<br \/>\ntail -n $ totalnum $ logname | grep &#8220;POINT_THREAD WARNING&#8221;<br \/>\nif [$? == 0]<br \/>\nthen<br \/>\nmail -s &#8220;cpuser point&#8221; port exception, handle! &#8220;test@aa.com &lt;\/ dev \/ null<br \/>\nfi&gt;<br \/>\nAnswer:<br \/>\n1.<br \/>\ngrep -E &#8216;warning | fatal&#8217; file | grep -v ignor | awk -F &#8220;:&#8221; &#8216;{print $ 5}&#8217;<\/p>\n<p>awk &#8216;\/ as \/ &amp;&amp; \/ end \/ {print $ 1};! \/ bd \/ &amp;&amp; \/ end \/ {print $ 1};!&#8217; in<\/p>\n<p>\/ A \/ {} line containing the A&#8217;s<br \/>\n! \/ A \/ does not contain a row of A<br \/>\nLine \/ A \/, \/ B \/ containing A, B that contains the<br \/>\n\/ A \/ &amp;&amp; \/ B \/ includes A, B, and contains the line<br \/>\n\/ A \/, \/ B \/ &amp;&amp;! \/ C \/ includes A, B does not contain the line that contains the C&#8217;s<br \/>\nLine \/ A \/ &amp;&amp;! \/ B \/, \/ C \/ &amp;&amp;! \/ B \/ A does not contain contain B, to contain and do not contain B, C<br \/>\n2.<br \/>\n#! \/ bin \/ sh<br \/>\necho -n &#8220;input var1:&#8221;<br \/>\nread var1<br \/>\necho -n &#8220;input var2:&#8221;<br \/>\nread var2<br \/>\necho $ (($ var1 &#8211; $ var2))<\/p>\n<p>3.<br \/>\n(1) command line replaced with anti-quotes<br \/>\n`sed -n&#8221; 1,1 p &#8220;$ flagfile`<br \/>\n(2) if [$? == 0] should be written as if [$? = 0], is used to determine whether the last command executed successfully<br \/>\nif [$? = 0]<br \/>\nthen<br \/>\necho success<br \/>\nfi<br \/>\n(3) The penultimate line should be&gt; \/ dev \/ null, behind the last fi&gt; remove<br \/>\n1 variable expansion, when the environment variable is not blank (space or tab key) when separated from the surrounding text,<br \/>\nPlease use a more explicit form of braces.<br \/>\n$ Myvar = &#8216;This is my environment variable!&#8217;<br \/>\n$ Echo foo $ {myvar} bar<br \/>\nfooThis is my environment variable! bar<\/p>\n<p>2 extracted from the file path for the file name and path name of the command basename, dirname<br \/>\n$ Basename \/usr\/local\/share\/doc\/foo\/foo.txt<br \/>\nfoo.txt<br \/>\n$ Dirname \/usr\/local\/share\/doc\/foo\/foo.txt<br \/>\n\/ usr \/ local \/ share \/ doc \/ foo<\/p>\n<p>3 command substitution, the results of the implementation of a command assigned to a variable, use `, or $ ()<br \/>\n$ MYDIR = `dirname \/ usr \/ local \/ share \/ doc \/ foo \/ foo.txt`<br \/>\n$ Echo $ MYDIR<br \/>\n\/ usr \/ local \/ share \/ doc \/ foo<br \/>\n$ MYDIR = $ (dirname \/usr\/local\/share\/doc\/foo\/foo.txt)<br \/>\n$ Echo $ MYDIR<br \/>\n\/ usr \/ local \/ share \/ doc \/ foo<br \/>\n4 string truncation, $ {MYVAR ## * fo}, $ {MYVAR # * fo}, $ {MYVAR %% * fo}, $ {MYVAR% * fo}<br \/>\n5. If statement in bash, all boolean expressions are enclosed in square brackets with<br \/>\nif [&#8220;$ {1 ## *.}&#8221; = &#8220;tar&#8221;]<br \/>\n6 references, you need to deal with all metacharacters quoted as follows:<br \/>\n? * [] &#8216;&#8221;\\ $;! &amp; () | ^ # Newline tab<br \/>\nFor a single meta-characters, can be \\ meta character escaping.<br \/>\nFor the entire string, you can add single quotes around the string (&#8216;), will make the whole string metacharacters lose all special meaning.<br \/>\nAll per word for the entire string with a few exceptions, the use of double quotes, double quotes prohibited except $ (variable) and `(backtick command domain) than<br \/>\nCharacter.<\/p>\n<p>Requirements: Completion of this program in a script<br \/>\n1 has been removed from the file user.list given user name and user group, these users and groups to the system by the rules<br \/>\n2 has been given to read the user&#8217;s password from password.list in.<\/p>\n<p>user.list follows<br \/>\nzhangsan adminuser, dbuser, updatauser<br \/>\nlisi dbuser, updatauser<br \/>\nwanger updatauser, wheel<br \/>\n#! \/ bin \/ bash<br \/>\n#group add<br \/>\nfor x in &#8216;awk&#8217; {print $ 2} &#8216;user.list | sed&#8217; s \/, \/ \\ n \/ g &#8216;| sort | uniq -c | sed&#8217; s \/ [^ a-zA-Z] \/\/ g &#8221;<br \/>\ndo<br \/>\ngroupadd $ x &amp;&gt; \/ dev \/ null<br \/>\ndone<\/p>\n<p>#back message<br \/>\nif (($? == 0))<br \/>\nthen<br \/>\necho &#8220;Group Ok !!&#8221;<br \/>\nelse<br \/>\nexit 1<br \/>\nfi<\/p>\n<p>#user add<br \/>\nfor i in &#8216;awk&#8217; {print $ 1} &#8216;user.list&#8217;<br \/>\ndo<br \/>\nfor y in &#8216;awk&#8217; {print $ 2} &#8216;password.list&#8217;<br \/>\ndo<br \/>\nuseradd $ i &amp;&gt; \/ dev \/ null<br \/>\necho $ y | passwd -stdin $ i &amp;&gt; \/ dev \/ null<br \/>\ndone<br \/>\ndone<\/p>\n<p>#back message<br \/>\nif (($? == 0))<br \/>\nthen<br \/>\necho &#8220;User Ok!&#8221;<br \/>\nelse<br \/>\nexit 1<br \/>\nfi<\/p>\n<p>#add users to groups<\/p>\n<p>for ((q = 1; q &lt;= 3; q ++))<br \/>\ndo<\/p>\n<p>usermod -G &#8216;awk &#8220;NR == $ q {print $ 2}&#8221; user.list | awk&#8217; {print $ 2} &#8220;&#8216;awk&#8221; NR == $ q {print $ 1} &#8221;<br \/>\nuser.list | awk &#8216;{print $ 1} &#8220;&amp;&gt; \/ dev \/ null<br \/>\ndone<\/p>\n<p>if (($? == 0))<br \/>\nthen<br \/>\necho &#8220;All Finished!&#8221;<br \/>\nfi<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>No. mission command combination<br \/>\nA delete 0 byte files find -type f -size 0 -exec rm -rf {} \\.;<br \/>\nfind. type f -size 0 -delete<br \/>\n2 Check the process, in descending order by memory ps -e -o &#8220;% C:% p:% z:% a&#8221; | sort -k5 -nr<br \/>\n3 Press cpu utilization in descending order ps -e -o &#8220;% C:% p:% z:% a&#8221; | sort -nr<br \/>\n4 print said cache in the URL grep -r -a jpg \/ data \/ cache \/ * | strings | grep &#8220;http:&#8221; | awk -F&#8217;http: &#8221; {print &#8220;http:&#8221; $ 2;} &#8216;<br \/>\nNumber of concurrent requests and TCP connection status 5 See http The netstat -n | awk &#8216;\/ ^ tcp \/ {++ S [$ NF]} END {for (a in S) print a, S [a]}&#8217;<br \/>\n6 sed in this text in Root row, matching Root line, replace the no into a yes. sed -i &#8216;\/ Root \/ s \/ no \/ yes \/&#8217; \/ etc \/ ssh \/ sshd_config<br \/>\n7 How to kill mysql process ps aux | grep mysql | grep -v grep | awk &#8216;{print $ 2}&#8217; | xargs kill -9<br \/>\nkillall -TERM mysqld<br \/>\nkill -9 `cat \/ usr \/ local \/ apache2 \/ logs \/ httpd.pid`<br \/>\n8 shows the operation of three-level open service (learned from the use of cut, intercept data) ls \/etc\/rc3.d\/S* | cut -c 15-<br \/>\n9 How to display more information in the preparation of SHELL, with EOF cat &lt;&lt; EOF<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; +<br \/>\n| === Welcome to Tunoff services === |<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; +<br \/>\nEOF<br \/>\n10 for usage (eg to build mysql soft link) cd \/ usr \/ local \/ mysql \/ bin<br \/>\nfor i in *<br \/>\ndo ln \/ usr \/ local \/ mysql \/ bin \/ $ i \/ usr \/ bin \/ $ i<br \/>\ndone<br \/>\n11 take IP address ifconfig eth0 | grep &#8220;inet addr:&#8221; | awk &#8216;{print $ 2}&#8217; | cut -c 6-<br \/>\nifconfig | grep &#8216;inet addr:&#8217; | grep -v &#8216;127.0.0.1&#8217; | cut -d: -f2 | awk &#8216;{print $ 1}&#8217;<br \/>\n12 memory size free -m | grep &#8220;Mem&#8221; | awk &#8216;{print $ 2}&#8217;<br \/>\n13 See the connection port 80 and sort netstat -an -t | grep &#8220;: 80&#8221; | grep ESTABLISHED | awk &#8216;{printf &#8220;% s% s \\ n&#8221;, $ 5, $ 6}&#8217; | sort<br \/>\nNumber of concurrent requests and TCP connection state 14 See the Apache netstat -n | awk &#8216;\/ ^ tcp \/ {++ S [$ NF]} END {for (a in S) print a, S [a]}&#8217;<br \/>\n15 statistics about the server all of the following jpg file size find \/ -name * .jpg -exec wc -c {} \\; | awk &#8216;{print $ 1}&#8217; | awk &#8216;{a + = $ 1} END {print a}&#8217;<br \/>\nNumber cat 16 CPU&#8217;s \/ proc \/ cpuinfo | grep -c processor<br \/>\n17 CPU load cat \/ proc \/ loadavg<br \/>\n18 CPU load mpstat 1 1<br \/>\n19 free memory space<br \/>\n20 disk space df -h<br \/>\n21 found a partition space close to exhaustion, you can enter the mount point of the partition, to find the most space a file or directory with the following command du -cks * | sort -rn | head -n 10<br \/>\n22 disk I \/ O load iostat -x 1 2<br \/>\n23 Network Load sar -n DEV<br \/>\n24 network error netstat -i<br \/>\ncat \/ proc \/ net \/ dev<br \/>\n25 The number of network connections netstat -an | grep -E &#8220;^ (tcp)&#8221; | cut -c 68- | sort | uniq -c | sort -n<br \/>\nThe total number of 26 processes ps aux | wc -l<br \/>\n27 See process tree ps aufx<br \/>\n28 The number of runnable processes vmwtat 1 5<br \/>\nCheck whether the 29 DNS Server is working properly, for example here in order to dig www.baidu.com @ 61.139.2.69 61.139.2.69<br \/>\n30 to check the number of users currently logged in who | wc -l<br \/>\n31 log view, search cat \/ var \/ log \/ rflogview \/ * errors<br \/>\ngrep -i error \/ var \/ log \/ messages<br \/>\ngrep -i fail \/ var \/ log \/ messages<br \/>\ntail -f -n 2000 \/ var \/ log \/ messages<br \/>\n32 kernel log dmesg<br \/>\n33 time date<br \/>\n34 have open handles several lsof | wc -l<br \/>\n35 network packet capture, direct output summary information to a file. tcpdump -c 10000 -i eth0 -n dst port 80&gt; \/ root \/ pkts<br \/>\n36 and then check the IP number of repetitions and small to large order note &#8220;-t \\ +0&#8221; in the middle of two spaces, use less command. less pkts | awk {&#8216;printf $ 3 &#8220;\\ n&#8221;&#8216;} | cut -d -f 1-4 | sort | uniq -c | awk {&#8216;printf $ 1 &#8220;&#8221; $ 2 &#8220;\\ n&#8221;&#8216;} | sort -n -. t \\ +0<br \/>\n37 kudzu View card type kudzu -probe -class = network<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux common SHELL 1 delete 0 byte file find -type f -size 0 -exec rm -rf {} \\; 2. view the process Arranged in descending memory ps -e -o &#8220;% C:% p:% z:% a&#8221; | sort -k5 -nr Press the cpu utilization in descending order ps -e -o &#8220;% C:% p:% z:% a&#8221; | sort [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3459"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3459"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3459\/revisions"}],"predecessor-version":[{"id":3461,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3459\/revisions\/3461"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}