{"id":8801,"date":"2023-06-12T17:55:01","date_gmt":"2023-06-12T09:55:01","guid":{"rendered":"\/?p=8801"},"modified":"2023-06-12T17:55:01","modified_gmt":"2023-06-12T09:55:01","slug":"10-linux%e5%b8%b8%e7%94%a8%e6%96%87%e6%9c%ac%e6%9f%a5%e7%9c%8b%e5%8f%8a%e5%a4%84%e7%90%86%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"\/?p=8801","title":{"rendered":"10-Linux\u5e38\u7528\u6587\u672c\u67e5\u770b\u53ca\u5904\u7406\u5de5\u5177"},"content":{"rendered":"<p>\u5e38\u89c1\u5904\u7406\u5de5\u5177\uff1a<code>wc<\/code>\u3001<code>cut<\/code>\u3001<code>sort<\/code>\u3001<code>uniq<\/code>\u3001<code>diff<\/code>\u3001<code>patch<\/code><\/p>\n<h3>wc<\/h3>\n<p><strong><em>word count\u5355\u8bcd\u7edf\u8ba1<\/em><\/strong><\/p>\n<pre><code>wc [OPTION]... [FILE]...\nwc [OPTION]... --files0-from=F\n\n-c, --bytes \u663e\u793a\u5b57\u8282\u6570\n      print the byte counts\n\n-m, --chars\n      print the character counts\n\n-l, --lines \u663e\u793a\u884c\u6570\n      print the newline counts\n\n--files0-from=F\n      read input from the files specified by NUL-terminated names in file F; If F is - then read names from standard input\n\n-L, --max-line-length\n      print the length of the longest line\n\n-w, --words \u663e\u793a\u5355\u8bcd\u6570\n      print the word counts\n\n--help display this help and exit\n\n--version\n      output version information and exit<\/code><\/pre>\n<p>WC [OPTION]...[FILE]..<\/p>\n<ul>\n<li><code>-l<\/code>:lines<\/li>\n<li><code>-w<\/code>:words<\/li>\n<li><code>-c<\/code>:bytes<\/li>\n<\/ul>\n<h3>cut<\/h3>\n<p>cut OPTION...[FILE]...<br \/>\nOPTION:<\/p>\n<ul>\n<li><code>-d CHAR<\/code>:\u4ee5\u6307\u5b9a\u7684\u5b57\u7b26\u4e3a\u5206\u9694\u7b26\uff1a<br \/>\n<code>-f FIELDS<\/code>:\u6311\u9009\u51fa\u7684\u5b57\u6bb5\uff1b<\/p>\n<ul>\n<li><code>#<\/code>:\u6307\u5b9a\u7684\u5355\u4e2a\u5b57\u6bb5\uff1a<\/li>\n<li><code>#-#<\/code>:\u8fde\u7eed\u7684\u591a\u4e2a\u5b57\u6bb5\uff1b<\/li>\n<li><code>#,#<\/code>:\u79bb\u6563\u7684\u591a\u4e2a\u5b57\u6bb5\uff1a<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">[root@VM-4-10-centos ~]# wc lovers.txt\n 4 16 82 lovers.txt\n# \u663e\u793a\u6587\u4ef6\u884c\u6570\n[root@VM-4-10-centos ~]# wc -l lovers.txt | cut -d &#039; &#039; -f1\n4<\/code><\/pre>\n<h3>sort<\/h3>\n<p>sort [OPTION]... [FILE]...<\/p>\n<ul>\n<li>\n<p>-<code>n<\/code>:\u57fa\u4e8e\u6570\u503c\u5927\u5c0f\u800c\u975e\u5b57\u7b26\u8fdb\u884c\u6392\u5e8f\uff1a<\/p>\n<\/li>\n<li>\n<p><code>-t CHAR<\/code>:\u6307\u5b9a\u5206\u9694\u7b26\uff1a<\/p>\n<\/li>\n<li>\n<p><code>-k#<\/code>:\u7528\u4e8e\u6392\u5e8f\u6bd4\u8f83\u7684\u5b57\u6bb5\uff1b<\/p>\n<pre><code class=\"language-bash\"># \u6309\u7b2c\u4e09\u4e2a\u6570\u503c\u6392\u5e8f\n[root@VM-4-10-centos ~]# sort -t: -k3 -n \/etc\/passwd\nroot:x:0:0:root:\/root:\/bin\/bash\nbin:x:1:1:bin:\/bin:\/sbin\/nologin\ndaemon:x:2:2:daemon:\/sbin:\/sbin\/nologin\nadm:x:3:4:adm:\/var\/adm:\/sbin\/nologin\nlp:x:4:7:lp:\/var\/spool\/lpd:\/sbin\/nologin\nsync:x:5:0:sync:\/sbin:\/bin\/sync\nshutdown:x:6:0:shutdown:\/sbin:\/sbin\/shutdown\nhalt:x:7:0:halt:\/sbin:\/sbin\/halt<\/code><\/pre>\n<\/li>\n<li>\n<p><code>-r<\/code>\uff1a\u9006\u5e8f\u6392\u5e8f<\/p>\n<\/li>\n<li>\n<p><code>-f<\/code>\uff1a\u5ffd\u7565\u5b57\u7b26\u5927\u5c0f\u5199<\/p>\n<\/li>\n<li>\n<p><code>-u<\/code>\uff1a\u91cd\u590d\u7684\u884c\uff08\u8fde\u7eed\u4e14\u76f8\u540c\uff09\u53ea\u4fdd\u7559\u4e00\u4efd<\/p>\n<pre><code class=\"language-bash\">[root@VM-4-10-centos ~]# cut -d: -f7 \/etc\/passwd | sort -u\n\/bin\/bash\n\/bin\/false \n\/bin\/sync\n\/sbin\/halt\n\/sbin\/nologin\n\/sbin\/shutdown\n[root@VM-4-10-centos ~]# cut -d: -f7 \/etc\/passwd | sort -u | wc -l\n6<\/code><\/pre>\n<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">[root@VM-4-10-centos ~]# cut -d: -f3 \/etc\/passwd | sort\n0\n1\n1000\n...\n997\n998\n999\n[root@VM-4-10-centos ~]# cut -d: -f3 \/etc\/passwd | sort -n\n0\n1\n2\n3\n4\n5\n6\n...\n\n1006\n1007\n1008\n1009\n# \u6309\u7b2c\u4e09\u4e2a\u6570\u503c\u6392\u5e8f\n[root@VM-4-10-centos ~]# sort -t: -k3 -n \/etc\/passwd\nroot:x:0:0:root:\/root:\/bin\/bash\nbin:x:1:1:bin:\/bin:\/sbin\/nologin\ndaemon:x:2:2:daemon:\/sbin:\/sbin\/nologin\nadm:x:3:4:adm:\/var\/adm:\/sbin\/nologin\nlp:x:4:7:lp:\/var\/spool\/lpd:\/sbin\/nologin\nsync:x:5:0:sync:\/sbin:\/bin\/sync\nshutdown:x:6:0:shutdown:\/sbin:\/sbin\/shutdown\nhalt:x:7:0:halt:\/sbin:\/sbin\/halt\nmail:x:8:12:mail:\/var\/spool\/mail:\/sbin\/nologin\noperator:x:11:0:operator:\/root:\/sbin\/nologin\ngames:x:12:100:games:\/usr\/games:\/sbin\/nologin\nftp:x:14:50:FTP User:\/var\/ftp:\/sbin\/nologin\nrpc:x:32:32:Rpcbind Daemon:\/var\/lib\/rpcbind:\/sbin\/nologin\nntp:x:38:38::\/etc\/ntp:\/sbin\/nologin\ntss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:\/dev\/null:\/sbin\/nologin\ntcpdump:x:72:72::\/:\/sbin\/nologin\nsshd:x:74:74:Privilege-separated SSH:\/var\/empty\/sshd:\/sbin\/nologin\ndbus:x:81:81:System message bus:\/:\/sbin\/nologin\npostfix:x:89:89::\/var\/spool\/postfix:\/sbin\/nologin\nnobody:x:99:99:Nobody:\/:\/sbin\/nologin\nabrt:x:173:173::\/etc\/abrt:\/sbin\/nologin\nsystemd-network:x:192:192:systemd Network Management:\/:\/sbin\/nologin\nredis:x:995:990:Redis Database Server:\/var\/lib\/redis:\/sbin\/nologin\nsyslog:x:996:994::\/home\/syslog:\/bin\/false\nchrony:x:997:995::\/var\/lib\/chrony:\/sbin\/nologin\nlibstoragemgmt:x:998:997:daemon account for libstoragemgmt:\/var\/run\/lsm:\/sbin\/nologin\npolkitd:x:999:998:User for polkitd:\/:\/sbin\/nologin\nwww:x:1000:1000::\/home\/www:\/sbin\/nologin\nmysql:x:1001:1001::\/home\/mysql:\/sbin\/nologin\nlighthouse:x:1002:1002::\/home\/lighthouse:\/bin\/bash\nlemon:x:1003:1003::\/home\/lemon:\/bin\/bash\nx:x:1004:1004::\/home\/x:\/bin\/bash\nuser3:x:1005:1005::\/home\/user3:\/bin\/bash\nbash:x:1006:1006::\/home\/bash:\/bin\/bash\nbasher:x:1007:1007::\/home\/basher:\/bin\/bash\nnologin:x:1008:1008::\/home\/nologin:\/sbin\/nologin\ntestbash:x:1009:1009::\/home\/testbash:\/bin\/bash\n<\/code><\/pre>\n<h3>uniq<\/h3>\n<p>uniq [OPTION]... [INPUT [OUTPUT]]<\/p>\n<ul>\n<li><code>-c<\/code>\uff1a\u663e\u793a\u6bcf\u884c\u7684\u91cd\u590d\u6b21\u6570<\/li>\n<li><code>-u<\/code>\uff1a\u4ec5\u663e\u793a\u672a\u66fe\u91cd\u590d\u8fc7\u7684\u884c<\/li>\n<li><code>-d<\/code>\uff1a\u4ec5\u663e\u793a\u91cd\u590d\u8fc7\u7684\u884c<\/li>\n<\/ul>\n<pre><code class=\"language-bash\"># \u91cd\u590d\u884c\u51fa\u73b0\u7684\u6b21\u6570\n[root@VM-4-10-centos ~]# cut -d: -f7 \/etc\/passwd | sort | uniq -c\n      8 \/bin\/bash\n      1 \/bin\/false\n      1 \/bin\/sync\n      1 \/sbin\/halt\n     25 \/sbin\/nologin\n      1 \/sbin\/shutdown\n# \u5b58\u5728\u91cd\u590d\u884c\u7684\u884c(\u81f3\u5c11\u4e24\u6b21)\n[root@VM-4-10-centos ~]# cut -d: -f7 \/etc\/passwd | sort | uniq -d\n\/bin\/bash\n\/sbin\/nologin<\/code><\/pre>\n<h3>diff\u3001patch<\/h3>\n<p><code>diff -u<\/code>: \u4f7f\u7528unfled\u673a\u5236\uff0c\u5373\u663e\u793a\u8981\u4fee\u6539\u7684\u884c\u7684\u4e0a\u4e0b\u6587\uff0c\u9ed8\u8ba4\u4e3a3\u884c\uff1a<\/p>\n<p><code>patch \/PATH\/TO\/OLDFILE &lt;\/PATH\/TO\/PATCH_FILE<\/code><\/p>\n<pre><code class=\"language-bash\">[root@VM-4-10-centos ~]# cp \/etc\/fstab .\/fstab\n[root@VM-4-10-centos ~]# cp fstab fstab.new\n# \u4fee\u6539\u6587\u4ef6\uff0c\u7b2c\u4e00\u884c\u6539\u6210is new\n[root@VM-4-10-centos ~]# vim fstab.new\n# diff\u6bd4\u8f83\n[root@VM-4-10-centos ~]# diff fstab fstab.new\n2c2\n&lt; #\n---\n> # is new\n# \u751f\u6210\u8865\u4e01\u6587\u4ef6\n[root@VM-4-10-centos ~]# diff fstab fstab.new  &gt; fstab.patch\n# \u4f7f\u7528patch\u6253\u8865\u4e01\n[root@VM-4-10-centos ~]# patch -i fstab.patch fstab\npatching file fstab\n# \u6210\u4e86\n[root@VM-4-10-centos ~]# cat fstab\n\n# is new\n# \/etc\/fstab\n# Created by anaconda on Thu Mar  7 06:38:37 2019\n#\n# Accessible filesystems, by reference, are maintained under &#039;\/dev\/disk&#039;\n# See man pages fstab(5), findfs(8), mount(8) and\/or blkid(8) for more info\n#\nUUID=4b499d76-769a-40a0-93dc-4a31a59add28 \/                       ext4    defaults        1 1\n# \u9006\u5411\u8865\u4e01\u2014\u2014\u8fd8\u539f\n[root@VM-4-10-centos ~]# patch -R -i fstab.patch fstab\npatching file fstab\n[root@VM-4-10-centos ~]# cat fstab\n\n#\n# \/etc\/fstab\n# Created by anaconda on Thu Mar  7 06:38:37 2019\n#\n# Accessible filesystems, by reference, are maintained under &#039;\/dev\/disk&#039;\n# See man pages fstab(5), findfs(8), mount(8) and\/or blkid(8) for more info\n#\nUUID=4b499d76-769a-40a0-93dc-4a31a59add28 \/                       ext4    defaults        1 1\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5e38\u89c1\u5904\u7406\u5de5\u5177\uff1awc\u3001cut\u3001sort\u3001uniq\u3001diff\u3001patch wc word count\u5355\u8bcd\u7edf\u8ba1 wc [OPTION]&#8230;    \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[131],"tags":[177,180,15,181,178,179,176],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/8801"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8801"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/8801\/revisions"}],"predecessor-version":[{"id":8802,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/8801\/revisions\/8802"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8801"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}