From 43cdc146ec86ebed6e35825522604cfe8dd236f6 Mon Sep 17 00:00:00 2001 From: Dable Lv Date: Sun, 4 Feb 2024 07:44:39 +0000 Subject: [PATCH] build:auto build and deploy --- docs/404.html | 6 +++--- .../builtin-builtin.html" | 6 +++--- .../command-builtin.html" | 6 +++--- .../declare-builtin.html" | 6 +++--- .../Shell\347\274\226\347\250\213/echo.html" | 6 +++--- .../enable-builtin.html" | 6 +++--- .../eval-builtin.html" | 6 +++--- .../exec-builtin.html" | 6 +++--- .../exit-builtin.html" | 6 +++--- .../expect.html" | 6 +++--- .../Shell\347\274\226\347\250\213/expr.html" | 6 +++--- .../let-builtin.html" | 6 +++--- .../printf.html" | 6 +++--- .../read-builtin.html" | 6 +++--- .../readonly-builtin.html" | 6 +++--- .../set-builtin.html" | 6 +++--- .../Shell\347\274\226\347\250\213/sleep.html" | 6 +++--- .../Shell\347\274\226\347\250\213/test.html" | 6 +++--- .../unset-builtin.html" | 6 +++--- .../wait-builtin.html" | 6 +++--- .../js/{101.c6b7074f.js => 101.e3f08fe5.js} | 2 +- .../js/{102.8031f6b0.js => 102.82e6bf65.js} | 2 +- .../js/{103.fe85cafb.js => 103.b830131b.js} | 2 +- .../js/{104.57b2416a.js => 104.32749cf1.js} | 2 +- .../js/{105.e078ce62.js => 105.2128987a.js} | 2 +- .../js/{108.7cd1f2d6.js => 108.f9ff02e0.js} | 2 +- .../js/{109.8164b26e.js => 109.6ccc99d7.js} | 2 +- .../js/{11.7412dbb5.js => 11.5f249f03.js} | 2 +- .../js/{110.06601f98.js => 110.b21b7308.js} | 2 +- .../js/{112.db15a109.js => 112.dfd0e3de.js} | 2 +- .../js/{114.70e69f22.js => 114.d6b3030d.js} | 2 +- .../js/{115.e6b44866.js => 115.4a46dbdc.js} | 2 +- .../js/{117.5bf674e0.js => 117.e03507a1.js} | 2 +- .../js/{118.a163d30a.js => 118.76493d64.js} | 2 +- .../js/{12.a41deb34.js => 12.108d7764.js} | 2 +- .../js/{120.aa7bde68.js => 120.4ccea9a8.js} | 2 +- .../js/{121.4da0a457.js => 121.2cc770c1.js} | 2 +- .../js/{122.05bd848b.js => 122.cc695705.js} | 2 +- .../js/{123.06a1a423.js => 123.4a43f0a6.js} | 2 +- .../js/{124.15db04e3.js => 124.15286044.js} | 2 +- .../js/{125.65fa3d3b.js => 125.dae362bc.js} | 2 +- .../js/{126.f92f3a36.js => 126.25f9c22e.js} | 2 +- .../js/{127.93f65539.js => 127.1ede57c6.js} | 2 +- .../js/{128.05bf72b6.js => 128.a9e3863d.js} | 2 +- .../js/{129.f9495992.js => 129.fda77f12.js} | 2 +- .../js/{130.75667145.js => 130.5496fa86.js} | 2 +- .../js/{131.8450cab7.js => 131.cc21dc48.js} | 2 +- .../js/{133.bace3ca3.js => 133.8a8dfb99.js} | 2 +- .../js/{134.10ea39ce.js => 134.9fa951a4.js} | 2 +- .../js/{135.e22176d1.js => 135.494e2786.js} | 2 +- .../js/{136.43aeda3b.js => 136.a86e4246.js} | 2 +- .../js/{137.5c4aa035.js => 137.846df3d9.js} | 2 +- .../js/{138.5589ca34.js => 138.ff2bcc5b.js} | 2 +- .../js/{139.4b5140ac.js => 139.b59d345e.js} | 2 +- .../js/{14.245e8c8c.js => 14.d33ddaf5.js} | 2 +- .../js/{140.e405a89e.js => 140.cac581cd.js} | 2 +- .../js/{141.b15c1fd4.js => 141.e5a8f71e.js} | 2 +- .../js/{142.89f0916e.js => 142.658ca8d7.js} | 2 +- .../js/{143.72bd88d7.js => 143.f790b313.js} | 2 +- .../js/{144.6ed48227.js => 144.7ad6227b.js} | 2 +- .../js/{145.8eddf90e.js => 145.e5347c51.js} | 2 +- .../js/{146.5be02a31.js => 146.ad8248af.js} | 2 +- .../js/{147.7649e895.js => 147.4861d28f.js} | 2 +- .../js/{148.f17bd9ae.js => 148.88d4453e.js} | 2 +- .../js/{15.00908673.js => 15.58042256.js} | 2 +- .../js/{150.6330a13d.js => 150.1f8cacf9.js} | 2 +- .../js/{151.ff7359bc.js => 151.227dfadb.js} | 2 +- .../js/{152.c12ae871.js => 152.2883f187.js} | 2 +- .../js/{153.d1e8ca3d.js => 153.42be52cc.js} | 2 +- .../js/{154.c8a07357.js => 154.949467b1.js} | 2 +- .../js/{155.1d74673f.js => 155.c1ee65c9.js} | 2 +- .../js/{156.00fb9a39.js => 156.beac7a1d.js} | 2 +- .../js/{157.3d53a780.js => 157.bcf56347.js} | 2 +- .../js/{158.62908fff.js => 158.76e6aaf3.js} | 2 +- .../js/{159.3d0e78f0.js => 159.4e0ef843.js} | 2 +- .../js/{160.b2a5ea7e.js => 160.3405e15e.js} | 2 +- .../js/{161.95827d38.js => 161.fe04d002.js} | 2 +- .../js/{162.4aa893b5.js => 162.e9e756cf.js} | 2 +- .../js/{163.8cf6b69e.js => 163.b730c08e.js} | 2 +- .../js/{164.b6e2642b.js => 164.542ecdf8.js} | 2 +- .../js/{165.b3460049.js => 165.f1433774.js} | 2 +- .../js/{166.80721841.js => 166.b0cec3f0.js} | 2 +- .../js/{167.7533d9f4.js => 167.8ba46445.js} | 2 +- .../js/{168.3d18e4f1.js => 168.ddf5b54f.js} | 2 +- .../js/{169.45554edd.js => 169.945c7b44.js} | 2 +- .../js/{170.b6fd8b8d.js => 170.111579b3.js} | 2 +- .../js/{171.e7fa6d1a.js => 171.e03333bf.js} | 2 +- .../js/{172.19043aa9.js => 172.2156a68f.js} | 2 +- .../js/{173.af4b63d9.js => 173.1937de43.js} | 2 +- .../js/{174.0a4174df.js => 174.ef4080da.js} | 2 +- .../js/{175.30cec117.js => 175.36311e46.js} | 2 +- .../js/{177.ca6ee119.js => 177.ac259fc9.js} | 2 +- .../js/{178.f763fab0.js => 178.9861f609.js} | 2 +- .../js/{179.48b2b8c7.js => 179.b26d696b.js} | 2 +- .../js/{18.16144ec2.js => 18.bab17c91.js} | 2 +- .../js/{180.e849dadd.js => 180.adb8ac22.js} | 2 +- .../js/{181.f506915f.js => 181.03cd8792.js} | 2 +- .../js/{182.ac8e41d7.js => 182.bf17fea9.js} | 2 +- .../js/{183.12a218e2.js => 183.7ad98d2d.js} | 2 +- .../js/{185.12ec503e.js => 185.fdf1285a.js} | 2 +- .../js/{186.a4b737e3.js => 186.749bf835.js} | 2 +- .../js/{187.81b2f311.js => 187.0adb8875.js} | 2 +- .../js/{188.215e8f15.js => 188.5a33dbbb.js} | 2 +- .../js/{189.4ff8fbf6.js => 189.2152f353.js} | 2 +- .../js/{19.f0f6febd.js => 19.1aaace09.js} | 2 +- .../js/{190.12e51b00.js => 190.b26a3fdd.js} | 2 +- .../js/{191.d61aafd1.js => 191.1007038f.js} | 2 +- .../js/{192.7fe0a5e6.js => 192.aa45a0b9.js} | 2 +- .../js/{193.d7fb4d11.js => 193.7a1b6a2e.js} | 2 +- .../js/{194.607980a6.js => 194.e70235a5.js} | 2 +- .../js/{195.016923fc.js => 195.95858df9.js} | 2 +- .../js/{196.03161d98.js => 196.1744887c.js} | 2 +- .../js/{197.f1fdc0c8.js => 197.51b463bc.js} | 2 +- .../js/{198.f3033c16.js => 198.cd86e035.js} | 2 +- .../js/{199.f6eccf3a.js => 199.1db49dd5.js} | 2 +- .../js/{200.307029a9.js => 200.5cf250fa.js} | 2 +- .../js/{201.98913093.js => 201.cd29885f.js} | 2 +- .../js/{202.b8b71d45.js => 202.245afbe9.js} | 2 +- .../js/{203.452a1bc2.js => 203.f934b74f.js} | 2 +- .../js/{204.5a138925.js => 204.a7c57ccc.js} | 2 +- .../js/{205.4d869a88.js => 205.5f7b3589.js} | 2 +- .../js/{206.8f2781dc.js => 206.c6907cd8.js} | 2 +- .../js/{207.041d8c24.js => 207.8a844aa7.js} | 2 +- .../js/{208.bea3ba74.js => 208.37dc8fe5.js} | 2 +- .../js/{209.dd81737d.js => 209.ee7aad55.js} | 2 +- .../js/{210.945b5191.js => 210.f26fb307.js} | 2 +- .../js/{211.324d3789.js => 211.1a4ee6fd.js} | 2 +- .../js/{212.d42332b0.js => 212.1ce63983.js} | 2 +- .../js/{213.34677472.js => 213.4f2ad89a.js} | 2 +- .../js/{214.1a2aa706.js => 214.ea2c243f.js} | 2 +- .../js/{215.24f9f8a9.js => 215.e4bf8d07.js} | 2 +- .../js/{218.247dffe2.js => 218.df2c14dc.js} | 2 +- .../js/{219.a63573f3.js => 219.18cd25f7.js} | 2 +- .../js/{220.1555ef65.js => 220.1e01caf3.js} | 2 +- .../js/{221.5c84c83a.js => 221.0ae60e88.js} | 2 +- .../js/{222.aa522974.js => 222.b7d59833.js} | 2 +- .../js/{223.79a0d911.js => 223.41331d25.js} | 2 +- .../js/{224.2bfc55a1.js => 224.ca15627f.js} | 2 +- .../js/{226.48f8a657.js => 226.7b4b577d.js} | 2 +- .../js/{227.ac526873.js => 227.766199c0.js} | 2 +- .../js/{228.1440a6b3.js => 228.05476d16.js} | 2 +- .../js/{229.3ac86fdb.js => 229.7776ef9a.js} | 2 +- .../js/{23.ab73c4d2.js => 23.70091262.js} | 2 +- .../js/{230.a32a74b0.js => 230.02e3ede4.js} | 2 +- .../js/{231.db290e3a.js => 231.800cea6b.js} | 2 +- .../js/{232.4475b7b7.js => 232.e9eb7c04.js} | 2 +- .../js/{233.4b8cce9b.js => 233.10a57554.js} | 2 +- .../js/{234.3c31a015.js => 234.890837b0.js} | 2 +- .../js/{235.a3d5ad49.js => 235.6a778ee4.js} | 2 +- .../js/{236.352e4073.js => 236.985b6840.js} | 2 +- .../js/{237.9803d8c6.js => 237.16386195.js} | 2 +- .../js/{238.5f39da1b.js => 238.52f8a14e.js} | 2 +- .../js/{239.d9cc10eb.js => 239.581e8a71.js} | 2 +- .../js/{24.0ac25ca6.js => 24.17e82bd9.js} | 2 +- .../js/{240.65728a11.js => 240.5c947fd3.js} | 2 +- .../js/{241.cd4a0baa.js => 241.85896648.js} | 2 +- .../js/{242.812244c1.js => 242.3bd75067.js} | 2 +- .../js/{243.2148efe4.js => 243.06b2198f.js} | 2 +- .../js/{245.dbdd2efc.js => 245.540385a8.js} | 2 +- .../js/{246.1c82f11b.js => 246.238b6bcf.js} | 2 +- .../js/{247.55fbf168.js => 247.a117184e.js} | 2 +- .../js/{250.fee94e23.js => 250.44940566.js} | 2 +- .../js/{253.85c32b1f.js => 253.5ace4a05.js} | 2 +- .../js/{254.055be0ac.js => 254.30797f36.js} | 2 +- .../js/{255.64273cc6.js => 255.d1b5773d.js} | 2 +- .../js/{256.7cd84114.js => 256.b27ffca2.js} | 2 +- .../js/{262.54239bc5.js => 262.2202bb04.js} | 2 +- .../js/{263.4ecc8054.js => 263.a9cd62cf.js} | 2 +- .../js/{266.e29ee88f.js => 266.e809fbca.js} | 2 +- .../js/{269.90b9b3f2.js => 269.837216a0.js} | 2 +- .../js/{28.eeeb2543.js => 28.0af33d1f.js} | 2 +- .../js/{29.f4580880.js => 29.4e5c4127.js} | 2 +- .../js/{3.7cb603f3.js => 3.5c1aba3c.js} | 2 +- .../js/{34.d7496255.js => 34.34b08198.js} | 2 +- .../js/{35.f94fbb4a.js => 35.0cff0ed8.js} | 2 +- .../js/{38.b36109f6.js => 38.975c385a.js} | 2 +- .../js/{40.6e62f88e.js => 40.dce5e506.js} | 2 +- .../js/{41.4470f69f.js => 41.0ff5d2fd.js} | 2 +- .../js/{42.88b6da06.js => 42.11fcc678.js} | 2 +- .../js/{46.f4a6a2ac.js => 46.a3b08735.js} | 2 +- .../js/{47.3fd19f8b.js => 47.abc5fa62.js} | 2 +- .../js/{50.e7d5dd4c.js => 50.ba6f1f61.js} | 2 +- .../js/{51.eba08463.js => 51.7caf0e6a.js} | 2 +- .../js/{52.baaf589b.js => 52.18e82357.js} | 2 +- .../js/{57.888a1255.js => 57.82912fa5.js} | 2 +- .../js/{58.96ed9197.js => 58.0040f6ff.js} | 2 +- .../js/{59.cf5efa9a.js => 59.ee42b23e.js} | 2 +- .../js/{60.98f10b81.js => 60.83aca878.js} | 2 +- .../js/{61.f0fb7504.js => 61.d292edc3.js} | 2 +- .../js/{62.e3e0d9fb.js => 62.1f4fe19c.js} | 2 +- .../js/{64.82a9cdc4.js => 64.117c6ec8.js} | 2 +- .../js/{65.76052c7c.js => 65.70fe6b66.js} | 2 +- .../js/{66.0ba5722f.js => 66.05ed3522.js} | 2 +- .../js/{71.c39ab5b0.js => 71.540bdbe5.js} | 2 +- .../js/{72.226d7dff.js => 72.47b1aa69.js} | 2 +- .../js/{73.21b2c5ff.js => 73.5991c526.js} | 2 +- .../js/{74.94e59b55.js => 74.cf09e241.js} | 2 +- .../js/{75.53b3a7cf.js => 75.cb07ea91.js} | 2 +- .../js/{78.4adb7027.js => 78.692cbe69.js} | 2 +- .../js/{79.99796167.js => 79.cf19e153.js} | 2 +- .../js/{83.07a9f040.js => 83.dc0d22be.js} | 2 +- .../js/{84.95b59f7c.js => 84.39ae4a57.js} | 2 +- .../js/{85.4ce5292e.js => 85.efc677c2.js} | 2 +- docs/assets/js/93.403da20b.js | 1 - docs/assets/js/93.f546f369.js | 1 + .../js/{94.b59bd6db.js => 94.aae6ca2b.js} | 2 +- .../js/{97.39e416f8.js => 97.2ce7ff96.js} | 2 +- .../js/{98.14e263df.js => 98.d0699989.js} | 2 +- .../js/{99.4f69f251.js => 99.33e0d46e.js} | 2 +- .../js/{app.26fafec0.js => app.b3191c1a.js} | 10 +++++----- docs/index.html | 6 +++--- .../c++filt.html" | 6 +++--- .../hexdump.html" | 6 +++--- .../nm.html" | 6 +++--- .../objcopy.html" | 6 +++--- .../objdump.html" | 6 +++--- .../od.html" | 6 +++--- .../readelf.html" | 6 +++--- .../size.html" | 6 +++--- .../strings.html" | 6 +++--- .../strip.html" | 6 +++--- .../alias-builtin.html" | 6 +++--- .../bc.html" | 6 +++--- .../cal.html" | 6 +++--- .../date.html" | 6 +++--- .../fc-builtin.html" | 6 +++--- .../history-builtin.html" | 6 +++--- .../ln.html" | 6 +++--- .../seq.html" | 6 +++--- .../type-builtin.html" | 6 +++--- .../unalias-builtin.html" | 6 +++--- .../yes.html" | 6 +++--- .../help-builtin.html" | 6 +++--- "docs/\345\270\256\345\212\251/info.html" | 6 +++--- "docs/\345\270\256\345\212\251/man.html" | 6 +++--- "docs/\345\270\256\345\212\251/whatis.html" | 6 +++--- .../bunzip2.html" | 6 +++--- .../bzip2.html" | 6 +++--- .../bzip2recover.html" | 6 +++--- .../gunzip.html" | 6 +++--- .../gzip.html" | 6 +++--- .../tar.html" | 6 +++--- .../unzip.html" | 6 +++--- .../zip.html" | 6 +++--- .../zipinfo.html" | 6 +++--- .../basename.html" | 6 +++--- .../cksum.html" | 6 +++--- .../diff.html" | 6 +++--- .../dir.html" | 6 +++--- .../dirname.html" | 6 +++--- .../dirs-builtin.html" | 6 +++--- .../file.html" | 6 +++--- .../ls.html" | 6 +++--- .../md5sum.html" | 6 +++--- .../pwd.html" | 6 +++--- .../realpath.html" | 6 +++--- .../sha1sum.html" | 6 +++--- .../stat.html" | 6 +++--- .../sum.html" | 6 +++--- .../tree.html" | 6 +++--- .../cd-builtin.html" | 6 +++--- .../cp.html" | 6 +++--- .../mkdir.html" | 6 +++--- .../mktemp.html" | 6 +++--- .../mv.html" | 6 +++--- .../rename.html" | 6 +++--- .../rm.html" | 6 +++--- .../rmdir.html" | 6 +++--- .../split.html" | 6 +++--- .../tee.html" | 6 +++--- .../touch.html" | 6 +++--- .../truncate.html" | 6 +++--- .../find.html" | 6 +++--- .../locate.html" | 6 +++--- .../whereis.html" | 6 +++--- .../which.html" | 6 +++--- .../cat.html" | 20 +++++++++---------- .../grep.html" | 6 +++--- .../head.html" | 6 +++--- .../less.html" | 6 +++--- .../more.html" | 6 +++--- .../nl.html" | 6 +++--- .../rev.html" | 6 +++--- .../tac.html" | 6 +++--- .../tail.html" | 6 +++--- .../wc.html" | 6 +++--- .../awk.html" | 6 +++--- .../col.html" | 6 +++--- .../cut.html" | 6 +++--- .../expand.html" | 6 +++--- .../iconv.html" | 6 +++--- .../indent.html" | 6 +++--- .../join.html" | 6 +++--- .../paste.html" | 6 +++--- .../sed.html" | 6 +++--- .../sort.html" | 6 +++--- .../tr.html" | 6 +++--- .../uniq.html" | 6 +++--- .../vim.html" | 6 +++--- .../df.html" | 6 +++--- .../du.html" | 6 +++--- .../fdisk.html" | 6 +++--- .../chattr.html" | 6 +++--- .../chgrp.html" | 6 +++--- .../chmod.html" | 6 +++--- .../chown.html" | 6 +++--- .../getfacl.html" | 6 +++--- .../lsattr.html" | 6 +++--- .../setfacl.html" | 6 +++--- .../su.html" | 6 +++--- .../sudo.html" | 6 +++--- .../umask-builtin.html" | 6 +++--- .../visudo.html" | 6 +++--- .../ac.html" | 6 +++--- .../adduser.html" | 6 +++--- .../chage.html" | 6 +++--- .../id.html" | 6 +++--- .../last.html" | 6 +++--- .../lastb.html" | 6 +++--- .../lastlog.html" | 6 +++--- .../logname.html" | 6 +++--- .../passwd.html" | 6 +++--- .../useradd.html" | 6 +++--- .../userdel.html" | 6 +++--- .../usermod.html" | 6 +++--- .../users.html" | 6 +++--- .../w.html" | 6 +++--- .../who.html" | 6 +++--- .../whoami.html" | 6 +++--- .../gpasswd.html" | 6 +++--- .../groupadd.html" | 6 +++--- .../groupdel.html" | 6 +++--- .../groupmod.html" | 6 +++--- .../groups.html" | 6 +++--- .../newgrp.html" | 6 +++--- .../git.html" | 6 +++--- .../svn.html" | 6 +++--- .../chkconfig.html" | 6 +++--- .../export-builtin.html" | 6 +++--- .../halt.html" | 6 +++--- .../init.html" | 6 +++--- .../ntsysv.html" | 6 +++--- .../poweroff.html" | 6 +++--- .../reboot.html" | 6 +++--- .../runlevel.html" | 6 +++--- .../service.html" | 6 +++--- .../shutdown.html" | 6 +++--- .../systemctl.html" | 6 +++--- .../dmesg.html" | 6 +++--- .../dnsdomainname.html" | 6 +++--- .../domainname.html" | 6 +++--- .../env.html" | 6 +++--- .../free.html" | 6 +++--- .../hostid.html" | 6 +++--- .../hostname.html" | 6 +++--- .../lscpu.html" | 6 +++--- .../uname.html" | 6 +++--- .../uptime.html" | 6 +++--- .../mandb.html" | 6 +++--- .../updatedb.html" | 6 +++--- .../bind-builtin.html" | 6 +++--- .../consoletype.html" | 6 +++--- .../ctrlaltdel.html" | 6 +++--- .../reset.html" | 6 +++--- .../shopt-builtin.html" | 6 +++--- .../stty.html" | 6 +++--- .../tput.html" | 6 +++--- .../tty.html" | 6 +++--- .../ar.html" | 6 +++--- .../as.html" | 6 +++--- .../g++.html" | 6 +++--- .../gdb.html" | 6 +++--- .../ld.html" | 6 +++--- .../ldconfig.html" | 6 +++--- .../ldd.html" | 6 +++--- .../curl.html" | 6 +++--- .../ftp.html" | 6 +++--- .../rz.html" | 6 +++--- .../scp.html" | 6 +++--- .../sz.html" | 6 +++--- .../wget.html" | 6 +++--- .../arp.html" | 6 +++--- .../arpd.html" | 6 +++--- .../arping.html" | 6 +++--- .../arpwatch.html" | 6 +++--- .../dhclient.html" | 6 +++--- .../dig.html" | 6 +++--- .../ethtool.html" | 6 +++--- .../host.html" | 6 +++--- .../ifcfg.html" | 6 +++--- .../ifconfig.html" | 6 +++--- .../ifdown.html" | 6 +++--- .../ifup.html" | 6 +++--- .../ip.html" | 6 +++--- .../ipcalc.html" | 6 +++--- .../iptables-restore.html" | 6 +++--- .../iptables-save.html" | 6 +++--- .../iptables.html" | 6 +++--- .../lnstat.html" | 6 +++--- .../mii-tool.html" | 6 +++--- .../ncat.html" | 6 +++--- .../netstat.html" | 6 +++--- .../nmap.html" | 6 +++--- .../nslookup.html" | 6 +++--- .../nstat.html" | 6 +++--- .../ping.html" | 6 +++--- .../route.html" | 6 +++--- .../ss.html" | 6 +++--- .../tcpdump.html" | 6 +++--- .../tracepath.html" | 6 +++--- .../traceroute.html" | 6 +++--- .../usernetctl.html" | 6 +++--- .../ssh-add.html" | 6 +++--- .../ssh-agent.html" | 6 +++--- .../ssh-copy-id.html" | 6 +++--- .../ssh-keygen.html" | 6 +++--- .../ssh-keyscan.html" | 6 +++--- .../ssh.html" | 6 +++--- .../sshd.html" | 6 +++--- .../telnet.html" | 6 +++--- .../iostat.html" | 6 +++--- .../lsof.html" | 6 +++--- .../top.html" | 6 +++--- .../valgrind.html" | 6 +++--- .../vmstat.html" | 6 +++--- .../at.html" | 6 +++--- .../atq.html" | 6 +++--- .../atrm.html" | 6 +++--- .../batch.html" | 6 +++--- .../bg-builtin.html" | 6 +++--- .../crontab.html" | 6 +++--- .../fg-builtin.html" | 6 +++--- .../ipcrm.html" | 6 +++--- .../ipcs.html" | 6 +++--- .../jobs-builtin.html" | 6 +++--- .../kill.html" | 6 +++--- .../killall.html" | 6 +++--- .../nice.html" | 6 +++--- .../nohup.html" | 6 +++--- .../pkill.html" | 6 +++--- .../renice.html" | 6 +++--- .../screen.html" | 6 +++--- .../skill.html" | 6 +++--- .../time.html" | 6 +++--- .../trap-builtin.html" | 6 +++--- .../ulimit-builtin.html" | 6 +++--- .../watch.html" | 6 +++--- .../xargs.html" | 6 +++--- .../pgrep.html" | 6 +++--- .../pidof.html" | 6 +++--- .../pmap.html" | 6 +++--- .../ps.html" | 6 +++--- .../pstack.html" | 6 +++--- .../pstree.html" | 6 +++--- .../strace.html" | 6 +++--- 455 files changed, 995 insertions(+), 995 deletions(-) rename docs/assets/js/{101.c6b7074f.js => 101.e3f08fe5.js} (99%) rename docs/assets/js/{102.8031f6b0.js => 102.82e6bf65.js} (99%) rename docs/assets/js/{103.fe85cafb.js => 103.b830131b.js} (99%) rename docs/assets/js/{104.57b2416a.js => 104.32749cf1.js} (98%) rename docs/assets/js/{105.e078ce62.js => 105.2128987a.js} (98%) rename docs/assets/js/{108.7cd1f2d6.js => 108.f9ff02e0.js} (98%) rename docs/assets/js/{109.8164b26e.js => 109.6ccc99d7.js} (98%) rename docs/assets/js/{11.7412dbb5.js => 11.5f249f03.js} (99%) rename docs/assets/js/{110.06601f98.js => 110.b21b7308.js} (99%) rename docs/assets/js/{112.db15a109.js => 112.dfd0e3de.js} (99%) rename docs/assets/js/{114.70e69f22.js => 114.d6b3030d.js} (99%) rename docs/assets/js/{115.e6b44866.js => 115.4a46dbdc.js} (99%) rename docs/assets/js/{117.5bf674e0.js => 117.e03507a1.js} (99%) rename docs/assets/js/{118.a163d30a.js => 118.76493d64.js} (99%) rename docs/assets/js/{12.a41deb34.js => 12.108d7764.js} (99%) rename docs/assets/js/{120.aa7bde68.js => 120.4ccea9a8.js} (99%) rename docs/assets/js/{121.4da0a457.js => 121.2cc770c1.js} (99%) rename docs/assets/js/{122.05bd848b.js => 122.cc695705.js} (99%) rename docs/assets/js/{123.06a1a423.js => 123.4a43f0a6.js} (97%) rename docs/assets/js/{124.15db04e3.js => 124.15286044.js} (99%) rename docs/assets/js/{125.65fa3d3b.js => 125.dae362bc.js} (98%) rename docs/assets/js/{126.f92f3a36.js => 126.25f9c22e.js} (99%) rename docs/assets/js/{127.93f65539.js => 127.1ede57c6.js} (98%) rename docs/assets/js/{128.05bf72b6.js => 128.a9e3863d.js} (99%) rename docs/assets/js/{129.f9495992.js => 129.fda77f12.js} (99%) rename docs/assets/js/{130.75667145.js => 130.5496fa86.js} (99%) rename docs/assets/js/{131.8450cab7.js => 131.cc21dc48.js} (99%) rename docs/assets/js/{133.bace3ca3.js => 133.8a8dfb99.js} (99%) rename docs/assets/js/{134.10ea39ce.js => 134.9fa951a4.js} (99%) rename docs/assets/js/{135.e22176d1.js => 135.494e2786.js} (99%) rename docs/assets/js/{136.43aeda3b.js => 136.a86e4246.js} (96%) rename docs/assets/js/{137.5c4aa035.js => 137.846df3d9.js} (98%) rename docs/assets/js/{138.5589ca34.js => 138.ff2bcc5b.js} (99%) rename docs/assets/js/{139.4b5140ac.js => 139.b59d345e.js} (98%) rename docs/assets/js/{14.245e8c8c.js => 14.d33ddaf5.js} (98%) rename docs/assets/js/{140.e405a89e.js => 140.cac581cd.js} (98%) rename docs/assets/js/{141.b15c1fd4.js => 141.e5a8f71e.js} (97%) rename docs/assets/js/{142.89f0916e.js => 142.658ca8d7.js} (99%) rename docs/assets/js/{143.72bd88d7.js => 143.f790b313.js} (99%) rename docs/assets/js/{144.6ed48227.js => 144.7ad6227b.js} (97%) rename docs/assets/js/{145.8eddf90e.js => 145.e5347c51.js} (98%) rename docs/assets/js/{146.5be02a31.js => 146.ad8248af.js} (98%) rename docs/assets/js/{147.7649e895.js => 147.4861d28f.js} (97%) rename docs/assets/js/{148.f17bd9ae.js => 148.88d4453e.js} (98%) rename docs/assets/js/{15.00908673.js => 15.58042256.js} (98%) rename docs/assets/js/{150.6330a13d.js => 150.1f8cacf9.js} (97%) rename docs/assets/js/{151.ff7359bc.js => 151.227dfadb.js} (99%) rename docs/assets/js/{152.c12ae871.js => 152.2883f187.js} (98%) rename docs/assets/js/{153.d1e8ca3d.js => 153.42be52cc.js} (99%) rename docs/assets/js/{154.c8a07357.js => 154.949467b1.js} (99%) rename docs/assets/js/{155.1d74673f.js => 155.c1ee65c9.js} (98%) rename docs/assets/js/{156.00fb9a39.js => 156.beac7a1d.js} (98%) rename docs/assets/js/{157.3d53a780.js => 157.bcf56347.js} (98%) rename docs/assets/js/{158.62908fff.js => 158.76e6aaf3.js} (98%) rename docs/assets/js/{159.3d0e78f0.js => 159.4e0ef843.js} (98%) rename docs/assets/js/{160.b2a5ea7e.js => 160.3405e15e.js} (98%) rename docs/assets/js/{161.95827d38.js => 161.fe04d002.js} (98%) rename docs/assets/js/{162.4aa893b5.js => 162.e9e756cf.js} (98%) rename docs/assets/js/{163.8cf6b69e.js => 163.b730c08e.js} (99%) rename docs/assets/js/{164.b6e2642b.js => 164.542ecdf8.js} (99%) rename docs/assets/js/{165.b3460049.js => 165.f1433774.js} (99%) rename docs/assets/js/{166.80721841.js => 166.b0cec3f0.js} (99%) rename docs/assets/js/{167.7533d9f4.js => 167.8ba46445.js} (99%) rename docs/assets/js/{168.3d18e4f1.js => 168.ddf5b54f.js} (99%) rename docs/assets/js/{169.45554edd.js => 169.945c7b44.js} (98%) rename docs/assets/js/{170.b6fd8b8d.js => 170.111579b3.js} (99%) rename docs/assets/js/{171.e7fa6d1a.js => 171.e03333bf.js} (99%) rename docs/assets/js/{172.19043aa9.js => 172.2156a68f.js} (98%) rename docs/assets/js/{173.af4b63d9.js => 173.1937de43.js} (99%) rename docs/assets/js/{174.0a4174df.js => 174.ef4080da.js} (99%) rename docs/assets/js/{175.30cec117.js => 175.36311e46.js} (98%) rename docs/assets/js/{177.ca6ee119.js => 177.ac259fc9.js} (98%) rename docs/assets/js/{178.f763fab0.js => 178.9861f609.js} (98%) rename docs/assets/js/{179.48b2b8c7.js => 179.b26d696b.js} (99%) rename docs/assets/js/{18.16144ec2.js => 18.bab17c91.js} (99%) rename docs/assets/js/{180.e849dadd.js => 180.adb8ac22.js} (99%) rename docs/assets/js/{181.f506915f.js => 181.03cd8792.js} (99%) rename docs/assets/js/{182.ac8e41d7.js => 182.bf17fea9.js} (99%) rename docs/assets/js/{183.12a218e2.js => 183.7ad98d2d.js} (98%) rename docs/assets/js/{185.12ec503e.js => 185.fdf1285a.js} (98%) rename docs/assets/js/{186.a4b737e3.js => 186.749bf835.js} (99%) rename docs/assets/js/{187.81b2f311.js => 187.0adb8875.js} (99%) rename docs/assets/js/{188.215e8f15.js => 188.5a33dbbb.js} (99%) rename docs/assets/js/{189.4ff8fbf6.js => 189.2152f353.js} (99%) rename docs/assets/js/{19.f0f6febd.js => 19.1aaace09.js} (99%) rename docs/assets/js/{190.12e51b00.js => 190.b26a3fdd.js} (99%) rename docs/assets/js/{191.d61aafd1.js => 191.1007038f.js} (99%) rename docs/assets/js/{192.7fe0a5e6.js => 192.aa45a0b9.js} (99%) rename docs/assets/js/{193.d7fb4d11.js => 193.7a1b6a2e.js} (98%) rename docs/assets/js/{194.607980a6.js => 194.e70235a5.js} (99%) rename docs/assets/js/{195.016923fc.js => 195.95858df9.js} (98%) rename docs/assets/js/{196.03161d98.js => 196.1744887c.js} (99%) rename docs/assets/js/{197.f1fdc0c8.js => 197.51b463bc.js} (99%) rename docs/assets/js/{198.f3033c16.js => 198.cd86e035.js} (99%) rename docs/assets/js/{199.f6eccf3a.js => 199.1db49dd5.js} (99%) rename docs/assets/js/{200.307029a9.js => 200.5cf250fa.js} (98%) rename docs/assets/js/{201.98913093.js => 201.cd29885f.js} (99%) rename docs/assets/js/{202.b8b71d45.js => 202.245afbe9.js} (99%) rename docs/assets/js/{203.452a1bc2.js => 203.f934b74f.js} (99%) rename docs/assets/js/{204.5a138925.js => 204.a7c57ccc.js} (99%) rename docs/assets/js/{205.4d869a88.js => 205.5f7b3589.js} (98%) rename docs/assets/js/{206.8f2781dc.js => 206.c6907cd8.js} (99%) rename docs/assets/js/{207.041d8c24.js => 207.8a844aa7.js} (97%) rename docs/assets/js/{208.bea3ba74.js => 208.37dc8fe5.js} (97%) rename docs/assets/js/{209.dd81737d.js => 209.ee7aad55.js} (99%) rename docs/assets/js/{210.945b5191.js => 210.f26fb307.js} (99%) rename docs/assets/js/{211.324d3789.js => 211.1a4ee6fd.js} (98%) rename docs/assets/js/{212.d42332b0.js => 212.1ce63983.js} (98%) rename docs/assets/js/{213.34677472.js => 213.4f2ad89a.js} (99%) rename docs/assets/js/{214.1a2aa706.js => 214.ea2c243f.js} (99%) rename docs/assets/js/{215.24f9f8a9.js => 215.e4bf8d07.js} (99%) rename docs/assets/js/{218.247dffe2.js => 218.df2c14dc.js} (99%) rename docs/assets/js/{219.a63573f3.js => 219.18cd25f7.js} (99%) rename docs/assets/js/{220.1555ef65.js => 220.1e01caf3.js} (99%) rename docs/assets/js/{221.5c84c83a.js => 221.0ae60e88.js} (99%) rename docs/assets/js/{222.aa522974.js => 222.b7d59833.js} (99%) rename docs/assets/js/{223.79a0d911.js => 223.41331d25.js} (99%) rename docs/assets/js/{224.2bfc55a1.js => 224.ca15627f.js} (99%) rename docs/assets/js/{226.48f8a657.js => 226.7b4b577d.js} (99%) rename docs/assets/js/{227.ac526873.js => 227.766199c0.js} (97%) rename docs/assets/js/{228.1440a6b3.js => 228.05476d16.js} (99%) rename docs/assets/js/{229.3ac86fdb.js => 229.7776ef9a.js} (99%) rename docs/assets/js/{23.ab73c4d2.js => 23.70091262.js} (99%) rename docs/assets/js/{230.a32a74b0.js => 230.02e3ede4.js} (98%) rename docs/assets/js/{231.db290e3a.js => 231.800cea6b.js} (99%) rename docs/assets/js/{232.4475b7b7.js => 232.e9eb7c04.js} (99%) rename docs/assets/js/{233.4b8cce9b.js => 233.10a57554.js} (99%) rename docs/assets/js/{234.3c31a015.js => 234.890837b0.js} (99%) rename docs/assets/js/{235.a3d5ad49.js => 235.6a778ee4.js} (99%) rename docs/assets/js/{236.352e4073.js => 236.985b6840.js} (99%) rename docs/assets/js/{237.9803d8c6.js => 237.16386195.js} (99%) rename docs/assets/js/{238.5f39da1b.js => 238.52f8a14e.js} (99%) rename docs/assets/js/{239.d9cc10eb.js => 239.581e8a71.js} (99%) rename docs/assets/js/{24.0ac25ca6.js => 24.17e82bd9.js} (99%) rename docs/assets/js/{240.65728a11.js => 240.5c947fd3.js} (99%) rename docs/assets/js/{241.cd4a0baa.js => 241.85896648.js} (99%) rename docs/assets/js/{242.812244c1.js => 242.3bd75067.js} (98%) rename docs/assets/js/{243.2148efe4.js => 243.06b2198f.js} (97%) rename docs/assets/js/{245.dbdd2efc.js => 245.540385a8.js} (99%) rename docs/assets/js/{246.1c82f11b.js => 246.238b6bcf.js} (99%) rename docs/assets/js/{247.55fbf168.js => 247.a117184e.js} (98%) rename docs/assets/js/{250.fee94e23.js => 250.44940566.js} (99%) rename docs/assets/js/{253.85c32b1f.js => 253.5ace4a05.js} (99%) rename docs/assets/js/{254.055be0ac.js => 254.30797f36.js} (98%) rename docs/assets/js/{255.64273cc6.js => 255.d1b5773d.js} (99%) rename docs/assets/js/{256.7cd84114.js => 256.b27ffca2.js} (98%) rename docs/assets/js/{262.54239bc5.js => 262.2202bb04.js} (98%) rename docs/assets/js/{263.4ecc8054.js => 263.a9cd62cf.js} (99%) rename docs/assets/js/{266.e29ee88f.js => 266.e809fbca.js} (99%) rename docs/assets/js/{269.90b9b3f2.js => 269.837216a0.js} (99%) rename docs/assets/js/{28.eeeb2543.js => 28.0af33d1f.js} (99%) rename docs/assets/js/{29.f4580880.js => 29.4e5c4127.js} (99%) rename docs/assets/js/{3.7cb603f3.js => 3.5c1aba3c.js} (99%) rename docs/assets/js/{34.d7496255.js => 34.34b08198.js} (99%) rename docs/assets/js/{35.f94fbb4a.js => 35.0cff0ed8.js} (98%) rename docs/assets/js/{38.b36109f6.js => 38.975c385a.js} (98%) rename docs/assets/js/{40.6e62f88e.js => 40.dce5e506.js} (98%) rename docs/assets/js/{41.4470f69f.js => 41.0ff5d2fd.js} (99%) rename docs/assets/js/{42.88b6da06.js => 42.11fcc678.js} (99%) rename docs/assets/js/{46.f4a6a2ac.js => 46.a3b08735.js} (99%) rename docs/assets/js/{47.3fd19f8b.js => 47.abc5fa62.js} (97%) rename docs/assets/js/{50.e7d5dd4c.js => 50.ba6f1f61.js} (99%) rename docs/assets/js/{51.eba08463.js => 51.7caf0e6a.js} (99%) rename docs/assets/js/{52.baaf589b.js => 52.18e82357.js} (99%) rename docs/assets/js/{57.888a1255.js => 57.82912fa5.js} (99%) rename docs/assets/js/{58.96ed9197.js => 58.0040f6ff.js} (98%) rename docs/assets/js/{59.cf5efa9a.js => 59.ee42b23e.js} (99%) rename docs/assets/js/{60.98f10b81.js => 60.83aca878.js} (99%) rename docs/assets/js/{61.f0fb7504.js => 61.d292edc3.js} (99%) rename docs/assets/js/{62.e3e0d9fb.js => 62.1f4fe19c.js} (98%) rename docs/assets/js/{64.82a9cdc4.js => 64.117c6ec8.js} (99%) rename docs/assets/js/{65.76052c7c.js => 65.70fe6b66.js} (99%) rename docs/assets/js/{66.0ba5722f.js => 66.05ed3522.js} (98%) rename docs/assets/js/{71.c39ab5b0.js => 71.540bdbe5.js} (99%) rename docs/assets/js/{72.226d7dff.js => 72.47b1aa69.js} (98%) rename docs/assets/js/{73.21b2c5ff.js => 73.5991c526.js} (99%) rename docs/assets/js/{74.94e59b55.js => 74.cf09e241.js} (99%) rename docs/assets/js/{75.53b3a7cf.js => 75.cb07ea91.js} (98%) rename docs/assets/js/{78.4adb7027.js => 78.692cbe69.js} (99%) rename docs/assets/js/{79.99796167.js => 79.cf19e153.js} (98%) rename docs/assets/js/{83.07a9f040.js => 83.dc0d22be.js} (99%) rename docs/assets/js/{84.95b59f7c.js => 84.39ae4a57.js} (97%) rename docs/assets/js/{85.4ce5292e.js => 85.efc677c2.js} (98%) delete mode 100644 docs/assets/js/93.403da20b.js create mode 100644 docs/assets/js/93.f546f369.js rename docs/assets/js/{94.b59bd6db.js => 94.aae6ca2b.js} (99%) rename docs/assets/js/{97.39e416f8.js => 97.2ce7ff96.js} (99%) rename docs/assets/js/{98.14e263df.js => 98.d0699989.js} (99%) rename docs/assets/js/{99.4f69f251.js => 99.33e0d46e.js} (98%) rename docs/assets/js/{app.26fafec0.js => app.b3191c1a.js} (59%) diff --git a/docs/404.html b/docs/404.html index ea7c242c3..a76c7d0b7 100644 --- a/docs/404.html +++ b/docs/404.html @@ -9,13 +9,13 @@ - + -

404

There's nothing here.
+ - + diff --git "a/docs/Shell\347\274\226\347\250\213/builtin-builtin.html" "b/docs/Shell\347\274\226\347\250\213/builtin-builtin.html" index 02338f449..072b39ee5 100644 --- "a/docs/Shell\347\274\226\347\250\213/builtin-builtin.html" +++ "b/docs/Shell\347\274\226\347\250\213/builtin-builtin.html" @@ -9,7 +9,7 @@ - + @@ -64,7 +64,7 @@ This is umask function

要想执行内置命令 umask,可以使用 builtin。

builtin umask
 0002
-

# 参考文献

builtin(1) - Linux manual page - linux.org (opens new window)

Last Updated: 1/31/2024, 12:50:12 PM

# 参考文献

builtin(1) - Linux manual page - linux.org (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/command-builtin.html" "b/docs/Shell\347\274\226\347\250\213/command-builtin.html" index a74fcc92d..6ce339d33 100644 --- "a/docs/Shell\347\274\226\347\250\213/command-builtin.html" +++ "b/docs/Shell\347\274\226\347\250\213/command-builtin.html" @@ -9,7 +9,7 @@ - + @@ -55,7 +55,7 @@ pwd

(3)查看命令的类型。

command -V pwd
 pwd is a shell builtin
-

# 参考文献

command(1) - Linux manual page - linux.org (opens new window)


# 参考文献

command(1) - Linux manual page - linux.org (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/declare-builtin.html" "b/docs/Shell\347\274\226\347\250\213/declare-builtin.html" index 607ca1be1..8a4cdf996 100644 --- "a/docs/Shell\347\274\226\347\250\213/declare-builtin.html" +++ "b/docs/Shell\347\274\226\347\250\213/declare-builtin.html" @@ -9,7 +9,7 @@ - + @@ -102,7 +102,7 @@

(5)显示所有 Shell 环境变量。

declare -x
 

(6)使用+x选项取消变量为环境变量。

delcare +x name1
 

(7)申明整型变量,赋值浮点型数值将报错。

declare -i integer=666
-

# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

declare(1) manual - linux.org (opens new window)

Shell数组与关联数组 (opens new window)

Linux指令范例速查手册.马玉军.北京:科学出版社,2008.P178-P183


# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

declare(1) manual - linux.org (opens new window)

Shell数组与关联数组 (opens new window)

Linux指令范例速查手册.马玉军.北京:科学出版社,2008.P178-P183

- + diff --git "a/docs/Shell\347\274\226\347\250\213/echo.html" "b/docs/Shell\347\274\226\347\250\213/echo.html" index 97dc6d251..205a1a725 100644 --- "a/docs/Shell\347\274\226\347\250\213/echo.html" +++ "b/docs/Shell\347\274\226\347\250\213/echo.html" @@ -9,7 +9,7 @@ - + @@ -70,7 +70,7 @@

其中 \033 是 ESC 健的八进制,\033[即告诉终端后面是设置颜色的参数,显示方式,前景色,背景色均是数字。

数字含义如下:

显示方式 意义
0 终端默认设置
1 高亮显示
4 使用下划线
5 闪烁
7 反白显示
8 不可见

颜色数字代号如下:

前景色 背景色 颜色
30 40 黑色
31 41 红色
32 42 绿色
33 43 黃色
34 44 蓝色
35 45 紫红色
36 46 青蓝色
37 47 白色

(a)显示红色字体:

echo -e "\e[1;31mThis is red text\e[0m"
 

输出:

This is red text

其中,\e[0m表示恢复终端默认设置。

(b)显示绿色背景字体。

echo -e "\e[1;42mGreen Background\e[0m"
 

输出:

在这里插入图片描述

(c)文字闪动。

使用前景色31(红色),背景色42(绿色)闪动:

echo -e "\033[5;31;42mMySQL Server Stop...\033[0m"
-

# 参考文献

echo(1) - Linux manual page - man7.org (opens new window)

echo命令 - Linux命令大全 (opens new window)

使用echo输出带颜色的字体 (opens new window)


# 参考文献

echo(1) - Linux manual page - man7.org (opens new window)

echo命令 - Linux命令大全 (opens new window)

使用echo输出带颜色的字体 (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/enable-builtin.html" "b/docs/Shell\347\274\226\347\250\213/enable-builtin.html" index 42d4fa23b..e193c45f4 100644 --- "a/docs/Shell\347\274\226\347\250\213/enable-builtin.html" +++ "b/docs/Shell\347\274\226\347\250\213/enable-builtin.html" @@ -9,7 +9,7 @@ - + @@ -124,7 +124,7 @@ enable times enable trap enable unset -

# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)


# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/eval-builtin.html" "b/docs/Shell\347\274\226\347\250\213/eval-builtin.html" index e5deb5d07..d037931b1 100644 --- "a/docs/Shell\347\274\226\347\250\213/eval-builtin.html" +++ "b/docs/Shell\347\274\226\347\250\213/eval-builtin.html" @@ -9,7 +9,7 @@ - + @@ -65,7 +65,7 @@ ./test.sh firstarg lastarg $2 lastarg -

# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

``和$()的区别及eval详解 - CSDN (opens new window)


# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

``和$()的区别及eval详解 - CSDN (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/exec-builtin.html" "b/docs/Shell\347\274\226\347\250\213/exec-builtin.html" index 1b0a04e74..74c71b96d 100644 --- "a/docs/Shell\347\274\226\347\250\213/exec-builtin.html" +++ "b/docs/Shell\347\274\226\347\250\213/exec-builtin.html" @@ -9,7 +9,7 @@ - + @@ -52,7 +52,7 @@

(2)在一个空环境中执行命令。

命令执行完后,然后退出当前终端。

exec -c ls
 

(3)find 和 exec 综合使用。

find ./ -name "test.txt" -exec ls -l {} \;
 -rw-rw-r--+ 1 root root 6 Nov 24 17:59 ./test/test.txt
-

# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)


# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/exit-builtin.html" "b/docs/Shell\347\274\226\347\250\213/exit-builtin.html" index 9a0574c6b..0a79d013c 100644 --- "a/docs/Shell\347\274\226\347\250\213/exit-builtin.html" +++ "b/docs/Shell\347\274\226\347\250\213/exit-builtin.html" @@ -9,7 +9,7 @@ - + @@ -57,7 +57,7 @@

执行exit.sh输出:

start
 before exit
 end
-

# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/expect.html" "b/docs/Shell\347\274\226\347\250\213/expect.html" index 432181f43..28bdd4030 100644 --- "a/docs/Shell\347\274\226\347\250\213/expect.html" +++ "b/docs/Shell\347\274\226\347\250\213/expect.html" @@ -9,7 +9,7 @@ - + @@ -134,7 +134,7 @@ "password" { send "root\n" } } expect eof -

# 参考文献

expect(1) - Linux manual page - man7.org (opens new window)

expect - 自动交互脚本 (opens new window)


# 参考文献

expect(1) - Linux manual page - man7.org (opens new window)

expect - 自动交互脚本 (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/expr.html" "b/docs/Shell\347\274\226\347\250\213/expr.html" index bb5d60420..fa817df0f 100644 --- "a/docs/Shell\347\274\226\347\250\213/expr.html" +++ "b/docs/Shell\347\274\226\347\250\213/expr.html" @@ -9,7 +9,7 @@ - + @@ -135,7 +135,7 @@ 6

(8)使用小括号,使得 expr 支持多个表达式。

expr 1 + \( 1 + 1 \)
 3
-

# 参考文献

expr(1) - Linux manual page - man7.org (opens new window)

SHELL脚本--expr命令全解 (opens new window)


# 参考文献

expr(1) - Linux manual page - man7.org (opens new window)

SHELL脚本--expr命令全解 (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/let-builtin.html" "b/docs/Shell\347\274\226\347\250\213/let-builtin.html" index 5b19cb19a..f7c47f210 100644 --- "a/docs/Shell\347\274\226\347\250\213/let-builtin.html" +++ "b/docs/Shell\347\274\226\347\250\213/let-builtin.html" @@ -9,7 +9,7 @@ - + @@ -84,7 +84,7 @@ echo $a 1 -

# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)


# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/printf.html" "b/docs/Shell\347\274\226\347\250\213/printf.html" index 36c08446d..74e21e3bc 100644 --- "a/docs/Shell\347\274\226\347\250\213/printf.html" +++ "b/docs/Shell\347\274\226\347\250\213/printf.html" @@ -9,7 +9,7 @@ - + @@ -87,7 +87,7 @@

小数位如果太长(数字总长度超过 8) 将被截断,我们可以指定小数位数。

printf "%d %.10f %e\n" 1 1.000000001 1.000000001
 1 1.0000000010 1.000000e+00
 

(7)输出百分比。对 % 进行转义即可。

printf "%d%%\n" 80
-

# 参考文献

printf(1) - Linux manual page - man7.org (opens new window)


# 参考文献

printf(1) - Linux manual page - man7.org (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/read-builtin.html" "b/docs/Shell\347\274\226\347\250\213/read-builtin.html" index a2c49c2e5..cfbbb921b 100644 --- "a/docs/Shell\347\274\226\347\250\213/read-builtin.html" +++ "b/docs/Shell\347\274\226\347\250\213/read-builtin.html" @@ -9,7 +9,7 @@ - + @@ -97,7 +97,7 @@ do echo $var1 $var2 done < file.txt -

# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

博客园.read指令使用方法 (opens new window)

CSDN.详细解析Shell中的IFS变量 (opens new window)

菜鸟教程.Linux read 命令 (opens new window)


# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

博客园.read指令使用方法 (opens new window)

CSDN.详细解析Shell中的IFS变量 (opens new window)

菜鸟教程.Linux read 命令 (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/readonly-builtin.html" "b/docs/Shell\347\274\226\347\250\213/readonly-builtin.html" index f63563554..be7c5bdc0 100644 --- "a/docs/Shell\347\274\226\347\250\213/readonly-builtin.html" +++ "b/docs/Shell\347\274\226\347\250\213/readonly-builtin.html" @@ -9,7 +9,7 @@ - + @@ -59,7 +59,7 @@ FOO="bar" -bash: FOO: readonly variable -

# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)


# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/set-builtin.html" "b/docs/Shell\347\274\226\347\250\213/set-builtin.html" index ccca06c0d..05b794bc1 100644 --- "a/docs/Shell\347\274\226\347\250\213/set-builtin.html" +++ "b/docs/Shell\347\274\226\347\250\213/set-builtin.html" @@ -9,7 +9,7 @@ - + @@ -136,7 +136,7 @@ + echo bar bar

可以看到,执行echo bar之前,该命令会先打印出来,行首以+表示。这对于调试复杂的脚本是很有用的。

-x 还有另一种写法 -o xtrace

set -o xtrace
-

# 5.选项名

执行环境的不同配置有对应的名称,一般与 set 选项也有对应的关系。

选项名 选项 说明
allexport -a 从这个选项中被设置开始就自动标明要输出的新变量或修改过的变量,直至选项被复位
braceexpand -B 打开花括号扩展,它是一个默认设置
emacs N/A 使用emacs内置编辑器进行命令行编辑,是一个默认设置
errexit -e 当命令返回一个非零退出状态(失败)时退出。读取初始化文件时不设置
histexpand -H 执行历史替换时打开!和!!扩展,是一个默认设置
history N/A 打开命令行历史、默认为打开
ignoreeof N/A 禁止用EOF(Ctrl+D)键退出shell。必须键入exit才能退出。等价于设置shell变量IGNOREEOF=10
keyword -k 将关键字参数放到命令的环境中
interactive-comments N/A 对于交互式shell,把#符后面的文本作为注释
monitor -m 设置作业控制
noclobber -C 防止文件在重定向时被重写
noexec -n 读命令,但不执行。用来检查脚本的语法。交互式运行时不开启
noglob -d 禁止用路径名扩展。即关闭通配符
notify -b 后台作业完成时通知用户
nounset -u 扩展一个未设置的变量时显示一个错误信息
onecmd -t 在读取和执行命令后退出
physical -P 设置时,在键入cd或pwd禁止符号链接。用物理目录代替
privileged -p 设置后,shell不读取.profile或ENV文件,且不从环境继承shell函数,将自动为setuid脚本开启特权
verbose -v 为调试打开verbose模式
vi N/A 使用vi内置编辑器进行命令行编辑
xtrace -x 为调试打开echo模式

# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

Bash 脚本set 命令教程- 阮一峰的网络日志 (opens new window)

# 5.选项名

执行环境的不同配置有对应的名称,一般与 set 选项也有对应的关系。

选项名 选项 说明
allexport -a 从这个选项中被设置开始就自动标明要输出的新变量或修改过的变量,直至选项被复位
braceexpand -B 打开花括号扩展,它是一个默认设置
emacs N/A 使用emacs内置编辑器进行命令行编辑,是一个默认设置
errexit -e 当命令返回一个非零退出状态(失败)时退出。读取初始化文件时不设置
histexpand -H 执行历史替换时打开!和!!扩展,是一个默认设置
history N/A 打开命令行历史、默认为打开
ignoreeof N/A 禁止用EOF(Ctrl+D)键退出shell。必须键入exit才能退出。等价于设置shell变量IGNOREEOF=10
keyword -k 将关键字参数放到命令的环境中
interactive-comments N/A 对于交互式shell,把#符后面的文本作为注释
monitor -m 设置作业控制
noclobber -C 防止文件在重定向时被重写
noexec -n 读命令,但不执行。用来检查脚本的语法。交互式运行时不开启
noglob -d 禁止用路径名扩展。即关闭通配符
notify -b 后台作业完成时通知用户
nounset -u 扩展一个未设置的变量时显示一个错误信息
onecmd -t 在读取和执行命令后退出
physical -P 设置时,在键入cd或pwd禁止符号链接。用物理目录代替
privileged -p 设置后,shell不读取.profile或ENV文件,且不从环境继承shell函数,将自动为setuid脚本开启特权
verbose -v 为调试打开verbose模式
vi N/A 使用vi内置编辑器进行命令行编辑
xtrace -x 为调试打开echo模式

# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

Bash 脚本set 命令教程- 阮一峰的网络日志 (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/sleep.html" "b/docs/Shell\347\274\226\347\250\213/sleep.html" index 317a6bf36..15b8cac4a 100644 --- "a/docs/Shell\347\274\226\347\250\213/sleep.html" +++ "b/docs/Shell\347\274\226\347\250\213/sleep.html" @@ -9,7 +9,7 @@ - + @@ -62,7 +62,7 @@ done echo

输出效果:

Progress:[####################################################################################################]100%
-

# 参考文献

sleep(1) - Linux manual page - man7.org (opens new window)

sleep(1p) - Linux manual page - man7.org (opens new window)

sleep - 将目前动作延迟一段时间- Linux 命令搜索引擎 (opens new window)


# 参考文献

sleep(1) - Linux manual page - man7.org (opens new window)

sleep(1p) - Linux manual page - man7.org (opens new window)

sleep - 将目前动作延迟一段时间- Linux 命令搜索引擎 (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/test.html" "b/docs/Shell\347\274\226\347\250\213/test.html" index b3d5fedc8..00353b8ad 100644 --- "a/docs/Shell\347\274\226\347\250\213/test.html" +++ "b/docs/Shell\347\274\226\347\250\213/test.html" @@ -9,7 +9,7 @@ - + @@ -132,7 +132,7 @@

test 退出状态码等于 1 表示不是同一个文件。

(5)当 /home 为目录,并且可写时为真。

test -d /home -a -w /home
 echo $?
 0
-

# 参考文献

Coreutils - GNU core utilities (opens new window)

test(1) - Linux manual page - man7.org (opens new window)


# 参考文献

Coreutils - GNU core utilities (opens new window)

test(1) - Linux manual page - man7.org (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/unset-builtin.html" "b/docs/Shell\347\274\226\347\250\213/unset-builtin.html" index cce13dbfb..9d93a5c7e 100644 --- "a/docs/Shell\347\274\226\347\250\213/unset-builtin.html" +++ "b/docs/Shell\347\274\226\347\250\213/unset-builtin.html" @@ -9,7 +9,7 @@ - + @@ -66,7 +66,7 @@

使用 unset 删除只读变量将报错并返回 1。

unset name || echo $?
 bash: unset: name: cannot unset: readonly variable
 1
-

# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)


# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

- + diff --git "a/docs/Shell\347\274\226\347\250\213/wait-builtin.html" "b/docs/Shell\347\274\226\347\250\213/wait-builtin.html" index 81e0cac49..675ca1a58 100644 --- "a/docs/Shell\347\274\226\347\250\213/wait-builtin.html" +++ "b/docs/Shell\347\274\226\347\250\213/wait-builtin.html" @@ -9,7 +9,7 @@ - + @@ -54,7 +54,7 @@ [1]+ Done sleep 10

输出当前存在作业号使用 jobs 命令。

jobs
 [1]+  Running                 sleep 10 &
-

# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)


# 参考文献

bash(1) - Linux manual page - man7.org (opens new window)

- + diff --git a/docs/assets/js/101.c6b7074f.js b/docs/assets/js/101.e3f08fe5.js similarity index 99% rename from docs/assets/js/101.c6b7074f.js rename to docs/assets/js/101.e3f08fe5.js index 562931f60..28382f4fd 100644 --- a/docs/assets/js/101.c6b7074f.js +++ b/docs/assets/js/101.e3f08fe5.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[101],{434:function(a,s,n){"use strict";n.r(s);var t=n(12),e=Object(t.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),s("p",[a._v("tail 用于显示文件尾部内容,与命令 head 作用相反。默认情况下,显示文件的末尾 10 行内容。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("tail [OPTION]... [FILE]...\n")])])]),s("p",[a._v("可以指定多个文件 FILE,种情况下,输出的内容前会列出所属文件名。如果未给定 FILE 或者 FILE 是 -,则从标准输入读取。")]),a._v(" "),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("-c, --bytes=K\n 输出最后 K 个字节;或者使用 +K 表示从文件的第 K 个字节开始到最后\n--retry\n 不停地尝试打开不可访问的文件,只与 -f 联用时有用。\n-f, --follow[={name|descriptor}]\n 按照指定时间间隔输出文件追加的内容; -f, --follow 以及 --follow=descriptor 作用相同。--follow=name 表示根据文件名检测而不是文件描述符,默认 5 次检测后文件未发生改变则重新打开文件\n-n, --lines=N\n 输出最后 N 行,而非默认的最后 10 行。\n--max-unchanged-stats=N\n 与选项 --follow=name 联用,N 次检测后如果文件未发生变化,则重新打开文件。此选项不常用,一般文件链接被重定向或者日志滚动时导致文件名发生变化时才使用该选项\n--pid=PID\n 与 -f 联用,表示在进程 ID 死掉之后结束 tail\n-q, --quiet, --silent\n 多个文件时输出的内容前隐藏文件名\n-s, --sleep-interval=S\n 与 -f 联用,表示检测文件变化的间隔,默认 1s\n-v, --verbose\n 多个文件时输出的内容前显示文件名(默认)\n--help\n 显示帮助信息后退出\n--version\n 输出版本信息后退出\n")])])]),s("p",[a._v("注意:\n(1)长选项的强制参数对于短选项也是强制的;\n(2)K 字节后可以有一个倍数后缀:"),s("code",[a._v("b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y")]),a._v(";\n(3)使用 -f, --follow 时,tail 默认后接文件描述符, 这意味着即使 tail 跟踪的文件改名了,tail 仍然可以显示其末尾部分。如果希望查询文件的实际名称而非文件描述符(例如日志滚动时), 应使用 --follow=name,tail 将周期性地重新打开所指定的文件。")]),a._v(" "),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)显示文件 /etc/passwd 的末尾 10 行。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("tail")]),a._v(" /etc/passwd\n\nrpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin\nnfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin\nsaslauth:x:996:76:Saslauthd user:/run/saslauthd:/sbin/nologin\navahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin\nuucp:x:10:14:Uucp user:/var/spool/uucp:/sbin/nologin\nnslcd:x:65:55:LDAP Client User:/:/sbin/nologin\narpwatch:x:77:77::/var/lib/arpwatch:/sbin/nologin\nsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin\ntcpdump:x:72:72::/:/sbin/nologin\nmysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin\n")])])]),s("p",[a._v("(2)显示文件 /etc/passwd 的末尾 3 行。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("tail")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-n3")]),a._v(" /etc/passwd\n\nsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin\ntcpdump:x:72:72::/:/sbin/nologin\nmysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin\n")])])]),s("p",[a._v("(3)从第 N 行开始显示文件的内容,以 /etc/passwd 为例,这里的 N 等于 30。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("tail")]),a._v(" -n+30 /etc/passwd\n\ntcpdump:x:72:72::/:/sbin/nologin\nmysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin\n")])])]),s("p",[a._v("(4)当文件增长时,动态查看文件追加的内容。")]),a._v(" "),s("p",[a._v("假设文件 my.log 是滚动的服务日志,每到指定大小将被重命名,这里始终跟踪最新的日志文件。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("tail")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--follow")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("name my.log\n")])])]),s("p",[a._v("(5)显示多个文件的最后 3 行,并且默认会显示文件名。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("tail")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-n3")]),a._v(" /etc/passwd /etc/group\n\n"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("==")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),a._v(" /etc/passwd "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<=")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("\nmqq:x:500:501::/usr/local/app:/bin/bash\ndev_mqq:x:501:501::/usr/local/dev:/bin/bash\ndev:x:502:501::/home/dev:/bin/bash\n\n"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("==")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),a._v(" /etc/group "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<=")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("\nscreen:x:84:\nadmin:x:500:\nmqq:x:501:\n")])])]),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/tail.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("tail(1) - Linux manual page - man7.org"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"https://www.linux.org/docs/man1/tail.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("tail(1) - Linux manual page - linux.org"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/95937014",target:"_blank",rel:"noopener noreferrer"}},[a._v("【Linux】一步一步学Linux——tail命令(42)"),s("OutboundLink")],1)]),a._v(" "),s("Vssue",{attrs:{title:"tail"}})],1)}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[101],{435:function(a,s,n){"use strict";n.r(s);var t=n(12),e=Object(t.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),s("p",[a._v("tail 用于显示文件尾部内容,与命令 head 作用相反。默认情况下,显示文件的末尾 10 行内容。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("tail [OPTION]... [FILE]...\n")])])]),s("p",[a._v("可以指定多个文件 FILE,种情况下,输出的内容前会列出所属文件名。如果未给定 FILE 或者 FILE 是 -,则从标准输入读取。")]),a._v(" "),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("-c, --bytes=K\n 输出最后 K 个字节;或者使用 +K 表示从文件的第 K 个字节开始到最后\n--retry\n 不停地尝试打开不可访问的文件,只与 -f 联用时有用。\n-f, --follow[={name|descriptor}]\n 按照指定时间间隔输出文件追加的内容; -f, --follow 以及 --follow=descriptor 作用相同。--follow=name 表示根据文件名检测而不是文件描述符,默认 5 次检测后文件未发生改变则重新打开文件\n-n, --lines=N\n 输出最后 N 行,而非默认的最后 10 行。\n--max-unchanged-stats=N\n 与选项 --follow=name 联用,N 次检测后如果文件未发生变化,则重新打开文件。此选项不常用,一般文件链接被重定向或者日志滚动时导致文件名发生变化时才使用该选项\n--pid=PID\n 与 -f 联用,表示在进程 ID 死掉之后结束 tail\n-q, --quiet, --silent\n 多个文件时输出的内容前隐藏文件名\n-s, --sleep-interval=S\n 与 -f 联用,表示检测文件变化的间隔,默认 1s\n-v, --verbose\n 多个文件时输出的内容前显示文件名(默认)\n--help\n 显示帮助信息后退出\n--version\n 输出版本信息后退出\n")])])]),s("p",[a._v("注意:\n(1)长选项的强制参数对于短选项也是强制的;\n(2)K 字节后可以有一个倍数后缀:"),s("code",[a._v("b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y")]),a._v(";\n(3)使用 -f, --follow 时,tail 默认后接文件描述符, 这意味着即使 tail 跟踪的文件改名了,tail 仍然可以显示其末尾部分。如果希望查询文件的实际名称而非文件描述符(例如日志滚动时), 应使用 --follow=name,tail 将周期性地重新打开所指定的文件。")]),a._v(" "),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)显示文件 /etc/passwd 的末尾 10 行。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("tail")]),a._v(" /etc/passwd\n\nrpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin\nnfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin\nsaslauth:x:996:76:Saslauthd user:/run/saslauthd:/sbin/nologin\navahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin\nuucp:x:10:14:Uucp user:/var/spool/uucp:/sbin/nologin\nnslcd:x:65:55:LDAP Client User:/:/sbin/nologin\narpwatch:x:77:77::/var/lib/arpwatch:/sbin/nologin\nsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin\ntcpdump:x:72:72::/:/sbin/nologin\nmysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin\n")])])]),s("p",[a._v("(2)显示文件 /etc/passwd 的末尾 3 行。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("tail")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-n3")]),a._v(" /etc/passwd\n\nsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin\ntcpdump:x:72:72::/:/sbin/nologin\nmysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin\n")])])]),s("p",[a._v("(3)从第 N 行开始显示文件的内容,以 /etc/passwd 为例,这里的 N 等于 30。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("tail")]),a._v(" -n+30 /etc/passwd\n\ntcpdump:x:72:72::/:/sbin/nologin\nmysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin\n")])])]),s("p",[a._v("(4)当文件增长时,动态查看文件追加的内容。")]),a._v(" "),s("p",[a._v("假设文件 my.log 是滚动的服务日志,每到指定大小将被重命名,这里始终跟踪最新的日志文件。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("tail")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--follow")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("name my.log\n")])])]),s("p",[a._v("(5)显示多个文件的最后 3 行,并且默认会显示文件名。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("tail")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-n3")]),a._v(" /etc/passwd /etc/group\n\n"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("==")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),a._v(" /etc/passwd "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<=")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("\nmqq:x:500:501::/usr/local/app:/bin/bash\ndev_mqq:x:501:501::/usr/local/dev:/bin/bash\ndev:x:502:501::/home/dev:/bin/bash\n\n"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("==")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),a._v(" /etc/group "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<=")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("\nscreen:x:84:\nadmin:x:500:\nmqq:x:501:\n")])])]),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/tail.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("tail(1) - Linux manual page - man7.org"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"https://www.linux.org/docs/man1/tail.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("tail(1) - Linux manual page - linux.org"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/95937014",target:"_blank",rel:"noopener noreferrer"}},[a._v("【Linux】一步一步学Linux——tail命令(42)"),s("OutboundLink")],1)]),a._v(" "),s("Vssue",{attrs:{title:"tail"}})],1)}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/102.8031f6b0.js b/docs/assets/js/102.82e6bf65.js similarity index 99% rename from docs/assets/js/102.8031f6b0.js rename to docs/assets/js/102.82e6bf65.js index e1acf9df0..8f47bcf83 100644 --- a/docs/assets/js/102.8031f6b0.js +++ b/docs/assets/js/102.82e6bf65.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[102],{435:function(a,t,s){"use strict";s.r(t);var e=s(12),n=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("wc(word count)用于统计文件字节、字符、单词与行的数量。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("wc [OPTION]... [FILE]...\nwc [OPTION]... --files0-from=F\n")])])]),t("p",[a._v("如果没有 FILE,或者 FILE 为 -,则读取标准输入。")]),a._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-c, --bytes\n\t仅显示字节数\n-m, --chars\n\t仅显示字符数\n-l, --lines\n\t仅显示行数\n--files0-from=F\n\t从文件 F 中获取以 NULL 字符结尾的文件名作为输入,如果 F 等于连字符 -,则从标准输入读取\n-L, --max-line-length\n\t显示文件中最长行的字符数\n-w, --words\n\t显示单词数,单词以空格分隔\n--help\n\t显示帮助信息并退出\n--version\n\t显示版本信息并退出\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("(1)使用 wc 统计 /etc/passwd 行数、单词数和字节数。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("wc")]),a._v(" /etc/passwd\n"),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("40")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("45")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("1719")]),a._v(" /etc/passwd\n")])])]),t("p",[a._v("40 是行数,45 是单词数,1719 是字节数。")]),a._v(" "),t("p",[a._v("(2)wc 的命令比较简单,每个参数使用如下:")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 统计行数,在统计记录数时,很常用")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("wc")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-l")]),a._v(" /etc/passwd\n"),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("40")]),a._v(" /etc/passwd "),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 表示系统有40个账户")]),a._v("\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 统计单词出现次数")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("wc")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-w")]),a._v(" /etc/passwd\n"),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("45")]),a._v(" /etc/passwd\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 统计文件的字节数")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("wc")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-c")]),a._v(" /etc/passwd\n"),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("1719")]),a._v("\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 统计文件的字符数,如果是 ASCII、Latin-1 等单字节编码的字符,字符数等于字节数")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("wc")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-m")]),a._v(" /etc/passwd\n"),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("1719")]),a._v("\n")])])]),t("p",[a._v("(3)从文件读取输入文件名。如果有多个文件名,并且希望 wc 从一个文件中读取它们,那么使用 -files0-from 选项。这里将文件名称必须以 NULL 字符结束写在文件fileNames.txt 中。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("wc")]),a._v(" --files0-from"),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("fileNames.txt\n")])])]),t("p",[a._v("在 vim 中输入 NULL 字符,可以通过 digraph 输入,具体操作步骤是:在输入模式按一下Ctrl+k,然后输入NU。关于 digraph 和其它输入方式具体参见 "),t("a",{attrs:{href:"https://blog.csdn.net/chenster/article/details/53307707",target:"_blank",rel:"noopener noreferrer"}},[a._v("Vim 中读写特殊字符"),t("OutboundLink")],1),a._v("。")]),a._v(" "),t("p",[a._v("(4)统计目录下条目的个数。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("ls")]),a._v(" DIR "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("wc")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-l")]),a._v("\n")])])]),t("p",[a._v("这个命令会将目录中的所有文件和子目录列出,并使用管道将它们传递给 wc 命令进行统计。-l 参数告诉 wc 命令统计行数,因为 ls 命令会为每个文件和目录输出一行。")]),a._v(" "),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/sort.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("sort(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/uniq.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("uniq(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/wc.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("wc(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://en.wikipedia.org/wiki/Wc_(Unix)",target:"_blank",rel:"noopener noreferrer"}},[a._v("wc (Unix) - Wikipedia"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"wc"}})],1)}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[102],{436:function(a,t,s){"use strict";s.r(t);var e=s(12),n=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("wc(word count)用于统计文件字节、字符、单词与行的数量。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("wc [OPTION]... [FILE]...\nwc [OPTION]... --files0-from=F\n")])])]),t("p",[a._v("如果没有 FILE,或者 FILE 为 -,则读取标准输入。")]),a._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-c, --bytes\n\t仅显示字节数\n-m, --chars\n\t仅显示字符数\n-l, --lines\n\t仅显示行数\n--files0-from=F\n\t从文件 F 中获取以 NULL 字符结尾的文件名作为输入,如果 F 等于连字符 -,则从标准输入读取\n-L, --max-line-length\n\t显示文件中最长行的字符数\n-w, --words\n\t显示单词数,单词以空格分隔\n--help\n\t显示帮助信息并退出\n--version\n\t显示版本信息并退出\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("(1)使用 wc 统计 /etc/passwd 行数、单词数和字节数。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("wc")]),a._v(" /etc/passwd\n"),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("40")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("45")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("1719")]),a._v(" /etc/passwd\n")])])]),t("p",[a._v("40 是行数,45 是单词数,1719 是字节数。")]),a._v(" "),t("p",[a._v("(2)wc 的命令比较简单,每个参数使用如下:")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 统计行数,在统计记录数时,很常用")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("wc")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-l")]),a._v(" /etc/passwd\n"),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("40")]),a._v(" /etc/passwd "),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 表示系统有40个账户")]),a._v("\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 统计单词出现次数")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("wc")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-w")]),a._v(" /etc/passwd\n"),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("45")]),a._v(" /etc/passwd\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 统计文件的字节数")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("wc")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-c")]),a._v(" /etc/passwd\n"),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("1719")]),a._v("\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 统计文件的字符数,如果是 ASCII、Latin-1 等单字节编码的字符,字符数等于字节数")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("wc")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-m")]),a._v(" /etc/passwd\n"),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("1719")]),a._v("\n")])])]),t("p",[a._v("(3)从文件读取输入文件名。如果有多个文件名,并且希望 wc 从一个文件中读取它们,那么使用 -files0-from 选项。这里将文件名称必须以 NULL 字符结束写在文件fileNames.txt 中。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("wc")]),a._v(" --files0-from"),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("fileNames.txt\n")])])]),t("p",[a._v("在 vim 中输入 NULL 字符,可以通过 digraph 输入,具体操作步骤是:在输入模式按一下Ctrl+k,然后输入NU。关于 digraph 和其它输入方式具体参见 "),t("a",{attrs:{href:"https://blog.csdn.net/chenster/article/details/53307707",target:"_blank",rel:"noopener noreferrer"}},[a._v("Vim 中读写特殊字符"),t("OutboundLink")],1),a._v("。")]),a._v(" "),t("p",[a._v("(4)统计目录下条目的个数。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("ls")]),a._v(" DIR "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("wc")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-l")]),a._v("\n")])])]),t("p",[a._v("这个命令会将目录中的所有文件和子目录列出,并使用管道将它们传递给 wc 命令进行统计。-l 参数告诉 wc 命令统计行数,因为 ls 命令会为每个文件和目录输出一行。")]),a._v(" "),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/sort.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("sort(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/uniq.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("uniq(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/wc.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("wc(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://en.wikipedia.org/wiki/Wc_(Unix)",target:"_blank",rel:"noopener noreferrer"}},[a._v("wc (Unix) - Wikipedia"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"wc"}})],1)}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/103.fe85cafb.js b/docs/assets/js/103.b830131b.js similarity index 99% rename from docs/assets/js/103.fe85cafb.js rename to docs/assets/js/103.b830131b.js index 05f36dca9..0733c2cfa 100644 --- a/docs/assets/js/103.fe85cafb.js +++ b/docs/assets/js/103.b830131b.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[103],{436:function(a,t,s){"use strict";s.r(t);var e=s(12),n=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("AWK 是文本处理语言,是一个强大的文本分析工具,是 Unix/Linux 环境中功能强大的数据处理引擎之一。数据可以来自标准输入(stdin)、一个或多个文件或其它命令的输出。它支持用户自定义函数和动态正则表达式等先进功能,是 Unix/Linux 下一个强大的编程工具。")]),a._v(" "),t("p",[a._v("AWK 有很多内建的功能,比如数组、函数等,这是它和 C 语言的相同之处,灵活性是 AWK 最大的优势。简单来说 AWK 就是把文件逐行的读入,以空格和 Tab 为默认分隔符将每行切片,切开的部分再进行各种分析处理。")]),a._v(" "),t("p",[a._v("AWK 名称来自于它的三位创始人 Alfred "),t("strong",[a._v("A")]),a._v("ho、Peter Jay "),t("strong",[a._v("W")]),a._v("einberger 和 Brian "),t("strong",[a._v("K")]),a._v("ernighan 姓氏的首个字母。AWK 有多个版本:awk, nawk, mawk 和 gawk,未作特别说明,一般指 gawk。gawk 是 AWK 的 GNU 版本。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("awk [OPTIONS]\nawk [OPTIONS] 'PATTERN{ACTION}' FILE...\n")])])]),t("p",[a._v("其中 PATTERN 一般为正则表达式,用斜杠括起来,用来查找匹配的行。ACTION 是在找到匹配的行时所执行的一系列命令。花括号 {} 对一系列指令进行功能分组,不需要始终出现。")]),a._v(" "),t("p",[a._v("尽管操作可能会很复杂,但语法总是这样。awk 通常用来格式化文本文件中的信息,是以文件的行为处理单位,每接收文件的一行,然后执行相应的命令来处理文本。")]),a._v(" "),t("p",[t("strong",[a._v("注意:")]),a._v("\n(1)PATTERN 缺省为 1,表示永真,ACTION 缺省为 print。\n(2)PATTERN + {ACTION} 可以同时存在多个,每个 PATTERN 之间的关系是或,只要当前行匹配 PATTERN,则执行 PATTERN 后大括号中的 action。")]),a._v(" "),t("h2",{attrs:{id:"_3-匹配模式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-匹配模式"}},[a._v("#")]),a._v(" 3.匹配模式")]),a._v(" "),t("p",[a._v("awk 的 PATTERN 可能是以下情况之一:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("BEGIN\nEND\nBEGINFILE\nENDFILE\n/regular expression/\nrelational expression\npattern && pattern\npattern || pattern\n! pattern\npattern ? pattern : pattern\n(pattern)\npattern1, pattern2\n")])])]),t("p",[a._v("BEGIN 和 END 是两个特殊的模式,不会对输入的内容进行测试。BEGIN 后的 action 在 awk 读取文本前执行,END 后的 action 在 awk 结束前执行。模式表达式中的 BEGIN 和 END 模式不能与其他模式组合。")]),a._v(" "),t("p",[a._v("BEGINFILE 和 ENDFILE 是额外的两个特殊模式,BEGINFILE 的 action 在读取每个命令行输入文件的第一条记录之前执行,ENDFILE 的 action 在读取每个文件的最后一条记录之后执行。与 BEGIN 和 END 的区别是,如果给定多个文件,BEGINFILE 和 ENDFILE 的 action 将被执行多次,而 BEGIN 和 END 不管是否给定文件,其 action 只会执行一次。")]),a._v(" "),t("p",[a._v("/regular expression/ 表示正则表达式,用于选择符合指定 pattern 的行。")]),a._v(" "),t("p",[a._v("relational expression 表示正则表达式的关系式,即多个正则表达式通过运算符进行组合。常见组合有:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("pattern && pattern\n\t逻辑与式,两个 pattern 同时满足才算满足\npattern || pattern\n\t逻辑或式,只要有一个 pattern 满足即满足\n! pattern\n\t逻辑非式,不符合 pattern 则为 true\npattern ? pattern : pattern\n\t条件运算符式,第一个 pattern 满足则判断第二个 pattern,否则判断第三个 pattern\n(pattern)\n\t括号用于改变 pattern 运算的优先级\npattern1, pattern2\n\t表示一个范围,用于选择所有记录行中第一个符合 pattern1 的记录到下一个符合 pattern2 的记录之间的记录\n")])])]),t("h2",{attrs:{id:"_4-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-选项说明"}},[a._v("#")]),a._v(" 4.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-C, --copyright\n\t显示版权信息并退出\n-c, --traditional\n\t是 awk 运行在兼容模式下,gawk 的任何扩展都不会生效\n-d, --dump-variables[=FILE]\n\t将 awk 排序后的全局变量的类型和值打印到指定的文件中,如果没有指定 FILE,则在当前目录默认生成一个 awkvars.out\n-E, --exec FILE\n\t功能类似于选项 -f,但脚本文件需要以 #! 开头;另外命令行的变量将不再生效\n-e, --source PROGRAM_TEXT\n\t指定 awk 的源码文件\n-F, --field-separator FS\n\t使用字符或字符串 FS 作为域分隔符。可以同时指定多个域分隔符,此时需要使用一对中括号括起来。例如使用-和|可写作 -F '[-|]'。如果用[]作为分隔符,可写作-F '[][]'。不指定分隔符,默认为空格和 Tab。注意,使用 -F' '显示指定空格时,Tab 也会被作为分隔符。使用 [] 指定多个分隔符时,又想使多个分隔符组成的字符串也作为分隔符,在 [] 后添加一个 +,如 -F\"[ab]+\",那么分隔符有三个,a,b 和 ab\n-f, --file PROGRAM_FILE\n\t从指定的 awk 脚本文件 PROGRAM_FILE 读取 awk 指令\n-g, --gen-pot\n\t解析 awk 程序,产生 .po(Portable Object Template) 格式的文件到标准输出,来标明程序中每一个可本地化的字符串位置\n-h, --help\n\t显示简要的帮助信息并退出\n-L, --lint[=VALUE]\n\t打印有关在其它版本 awk 中出现可疑的或不可移植结构的警告。该选项提供了一个可选的参数 fatal,即将警告视为致命的错误\n-m{f|r} VAL\n\t-mf 将最大字段数设为 VAL;-mr 将最大记录数设为 VAL。这两个功能是 Bell 实验室版awk 的扩展功能,在标准 awk 中不适用\n-N, --use-lc-numeric\n\t使用本地小数点解析输入的数据\n-n, --non-decimal-data\n\t识别输入数据中八进制和十六进制数\n-O, --optimize\n\t在程序的内部表示上启用优化。目前,这只包括简单的常量折叠。gawk 维护者希望随着时间的推移增加额外的优化\n-P, --posix\n\t打开兼容模式,会出现以下限制:\n\t不识别 \\x;\n\t当域分隔符 FS 是一个空格时,只有空格和 Tab 能作为域分隔符,换行符将不能作为一个域分隔符;\n\t在 ? 和 : 之后,不能继续当前行;\n\t函数关键字 func 将不能被识别;\n\t操作符 ** 和 **= 不能代替 ^ 和 ^=;\n\tfflush 函数无效。\n-R, --command FILE\n\t只限于 Dgawk。从文件中读取调试器命令\n-r, --re-interval\n\t允许间隔正则表达式的使用。为默认选项\n-S, --sandbox\n\t在沙盒模式下运行gawk,禁用 system() 函数,使用 getline 进行输入重定向,使用 print 和 printf 进行输出重定向,以及加载动态扩展。命令执行也被禁用,这有效地阻止了脚本访问本地资源\n-t, --lint-old\n\t打印关于不能向传统 Unix awk 移植的构造的警告\n--profile[=FILE]\n\t输出性能分析报告至指定的文件,默认输出到 awkprof.out\n-V, --version\n\t打印版本信息并退出\n-v, --assign VAR=VAL\n\t定义一个 awk 变量并赋值,可以将外部变量传递给 awk\n--\n\t标识命令选项结束\n")])])]),t("h2",{attrs:{id:"_5-调用方式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-调用方式"}},[a._v("#")]),a._v(" 5.调用方式")]),a._v(" "),t("p",[a._v("有三种方式调用 awk。")]),a._v(" "),t("p",[a._v("(1)命令行方式。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("-F FS"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'PATTERN + {ACTION}'")]),a._v(" FILE"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),a._v(".\n")])])]),t("p",[a._v("在 awk 中,文件的每一行中,由域分隔符分开的每一项称为一个域。通常,在不指明域分隔符的情况下,默认为空格和 Tab。")]),a._v(" "),t("p",[a._v("(2)Shell 脚本方式。\n将所有的 awk 命令插入一个文件,脚本中在首行注明使用 awk 命令来解析执行,相当于将 Shell 脚本首行的"),t("code",[a._v("#!/bin/sh")]),a._v("换成"),t("code",[a._v("#!/bin/awk")]),a._v(",最后通过键入脚本名称来调用。")]),a._v(" "),t("p",[a._v("(3)将所有的 awk 命令插入到一个单独文件,然后使用 -f 选项调用。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("awk -f awk-script-file FILE...\n")])])]),t("p",[a._v("其中,-f 选项加载 awk-script-file 中的 awk 脚本,FILE... 跟上面的是一样的。")]),a._v(" "),t("h2",{attrs:{id:"_6-内置变量"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_6-内置变量"}},[a._v("#")]),a._v(" 6.内置变量")]),a._v(" "),t("p",[a._v("gawk 有许多内置变量用来设置环境信息,这些变量可以被改变,下面给出常见的内置变量说明。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$0")]),a._v("\t\t\t\t当前处理行\n"),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$n")]),a._v("\t\t\t\t当前记录的第 n 个字段,n 从 "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("1")]),a._v(" 开始,字段间由 FS 分隔\nARGC \t命令行参数个数\nARGIND \t\t\t当前处理命令行中的第几个文件,文件下标从 "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v(" 开始\nARGV 命令行参数数组\nCONVFMT\t\t\t数字转换格式,默认值为%.6g\nENVIRON 支持队列中系统环境变量的使用\nERRNO\t\t\t最后一个系统错误的描述\nFIELDWIDTHS\t\t字段宽度列表"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("用空格键分隔"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v("\nFILENAME awk浏览的文件名\nFNR 当前被处理文件的记录数\nFS 设置输入域分隔符,等价于命令行-F选项\nIGNORECASE\t\t如果为真,则进行忽略大小写的匹配\nLINT\t\t\t动态控制--lint选项是否生效,为false不生效,为true则生效;\nNF 浏览记录的域的个数\nNR 已读的记录数\nOFMT\t\t\t数字的输出格式,默认值是%.6g\nOFS 输出域分隔符\nORS 输出记录分隔符\t\t\t\t\nRS The input record separator,输入记录的分隔符,默认为换行符\nRT\t\t\t\tThe record terminator,输入记录的结束符\t\t\nRSTART\t\t\t由 match 函数所匹配的字符串的第一个位置\nRLENGTH\t\t\t由 match 函数所匹配的字符串的长度\nSUBSEP\t\t\t数组下标分隔符(默认值是 "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("\\")]),a._v("034)\nTEXTDOMAIN\t\t"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" 程序所使用的文本所处的地域\n")])])]),t("h2",{attrs:{id:"_7-编程示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_7-编程示例"}},[a._v("#")]),a._v(" 7.编程示例")]),a._v(" "),t("h3",{attrs:{id:"_7-1-基础打印输出"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_7-1-基础打印输出"}},[a._v("#")]),a._v(" 7.1 基础打印输出")]),a._v(" "),t("p",[a._v("(1)假设 last -n 5 的输出如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("root pts/1 192.168.1.100 Tue Feb 10 11:21 still logged in\nroot pts/1 192.168.1.100 Tue Feb 10 00:46 - 02:28 (01:41)\nroot pts/1 192.168.1.100 Mon Feb 9 11:41 - 18:30 (06:48)\ndmtsai pts/1 192.168.1.100 Mon Feb 9 11:41 - 11:41 (00:00)\nroot tty1 Fri Sep 5 14:09 - 14:10 (00:01)\n")])])]),t("p",[a._v("如果只是显示最近登录的5个帐号:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("last -n 5 | awk '{print $1}'\nroot\nroot\nroot\ndmtsai\nroot\n")])])]),t("p",[a._v("awk 工作流程是这样的:读入有换行符分隔的一条记录,然后将记录按指定的域分隔符划分,"),t("code",[a._v("$0")]),a._v("则表示所有域,"),t("code",[a._v("$1")]),a._v("表示第一个域,"),t("code",[a._v("$n")]),a._v("表示第 n 个域。默认域分隔符是空格或 Tab 符,所以"),t("code",[a._v("$1")]),a._v("表示登录用户,"),t("code",[a._v("$3")]),a._v("表示登录用户 ip,以此类推。")]),a._v(" "),t("p",[a._v("(2)如果想显示 /etc/passwd 配置文件中的账户以及账户对应的 Shell,而账户与 Shell 之间以Tab符分隔。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" /etc/passwd "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-F")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("':'")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'{print $1\"\\t\"$7}'")]),a._v("\nroot /bin/bash\ndaemon /bin/sh\nbin /bin/sh\nsys /bin/sh\n")])])]),t("p",[a._v("注意,这里使用了 -F 指定域分隔符为冒号 :。")]),a._v(" "),t("p",[a._v("(3)如果只是显示 /etc/passwd 的账户和账户对应的 Shell,而账户与 Shell 之间以逗号分隔,而且在所有行添加列名 name,shell,在最后一行添加 blue,/bin/nosh。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" /etc/passwd "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-F")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("':'")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('\'BEGIN {print "name,shell"} {print $1","$7} END {print "blue,/bin/nosh"}\'')]),a._v("\nname,shell\nroot,/bin/bash\ndaemon,/bin/sh\nbin,/bin/sh\nsys,/bin/sh\n"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),a._v("\nblue,/bin/nosh\n")])])]),t("p",[a._v("awk 工作流程是这样的:先执行 BEGING,然后读取文件,读入有/n换行符分割的一条记录,然后将记录按指定的域分隔符划分域,填充域,$0则表示所有域,"),t("code",[a._v("$1")]),a._v("表示第一个域,"),t("code",[a._v("$n")]),a._v("表示第 n 个域,随后开始执行模式所对应的动作action。接着开始读入第二条记录······直到所有的记录都读完,最后执行END操作。")]),a._v(" "),t("p",[a._v("(4)搜索 /etc/passwd 有 root 关键字的所有行。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" -F: "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'/root/'")]),a._v(" /etc/passwd\nroot:x:0:0:root:/root:/bin/bash\n")])])]),t("p",[a._v("上面三种是 awk 的 action 的使用示例,而这种是 pattern 的使用示例,匹配了 pattern(这里是root)的行才会执行 action(没有指定 action,默认输出每行的内容)。")]),a._v(" "),t("p",[a._v("搜索支持正则表达式,例如找 root 开头的所有行。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" -F: "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'/^root/'")]),a._v(" /etc/passwd\n")])])]),t("p",[a._v("(5)搜索/etc/passwd有 root 关键字的所有行,并显示对应的 Shell。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" -F: "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'/root/{print $7}'")]),a._v(" /etc/passwd\n/bin/bash\n")])])]),t("p",[a._v("这里是 awk 的 pattern+action 示例用法,同时指明了 action 是 {print $7}。")]),a._v(" "),t("p",[a._v("(6)打印 /etc/passwd 第三行的第一列和第二列。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" -F: "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'NR==3{print $1,$2;}'")]),a._v(" /etc/passwd\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#输出结果:")]),a._v("\ndaemon x\n")])])]),t("h3",{attrs:{id:"_7-2-awk-在每一列后添加字符串后输出"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_7-2-awk-在每一列后添加字符串后输出"}},[a._v("#")]),a._v(" 7.2 awk 在每一列后添加字符串后输出")]),a._v(" "),t("p",[a._v("设定变量内容:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v('a="/test.html /dir1 /abc.txt"\n')])])]),t("p",[a._v("希望得到")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$a")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--exclude")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/test.html "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--exclude")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/dir1 "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--exclude")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/abc.txt\n")])])]),t("p",[a._v("如何用 awk 实现。")]),a._v(" "),t("p",[a._v("解决办法:")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$a")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('\'{for(i=1;i<=NF-1;++i){printf "-execute=%s ",$i}}{print "--exclude="$NF""}\'')]),a._v("\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#或者")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$a")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('\'{for(i=1;i<=NF;i++){printf "--exclude="$i" "}{print ""}}\'')]),a._v("\n")])])]),t("p",[a._v("后者是网友给出的答案,和我上面的写法差不多,只是对 printf 在使用形式上有所差别而已。第二种方法"),t("code",[a._v('print ""')]),a._v("用于换行,print 每次输出后默认进行换行。")]),a._v(" "),t("h3",{attrs:{id:"_7-3-shell-编程使用-awk-浮点运算保留两位小数"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_7-3-shell-编程使用-awk-浮点运算保留两位小数"}},[a._v("#")]),a._v(" 7.3 Shell 编程使用 awk 浮点运算保留两位小数")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("a=3\nb=10\nc=$(awk 'BEGIN{printf \"%.2f\",'$a'*100/'$b'}')\necho c:$c%\n")])])]),t("p",[a._v("或者:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("c=$(awk -v n=$a -v m=$b 'BEGIN{printf \"%.2f\",n*100/m}')\necho c:$c%\n")])])]),t("p",[a._v("-v表示定义awk的变量!v是variable的首字母。输出:c:30.00%。")]),a._v(" "),t("h3",{attrs:{id:"_7-4-awk-访问-shell-变量"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_7-4-awk-访问-shell-变量"}},[a._v("#")]),a._v(" 7.4 awk 访问 Shell 变量")]),a._v(" "),t("p",[a._v("awk 默认是无法访问shell变量的,我所知道的有三种方法。\n方法一:awk -v 选项让awk 里使用shell变量。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var0")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("dablelv0\n"),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var1")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("dablelv1\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-v")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("tmpVar0")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$var0")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-v")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("tmpVar1")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$var1")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'BEGIN{print tmpVar0\" \"tmpVar1}'")]),a._v("\n")])])]),t("p",[a._v("输出: dablelv0 dablelv1\n注意: BEGIN 必须大写,awk 的 {action} 必须要使用单引号括起来。")]),a._v(" "),t("p",[a._v("方法二:"),t("code",[a._v("'\"$var\"'")]),a._v("\n这种写法是老外常用的写法。如:")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"test"')]),a._v(" \n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'BEGIN{print \"'")]),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$var")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'\"}'")]),a._v("\n")])])]),t("p",[a._v("这种写法其实际是双括号变为单括号的常量,传递给了awk。")]),a._v(" "),t("p",[a._v("如果var中含空格,为了shell不把空格作为分格符,应该如下使用:")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"this is a test"')]),a._v(" \n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'BEGIN{print \"'")]),a._v('"'),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$var")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"\'"')]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("}")]),a._v("' \n")])])]),t("p",[a._v("方法三:export 变量,将变量设置为临时会话环境变量,仅在当前shell会话中有效。在awk中使用"),t("code",[a._v('ENVIRON["var"]')]),a._v("形式访问变量。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"this is a test"')]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("export")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$var")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#或者 export var")]),a._v("\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#或者")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("export")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"this is a test"')]),a._v("\n\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'BEGIN{print ENVIRON[\"var\"]}'")]),a._v(" \n")])])]),t("h3",{attrs:{id:"_7-5-awk-执行-shell-命令"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_7-5-awk-执行-shell-命令"}},[a._v("#")]),a._v(" 7.5 awk 执行 Shell 命令")]),a._v(" "),t("p",[a._v("awk 执行 Shell 命令有两种方法。\n方法一:使用awk的system()函数。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("export")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("dablelv\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'BEGIN{system(\"echo $var\")}'")]),a._v("\n")])])]),t("p",[a._v("输出:dablelv\n注意:一定要使用export将变量设置为临时环境变量,因为awk的system()实际上是新建了一个shell进程来执行给定的shell命令,否则无法访问父进程的变量。")]),a._v(" "),t("p",[a._v("方法二:使用"),t("code",[a._v('使用print cmd | "/bin/bash"')])]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"this is a test"')]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('\'BEGIN{print "echo ""\'')]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"'),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$var")]),a._v('"')]),a._v("'"),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"|"')]),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("sh")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"}\'\n\n#或者\nvar="')]),a._v("this is a "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("test")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"\nawk -v varTmp="')]),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$var")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('" \'BEGIN{print "')]),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"varTmp|"')]),a._v('sh"'),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("}")]),a._v("'\n")])])]),t("p",[a._v("输出:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("this is a test\n")])])]),t("p",[a._v("注意:\n(1)指定bash的时候需要双引号括起来;\n(2)方法二与方法一的区别在于方法二是将变量在awk解析后再通过管道传给shell,所以无需将变量设置为临时环境变量,因为shell接收到的变量已经是变量的值。")]),a._v(" "),t("h2",{attrs:{id:"_8-faq"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_8-faq"}},[a._v("#")]),a._v(" 8.FAQ")]),a._v(" "),t("p",[a._v("(1)awk 默认以空格和 Tab 作为域分隔符,现在只以空格为分隔符,需要使用中括号的方式,不使用中括号,则仍然会将 Tab 作为域分隔符。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 错误的写法")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" -F"),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("' '")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'{print $1;}'")]),a._v(" test.txt\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 正确的写法")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" -F"),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'[ ]'")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'{print $1;}'")]),a._v(" test.txt \n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://www.linux.org/docs/man1/awk.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("awk manual - linux.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/awk.1p.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("awk(1p) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://awk.js.org/",target:"_blank",rel:"noopener noreferrer"}},[a._v("awk online"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://man.linuxde.net/awk",target:"_blank",rel:"noopener noreferrer"}},[a._v("Linux命令大全.awk命令"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://www.runoob.com/linux/linux-comm-awk.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("菜鸟教程.Linux awk 命令"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858470.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("博客园.linux awk命令详解"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://blog.csdn.net/yakoo5/article/details/43952713",target:"_blank",rel:"noopener noreferrer"}},[a._v("Shell脚本之awk篇"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://blog.163.com/zihuan_xuan/blog/static/1287942432012111041854341/",target:"_blank",rel:"noopener noreferrer"}},[a._v("awk使用shell变量"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://blog.chinaunix.net/uid-280990-id-2449802.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("awk中使用shell命令"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/hongchangfirst/article/details/25071937",target:"_blank",rel:"noopener noreferrer"}},[a._v("awk按照多个分隔符进行分割"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"awk"}})],1)}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[103],{434:function(a,t,s){"use strict";s.r(t);var e=s(12),n=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("AWK 是文本处理语言,是一个强大的文本分析工具,是 Unix/Linux 环境中功能强大的数据处理引擎之一。数据可以来自标准输入(stdin)、一个或多个文件或其它命令的输出。它支持用户自定义函数和动态正则表达式等先进功能,是 Unix/Linux 下一个强大的编程工具。")]),a._v(" "),t("p",[a._v("AWK 有很多内建的功能,比如数组、函数等,这是它和 C 语言的相同之处,灵活性是 AWK 最大的优势。简单来说 AWK 就是把文件逐行的读入,以空格和 Tab 为默认分隔符将每行切片,切开的部分再进行各种分析处理。")]),a._v(" "),t("p",[a._v("AWK 名称来自于它的三位创始人 Alfred "),t("strong",[a._v("A")]),a._v("ho、Peter Jay "),t("strong",[a._v("W")]),a._v("einberger 和 Brian "),t("strong",[a._v("K")]),a._v("ernighan 姓氏的首个字母。AWK 有多个版本:awk, nawk, mawk 和 gawk,未作特别说明,一般指 gawk。gawk 是 AWK 的 GNU 版本。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("awk [OPTIONS]\nawk [OPTIONS] 'PATTERN{ACTION}' FILE...\n")])])]),t("p",[a._v("其中 PATTERN 一般为正则表达式,用斜杠括起来,用来查找匹配的行。ACTION 是在找到匹配的行时所执行的一系列命令。花括号 {} 对一系列指令进行功能分组,不需要始终出现。")]),a._v(" "),t("p",[a._v("尽管操作可能会很复杂,但语法总是这样。awk 通常用来格式化文本文件中的信息,是以文件的行为处理单位,每接收文件的一行,然后执行相应的命令来处理文本。")]),a._v(" "),t("p",[t("strong",[a._v("注意:")]),a._v("\n(1)PATTERN 缺省为 1,表示永真,ACTION 缺省为 print。\n(2)PATTERN + {ACTION} 可以同时存在多个,每个 PATTERN 之间的关系是或,只要当前行匹配 PATTERN,则执行 PATTERN 后大括号中的 action。")]),a._v(" "),t("h2",{attrs:{id:"_3-匹配模式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-匹配模式"}},[a._v("#")]),a._v(" 3.匹配模式")]),a._v(" "),t("p",[a._v("awk 的 PATTERN 可能是以下情况之一:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("BEGIN\nEND\nBEGINFILE\nENDFILE\n/regular expression/\nrelational expression\npattern && pattern\npattern || pattern\n! pattern\npattern ? pattern : pattern\n(pattern)\npattern1, pattern2\n")])])]),t("p",[a._v("BEGIN 和 END 是两个特殊的模式,不会对输入的内容进行测试。BEGIN 后的 action 在 awk 读取文本前执行,END 后的 action 在 awk 结束前执行。模式表达式中的 BEGIN 和 END 模式不能与其他模式组合。")]),a._v(" "),t("p",[a._v("BEGINFILE 和 ENDFILE 是额外的两个特殊模式,BEGINFILE 的 action 在读取每个命令行输入文件的第一条记录之前执行,ENDFILE 的 action 在读取每个文件的最后一条记录之后执行。与 BEGIN 和 END 的区别是,如果给定多个文件,BEGINFILE 和 ENDFILE 的 action 将被执行多次,而 BEGIN 和 END 不管是否给定文件,其 action 只会执行一次。")]),a._v(" "),t("p",[a._v("/regular expression/ 表示正则表达式,用于选择符合指定 pattern 的行。")]),a._v(" "),t("p",[a._v("relational expression 表示正则表达式的关系式,即多个正则表达式通过运算符进行组合。常见组合有:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("pattern && pattern\n\t逻辑与式,两个 pattern 同时满足才算满足\npattern || pattern\n\t逻辑或式,只要有一个 pattern 满足即满足\n! pattern\n\t逻辑非式,不符合 pattern 则为 true\npattern ? pattern : pattern\n\t条件运算符式,第一个 pattern 满足则判断第二个 pattern,否则判断第三个 pattern\n(pattern)\n\t括号用于改变 pattern 运算的优先级\npattern1, pattern2\n\t表示一个范围,用于选择所有记录行中第一个符合 pattern1 的记录到下一个符合 pattern2 的记录之间的记录\n")])])]),t("h2",{attrs:{id:"_4-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-选项说明"}},[a._v("#")]),a._v(" 4.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-C, --copyright\n\t显示版权信息并退出\n-c, --traditional\n\t是 awk 运行在兼容模式下,gawk 的任何扩展都不会生效\n-d, --dump-variables[=FILE]\n\t将 awk 排序后的全局变量的类型和值打印到指定的文件中,如果没有指定 FILE,则在当前目录默认生成一个 awkvars.out\n-E, --exec FILE\n\t功能类似于选项 -f,但脚本文件需要以 #! 开头;另外命令行的变量将不再生效\n-e, --source PROGRAM_TEXT\n\t指定 awk 的源码文件\n-F, --field-separator FS\n\t使用字符或字符串 FS 作为域分隔符。可以同时指定多个域分隔符,此时需要使用一对中括号括起来。例如使用-和|可写作 -F '[-|]'。如果用[]作为分隔符,可写作-F '[][]'。不指定分隔符,默认为空格和 Tab。注意,使用 -F' '显示指定空格时,Tab 也会被作为分隔符。使用 [] 指定多个分隔符时,又想使多个分隔符组成的字符串也作为分隔符,在 [] 后添加一个 +,如 -F\"[ab]+\",那么分隔符有三个,a,b 和 ab\n-f, --file PROGRAM_FILE\n\t从指定的 awk 脚本文件 PROGRAM_FILE 读取 awk 指令\n-g, --gen-pot\n\t解析 awk 程序,产生 .po(Portable Object Template) 格式的文件到标准输出,来标明程序中每一个可本地化的字符串位置\n-h, --help\n\t显示简要的帮助信息并退出\n-L, --lint[=VALUE]\n\t打印有关在其它版本 awk 中出现可疑的或不可移植结构的警告。该选项提供了一个可选的参数 fatal,即将警告视为致命的错误\n-m{f|r} VAL\n\t-mf 将最大字段数设为 VAL;-mr 将最大记录数设为 VAL。这两个功能是 Bell 实验室版awk 的扩展功能,在标准 awk 中不适用\n-N, --use-lc-numeric\n\t使用本地小数点解析输入的数据\n-n, --non-decimal-data\n\t识别输入数据中八进制和十六进制数\n-O, --optimize\n\t在程序的内部表示上启用优化。目前,这只包括简单的常量折叠。gawk 维护者希望随着时间的推移增加额外的优化\n-P, --posix\n\t打开兼容模式,会出现以下限制:\n\t不识别 \\x;\n\t当域分隔符 FS 是一个空格时,只有空格和 Tab 能作为域分隔符,换行符将不能作为一个域分隔符;\n\t在 ? 和 : 之后,不能继续当前行;\n\t函数关键字 func 将不能被识别;\n\t操作符 ** 和 **= 不能代替 ^ 和 ^=;\n\tfflush 函数无效。\n-R, --command FILE\n\t只限于 Dgawk。从文件中读取调试器命令\n-r, --re-interval\n\t允许间隔正则表达式的使用。为默认选项\n-S, --sandbox\n\t在沙盒模式下运行gawk,禁用 system() 函数,使用 getline 进行输入重定向,使用 print 和 printf 进行输出重定向,以及加载动态扩展。命令执行也被禁用,这有效地阻止了脚本访问本地资源\n-t, --lint-old\n\t打印关于不能向传统 Unix awk 移植的构造的警告\n--profile[=FILE]\n\t输出性能分析报告至指定的文件,默认输出到 awkprof.out\n-V, --version\n\t打印版本信息并退出\n-v, --assign VAR=VAL\n\t定义一个 awk 变量并赋值,可以将外部变量传递给 awk\n--\n\t标识命令选项结束\n")])])]),t("h2",{attrs:{id:"_5-调用方式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-调用方式"}},[a._v("#")]),a._v(" 5.调用方式")]),a._v(" "),t("p",[a._v("有三种方式调用 awk。")]),a._v(" "),t("p",[a._v("(1)命令行方式。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("-F FS"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'PATTERN + {ACTION}'")]),a._v(" FILE"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),a._v(".\n")])])]),t("p",[a._v("在 awk 中,文件的每一行中,由域分隔符分开的每一项称为一个域。通常,在不指明域分隔符的情况下,默认为空格和 Tab。")]),a._v(" "),t("p",[a._v("(2)Shell 脚本方式。\n将所有的 awk 命令插入一个文件,脚本中在首行注明使用 awk 命令来解析执行,相当于将 Shell 脚本首行的"),t("code",[a._v("#!/bin/sh")]),a._v("换成"),t("code",[a._v("#!/bin/awk")]),a._v(",最后通过键入脚本名称来调用。")]),a._v(" "),t("p",[a._v("(3)将所有的 awk 命令插入到一个单独文件,然后使用 -f 选项调用。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("awk -f awk-script-file FILE...\n")])])]),t("p",[a._v("其中,-f 选项加载 awk-script-file 中的 awk 脚本,FILE... 跟上面的是一样的。")]),a._v(" "),t("h2",{attrs:{id:"_6-内置变量"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_6-内置变量"}},[a._v("#")]),a._v(" 6.内置变量")]),a._v(" "),t("p",[a._v("gawk 有许多内置变量用来设置环境信息,这些变量可以被改变,下面给出常见的内置变量说明。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$0")]),a._v("\t\t\t\t当前处理行\n"),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$n")]),a._v("\t\t\t\t当前记录的第 n 个字段,n 从 "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("1")]),a._v(" 开始,字段间由 FS 分隔\nARGC \t命令行参数个数\nARGIND \t\t\t当前处理命令行中的第几个文件,文件下标从 "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v(" 开始\nARGV 命令行参数数组\nCONVFMT\t\t\t数字转换格式,默认值为%.6g\nENVIRON 支持队列中系统环境变量的使用\nERRNO\t\t\t最后一个系统错误的描述\nFIELDWIDTHS\t\t字段宽度列表"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("用空格键分隔"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v("\nFILENAME awk浏览的文件名\nFNR 当前被处理文件的记录数\nFS 设置输入域分隔符,等价于命令行-F选项\nIGNORECASE\t\t如果为真,则进行忽略大小写的匹配\nLINT\t\t\t动态控制--lint选项是否生效,为false不生效,为true则生效;\nNF 浏览记录的域的个数\nNR 已读的记录数\nOFMT\t\t\t数字的输出格式,默认值是%.6g\nOFS 输出域分隔符\nORS 输出记录分隔符\t\t\t\t\nRS The input record separator,输入记录的分隔符,默认为换行符\nRT\t\t\t\tThe record terminator,输入记录的结束符\t\t\nRSTART\t\t\t由 match 函数所匹配的字符串的第一个位置\nRLENGTH\t\t\t由 match 函数所匹配的字符串的长度\nSUBSEP\t\t\t数组下标分隔符(默认值是 "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("\\")]),a._v("034)\nTEXTDOMAIN\t\t"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" 程序所使用的文本所处的地域\n")])])]),t("h2",{attrs:{id:"_7-编程示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_7-编程示例"}},[a._v("#")]),a._v(" 7.编程示例")]),a._v(" "),t("h3",{attrs:{id:"_7-1-基础打印输出"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_7-1-基础打印输出"}},[a._v("#")]),a._v(" 7.1 基础打印输出")]),a._v(" "),t("p",[a._v("(1)假设 last -n 5 的输出如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("root pts/1 192.168.1.100 Tue Feb 10 11:21 still logged in\nroot pts/1 192.168.1.100 Tue Feb 10 00:46 - 02:28 (01:41)\nroot pts/1 192.168.1.100 Mon Feb 9 11:41 - 18:30 (06:48)\ndmtsai pts/1 192.168.1.100 Mon Feb 9 11:41 - 11:41 (00:00)\nroot tty1 Fri Sep 5 14:09 - 14:10 (00:01)\n")])])]),t("p",[a._v("如果只是显示最近登录的5个帐号:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("last -n 5 | awk '{print $1}'\nroot\nroot\nroot\ndmtsai\nroot\n")])])]),t("p",[a._v("awk 工作流程是这样的:读入有换行符分隔的一条记录,然后将记录按指定的域分隔符划分,"),t("code",[a._v("$0")]),a._v("则表示所有域,"),t("code",[a._v("$1")]),a._v("表示第一个域,"),t("code",[a._v("$n")]),a._v("表示第 n 个域。默认域分隔符是空格或 Tab 符,所以"),t("code",[a._v("$1")]),a._v("表示登录用户,"),t("code",[a._v("$3")]),a._v("表示登录用户 ip,以此类推。")]),a._v(" "),t("p",[a._v("(2)如果想显示 /etc/passwd 配置文件中的账户以及账户对应的 Shell,而账户与 Shell 之间以Tab符分隔。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" /etc/passwd "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-F")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("':'")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'{print $1\"\\t\"$7}'")]),a._v("\nroot /bin/bash\ndaemon /bin/sh\nbin /bin/sh\nsys /bin/sh\n")])])]),t("p",[a._v("注意,这里使用了 -F 指定域分隔符为冒号 :。")]),a._v(" "),t("p",[a._v("(3)如果只是显示 /etc/passwd 的账户和账户对应的 Shell,而账户与 Shell 之间以逗号分隔,而且在所有行添加列名 name,shell,在最后一行添加 blue,/bin/nosh。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" /etc/passwd "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-F")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("':'")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('\'BEGIN {print "name,shell"} {print $1","$7} END {print "blue,/bin/nosh"}\'')]),a._v("\nname,shell\nroot,/bin/bash\ndaemon,/bin/sh\nbin,/bin/sh\nsys,/bin/sh\n"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),a._v("\nblue,/bin/nosh\n")])])]),t("p",[a._v("awk 工作流程是这样的:先执行 BEGING,然后读取文件,读入有/n换行符分割的一条记录,然后将记录按指定的域分隔符划分域,填充域,$0则表示所有域,"),t("code",[a._v("$1")]),a._v("表示第一个域,"),t("code",[a._v("$n")]),a._v("表示第 n 个域,随后开始执行模式所对应的动作action。接着开始读入第二条记录······直到所有的记录都读完,最后执行END操作。")]),a._v(" "),t("p",[a._v("(4)搜索 /etc/passwd 有 root 关键字的所有行。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" -F: "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'/root/'")]),a._v(" /etc/passwd\nroot:x:0:0:root:/root:/bin/bash\n")])])]),t("p",[a._v("上面三种是 awk 的 action 的使用示例,而这种是 pattern 的使用示例,匹配了 pattern(这里是root)的行才会执行 action(没有指定 action,默认输出每行的内容)。")]),a._v(" "),t("p",[a._v("搜索支持正则表达式,例如找 root 开头的所有行。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" -F: "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'/^root/'")]),a._v(" /etc/passwd\n")])])]),t("p",[a._v("(5)搜索/etc/passwd有 root 关键字的所有行,并显示对应的 Shell。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" -F: "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'/root/{print $7}'")]),a._v(" /etc/passwd\n/bin/bash\n")])])]),t("p",[a._v("这里是 awk 的 pattern+action 示例用法,同时指明了 action 是 {print $7}。")]),a._v(" "),t("p",[a._v("(6)打印 /etc/passwd 第三行的第一列和第二列。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" -F: "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'NR==3{print $1,$2;}'")]),a._v(" /etc/passwd\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#输出结果:")]),a._v("\ndaemon x\n")])])]),t("h3",{attrs:{id:"_7-2-awk-在每一列后添加字符串后输出"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_7-2-awk-在每一列后添加字符串后输出"}},[a._v("#")]),a._v(" 7.2 awk 在每一列后添加字符串后输出")]),a._v(" "),t("p",[a._v("设定变量内容:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v('a="/test.html /dir1 /abc.txt"\n')])])]),t("p",[a._v("希望得到")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$a")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--exclude")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/test.html "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--exclude")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/dir1 "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--exclude")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/abc.txt\n")])])]),t("p",[a._v("如何用 awk 实现。")]),a._v(" "),t("p",[a._v("解决办法:")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$a")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('\'{for(i=1;i<=NF-1;++i){printf "-execute=%s ",$i}}{print "--exclude="$NF""}\'')]),a._v("\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#或者")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$a")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('\'{for(i=1;i<=NF;i++){printf "--exclude="$i" "}{print ""}}\'')]),a._v("\n")])])]),t("p",[a._v("后者是网友给出的答案,和我上面的写法差不多,只是对 printf 在使用形式上有所差别而已。第二种方法"),t("code",[a._v('print ""')]),a._v("用于换行,print 每次输出后默认进行换行。")]),a._v(" "),t("h3",{attrs:{id:"_7-3-shell-编程使用-awk-浮点运算保留两位小数"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_7-3-shell-编程使用-awk-浮点运算保留两位小数"}},[a._v("#")]),a._v(" 7.3 Shell 编程使用 awk 浮点运算保留两位小数")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("a=3\nb=10\nc=$(awk 'BEGIN{printf \"%.2f\",'$a'*100/'$b'}')\necho c:$c%\n")])])]),t("p",[a._v("或者:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("c=$(awk -v n=$a -v m=$b 'BEGIN{printf \"%.2f\",n*100/m}')\necho c:$c%\n")])])]),t("p",[a._v("-v表示定义awk的变量!v是variable的首字母。输出:c:30.00%。")]),a._v(" "),t("h3",{attrs:{id:"_7-4-awk-访问-shell-变量"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_7-4-awk-访问-shell-变量"}},[a._v("#")]),a._v(" 7.4 awk 访问 Shell 变量")]),a._v(" "),t("p",[a._v("awk 默认是无法访问shell变量的,我所知道的有三种方法。\n方法一:awk -v 选项让awk 里使用shell变量。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var0")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("dablelv0\n"),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var1")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("dablelv1\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-v")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("tmpVar0")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$var0")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-v")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("tmpVar1")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$var1")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'BEGIN{print tmpVar0\" \"tmpVar1}'")]),a._v("\n")])])]),t("p",[a._v("输出: dablelv0 dablelv1\n注意: BEGIN 必须大写,awk 的 {action} 必须要使用单引号括起来。")]),a._v(" "),t("p",[a._v("方法二:"),t("code",[a._v("'\"$var\"'")]),a._v("\n这种写法是老外常用的写法。如:")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"test"')]),a._v(" \n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'BEGIN{print \"'")]),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$var")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'\"}'")]),a._v("\n")])])]),t("p",[a._v("这种写法其实际是双括号变为单括号的常量,传递给了awk。")]),a._v(" "),t("p",[a._v("如果var中含空格,为了shell不把空格作为分格符,应该如下使用:")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"this is a test"')]),a._v(" \n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'BEGIN{print \"'")]),a._v('"'),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$var")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"\'"')]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("}")]),a._v("' \n")])])]),t("p",[a._v("方法三:export 变量,将变量设置为临时会话环境变量,仅在当前shell会话中有效。在awk中使用"),t("code",[a._v('ENVIRON["var"]')]),a._v("形式访问变量。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"this is a test"')]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("export")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$var")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#或者 export var")]),a._v("\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#或者")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("export")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"this is a test"')]),a._v("\n\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'BEGIN{print ENVIRON[\"var\"]}'")]),a._v(" \n")])])]),t("h3",{attrs:{id:"_7-5-awk-执行-shell-命令"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_7-5-awk-执行-shell-命令"}},[a._v("#")]),a._v(" 7.5 awk 执行 Shell 命令")]),a._v(" "),t("p",[a._v("awk 执行 Shell 命令有两种方法。\n方法一:使用awk的system()函数。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("export")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("dablelv\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'BEGIN{system(\"echo $var\")}'")]),a._v("\n")])])]),t("p",[a._v("输出:dablelv\n注意:一定要使用export将变量设置为临时环境变量,因为awk的system()实际上是新建了一个shell进程来执行给定的shell命令,否则无法访问父进程的变量。")]),a._v(" "),t("p",[a._v("方法二:使用"),t("code",[a._v('使用print cmd | "/bin/bash"')])]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("var")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"this is a test"')]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('\'BEGIN{print "echo ""\'')]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"'),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$var")]),a._v('"')]),a._v("'"),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"|"')]),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("sh")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"}\'\n\n#或者\nvar="')]),a._v("this is a "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("test")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"\nawk -v varTmp="')]),t("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$var")]),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('" \'BEGIN{print "')]),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"varTmp|"')]),a._v('sh"'),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("}")]),a._v("'\n")])])]),t("p",[a._v("输出:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("this is a test\n")])])]),t("p",[a._v("注意:\n(1)指定bash的时候需要双引号括起来;\n(2)方法二与方法一的区别在于方法二是将变量在awk解析后再通过管道传给shell,所以无需将变量设置为临时环境变量,因为shell接收到的变量已经是变量的值。")]),a._v(" "),t("h2",{attrs:{id:"_8-faq"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_8-faq"}},[a._v("#")]),a._v(" 8.FAQ")]),a._v(" "),t("p",[a._v("(1)awk 默认以空格和 Tab 作为域分隔符,现在只以空格为分隔符,需要使用中括号的方式,不使用中括号,则仍然会将 Tab 作为域分隔符。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 错误的写法")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" -F"),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("' '")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'{print $1;}'")]),a._v(" test.txt\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 正确的写法")]),a._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("awk")]),a._v(" -F"),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'[ ]'")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'{print $1;}'")]),a._v(" test.txt \n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://www.linux.org/docs/man1/awk.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("awk manual - linux.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/awk.1p.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("awk(1p) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://awk.js.org/",target:"_blank",rel:"noopener noreferrer"}},[a._v("awk online"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://man.linuxde.net/awk",target:"_blank",rel:"noopener noreferrer"}},[a._v("Linux命令大全.awk命令"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://www.runoob.com/linux/linux-comm-awk.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("菜鸟教程.Linux awk 命令"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858470.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("博客园.linux awk命令详解"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://blog.csdn.net/yakoo5/article/details/43952713",target:"_blank",rel:"noopener noreferrer"}},[a._v("Shell脚本之awk篇"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://blog.163.com/zihuan_xuan/blog/static/1287942432012111041854341/",target:"_blank",rel:"noopener noreferrer"}},[a._v("awk使用shell变量"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://blog.chinaunix.net/uid-280990-id-2449802.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("awk中使用shell命令"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/hongchangfirst/article/details/25071937",target:"_blank",rel:"noopener noreferrer"}},[a._v("awk按照多个分隔符进行分割"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"awk"}})],1)}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/104.57b2416a.js b/docs/assets/js/104.32749cf1.js similarity index 98% rename from docs/assets/js/104.57b2416a.js rename to docs/assets/js/104.32749cf1.js index fa15dbf4b..06e9792e3 100644 --- a/docs/assets/js/104.57b2416a.js +++ b/docs/assets/js/104.32749cf1.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[104],{438:function(a,e,t){"use strict";t.r(e);var r=t(12),s=Object(r.a)({},(function(){var a=this,e=a._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[e("h2",{attrs:{id:"_1-命令简介"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),e("p",[a._v("col(control)是一个标准输入文本过滤器。")]),a._v(" "),e("p",[a._v("col 从标准输入读取内容,过滤掉控制字符反向换行符(RLF-Reverse Line Feed)和半反向换行符(HRLF-Halt RLF)后输出到标准输出。还可以将空白符用等价制表符(Tab)或空格(Space)来替换。")]),a._v(" "),e("p",[a._v("在许多 Linux 说明文件里,包含控制字符。当我们运用 Shell 特殊字符 > 和 >> 把说明文件的内容输出成纯文本文件时,控制字符会变成乱码,col 命令则能有效滤除这些控制字符。")]),a._v(" "),e("h2",{attrs:{id:"_2-命令格式"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[a._v("col [OPTIONS]\n")])])]),e("h2",{attrs:{id:"_3-选项说明"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[a._v("-b, --no-backspaces\n\t不输出任何退格符,只打印写入每个列位置的最后一个字符\n-f, --fine\n\t允许正向半换行符(half-forward line feeds)。通常,处于半行分界线上的字符打印在下一行\n-h, --tabs\n\t将多个空格转换为Tab,一般 4 个 空格转为 1 个 Tab\n-l, --lines NUMBER\n\t设置缓冲行为 NUMBER,默认为 128\n-p, --pass\n\t不转换未识别的控制符\n-x, --spaces\n\t将 Tab 转为多个空格,一般 1 一个 Tab 转为 4 个空格\n-H, --help\n\t显示帮助信息并退出\n-V, --version\n\t显示版本信息并退出\n")])])]),e("h2",{attrs:{id:"_4-常用示例"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),e("p",[a._v("(1)将 Tab 替换为空格,一般 1 个 Tab 转为 4 个空格。")]),a._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[a._v('echo -e "123\\t456" | col -x\n')])])]),e("p",[a._v("(2)将空格替换为 Tab,一般 4 个 空格转为 1 个 Tab。")]),a._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[a._v('echo -e "123 456" | col -h\n')])])]),e("p",[a._v("(3)将帮助文档内的控制符删除。以 col 命令的 manual 为例。")]),a._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[a._v("man col | col -b > newFile\n")])])]),e("h2",{attrs:{id:"_5-相关疑问"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_5-相关疑问"}},[a._v("#")]),a._v(" 5.相关疑问")]),a._v(" "),e("p",[a._v("RLF 字符(reverse line feed)是反向换行符,HRLF字符(half-reverse line feed)是半反向换行符。百度知道中有网友的回答,但是我还是不太清楚这两个字符的作用和应用场景,请知道的大牛评论告知,万分感谢。")]),a._v(" "),e("hr"),a._v(" "),e("h2",{attrs:{id:"参考文献"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),e("p",[e("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/col.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("col(1) - Linux manual page - man7.org"),e("OutboundLink")],1)]),a._v(" "),e("p",[e("a",{attrs:{href:"http://linux.51yip.com/search/col",target:"_blank",rel:"noopener noreferrer"}},[a._v("linux 命令手册.col 命令 "),e("OutboundLink")],1)]),a._v(" "),e("p",[e("a",{attrs:{href:"https://man.linuxde.net/col",target:"_blank",rel:"noopener noreferrer"}},[a._v("Linux 命令大全.col 命令"),e("OutboundLink")],1)]),a._v(" "),e("p",[e("a",{attrs:{href:"https://stackoverflow.com/questions/10638382/what-is-a-reverse-line-feed",target:"_blank",rel:"noopener noreferrer"}},[a._v("Stack Overflow.What is a reverse line feed"),e("OutboundLink")],1)]),a._v(" "),e("Vssue",{attrs:{title:"col"}})],1)}),[],!1,null,null,null);e.default=s.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[104],{437:function(a,e,t){"use strict";t.r(e);var r=t(12),s=Object(r.a)({},(function(){var a=this,e=a._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[e("h2",{attrs:{id:"_1-命令简介"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),e("p",[a._v("col(control)是一个标准输入文本过滤器。")]),a._v(" "),e("p",[a._v("col 从标准输入读取内容,过滤掉控制字符反向换行符(RLF-Reverse Line Feed)和半反向换行符(HRLF-Halt RLF)后输出到标准输出。还可以将空白符用等价制表符(Tab)或空格(Space)来替换。")]),a._v(" "),e("p",[a._v("在许多 Linux 说明文件里,包含控制字符。当我们运用 Shell 特殊字符 > 和 >> 把说明文件的内容输出成纯文本文件时,控制字符会变成乱码,col 命令则能有效滤除这些控制字符。")]),a._v(" "),e("h2",{attrs:{id:"_2-命令格式"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[a._v("col [OPTIONS]\n")])])]),e("h2",{attrs:{id:"_3-选项说明"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[a._v("-b, --no-backspaces\n\t不输出任何退格符,只打印写入每个列位置的最后一个字符\n-f, --fine\n\t允许正向半换行符(half-forward line feeds)。通常,处于半行分界线上的字符打印在下一行\n-h, --tabs\n\t将多个空格转换为Tab,一般 4 个 空格转为 1 个 Tab\n-l, --lines NUMBER\n\t设置缓冲行为 NUMBER,默认为 128\n-p, --pass\n\t不转换未识别的控制符\n-x, --spaces\n\t将 Tab 转为多个空格,一般 1 一个 Tab 转为 4 个空格\n-H, --help\n\t显示帮助信息并退出\n-V, --version\n\t显示版本信息并退出\n")])])]),e("h2",{attrs:{id:"_4-常用示例"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),e("p",[a._v("(1)将 Tab 替换为空格,一般 1 个 Tab 转为 4 个空格。")]),a._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[a._v('echo -e "123\\t456" | col -x\n')])])]),e("p",[a._v("(2)将空格替换为 Tab,一般 4 个 空格转为 1 个 Tab。")]),a._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[a._v('echo -e "123 456" | col -h\n')])])]),e("p",[a._v("(3)将帮助文档内的控制符删除。以 col 命令的 manual 为例。")]),a._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[a._v("man col | col -b > newFile\n")])])]),e("h2",{attrs:{id:"_5-相关疑问"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_5-相关疑问"}},[a._v("#")]),a._v(" 5.相关疑问")]),a._v(" "),e("p",[a._v("RLF 字符(reverse line feed)是反向换行符,HRLF字符(half-reverse line feed)是半反向换行符。百度知道中有网友的回答,但是我还是不太清楚这两个字符的作用和应用场景,请知道的大牛评论告知,万分感谢。")]),a._v(" "),e("hr"),a._v(" "),e("h2",{attrs:{id:"参考文献"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),e("p",[e("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/col.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("col(1) - Linux manual page - man7.org"),e("OutboundLink")],1)]),a._v(" "),e("p",[e("a",{attrs:{href:"http://linux.51yip.com/search/col",target:"_blank",rel:"noopener noreferrer"}},[a._v("linux 命令手册.col 命令 "),e("OutboundLink")],1)]),a._v(" "),e("p",[e("a",{attrs:{href:"https://man.linuxde.net/col",target:"_blank",rel:"noopener noreferrer"}},[a._v("Linux 命令大全.col 命令"),e("OutboundLink")],1)]),a._v(" "),e("p",[e("a",{attrs:{href:"https://stackoverflow.com/questions/10638382/what-is-a-reverse-line-feed",target:"_blank",rel:"noopener noreferrer"}},[a._v("Stack Overflow.What is a reverse line feed"),e("OutboundLink")],1)]),a._v(" "),e("Vssue",{attrs:{title:"col"}})],1)}),[],!1,null,null,null);e.default=s.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/105.e078ce62.js b/docs/assets/js/105.2128987a.js similarity index 98% rename from docs/assets/js/105.e078ce62.js rename to docs/assets/js/105.2128987a.js index b6b4924b3..e4745e958 100644 --- a/docs/assets/js/105.e078ce62.js +++ b/docs/assets/js/105.2128987a.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[105],{439:function(t,a,e){"use strict";e.r(a);var s=e(12),n=Object(s.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h1",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("cut 是一个选取命令,以行为单位,选择性输出符合条件的内容到标准输出。")]),t._v(" "),a("p",[t._v("cut 命令主要用途有两个,其一是用来显示文件的内容,它依次读取所指明的文件列表,将它们的内容输出到标准输出上;其二是连接两个或多个文件,如 cut f1 f2 > f3 将把文件 f1 和 f2 的内容合并起来,然后通过输出重定向符 > 的作用,将它们放入文件 f3 中。")]),t._v(" "),a("h1",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("cut OPTION... [FILE]...\n")])])]),a("p",[t._v("在没有提供文件或文件是 - 的情况下,cut 从标准输入读取内容。")]),t._v(" "),a("h1",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("p",[t._v("注意,长选项的强制性参数对于短选项也是强制的。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-b, --bytes=LIST\n\t设置输出的字节数或范围\n-c, --characters=LIST\n\t设置输出的字符数或范围\n-d, --delimiter=DELIM\n\t指定列(或字段)的分隔字符。默认分隔符是制表符 Tab。只能和 -f 选项一起使用\n-f, --fields=LIST\n\t设置输出字段,默认字段分隔符是空格。-f 会打印不包含分隔符的行,除非指定了 -s 选项\n-n\n\t与 -b 选项连用,不分割多字节字符\n--complement\n\t反向选择字节、字符或字段\n-s, --only-delimited\n\t若行没有分隔符,则不显示该行。此选项只能和 -f 选项一起使用\n--output-delimiter=STRING\n\t使用字符串作为输出分隔符,默认是输入分隔符\n-z, --zero-terminated\n\t行分隔符是 NUL,而不是 LF\n--help\n\t显示帮助信息并退出\n--version\n\t显示版本信息并退出\n")])])]),a("p",[t._v("当使用 -b、-c 或 -f 选项时,LIST 由一个范围(range)或逗号隔开的多个范围组成。范围的表示形式有:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("N\n 第 N 个字节、字符或字段。N 从 1 开始计数 \nN-\n 从第 N 个字节、字符或字段直至行尾 \nN-M\n\t从第 N 到第 M(包括 M)个字节、字符或字段 \n-M\n\t从第 1 到第 M(并包 M)个字节、字符或字段\n")])])]),a("h1",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("p",[t._v("首先给出用于测试的本文件 testfile,其内容如下:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("hello world\ni am lvlv\ni like linux\n")])])]),a("p",[t._v("(1)以字符为单位输出指定范围的字符。使用 cut 命令选择第 3 到第 5 个字符输出:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("cut -c 3-5 testfile\nllo\nam \nlik\n")])])]),a("p",[t._v("如果没有指定结束字符的位置,即"),a("code",[t._v("cut -c 3- testfile")]),t._v(",则输出第三个字符到最后一个字符。同样我们可以使用字节为单位来进行,如果文本文件是单字节编码的字符,那么"),a("code",[t._v("cut -b 3-5 testfile")]),t._v("等同于"),a("code",[t._v("cut -c 3-5 testfile")]),t._v("。")]),t._v(" "),a("p",[t._v("(2)以字段为单位输出指定字段。输出第二列和第三列的内容:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('cut -d " " -f 1 testfile\nworld\nam lvlv\nlike linux\n')])])]),a("p",[t._v("注意,因为第一行没有第三列,所以输出为空。")]),t._v(" "),a("p",[t._v("(3)选项提取指定字段之外的列。输出第一列之外的内容:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('cut -d " " -f 1 --complement testfile\nworld\nam lvlv\nlike linux\n')])])]),a("hr"),t._v(" "),a("h1",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/cut.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("cut(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man.linuxde.net/cut",target:"_blank",rel:"noopener noreferrer"}},[t._v("Linux 命令大全.cut 命令"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"cut"}})],1)}),[],!1,null,null,null);a.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[105],{438:function(t,a,e){"use strict";e.r(a);var s=e(12),n=Object(s.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h1",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("cut 是一个选取命令,以行为单位,选择性输出符合条件的内容到标准输出。")]),t._v(" "),a("p",[t._v("cut 命令主要用途有两个,其一是用来显示文件的内容,它依次读取所指明的文件列表,将它们的内容输出到标准输出上;其二是连接两个或多个文件,如 cut f1 f2 > f3 将把文件 f1 和 f2 的内容合并起来,然后通过输出重定向符 > 的作用,将它们放入文件 f3 中。")]),t._v(" "),a("h1",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("cut OPTION... [FILE]...\n")])])]),a("p",[t._v("在没有提供文件或文件是 - 的情况下,cut 从标准输入读取内容。")]),t._v(" "),a("h1",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("p",[t._v("注意,长选项的强制性参数对于短选项也是强制的。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-b, --bytes=LIST\n\t设置输出的字节数或范围\n-c, --characters=LIST\n\t设置输出的字符数或范围\n-d, --delimiter=DELIM\n\t指定列(或字段)的分隔字符。默认分隔符是制表符 Tab。只能和 -f 选项一起使用\n-f, --fields=LIST\n\t设置输出字段,默认字段分隔符是空格。-f 会打印不包含分隔符的行,除非指定了 -s 选项\n-n\n\t与 -b 选项连用,不分割多字节字符\n--complement\n\t反向选择字节、字符或字段\n-s, --only-delimited\n\t若行没有分隔符,则不显示该行。此选项只能和 -f 选项一起使用\n--output-delimiter=STRING\n\t使用字符串作为输出分隔符,默认是输入分隔符\n-z, --zero-terminated\n\t行分隔符是 NUL,而不是 LF\n--help\n\t显示帮助信息并退出\n--version\n\t显示版本信息并退出\n")])])]),a("p",[t._v("当使用 -b、-c 或 -f 选项时,LIST 由一个范围(range)或逗号隔开的多个范围组成。范围的表示形式有:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("N\n 第 N 个字节、字符或字段。N 从 1 开始计数 \nN-\n 从第 N 个字节、字符或字段直至行尾 \nN-M\n\t从第 N 到第 M(包括 M)个字节、字符或字段 \n-M\n\t从第 1 到第 M(并包 M)个字节、字符或字段\n")])])]),a("h1",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("p",[t._v("首先给出用于测试的本文件 testfile,其内容如下:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("hello world\ni am lvlv\ni like linux\n")])])]),a("p",[t._v("(1)以字符为单位输出指定范围的字符。使用 cut 命令选择第 3 到第 5 个字符输出:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("cut -c 3-5 testfile\nllo\nam \nlik\n")])])]),a("p",[t._v("如果没有指定结束字符的位置,即"),a("code",[t._v("cut -c 3- testfile")]),t._v(",则输出第三个字符到最后一个字符。同样我们可以使用字节为单位来进行,如果文本文件是单字节编码的字符,那么"),a("code",[t._v("cut -b 3-5 testfile")]),t._v("等同于"),a("code",[t._v("cut -c 3-5 testfile")]),t._v("。")]),t._v(" "),a("p",[t._v("(2)以字段为单位输出指定字段。输出第二列和第三列的内容:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('cut -d " " -f 1 testfile\nworld\nam lvlv\nlike linux\n')])])]),a("p",[t._v("注意,因为第一行没有第三列,所以输出为空。")]),t._v(" "),a("p",[t._v("(3)选项提取指定字段之外的列。输出第一列之外的内容:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('cut -d " " -f 1 --complement testfile\nworld\nam lvlv\nlike linux\n')])])]),a("hr"),t._v(" "),a("h1",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/cut.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("cut(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man.linuxde.net/cut",target:"_blank",rel:"noopener noreferrer"}},[t._v("Linux 命令大全.cut 命令"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"cut"}})],1)}),[],!1,null,null,null);a.default=n.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/108.7cd1f2d6.js b/docs/assets/js/108.f9ff02e0.js similarity index 98% rename from docs/assets/js/108.7cd1f2d6.js rename to docs/assets/js/108.f9ff02e0.js index c9f77d035..cf6ddfa3a 100644 --- a/docs/assets/js/108.7cd1f2d6.js +++ b/docs/assets/js/108.f9ff02e0.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[108],{442:function(a,n,t){"use strict";t.r(n);var e=t(12),s=Object(e.a)({},(function(){var a=this,n=a._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[n("h2",{attrs:{id:"_1-命令简介"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),n("p",[a._v("join 将"),n("strong",[a._v("两个文件")]),a._v("按照指定的相同字段进行笛卡尔乘积"),n("strong",[a._v("横向拼接")]),a._v(",并输出到标准输出。")]),a._v(" "),n("p",[a._v("默认情况下,join 字段分隔符是空格或 Tab。join 时,两个文件需要按照某个字段排好序。")]),a._v(" "),n("p",[a._v("笛卡尔乘积指两个集合 X 和 Y 成员相互组合构成的有序对的集合。比如集合 X={a,b},Y={0,1,2},则")]),a._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[a._v("X×Y={(a, 0), (a, 1), (a, 2), (b, 0), (b, 1), (b, 2)}\nY×X={(0, a), (0, b), (1, a), (1, b), (2, a), (2, b)}\n")])])]),n("h2",{attrs:{id:"_2-命令格式"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[a._v("join [OPTIONS] FILE1 FILE2\n")])])]),n("p",[a._v("当 FILE1 或 FILE2 是连字符 -(二者不能同时是 -),那么内容从标准输入读取。")]),a._v(" "),n("h2",{attrs:{id:"_3-选项说明"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[a._v("-a FILENUM\n\t除了显示原来的输出内容之外,还显示文件中没有相同栏位的行。FILENUM 取值为 1 或 2,分别对应 FILE1 和 FILE2\n-e EMPTY\n\t若 FILE1 与 FILE2 中找不到指定的列,则在输出中填入选项中的字符串\n-i, --igore-case\n\t比较列内容时,忽略大小写\n-j FIELD\n\t等价于 -1 FIELD -2 FIELD\n-o FORMAT\n\t按照指定的格式显示结果\n-t CHAR\n\t指定输入和输出列的分隔字符\n-v FILENUM\n\t作用类似于 -a FILENUM,但是只显示文件中没有相同列的行\n-1 FIELD\n\t连接 FILE1 指定的列。FIELD 取 1 表示第一列,2 表示第二列,以此类推\n-2 FIELD\n\t连接 FILE2 指定的列。FIELD 取 1 表示第一列,2 表示第二列,以此类推\n--check-order\n\t默认选项,检查文件是否已经排序\n--nocheck-order\n\t不检查检查文件是否已经排序\n--help\n\t显示帮助信息并退出\n--version\n\t显示版本信息并退出\n")])])]),n("h2",{attrs:{id:"_4-常用示例"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),n("p",[a._v("(1)连接两个文件,默认以第一列作为连接字段。")]),a._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[a._v("# file1 内容如下\nlvlv dablelv 25\nzhangsan San 12\n\n# file2 内容如下\nlvlv english 15\nlvlv math 75\nzhangsan math 14\nzhouxun english 45\n\njoin file1 file2\nlvlv dablelv 25 english 15\nlvlv dablelv 25 math 75\nzhangsan San 12 math 14\n")])])]),n("p",[a._v("(2)还是以上面的两个文件为例,显示指明按照第一列中文名进行连接。")]),a._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[a._v("join -j 1 file1 file2\n# 或\njoin -1 1 -2 1 file1 file2\n")])])]),n("p",[a._v("(3)如果想显示没有相同字段的行,使用 -a1 或 -a2 指定显示第一个或者第二个文件的行。")]),a._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[a._v("join -a2 file1 file2\nlvlv dablelv 25 english 15\nlvlv dablelv 25 math 75\nzhangsan San 12 math 14\nzhouxun english 45 \t\t//显示了文件 file2 中未匹配的一行\n")])])]),n("hr"),a._v(" "),n("h2",{attrs:{id:"参考文献"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),n("p",[n("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/join.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("join(1) - Linux manual page - man7.org"),n("OutboundLink")],1)]),a._v(" "),n("Vssue",{attrs:{title:"join"}})],1)}),[],!1,null,null,null);n.default=s.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[108],{443:function(a,n,t){"use strict";t.r(n);var e=t(12),s=Object(e.a)({},(function(){var a=this,n=a._self._c;return n("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[n("h2",{attrs:{id:"_1-命令简介"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),n("p",[a._v("join 将"),n("strong",[a._v("两个文件")]),a._v("按照指定的相同字段进行笛卡尔乘积"),n("strong",[a._v("横向拼接")]),a._v(",并输出到标准输出。")]),a._v(" "),n("p",[a._v("默认情况下,join 字段分隔符是空格或 Tab。join 时,两个文件需要按照某个字段排好序。")]),a._v(" "),n("p",[a._v("笛卡尔乘积指两个集合 X 和 Y 成员相互组合构成的有序对的集合。比如集合 X={a,b},Y={0,1,2},则")]),a._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[a._v("X×Y={(a, 0), (a, 1), (a, 2), (b, 0), (b, 1), (b, 2)}\nY×X={(0, a), (0, b), (1, a), (1, b), (2, a), (2, b)}\n")])])]),n("h2",{attrs:{id:"_2-命令格式"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[a._v("join [OPTIONS] FILE1 FILE2\n")])])]),n("p",[a._v("当 FILE1 或 FILE2 是连字符 -(二者不能同时是 -),那么内容从标准输入读取。")]),a._v(" "),n("h2",{attrs:{id:"_3-选项说明"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[a._v("-a FILENUM\n\t除了显示原来的输出内容之外,还显示文件中没有相同栏位的行。FILENUM 取值为 1 或 2,分别对应 FILE1 和 FILE2\n-e EMPTY\n\t若 FILE1 与 FILE2 中找不到指定的列,则在输出中填入选项中的字符串\n-i, --igore-case\n\t比较列内容时,忽略大小写\n-j FIELD\n\t等价于 -1 FIELD -2 FIELD\n-o FORMAT\n\t按照指定的格式显示结果\n-t CHAR\n\t指定输入和输出列的分隔字符\n-v FILENUM\n\t作用类似于 -a FILENUM,但是只显示文件中没有相同列的行\n-1 FIELD\n\t连接 FILE1 指定的列。FIELD 取 1 表示第一列,2 表示第二列,以此类推\n-2 FIELD\n\t连接 FILE2 指定的列。FIELD 取 1 表示第一列,2 表示第二列,以此类推\n--check-order\n\t默认选项,检查文件是否已经排序\n--nocheck-order\n\t不检查检查文件是否已经排序\n--help\n\t显示帮助信息并退出\n--version\n\t显示版本信息并退出\n")])])]),n("h2",{attrs:{id:"_4-常用示例"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),n("p",[a._v("(1)连接两个文件,默认以第一列作为连接字段。")]),a._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[a._v("# file1 内容如下\nlvlv dablelv 25\nzhangsan San 12\n\n# file2 内容如下\nlvlv english 15\nlvlv math 75\nzhangsan math 14\nzhouxun english 45\n\njoin file1 file2\nlvlv dablelv 25 english 15\nlvlv dablelv 25 math 75\nzhangsan San 12 math 14\n")])])]),n("p",[a._v("(2)还是以上面的两个文件为例,显示指明按照第一列中文名进行连接。")]),a._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[a._v("join -j 1 file1 file2\n# 或\njoin -1 1 -2 1 file1 file2\n")])])]),n("p",[a._v("(3)如果想显示没有相同字段的行,使用 -a1 或 -a2 指定显示第一个或者第二个文件的行。")]),a._v(" "),n("div",{staticClass:"language- extra-class"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[a._v("join -a2 file1 file2\nlvlv dablelv 25 english 15\nlvlv dablelv 25 math 75\nzhangsan San 12 math 14\nzhouxun english 45 \t\t//显示了文件 file2 中未匹配的一行\n")])])]),n("hr"),a._v(" "),n("h2",{attrs:{id:"参考文献"}},[n("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),n("p",[n("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/join.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("join(1) - Linux manual page - man7.org"),n("OutboundLink")],1)]),a._v(" "),n("Vssue",{attrs:{title:"join"}})],1)}),[],!1,null,null,null);n.default=s.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/109.8164b26e.js b/docs/assets/js/109.6ccc99d7.js similarity index 98% rename from docs/assets/js/109.8164b26e.js rename to docs/assets/js/109.6ccc99d7.js index 301a28c7e..6764e5b57 100644 --- a/docs/assets/js/109.8164b26e.js +++ b/docs/assets/js/109.6ccc99d7.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[109],{444:function(t,a,e){"use strict";e.r(a);var s=e(12),n=Object(s.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("paste 将多个文件的相应行默认以 Tab 分隔符横向连接起来,输出到标准输出。")]),t._v(" "),a("p",[t._v("paste 后可接多个文件,不限于 2 个文件。如果文件写成连字符 -,表示内容来自标准输入。paste 相对于 join 来说,简单许多,不需要有相同的字段也可按行拼接。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("pasete [OPTIONS] [FILES]\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-d,--delimiters=LIST\n\t用指定的域分隔符取代Tab。\n-s,--serial\n\t顺序地合并一个文件的所有行到一行\n--help\n\t显示帮助信息并退出\n--version\n\t显示版本信息并退出\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("p",[t._v("有两个文件 file1.txt 和 file2.txt,内容如下:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("# file1 内容\nabc\ndef\nghi\n\n# file2 内容\n123\n456\n789\n012\n")])])]),a("p",[t._v("(1)将文件 file1.txt 的所有行合并到一行。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("paste -s file1.txt\nabc\tdef\tghi\n\n# 指定域分隔符为冒号:\npaste -s -d : file1.txt\nabc:def:ghi\n")])])]),a("p",[t._v("(2)将多个文件的所有行分别合并为一行。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("paste -s file1.txt file2.txt\nabc\tdef\tghi\n123\t456\t789\t012\n")])])]),a("p",[t._v("(3)横向连接两个文件,默认以 Tab 分隔。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("paste file1.txt file2.txt\nabc\t123\ndef\t456\nghi\t789\n\t012\n\n# 通过交换文件名可指定列的位置\npaste file2.txt file1.txt\n123\tabc\n456\tdef\n789\tghi\n012\t\n")])])]),a("p",[t._v("(4)paste 黏贴的内容(行)从标准输入读取,此时可以使用 - 来指代。例如查看 /etc 下的文件列表,并用 paste 打印成每行显示五个文件名。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("ls /etc/ | paste -d: - - - - -\ncpi:adjtime:aliases:alternatives:anacrontab\nanthy-conf:asound.conf:at.deny:audisp:audit\nbash-command-not-found:bash_completion.d:bashrc:blkid:bonobo-activation\n...\n")])])]),a("h2",{attrs:{id:"_5-注意事项"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_5-注意事项"}},[t._v("#")]),t._v(" 5.注意事项")]),t._v(" "),a("p",[t._v("如果文件格式是 DOS,文件换行符是"),a("code",[t._v("\\r\\n")]),t._v(",那么会出现内容覆盖的情况。比如 file1.txt 和 file2.txt 格式是 DOS,paste 这两个文件会出现如下情况:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("[root@tencent ~]# paste file1.txt file2.txt\n:123\n:456\n:789\n:012\n")])])]),a("p",[t._v("从结果可以看出,来自 file1.txt 的行被 file2.txt 的行覆盖,解决办法是,使用 vim 的末行命令"),a("code",[t._v(":set ff=unix")]),t._v("将文本格式改为 Unix。")]),t._v(" "),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/paste.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("paste(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"https://blog.csdn.net/wanglei_storage/article/details/48256311",target:"_blank",rel:"noopener noreferrer"}},[t._v("Shell基础之-paste命令"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"paste"}})],1)}),[],!1,null,null,null);a.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[109],{442:function(t,a,e){"use strict";e.r(a);var s=e(12),n=Object(s.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("paste 将多个文件的相应行默认以 Tab 分隔符横向连接起来,输出到标准输出。")]),t._v(" "),a("p",[t._v("paste 后可接多个文件,不限于 2 个文件。如果文件写成连字符 -,表示内容来自标准输入。paste 相对于 join 来说,简单许多,不需要有相同的字段也可按行拼接。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("pasete [OPTIONS] [FILES]\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-d,--delimiters=LIST\n\t用指定的域分隔符取代Tab。\n-s,--serial\n\t顺序地合并一个文件的所有行到一行\n--help\n\t显示帮助信息并退出\n--version\n\t显示版本信息并退出\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("p",[t._v("有两个文件 file1.txt 和 file2.txt,内容如下:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("# file1 内容\nabc\ndef\nghi\n\n# file2 内容\n123\n456\n789\n012\n")])])]),a("p",[t._v("(1)将文件 file1.txt 的所有行合并到一行。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("paste -s file1.txt\nabc\tdef\tghi\n\n# 指定域分隔符为冒号:\npaste -s -d : file1.txt\nabc:def:ghi\n")])])]),a("p",[t._v("(2)将多个文件的所有行分别合并为一行。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("paste -s file1.txt file2.txt\nabc\tdef\tghi\n123\t456\t789\t012\n")])])]),a("p",[t._v("(3)横向连接两个文件,默认以 Tab 分隔。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("paste file1.txt file2.txt\nabc\t123\ndef\t456\nghi\t789\n\t012\n\n# 通过交换文件名可指定列的位置\npaste file2.txt file1.txt\n123\tabc\n456\tdef\n789\tghi\n012\t\n")])])]),a("p",[t._v("(4)paste 黏贴的内容(行)从标准输入读取,此时可以使用 - 来指代。例如查看 /etc 下的文件列表,并用 paste 打印成每行显示五个文件名。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("ls /etc/ | paste -d: - - - - -\ncpi:adjtime:aliases:alternatives:anacrontab\nanthy-conf:asound.conf:at.deny:audisp:audit\nbash-command-not-found:bash_completion.d:bashrc:blkid:bonobo-activation\n...\n")])])]),a("h2",{attrs:{id:"_5-注意事项"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_5-注意事项"}},[t._v("#")]),t._v(" 5.注意事项")]),t._v(" "),a("p",[t._v("如果文件格式是 DOS,文件换行符是"),a("code",[t._v("\\r\\n")]),t._v(",那么会出现内容覆盖的情况。比如 file1.txt 和 file2.txt 格式是 DOS,paste 这两个文件会出现如下情况:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("[root@tencent ~]# paste file1.txt file2.txt\n:123\n:456\n:789\n:012\n")])])]),a("p",[t._v("从结果可以看出,来自 file1.txt 的行被 file2.txt 的行覆盖,解决办法是,使用 vim 的末行命令"),a("code",[t._v(":set ff=unix")]),t._v("将文本格式改为 Unix。")]),t._v(" "),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/paste.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("paste(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"https://blog.csdn.net/wanglei_storage/article/details/48256311",target:"_blank",rel:"noopener noreferrer"}},[t._v("Shell基础之-paste命令"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"paste"}})],1)}),[],!1,null,null,null);a.default=n.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/11.7412dbb5.js b/docs/assets/js/11.5f249f03.js similarity index 99% rename from docs/assets/js/11.7412dbb5.js rename to docs/assets/js/11.5f249f03.js index b558d2b17..b04f4582e 100644 --- a/docs/assets/js/11.7412dbb5.js +++ b/docs/assets/js/11.5f249f03.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[11],{344:function(a,s,t){"use strict";t.r(s);var e=t(12),n=Object(e.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-功能简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-功能简介"}},[a._v("#")]),a._v(" 1.功能简介")]),a._v(" "),s("p",[a._v("declare 设置变量值和属性。")]),a._v(" "),s("p",[a._v("declare(别名 typeset)属 Shell 内建命令,用于申明 Shell 变量并设置变量属性,或查看已定义的 Shell 变量和函数。若不加上任何参数,只执行 declare/typeset 则会显示全部的 Shell 变量与函数(与执行 set 指令的效果相同)。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("declare [-aAfFgilrtux] [-p] [name[=value] ...]\ntypeset [-aAfFgilrtux] [-p] [name[=value] ...]\n")])])]),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("-a\n\t申明数组变量\n-A\n\t申明关联数组,可以使用字符串作为数组索引\n-f\n\t仅显示已定义的函数\n-F\n\t不显示函数定义\n-g\n\t指定变量为全局变量,即使在函数内定义变量\n-i\n\t声明整型变量\n-l\n\t将变量值的大写字母变为小写\n-r\n\t设置只读属性\n-t\n\t设置变量跟踪属性,用于跟踪函数进行调试,对于变量没有特殊意义\n-u\n\t变量值的小写字母变为大写\n-x\n\t将指定的Shell变量换成环境变量\n-p\n\t显示变量定义的方式和值\n+\n\t取消变量属性,但是 +a 和 +r 无效,无法删除数组和只读属性,可以使用unset删除数组,但是 unset 不能删除只读变量\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)定义关联数组并访问。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-A")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("assArray")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("lucy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("beijing "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("yoona"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("shanghai"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#读取关联数组全部内容")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${assArray"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("*"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("}")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#或")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${assArray"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("@"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("}")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#输出")]),a._v("\nbeijing shanghai\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#读取指定索引的数组值")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${assArray"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("lucy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("}")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#输出")]),a._v("\nbeijing\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#列出数组索引列表")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("!")]),a._v("assArray"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("*"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("}")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#或")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("!")]),a._v("assArray"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("@"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("}")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#输出")]),a._v("\nyoona lucy\n")])])]),s("p",[a._v("(2)定义只读变量。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-r")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"foo"')]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 或")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("typeset")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-r")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"bar"')]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 或")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("readonly")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"baz"')]),a._v("\n")])])]),s("p",[a._v("Shell 规定,只读变量生命周期与当前 Shell 脚本进程相同,且不能消除只读属性和删除只读变量,除非 kill 当前 Shell 脚本进程。")]),a._v(" "),s("p",[a._v("(3)使用"),s("code",[a._v("-p")]),a._v("选项显示变量 name1 和 name2 的定义方式和当前值。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-p")]),a._v(" name1 name2\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 输出")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-r")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("name1")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"lvlv1"')]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-r")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("name2")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"lvlv2"')]),a._v("\n")])])]),s("p",[a._v("(4)使用"),s("code",[a._v("-x")]),a._v("选项将shell变量转换为临时环境变量,供当前Shell会话的其他shell进程使用,退出当前Shell会话则失效。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-x")]),a._v(" name1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(";")]),a._v("\n")])])]),s("p",[a._v("(5)显示所有 Shell 环境变量。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-x")]),a._v("\n")])])]),s("p",[a._v("(6)使用"),s("code",[a._v("+x")]),a._v("选项取消变量为环境变量。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("delcare +x name1\n")])])]),s("p",[a._v("(7)申明整型变量,赋值浮点型数值将报错。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-i")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("integer")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("666")]),a._v("\n")])])]),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://www.man7.org/linux/man-pages/man1/bash.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("bash(1) - Linux manual page - man7.org"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"https://www.linux.org/docs/man1/declare.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("declare(1) manual - linux.org"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"http://blog.csdn.net/sunnyyoona/article/details/51526312",target:"_blank",rel:"noopener noreferrer"}},[a._v("Shell数组与关联数组"),s("OutboundLink")],1)]),a._v(" "),s("p",[a._v("Linux指令范例速查手册.马玉军.北京:科学出版社,2008.P178-P183")]),a._v(" "),s("Vssue",{attrs:{title:"declare-builtin"}})],1)}),[],!1,null,null,null);s.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[11],{346:function(a,s,t){"use strict";t.r(s);var e=t(12),n=Object(e.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-功能简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-功能简介"}},[a._v("#")]),a._v(" 1.功能简介")]),a._v(" "),s("p",[a._v("declare 设置变量值和属性。")]),a._v(" "),s("p",[a._v("declare(别名 typeset)属 Shell 内建命令,用于申明 Shell 变量并设置变量属性,或查看已定义的 Shell 变量和函数。若不加上任何参数,只执行 declare/typeset 则会显示全部的 Shell 变量与函数(与执行 set 指令的效果相同)。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("declare [-aAfFgilrtux] [-p] [name[=value] ...]\ntypeset [-aAfFgilrtux] [-p] [name[=value] ...]\n")])])]),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("-a\n\t申明数组变量\n-A\n\t申明关联数组,可以使用字符串作为数组索引\n-f\n\t仅显示已定义的函数\n-F\n\t不显示函数定义\n-g\n\t指定变量为全局变量,即使在函数内定义变量\n-i\n\t声明整型变量\n-l\n\t将变量值的大写字母变为小写\n-r\n\t设置只读属性\n-t\n\t设置变量跟踪属性,用于跟踪函数进行调试,对于变量没有特殊意义\n-u\n\t变量值的小写字母变为大写\n-x\n\t将指定的Shell变量换成环境变量\n-p\n\t显示变量定义的方式和值\n+\n\t取消变量属性,但是 +a 和 +r 无效,无法删除数组和只读属性,可以使用unset删除数组,但是 unset 不能删除只读变量\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)定义关联数组并访问。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-A")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("assArray")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("lucy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("beijing "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("yoona"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("shanghai"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#读取关联数组全部内容")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${assArray"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("*"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("}")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#或")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${assArray"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("@"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("}")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#输出")]),a._v("\nbeijing shanghai\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#读取指定索引的数组值")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${assArray"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("lucy"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("}")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#输出")]),a._v("\nbeijing\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#列出数组索引列表")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("!")]),a._v("assArray"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("*"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("}")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#或")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("${"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("!")]),a._v("assArray"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("@"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("}")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#输出")]),a._v("\nyoona lucy\n")])])]),s("p",[a._v("(2)定义只读变量。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-r")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"foo"')]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 或")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("typeset")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-r")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"bar"')]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 或")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("readonly")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"baz"')]),a._v("\n")])])]),s("p",[a._v("Shell 规定,只读变量生命周期与当前 Shell 脚本进程相同,且不能消除只读属性和删除只读变量,除非 kill 当前 Shell 脚本进程。")]),a._v(" "),s("p",[a._v("(3)使用"),s("code",[a._v("-p")]),a._v("选项显示变量 name1 和 name2 的定义方式和当前值。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-p")]),a._v(" name1 name2\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 输出")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-r")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("name1")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"lvlv1"')]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-r")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("name2")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"lvlv2"')]),a._v("\n")])])]),s("p",[a._v("(4)使用"),s("code",[a._v("-x")]),a._v("选项将shell变量转换为临时环境变量,供当前Shell会话的其他shell进程使用,退出当前Shell会话则失效。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-x")]),a._v(" name1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(";")]),a._v("\n")])])]),s("p",[a._v("(5)显示所有 Shell 环境变量。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-x")]),a._v("\n")])])]),s("p",[a._v("(6)使用"),s("code",[a._v("+x")]),a._v("选项取消变量为环境变量。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("delcare +x name1\n")])])]),s("p",[a._v("(7)申明整型变量,赋值浮点型数值将报错。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("declare")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-i")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("integer")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("666")]),a._v("\n")])])]),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://www.man7.org/linux/man-pages/man1/bash.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("bash(1) - Linux manual page - man7.org"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"https://www.linux.org/docs/man1/declare.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("declare(1) manual - linux.org"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"http://blog.csdn.net/sunnyyoona/article/details/51526312",target:"_blank",rel:"noopener noreferrer"}},[a._v("Shell数组与关联数组"),s("OutboundLink")],1)]),a._v(" "),s("p",[a._v("Linux指令范例速查手册.马玉军.北京:科学出版社,2008.P178-P183")]),a._v(" "),s("Vssue",{attrs:{title:"declare-builtin"}})],1)}),[],!1,null,null,null);s.default=n.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/110.06601f98.js b/docs/assets/js/110.b21b7308.js similarity index 99% rename from docs/assets/js/110.06601f98.js rename to docs/assets/js/110.b21b7308.js index 941d6f570..f5a289495 100644 --- a/docs/assets/js/110.06601f98.js +++ b/docs/assets/js/110.b21b7308.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[110],{443:function(s,t,a){"use strict";a.r(t);var e=a(12),n=Object(e.a)({},(function(){var s=this,t=s._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[t("h2",{attrs:{id:"_1-功能简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-功能简介"}},[s._v("#")]),s._v(" 1.功能简介")]),s._v(" "),t("p",[s._v("sed(Stream EDitor)是一种流文件编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(Pattern Space),接着用 sed 命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕,接着处理下一行,直到文件末尾。文件内容并没有改变,除非使用"),t("code",[s._v("-i")]),s._v("选项。sed 主要用来编辑一个或多个文件,简化对文件的反复操作或者用来编写转换程序等。")]),s._v(" "),t("p",[s._v("sed 功能同 awk 类似,差别在于,sed 简单,对列处理的功能要差一些,awk 功能复杂,对列处理的功能比较强大。")]),s._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("sed")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("OPTION"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("..")]),s._v(". "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("script-only-if-no-other-script"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("input-file"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("..")]),s._v(".\n")])])]),t("p",[s._v("其中 OPTION 为命令选项,script-only-if-no-other-script 为处理动作,可以由"),t("code",[s._v("-e")]),s._v("指定多个,input-file为输入文件,可指定多个。")]),s._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[s._v("选项:\n-n,--quiet,--silent\n\t使用安静模式。sed的一般用法中,所有来自STDIN的数据一般都会被打印到终端上,如果加上-n后,则只有经过sed特殊处理的那一行才会被列出来。\n"),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-e")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("script"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(",--expression"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("script"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\n\t指定sed动作,可以由多个-e指定多个动作。\n"),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-f")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("script-file"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(",--file"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("script-file"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\n\t直接将sed的动作写在一个文件内,-f filename则可以运行filename 内的sed动作;\n-r,--regexp-extended\n\tsed支持扩展正则表达式"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("默认是基础正则表达式"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("。\n"),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-i")]),s._v(" \n\t直接修改读取的文件内容,而不是输出到终端。\n"),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--help")]),s._v("\n\t显示帮助\n"),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--version")]),s._v("\n\t显示版本\n\n动作说明:"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("n1"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v(",n2"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("function\nn1, n2 :不见得会存在,一般代表“选择进行动作的行数”,举例来说,如果我的动作是需要在 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(" 到 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(" 行之间进行,则写作“10,20动作行为”。\n\nfunction:\na \n\t新增, a 的后面可以接字串,而这些字串会在新的一行出现"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("目前的下一行"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("~\nc \n\t取代, c 的后面可以接字串,这些字串可以取代 n1,n2 之间的行!\nd \n\t删除,因为是删除啊,所以 d 后面通常不接任何内容;\ni \n\t插入, i 的后面可以接字串,而这些字串会在新的一行出现"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("目前的上一行"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(";\np \n\t列印,亦即将某个选择的数据印出。通常 p 会与参数 "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("sed")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-n")]),s._v(" 一起运行~\ns/"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("regexp"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("/"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("replacement"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("/ \n\t替换,支持正规匹配\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[s._v("#")]),s._v(" 4.常用示例")]),s._v(" "),t("h3",{attrs:{id:"_4-1-删除行操作"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-1-删除行操作"}},[s._v("#")]),s._v(" 4.1 删除行操作")]),s._v(" "),t("p",[s._v("(1)将 /etc/passwd 的内容列出并且列印行号,同时,请将第 2~5 行删除。")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl -n ln /etc/passwd | sed '2,5d'\n1 root:x:0:0:root:/root:/bin/bash\n6 sync:x:5:0:sync:/sbin:/bin/sync\n7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\n.....(后面省略).....\n")])])]),t("p",[s._v("注意:原本应该是要下达 sed -e 才对,当只有一个动作的时候,没有 -e 也行,但是多于一个动作时必须要使用-e选项来指定动作。同时也要注意的是, sed 后面接的动作,请务必以两个单引号括住。")]),s._v(" "),t("p",[s._v("(2)只要删除第 2 行。")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("nl /etc/passwd | sed '2d' \n")])])]),t("p",[s._v("(3)要删除第 3 到最后一行")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("nl /etc/passwd | sed '3,$d' \n")])])]),t("h3",{attrs:{id:"_4-2-新增行操作"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-2-新增行操作"}},[s._v("#")]),s._v(" 4.2 新增行操作")]),s._v(" "),t("p",[s._v('(1)在第二行后加上"I like drinking tea"。')]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl -n ln /etc/passwd | sed '2a I like drinking tea'\n1\troot:x:0:0:root:/root:/bin/bash\n2\tbin:x:1:1:bin:/bin:/sbin/nologin\nI like drinking tea\n3\tdaemon:x:2:2:daemon:/sbin:/sbin/nologin\n.....(后面省略).....\n")])])]),t("p",[s._v("(2)那如果是要在第二行前加入。")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("nl /etc/passwd | sed '2i drink tea'\n//或\nnl /etc/passwd | sed '1a drink tea'\n")])])]),t("p",[s._v('(3)在第二行后面加入两行,"I like drinking tea"与"I like drinking beer"。')]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl -n ln /etc/passwd | sed '2a I like drinking tea\\nI like drinking beer'\n1 \troot:x:0:0:root:/root:/bin/bash\n2 \tbin:x:1:1:bin:/bin:/sbin/nologin\nI like drinking tea\nI like drinking beer\n3 \tdaemon:x:2:2:daemon:/sbin:/sbin/nologin\n…(后面省略)…\n")])])]),t("p",[s._v("或者每一行使用反斜杠\\来分开,就可以在命令行中将一条命令分开多行输入,如下:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl -n ln /etc/passwd | sed '2a I like drinking tea\\\n> I like drinking beer'\n")])])]),t("h3",{attrs:{id:"_4-3-替换行操作"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-3-替换行操作"}},[s._v("#")]),s._v(" 4.3 替换行操作")]),s._v(" "),t("p",[s._v('(1)将第2-5行的内容替换成为"No 2-5 number"。')]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl -nln /etc/passwd | sed '2,5c No 2-5 number'\n1 \troot:x:0:0:root:/root:/bin/bash\nNo 2-5 number\n6 \tsync:x:5:0:sync:/sbin:/bin/sync\n.....(后面省略).....\n")])])]),t("h3",{attrs:{id:"_4-4-选择行打印"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-4-选择行打印"}},[s._v("#")]),s._v(" 4.4 选择行打印")]),s._v(" "),t("p",[s._v("(1)仅列出 /etc/passwd 文件内的第 5-7 行。")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[root@www ~]# nl -nln /etc/passwd | sed -n '5,7p'\n5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin\n6 sync:x:5:0:sync:/sbin:/bin/sync\n7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\n")])])]),t("h3",{attrs:{id:"_4-5-数据的查找并进行相关操作"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-5-数据的查找并进行相关操作"}},[s._v("#")]),s._v(" 4.5 数据的查找并进行相关操作")]),s._v(" "),t("p",[s._v("(1)数据的查找并显示\n搜索 /etc/passwd有root关键字的行并输出。")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl /etc/passwd | sed -n '/root/p'\n1\troot:x:0:0:root:/root:/bin/bash\n11\toperator:x:11:0:operator:/root:/sbin/nologin\n")])])]),t("p",[s._v("(2)数据的查找并删除\n删除/etc/passwd所有包含root的行,其他行输出。")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl /etc/passwd | sed '/root/d'\n2 daemon:x:1:1:daemon:/usr/sbin:/bin/sh\n3 bin:x:2:2:bin:/bin:/bin/sh\n…(下面忽略)…\n")])])]),t("p",[s._v("如果想删除匹配的字符串,使用如下命令:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl /etc/passwd | sed 's/root//g'\n")])])]),t("p",[s._v("(3)数据的查找并替换\n除了整行的处理模式之外, sed 还可以用行为单位进行部分数据的搜寻并取代。基本上 sed 的搜寻与替代的与 vi 相当的类似!他有点像这样:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("sed 's/被取代的字串/新的字串/g'\n")])])]),t("p",[s._v("(4)数据的搜寻并执行命令\n搜索/etc/passwd,找到root对应的行,执行后面花括号中的一组命令,每个命令之间用分号分隔,这里把bash替换为blueshell,再输出这行:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("nl /etc/passwd | sed -n '/root/{s/bash/blueshell/;p}'\n1 root:x:0:0:root:/root:/bin/blueshell\n")])])]),t("p",[s._v("如果只替换/etc/passwd的第一个bash关键字为blueshell,就退出")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("nl /etc/passwd | sed -n '/bash/{s/bash/blueshell/;p;q}' \n1 root:x:0:0:root:/root:/bin/blueshell\n")])])]),t("h3",{attrs:{id:"_4-6-多点编辑"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-6-多点编辑"}},[s._v("#")]),s._v(" 4.6 多点编辑")]),s._v(" "),t("p",[s._v("一条sed命令,删除/etc/passwd第三行到末尾的数据,并把bash替换为blueshell")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("nl /etc/passwd | sed -e '3,$d' -e 's/bash/blueshell/'\n1 root:x:0:0:root:/root:/bin/blueshell\n2 daemon:x:1:1:daemon:/usr/sbin:/bin/sh\n")])])]),t("p",[s._v("-e表示多点编辑,第一个编辑命令删除/etc/passwd第三行到末尾的数据,第二条命令搜索bash替换为blueshell。")]),s._v(" "),t("h3",{attrs:{id:"_4-7-直接修改文件"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-7-直接修改文件"}},[s._v("#")]),s._v(" 4.7 直接修改文件")]),s._v(" "),t("p",[s._v("sed 可以直接修改文件的内容,不必使用管道命令或数据流重导向! 不过,由於这个动作会直接修改到原始的文件,所以请你千万不要随便拿系统配置来测试,使用时也要慎重。我们使用下载的regular_express.txt 文件来测试看看吧!")]),s._v(" "),t("p",[s._v("利用 sed 将 regular_express.txt 内每一行结尾若为 . 则换成 !")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("sed -i 's/\\.$/!/g' regular_express.txt\n")])])]),t("p",[s._v('利用 sed 直接在 regular_express.txt 最后一行加入"# This is a test"。')]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("sed -i '$a # This is a test' regular_express.txt\n")])])]),t("p",[s._v('由於 $ 代表的是最后一行,而 a 的动作是新增,因此该文件最后新增"# This is a test"。')]),s._v(" "),t("p",[s._v("sed 的"),t("code",[s._v("-i")]),s._v("选项可以直接修改文件内容,这功能非常有帮助!举例来说,如果你有一个 100 万行的文件,你要在第 100 行加某些文字,此时使用 vim 可能会疯掉!因为文件太大了!那怎办?就利用 sed 啊!透过 sed 直接修改/取代的功能,你甚至不需要使用 vim 去修订!")]),s._v(" "),t("hr"),s._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),t("p",[t("a",{attrs:{href:"http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856901.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("Linux sed命令详解"),t("OutboundLink")],1)]),s._v(" "),t("p",[s._v("鸟哥.鸟哥的私房菜基础学习篇第三版[M].北京:人民邮电出版社,2010:357-360")]),s._v(" "),t("Vssue",{attrs:{title:"sed"}})],1)}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[110],{444:function(s,t,a){"use strict";a.r(t);var e=a(12),n=Object(e.a)({},(function(){var s=this,t=s._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[t("h2",{attrs:{id:"_1-功能简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-功能简介"}},[s._v("#")]),s._v(" 1.功能简介")]),s._v(" "),t("p",[s._v("sed(Stream EDitor)是一种流文件编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(Pattern Space),接着用 sed 命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕,接着处理下一行,直到文件末尾。文件内容并没有改变,除非使用"),t("code",[s._v("-i")]),s._v("选项。sed 主要用来编辑一个或多个文件,简化对文件的反复操作或者用来编写转换程序等。")]),s._v(" "),t("p",[s._v("sed 功能同 awk 类似,差别在于,sed 简单,对列处理的功能要差一些,awk 功能复杂,对列处理的功能比较强大。")]),s._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("sed")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("OPTION"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("..")]),s._v(". "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("script-only-if-no-other-script"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("input-file"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("..")]),s._v(".\n")])])]),t("p",[s._v("其中 OPTION 为命令选项,script-only-if-no-other-script 为处理动作,可以由"),t("code",[s._v("-e")]),s._v("指定多个,input-file为输入文件,可指定多个。")]),s._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[s._v("选项:\n-n,--quiet,--silent\n\t使用安静模式。sed的一般用法中,所有来自STDIN的数据一般都会被打印到终端上,如果加上-n后,则只有经过sed特殊处理的那一行才会被列出来。\n"),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-e")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("script"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(",--expression"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("script"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\n\t指定sed动作,可以由多个-e指定多个动作。\n"),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-f")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("script-file"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(",--file"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("script-file"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\n\t直接将sed的动作写在一个文件内,-f filename则可以运行filename 内的sed动作;\n-r,--regexp-extended\n\tsed支持扩展正则表达式"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("默认是基础正则表达式"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("。\n"),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-i")]),s._v(" \n\t直接修改读取的文件内容,而不是输出到终端。\n"),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--help")]),s._v("\n\t显示帮助\n"),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--version")]),s._v("\n\t显示版本\n\n动作说明:"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("n1"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v(",n2"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("function\nn1, n2 :不见得会存在,一般代表“选择进行动作的行数”,举例来说,如果我的动作是需要在 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(" 到 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(" 行之间进行,则写作“10,20动作行为”。\n\nfunction:\na \n\t新增, a 的后面可以接字串,而这些字串会在新的一行出现"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("目前的下一行"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("~\nc \n\t取代, c 的后面可以接字串,这些字串可以取代 n1,n2 之间的行!\nd \n\t删除,因为是删除啊,所以 d 后面通常不接任何内容;\ni \n\t插入, i 的后面可以接字串,而这些字串会在新的一行出现"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("目前的上一行"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(";\np \n\t列印,亦即将某个选择的数据印出。通常 p 会与参数 "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("sed")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-n")]),s._v(" 一起运行~\ns/"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("regexp"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("/"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("replacement"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("/ \n\t替换,支持正规匹配\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[s._v("#")]),s._v(" 4.常用示例")]),s._v(" "),t("h3",{attrs:{id:"_4-1-删除行操作"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-1-删除行操作"}},[s._v("#")]),s._v(" 4.1 删除行操作")]),s._v(" "),t("p",[s._v("(1)将 /etc/passwd 的内容列出并且列印行号,同时,请将第 2~5 行删除。")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl -n ln /etc/passwd | sed '2,5d'\n1 root:x:0:0:root:/root:/bin/bash\n6 sync:x:5:0:sync:/sbin:/bin/sync\n7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\n.....(后面省略).....\n")])])]),t("p",[s._v("注意:原本应该是要下达 sed -e 才对,当只有一个动作的时候,没有 -e 也行,但是多于一个动作时必须要使用-e选项来指定动作。同时也要注意的是, sed 后面接的动作,请务必以两个单引号括住。")]),s._v(" "),t("p",[s._v("(2)只要删除第 2 行。")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("nl /etc/passwd | sed '2d' \n")])])]),t("p",[s._v("(3)要删除第 3 到最后一行")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("nl /etc/passwd | sed '3,$d' \n")])])]),t("h3",{attrs:{id:"_4-2-新增行操作"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-2-新增行操作"}},[s._v("#")]),s._v(" 4.2 新增行操作")]),s._v(" "),t("p",[s._v('(1)在第二行后加上"I like drinking tea"。')]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl -n ln /etc/passwd | sed '2a I like drinking tea'\n1\troot:x:0:0:root:/root:/bin/bash\n2\tbin:x:1:1:bin:/bin:/sbin/nologin\nI like drinking tea\n3\tdaemon:x:2:2:daemon:/sbin:/sbin/nologin\n.....(后面省略).....\n")])])]),t("p",[s._v("(2)那如果是要在第二行前加入。")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("nl /etc/passwd | sed '2i drink tea'\n//或\nnl /etc/passwd | sed '1a drink tea'\n")])])]),t("p",[s._v('(3)在第二行后面加入两行,"I like drinking tea"与"I like drinking beer"。')]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl -n ln /etc/passwd | sed '2a I like drinking tea\\nI like drinking beer'\n1 \troot:x:0:0:root:/root:/bin/bash\n2 \tbin:x:1:1:bin:/bin:/sbin/nologin\nI like drinking tea\nI like drinking beer\n3 \tdaemon:x:2:2:daemon:/sbin:/sbin/nologin\n…(后面省略)…\n")])])]),t("p",[s._v("或者每一行使用反斜杠\\来分开,就可以在命令行中将一条命令分开多行输入,如下:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl -n ln /etc/passwd | sed '2a I like drinking tea\\\n> I like drinking beer'\n")])])]),t("h3",{attrs:{id:"_4-3-替换行操作"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-3-替换行操作"}},[s._v("#")]),s._v(" 4.3 替换行操作")]),s._v(" "),t("p",[s._v('(1)将第2-5行的内容替换成为"No 2-5 number"。')]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl -nln /etc/passwd | sed '2,5c No 2-5 number'\n1 \troot:x:0:0:root:/root:/bin/bash\nNo 2-5 number\n6 \tsync:x:5:0:sync:/sbin:/bin/sync\n.....(后面省略).....\n")])])]),t("h3",{attrs:{id:"_4-4-选择行打印"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-4-选择行打印"}},[s._v("#")]),s._v(" 4.4 选择行打印")]),s._v(" "),t("p",[s._v("(1)仅列出 /etc/passwd 文件内的第 5-7 行。")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[root@www ~]# nl -nln /etc/passwd | sed -n '5,7p'\n5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin\n6 sync:x:5:0:sync:/sbin:/bin/sync\n7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\n")])])]),t("h3",{attrs:{id:"_4-5-数据的查找并进行相关操作"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-5-数据的查找并进行相关操作"}},[s._v("#")]),s._v(" 4.5 数据的查找并进行相关操作")]),s._v(" "),t("p",[s._v("(1)数据的查找并显示\n搜索 /etc/passwd有root关键字的行并输出。")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl /etc/passwd | sed -n '/root/p'\n1\troot:x:0:0:root:/root:/bin/bash\n11\toperator:x:11:0:operator:/root:/sbin/nologin\n")])])]),t("p",[s._v("(2)数据的查找并删除\n删除/etc/passwd所有包含root的行,其他行输出。")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl /etc/passwd | sed '/root/d'\n2 daemon:x:1:1:daemon:/usr/sbin:/bin/sh\n3 bin:x:2:2:bin:/bin:/bin/sh\n…(下面忽略)…\n")])])]),t("p",[s._v("如果想删除匹配的字符串,使用如下命令:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("[b3335@MIC ~]$ nl /etc/passwd | sed 's/root//g'\n")])])]),t("p",[s._v("(3)数据的查找并替换\n除了整行的处理模式之外, sed 还可以用行为单位进行部分数据的搜寻并取代。基本上 sed 的搜寻与替代的与 vi 相当的类似!他有点像这样:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("sed 's/被取代的字串/新的字串/g'\n")])])]),t("p",[s._v("(4)数据的搜寻并执行命令\n搜索/etc/passwd,找到root对应的行,执行后面花括号中的一组命令,每个命令之间用分号分隔,这里把bash替换为blueshell,再输出这行:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("nl /etc/passwd | sed -n '/root/{s/bash/blueshell/;p}'\n1 root:x:0:0:root:/root:/bin/blueshell\n")])])]),t("p",[s._v("如果只替换/etc/passwd的第一个bash关键字为blueshell,就退出")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("nl /etc/passwd | sed -n '/bash/{s/bash/blueshell/;p;q}' \n1 root:x:0:0:root:/root:/bin/blueshell\n")])])]),t("h3",{attrs:{id:"_4-6-多点编辑"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-6-多点编辑"}},[s._v("#")]),s._v(" 4.6 多点编辑")]),s._v(" "),t("p",[s._v("一条sed命令,删除/etc/passwd第三行到末尾的数据,并把bash替换为blueshell")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("nl /etc/passwd | sed -e '3,$d' -e 's/bash/blueshell/'\n1 root:x:0:0:root:/root:/bin/blueshell\n2 daemon:x:1:1:daemon:/usr/sbin:/bin/sh\n")])])]),t("p",[s._v("-e表示多点编辑,第一个编辑命令删除/etc/passwd第三行到末尾的数据,第二条命令搜索bash替换为blueshell。")]),s._v(" "),t("h3",{attrs:{id:"_4-7-直接修改文件"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-7-直接修改文件"}},[s._v("#")]),s._v(" 4.7 直接修改文件")]),s._v(" "),t("p",[s._v("sed 可以直接修改文件的内容,不必使用管道命令或数据流重导向! 不过,由於这个动作会直接修改到原始的文件,所以请你千万不要随便拿系统配置来测试,使用时也要慎重。我们使用下载的regular_express.txt 文件来测试看看吧!")]),s._v(" "),t("p",[s._v("利用 sed 将 regular_express.txt 内每一行结尾若为 . 则换成 !")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("sed -i 's/\\.$/!/g' regular_express.txt\n")])])]),t("p",[s._v('利用 sed 直接在 regular_express.txt 最后一行加入"# This is a test"。')]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("sed -i '$a # This is a test' regular_express.txt\n")])])]),t("p",[s._v('由於 $ 代表的是最后一行,而 a 的动作是新增,因此该文件最后新增"# This is a test"。')]),s._v(" "),t("p",[s._v("sed 的"),t("code",[s._v("-i")]),s._v("选项可以直接修改文件内容,这功能非常有帮助!举例来说,如果你有一个 100 万行的文件,你要在第 100 行加某些文字,此时使用 vim 可能会疯掉!因为文件太大了!那怎办?就利用 sed 啊!透过 sed 直接修改/取代的功能,你甚至不需要使用 vim 去修订!")]),s._v(" "),t("hr"),s._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),t("p",[t("a",{attrs:{href:"http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856901.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("Linux sed命令详解"),t("OutboundLink")],1)]),s._v(" "),t("p",[s._v("鸟哥.鸟哥的私房菜基础学习篇第三版[M].北京:人民邮电出版社,2010:357-360")]),s._v(" "),t("Vssue",{attrs:{title:"sed"}})],1)}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/112.db15a109.js b/docs/assets/js/112.dfd0e3de.js similarity index 99% rename from docs/assets/js/112.db15a109.js rename to docs/assets/js/112.dfd0e3de.js index 52ff0de96..59b109959 100644 --- a/docs/assets/js/112.db15a109.js +++ b/docs/assets/js/112.dfd0e3de.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[112],{446:function(a,t,s){"use strict";s.r(t);var e=s(12),r=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("tr(translate)用来转换或删除一段文字。")]),a._v(" "),t("p",[a._v("tr 所有的功能均可由 "),t("a",{attrs:{href:"https://dablelv.blog.csdn.net/article/details/53197905",target:"_blank",rel:"noopener noreferrer"}},[a._v("sed"),t("OutboundLink")],1),a._v(" 来完成,可以将 tr 视为 sed 的一个极简实现。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("OPTION"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),a._v(". SET1 "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("SET2"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-c, -C, --complement SET1 [SET2]\n\t将字符集 SET1 以外的其他字符删除或者转换为字符集 SET2 中的最后一个字符(如果你指定了多个字符的话)。\n-d, --delete\n\t删除指定字符集中的字符。\n-s, --squeeze-repeats\n\t如果 SET1 中的字符连续出现多次,压缩重复的字符,只保留一个。\n-t, --truncate-set1\n\t先将 SET1 的长度截为和 SET2 相等。\n--help\n\t显示帮助信息并退出。\n--version\n\t显示版本信息并退出。\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("(1)将 last 输出的信息中所有小写的字符变成大写字符。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[a._v("last "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("a-z"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("A-Z"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n")])])]),t("p",[a._v("(2)将 /etc/passwd 输出的信息中的冒号 : 删除。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" /etc/passwd "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-d")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("':'")]),a._v("\n")])])]),t("p",[a._v("(3)将 DOS 文件转成 Unix 文件。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" /etc/passwd "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-d")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'\\r'")]),a._v("\n")])])]),t("p",[a._v("(4)删除空行。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("file")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-s")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"'),t("span",{pre:!0,attrs:{class:"token entity",title:"\\n"}},[a._v("\\n")]),a._v('"')]),a._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),a._v(" new_file\n")])])]),t("p",[a._v('(5)将文件中 "abc" 分别替换为 "xyz" 中对应的字符。')]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("file")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"abc"')]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"xyz"')]),a._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),a._v(" newFile\n")])])]),t("p",[t("strong",[a._v("注意:")]),a._v(' 这里凡是在 file 中出现的"a"字母,都替换成"x"字母,"b"字母替换为"y"字母,"c"字母替换为"z"字母,而不是将字符串"abc"替换为字符串"xyz"。')]),a._v(" "),t("p",[a._v("(6)替换指定字符集以外的字符。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-n")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"alv blv"')]),a._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-c")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"lv "')]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"x"')]),a._v("\nxlv xlv\n")])])]),t("p",[a._v("echo -n 表示不输出换行符。")]),a._v(" "),t("p",[a._v("(7)从输入文本中将不在补集中的所有字符删除。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-n")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"alv blv"')]),a._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-dc")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"lv"')]),a._v("\nlvlv\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/tr.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("tr(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"tr"}})],1)}),[],!1,null,null,null);t.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[112],{448:function(a,t,s){"use strict";s.r(t);var e=s(12),r=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("tr(translate)用来转换或删除一段文字。")]),a._v(" "),t("p",[a._v("tr 所有的功能均可由 "),t("a",{attrs:{href:"https://dablelv.blog.csdn.net/article/details/53197905",target:"_blank",rel:"noopener noreferrer"}},[a._v("sed"),t("OutboundLink")],1),a._v(" 来完成,可以将 tr 视为 sed 的一个极简实现。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("OPTION"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),a._v(". SET1 "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("SET2"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-c, -C, --complement SET1 [SET2]\n\t将字符集 SET1 以外的其他字符删除或者转换为字符集 SET2 中的最后一个字符(如果你指定了多个字符的话)。\n-d, --delete\n\t删除指定字符集中的字符。\n-s, --squeeze-repeats\n\t如果 SET1 中的字符连续出现多次,压缩重复的字符,只保留一个。\n-t, --truncate-set1\n\t先将 SET1 的长度截为和 SET2 相等。\n--help\n\t显示帮助信息并退出。\n--version\n\t显示版本信息并退出。\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("(1)将 last 输出的信息中所有小写的字符变成大写字符。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[a._v("last "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("a-z"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("A-Z"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n")])])]),t("p",[a._v("(2)将 /etc/passwd 输出的信息中的冒号 : 删除。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" /etc/passwd "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-d")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("':'")]),a._v("\n")])])]),t("p",[a._v("(3)将 DOS 文件转成 Unix 文件。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" /etc/passwd "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-d")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v("'\\r'")]),a._v("\n")])])]),t("p",[a._v("(4)删除空行。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("file")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-s")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"'),t("span",{pre:!0,attrs:{class:"token entity",title:"\\n"}},[a._v("\\n")]),a._v('"')]),a._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),a._v(" new_file\n")])])]),t("p",[a._v('(5)将文件中 "abc" 分别替换为 "xyz" 中对应的字符。')]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("file")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"abc"')]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"xyz"')]),a._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),a._v(" newFile\n")])])]),t("p",[t("strong",[a._v("注意:")]),a._v(' 这里凡是在 file 中出现的"a"字母,都替换成"x"字母,"b"字母替换为"y"字母,"c"字母替换为"z"字母,而不是将字符串"abc"替换为字符串"xyz"。')]),a._v(" "),t("p",[a._v("(6)替换指定字符集以外的字符。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-n")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"alv blv"')]),a._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-c")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"lv "')]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"x"')]),a._v("\nxlv xlv\n")])])]),t("p",[a._v("echo -n 表示不输出换行符。")]),a._v(" "),t("p",[a._v("(7)从输入文本中将不在补集中的所有字符删除。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-n")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"alv blv"')]),a._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[a._v("tr")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-dc")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token string"}},[a._v('"lv"')]),a._v("\nlvlv\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/tr.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("tr(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"tr"}})],1)}),[],!1,null,null,null);t.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/114.70e69f22.js b/docs/assets/js/114.d6b3030d.js similarity index 99% rename from docs/assets/js/114.70e69f22.js rename to docs/assets/js/114.d6b3030d.js index 77b37e6fd..e37c53ad4 100644 --- a/docs/assets/js/114.70e69f22.js +++ b/docs/assets/js/114.d6b3030d.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[114],{453:function(n,t,e){"use strict";e.r(t);var a=e(12),v=Object(a.a)({},(function(){var n=this,t=n._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":n.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[n._v("#")]),n._v(" 1.命令简介")]),n._v(" "),t("p",[n._v("vim 是 Linux 中最通用的全屏幕文本编辑器,是 vi 的增强版(vi iMproved),与 vi 完全兼容,且扩充了很多功能。")]),n._v(" "),t("p",[n._v("vim 编辑器支持编辑模式和命令模式,编辑模式下可以完成文本的编辑功能,命令模式下可以完成对文件的操作命令,要正确使用 vim 编辑器就必须熟练掌握这两种模式的切换。默认情况下,打开 vim 后自动进入命令模式。从编辑模式切换到命令模式使用 ESC 键,从命令模式切换到编辑模式使用 A、a、O、o、I、i 键。")]),n._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[n._v("#")]),n._v(" 2.命令格式")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v("vim [OPTIONS] [FILE...]\nvim [OPTIONS] -\nvim [OPTIONS] -t TAG\nvim [OPTIONS] -q [ERRORFILE]\n")])])]),t("p",[t("code",[n._v("[FILE...]")]),n._v("表示一系列使用 vim 编辑的文件,使用"),t("code",[n._v(":next")]),n._v("命令可以向前切换所编辑的文件,使用"),t("code",[n._v("--")]),n._v("可以向后切换,这是 vim 常用启动格式。")]),n._v(" "),t("p",[t("code",[n._v("-")]),n._v(":表示待编辑的文件从标准输入读取。")]),n._v(" "),t("p",[t("code",[n._v("-t TAG")]),n._v(":要编辑的文件和光标的初始位置取决于一个标签,一种 goto 标签。标签在标签文件中查找,与标签关联的文件成为当前文件并执行关联的命令。主要用于 C 程序,在这种情况下 TAG 可以是函数名,其结果是包含该函数的文件成为当前文件,并且光标位于函数的开头。参见:"),t("code",[n._v(":help tag-commands")]),n._v("。")]),n._v(" "),t("p",[t("code",[n._v("-q [ERRORFILE]")]),n._v(":使用 quickFix 模式启动 vim,文件 ERRORFILE 将被读取并显示第一个错误。如果 ERRORFILE 省略,则默认为 AztecC.Err(Amiga 系统)或 errors.err(其它系统)。关于 quickFix 模式说明,可以使用"),t("code",[n._v(":help quickfix")]),n._v("查看。")]),n._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[n._v("#")]),n._v(" 3.选项说明")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v("+NUM\n\t打开文件时光标跳转到由 NUM 指定的行首\n+/PAT\n\t打开文件时光标跳转到匹配的模式字符串 PAT\n+, -c CMD\n\t在完成对第一个文件的读取后,执行给出的指令\n-b\n\t以二进制模式打开文件,用于编辑二进制文件和可执行文件\n-C\n\t以兼容模式运行 vim,使 vim 的表现更像 vi,即使存在 .vimrc 文件\n-d\n\t以 diff 模式打开文件,当多个文件编辑时,显示文件差异部分\n-e\n\t进入 Ex 模式,即进入冒号开头的末行模式。ex是Unix编辑器\n-E\n\t进入增强 Ex 模式,就像执行命令 exim\n-l\n\t使用 lisp 模式,打开 lisp 和 showmatch\n-m\n\t取消写文件功能,重设 write 选项。你仍然可以修改缓冲内容,但是不可以写入文件\n-M\n\t关闭修改功能\n-N\n\t非兼容模式运行 vim,这会使 vim 表现的更好,但是可能会存在与 vi 不兼容的情况,即使存在 .vimrc 文件\n-n\n\t不使用 swap file,这可能会导致在 vim 意外崩溃的情况下无法恢复未保存的内容\n-o [N]\n\t以上下排列方式同时打开 N 个 vim 窗口,如果未指定 N ,则为每一个文件单独打开一个窗口\n-O [N]\n\t以左右下排列方式同时打开 N 个 vim 窗口,如果未指定 N ,则为每一个文件单独打开一个窗口\n-R\n\t以只读方式打开文件\n-r\n\t列出 swap file\n-r FILE\n\t以指定的交换文件来恢复崩溃的编辑会话。交换文件名后缀为.swp\n-s\n\t安静模式,与 -e 选项结合使用\n-u VIMRC\n\t使用指定的 vimrc 文件中的命令来初始化 vim,所有其它的初始化操作将被跳过。可以给定“NONE”来跳过所有的初始化\n-U GVIMRC\n\t使用指定的 gvimrc 文件中的命令来初始化 GUI,所有其它的 GUI 初始化操作将被跳过。可以给定 “NONE” 来跳过所有的 GUI 初始化\n-V [N]\n\t以冗余模式执行 vim,打印 vim 读取了哪些配置文件 vimrc。可选的数字 N 表示冗余级别,数值越大级别越高,取值范围是 0~10,默认是 10\n-x\n\t写文件时进行加密,会提示输入加密密钥\n-h, --help\n\t显示帮助信息并退出\n--version\n\t显示版本信息并退出\n")])])]),t("h2",{attrs:{id:"_4-内置命令"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-内置命令"}},[n._v("#")]),n._v(" 4.内置命令")]),n._v(" "),t("p",[n._v("vim 提供了丰富的内置命令,有些内置命令使用键盘组合键即可完成,有些内置命令则需要以冒号 : 开头输入。常用内置命令如下:")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v('Ctrl+u:向下滚动半屏\nCtrl+d:向上滚动半屏\nCtrl+f:向下滚动一屏\nCtrl+b:向上滚动一屏\nCtrl+e:向下滚动一行\nCtrl+y:向上滚动一行\nEnter:回车向下滚动一行\nEsc:从编辑模式切换到命令模式\nZZ:命令模式下保存当前文件所做的修改后退出 vim\n:[行号]:光标跳转到指定行的行首\n:$:光标跳转到最后一行的行首\ngg:跳转到首行;\nG:跳转到尾行\nCtrl+g:显示总行数\nx, X:删除一个字符或选中的内容。当删除一个字符时,x 删除光标后的,X 删除光标前的。删除即剪切\nd:删除选中的文本,删除即剪切\nD:删除从当前光标到光标所在行尾的全部字符。删除即剪切\ndd:删除光标所在行的整行内容。删除即剪切\nndd:删除当前行及其后n-1行,n为一个数字。删除即剪切\ny:复制选中的文本\ny0:复制光标前一个字符到行首的内容\ny$:复制光标后一个字符到行尾的内容\nyh:复制光标前的1个字符\nyl:复制光标后的1个字符\nnyh:复制光标前的n个字符,比如4yh复制光标前的4个字符\nnyl:复制光标后的n个字符,比如4yl复制光标后的4个字符\nyy:复制光标所在行\nnyy:复制当前行以及其后n-1行,n为一个数字;\np:小写p,粘贴文本操作,用于将缓存区的内容粘贴到当前光标所在位置的下方\nP:大写P,粘贴文本操作,用于将缓存区的内容粘贴到当前光标所在位置的上方;\n/[字符串]:向后搜索,支持正则表达式。用于从当前光标所在位置开始向文件尾部查找指定字符串的内容,查找的字符串会被加亮显示。键入字符 n 跳转到下一个,N 跳转到前一个\n?[字符串]:向前搜索,支持正则表达式。用于从当前光标所在位置开始向文件头部查找指定字符串的内容,查找的字符串会被加亮显示。键入字符 n 跳转到下一个,N 跳转到前一个\n:a,bs/F/T:替换文本操作,将a到b行之间第一个F换成T字符串。其中,":s/"表示进行替换操作。不指定a和b,则默认为当前行;如果b为$,表示替换到末行;如果是a,b为%,即:%s/F/T,表示从第一行替换至末行\n:a,bs/F/T/g:替换文本操作,替换第a行到b行,每一行所有F为T。a,b的取值规则同上一条;\na:在当前字符后添加文本\nA:在当前行末添加文本\ni:在当前字符前插入文本\nI:在当前行首插入文本\nno:在当前行后面插入n个空行,n为具体的数值\nnO:在当前行前面插入n个空行,n为具体的数值\n:wq:执行存盘退出操作\n:w:执行存盘操作\n:w!:执行强制存盘操作\n:q:执行退出操作\n:q!:执行强制退出操作\n:e [文件名]:打开并编辑指定名称的文件\n:n:如果同时打开多个文件,则继续编辑下一个文件\n:f:显示当前的文件名、文件总行数、光标所在行号占总行数的比例\n:set number:在最左端显示行号\n:set nonumber:在最左端不显示行号\njkhl或方向键:光标移动快捷键,分别为上下左右\nu:撤销\nctrl+r:反向撤销\nv+移动光标:使用v进行选择模式,移动光标可选择文本\nw:word,右移一个单词,光标停留在单词首部\ne:end,右移一个单词,光标停留单词的尾部\nb:back,左移一个单词,光标停留在单词首部\n^ 或 (:移至行头\n$ 或 ):移至行尾\ngd:高亮显示光标所在的单词\n')])])]),t("h2",{attrs:{id:"_5-vim-需知"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-vim-需知"}},[n._v("#")]),n._v(" 5.vim 需知")]),n._v(" "),t("h3",{attrs:{id:"_5-1-四大模式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-1-四大模式"}},[n._v("#")]),n._v(" 5.1 四大模式")]),n._v(" "),t("p",[n._v("众所周知,vim 里面最具特色的东西就是它可以切换模式,那什么是模式呢?可以简单的理解为在不同的模式下面按相同的键而得到不同的效果。比如 vim 在插入模式下面连按两次 d,那么就会在光标位置插入两个字母 d,如果在正常模式下面连按两次 d,那么光标所在当前行将会被删除。")]),n._v(" "),t("p",[n._v("既然说是 vim 的四大模式,那么 vim 到底有那四大模式呢?")]),n._v(" "),t("ul",[t("li",[n._v("正常模式(normal mode)")]),n._v(" "),t("li",[n._v("可视模式(visual mode)")]),n._v(" "),t("li",[n._v("插入模式(insert mode)")]),n._v(" "),t("li",[n._v("命令行模式(command-line mode)")])]),n._v(" "),t("p",[n._v("用户可以通过按 ESC 在各个模式之间进行切换。关于 vim 的模式说明,可以打开 vim 后键入 "),t("code",[n._v(":help mode")]),n._v(" 来查看。")]),n._v(" "),t("ul",[t("li",[t("strong",[n._v("正常模式 (command mode)")])])]),n._v(" "),t("p",[n._v("不管用户处于何种模式,只要按一下 ESC 键,即可进入正常模式。启动 vim 命令默认情况下进入正常模式。")]),n._v(" "),t("p",[n._v("在正常模式下,用户可以输入各种合法的 vim 命令,用于管理自己的文档。此时从键盘上输入的任何字符都被当做编辑命令来解释,若输入的字符是合法的 vim 命令,则 vim 在接受用户命令之后完成相应的动作。但需注意的是,所输入的命令并不在屏幕上显示出来。若输入的字符不是 vim 的合法命令,vim 会响铃报警。")]),n._v(" "),t("ul",[t("li",[t("strong",[n._v("可视模式(visual mode)")])])]),n._v(" "),t("p",[n._v("可视模式简单来说就是选中一块编辑区域,然后在上面执行一些操作,比如删除,替换,改变大小写等。")]),n._v(" "),t("p",[n._v("在正常模式按下 v(逐个字符选择文本)、 V(逐行选择文本)、Ctrl+v(按照块的方式选择文本),可以进入可视模式。可视模式中的操作有点像拿鼠标进行操作,选择文本的时候有一种鼠标选择的即视感,有时候会很方便。")]),n._v(" "),t("ul",[t("li",[t("strong",[n._v("插入模式 (insert mode)")])])]),n._v(" "),t("p",[n._v("在正常模式下输入插入命令 i(insert)、附加命令 a (append)、打开命令 o(open)、修改命令 c(change)、取代命令 r(replace)或替换命令 s(substitute)都可以进入插入模式。在该模式下,用户输入的任何字符都被Vi当做文件内容保存起来,并将其显示在屏幕上。在文本输入过程中,若想回到命令模式下,键入 ESC 键即可。")]),n._v(" "),t("ul",[t("li",[t("strong",[n._v("命令行模式 (command-line mode)")])])]),n._v(" "),t("p",[n._v("命令行模式又称为 ex 模式。ex 是 EXtended 的简称,是 Unix 系统上的纯文本编辑器。ex 命令可启动 vim,执行 ex 命令,键入 visual 就可以进入 vim 的正常模式。")]),n._v(" "),t("p",[n._v("vim 和 ex 编辑器的功能是相同的,二者主要区别是用户界面。在 vim 中,命令通常是单个键,例如 i、a、o 等;而在 ex 中,命令是以按回车键结束的行。在正常模式下,用户按冒号即可进入命令行模式,此时 vim 会在显示窗口的最后一行显示一个冒号作为命令行模式的提示符,等待用户输入命令。多数文件管理命令都是在此模式下执行的(如把编辑缓冲区的内容写到文件中等)。命令执行完后,vim 自动回到正常模式。")]),n._v(" "),t("h3",{attrs:{id:"_5-2-编码选项"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-2-编码选项"}},[n._v("#")]),n._v(" 5.2 编码选项")]),n._v(" "),t("p",[n._v("文件的编码和显示是一个令人头痛的东西,真希望这个世界上只存在 UTF8 编码,那就没那么痛苦了。vim编码配置涉及4个选项,分别是encoding 、fileencoding、fileencodings和termencoding,四者对应的简写分别为enc、fenc、fencs和tenc。")]),n._v(" "),t("p",[n._v("(1)encoding\nencoding 是 vim 内部使用的编码。vim 运行时,其菜单、标签、以及各个缓冲区统一使用 encoding 作为字符编码。")]),n._v(" "),t("p",[n._v("(2)fileencoding\nfileencoding为文件采用的编码方式。使用vim打开文件后,可以使用末行命令"),t("code",[n._v(":set fenc=utf-8")]),n._v("将文件编码方式更改为UTF-8,注意,前提是vim打开文件时已经正确识别出文件编码,即未出现乱码。")]),n._v(" "),t("p",[n._v("(3)fileencodings\nfileencodings用于vim在打开文件的时候进行解码的猜测列表。文件编码没有百分百正确的判断方法,所以vim只能猜测文件编码。~/.vimrc里面fileencodings的设置一般为")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v("set fileencodings=utf-8,gb18030,latin1\n")])])]),t("p",[n._v("(4)termencoding\n终端所使用的文本编码。这个选项的值用于告诉 vim 终端使用了哪种文本编码用于文本输入和显示。如果该值为空,那么它被设置为 encoding 的值。")]),n._v(" "),t("h3",{attrs:{id:"_5-3-读写文件时编码转换过程"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-3-读写文件时编码转换过程"}},[n._v("#")]),n._v(" 5.3 读写文件时编码转换过程")]),n._v(" "),t("p",[n._v("(1)读文件\nvim 打开文件时,需要将磁盘文件内容载入缓存,并将缓存中的字符转为换终端编码,通过网络传输的方式,传输到终端进行显示。两个转换环节,有一个出错都会出现乱码。")]),n._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[n._v("fileencoding -"),t("span",{pre:!0,attrs:{class:"token operator"}},[n._v(">")]),n._v(" encoding -"),t("span",{pre:!0,attrs:{class:"token operator"}},[n._v(">")]),n._v(" termencoding\n")])])]),t("p",[n._v("(2)写文件\n通过终端编辑文件时,字符编码转换过程是vim读文件的逆过程。")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v("termencoding -> encoding -> fileencoding \n")])])]),t("p",[n._v("注意:使用 vim 读写文件时为避免出现乱码,至关重要的一点就是终端,比如 SecureCRT 或 XShell 的编码设置要与 vim 的 termencoding 设置相同,如果不同还是还是会出现乱码,尽管 vim 已经采用正确的编码格式解析了文件。")]),n._v(" "),t("p",[n._v("比如将 XShell 设置为 UTF8。")]),n._v(" "),t("p",[t("img",{attrs:{src:"https://img-blog.csdn.net/20181012195217621",alt:"在这里插入图片描述"}})]),n._v(" "),t("h2",{attrs:{id:"_6-常见用法"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_6-常见用法"}},[n._v("#")]),n._v(" 6.常见用法")]),n._v(" "),t("ol",[t("li",[n._v("查看文件编码。")])]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v(":set fileencoding\n或者简写\n:set fenc\n")])])]),t("p",[n._v("可显示文件编码格式。这个命令有致命的缺点。原因是只有正常显示文件内容时,该命令显示的文件编码格式才是文件本身的编码格式。因为该命令显示的编码格式并不是文件本身的编码格式,而是当前打开该文件所使用的编码格式。因此,这个命令在网上的说明大都是不准确的,特此说明。")]),n._v(" "),t("ol",{attrs:{start:"2"}},[t("li",[n._v("修改编码类型。")])]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v(":set fileencoding=gbk\n#或者\n:set fenc=gbk\n")])])]),t("p",[n._v("还可以使用 iconv 修改文件编码类型。")]),n._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[n._v("iconv")]),n._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[n._v("-f")]),n._v(" encoding "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[n._v("-t")]),n._v(" encoding inputfile\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[n._v("# 比如将一个GBK编码的文件转换成 UTF8 编码")]),n._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[n._v("iconv")]),n._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[n._v("-f")]),n._v(" GBK "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[n._v("-t")]),n._v(" UTF-8 file1 "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[n._v("-o")]),n._v(" file2UTF-8\n")])])]),t("p",[n._v("iconv 参数说明:")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v("-f, --from-code=名称,原始文本编码\n-t, --to-code=名称,输出编码\n-l, --list 列举所有已知的字符集\n-c 从输出中忽略无效的字符\n-o, --output=FILE,输出文件\n-s, --silent,关闭警告\n--verbose,打印进度信息\n")])])]),t("ol",{attrs:{start:"3"}},[t("li",[n._v("指定编码类型浏览文件。")])]),n._v(" "),t("p",[n._v("如果知道了文件的编码类型,可显示指定编码类型来解析文件,而不用vim去猜测文件的编码类型,事实上猜测的往往是错误。命令如下:")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v('vim file_name -c "e ++enc=utf-8"\n')])])]),t("p",[n._v("或者在使用 vim 打开文件之后,在末行模式使用如下命令:")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v(":e ++enc=utf-8\n")])])]),t("ol",{attrs:{start:"4"}},[t("li",[n._v("新增空白行")])]),n._v(" "),t("p",[n._v("在命令行模式下输入 o。如果想添加三行的话,键入 3o ,如果想添加 n 行则键入 n 个 o。如果键入 3o 后立即退出插入模式的话,就可以添加三个空白行。如果输入一些内容再退出,可以添加三行相同的内容。")]),n._v(" "),t("p",[n._v("如果想在每一行执行相同的命令,在 vim 里可以用 :g 实现。一般的语法是:")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v(":g/pattern/cmd\n")])])]),t("p",[n._v("它表示在匹配 /pattern/ 这个正则表达式的行上执行 cmd 命令(也称冒号命令)。而 /^/ 这个表达式,用于匹配行首。因为任何一行都有行首,你的要求就很容易实现了。")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v(":g/^/norm 3o\n")])])]),t("p",[n._v("norm 这个命令的意思是,把后面的参数看成是在普通模式下的按键,即命令模式下的按键。")]),n._v(" "),t("ol",{attrs:{start:"5"}},[t("li",[n._v("高亮显示选中的单词。")])]),n._v(" "),t("p",[n._v("将光标移到需要高亮显示的单词上,在命令模式下输入 gd,那么就可以将当前的单词在当前文本中全部高亮显示。")]),n._v(" "),t("p",[n._v("如下图所示,高亮显示 dwBeInvitedUinLen。\n"),t("img",{attrs:{src:"https://imgconvert.csdnimg.cn/aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTYwODAyMTYwNzMyMTMx",alt:"这里写图片描述"}})]),n._v(" "),t("ol",{attrs:{start:"6"}},[t("li",[n._v("输入特殊字符")])]),n._v(" "),t("p",[n._v("有三种方法,第一种是使用字符编码,第二种是使用二合字母(digraph),三是使用快捷键(Ctrl+字母)。")]),n._v(" "),t("ul",[t("li",[n._v("使用字符编码")])]),n._v(" "),t("p",[n._v("vim 可以用字符编码插入任意字符,使用此功能可以方便地输入键盘上找不到的字符。使用步骤如下:\n(1)编辑模式下按下 Ctrl+v;\n(2)如果是 ASCII 字符,则输入三位十进制 ASCII 码值,不足三位,前补0。比如输入大写字母 A,则输入 065;如果是 Unicode 字符,则输入“u+四位十六进制码值”。比如输入大写字母 A,则输入 u0041。")]),n._v(" "),t("p",[n._v("更多详情内容可参见 vim 帮助文档,末行模式输入"),t("code",[n._v(":h i_ctrl-v_digit")]),n._v("。")]),n._v(" "),t("ul",[t("li",[n._v("使用二合字母(digraph)")])]),n._v(" "),t("p",[n._v("二合字母顾名思义,使用两个字母的组合来标识特殊字符。使用步骤如下:\n(1)编辑模式下按下 Ctrl+K。\n(2)输入特殊字符对应的二合字母。可以使用"),t("code",[n._v(":dig")]),n._v("或"),t("code",[n._v(":h digraph-table")]),n._v("查看对应二合字母。比如回车符(Carriage Return) 的二合字母是 CR。")]),n._v(" "),t("ul",[t("li",[n._v("Ctrl+字母")])]),n._v(" "),t("p",[n._v("在 vim 中使用"),t("code",[n._v(":set list")]),n._v("显示所有字符时,经常会看到有"),t("code",[n._v("^I、^M")]),n._v("等符号,代表的字符可以使用"),t("code",[n._v(":h digraph-table")]),n._v("查看,特殊字符列表如下:")]),n._v(" "),t("p",[t("img",{attrs:{src:"https://img-blog.csdn.net/20180608145829247?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0szNDZLMzQ2/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70",alt:"这里写图片描述"}}),n._v('\n在 vim 的编辑模式下,可使用“Ctrl+字母”进行输入,例如使用"Ctrl+I"可以输入字符'),t("code",[n._v("^I")]),n._v('(Tab),使用"Ctrl+M"可以输入字符'),t("code",[n._v("^M")]),n._v("(回车)。")]),n._v(" "),t("ol",{attrs:{start:"7"}},[t("li",[n._v("其它常见操作")])]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v("#显示行号\n:set number\n\n#取消行号\n:set nonu\n\n#取消高亮显示查找后的字符串\n:nohl\n\n#显示换行符\n:set list\n\n#不显示换行符 \n:set nolist \n")])])]),t("h2",{attrs:{id:"_7-小结"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_7-小结"}},[n._v("#")]),n._v(" 7.小结")]),n._v(" "),t("p",[n._v("vim 仍有很多未知的东西等待我们去发现,如果 vim 使用过程中有问题,欢迎留言,一同探讨解决进步。")]),n._v(" "),t("hr"),n._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[n._v("#")]),n._v(" 参考文献")]),n._v(" "),t("p",[t("a",{attrs:{href:"https://www.linux.org/docs/man1/vim.html",target:"_blank",rel:"noopener noreferrer"}},[n._v("vim(1) manual - linux.org"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/vi.1p.html",target:"_blank",rel:"noopener noreferrer"}},[n._v("vi(1p) - Linux manual page - man7.org"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"http://man.linuxde.net/vi",target:"_blank",rel:"noopener noreferrer"}},[n._v("Linux命令大全.vi命令"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"http://blog.csdn.net/keepliving/article/details/5623362",target:"_blank",rel:"noopener noreferrer"}},[n._v("VIM乱码原因与解决方案"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/a627088424/article/details/38941589",target:"_blank",rel:"noopener noreferrer"}},[n._v("Vim如何插入特殊字符"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/smstong/article/details/51279810",target:"_blank",rel:"noopener noreferrer"}},[n._v("让VIM彻底告别乱码"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"https://www.jianshu.com/p/49b7281c18b6",target:"_blank",rel:"noopener noreferrer"}},[n._v("vim复制字符"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/ii1245712564/article/details/46768097",target:"_blank",rel:"noopener noreferrer"}},[n._v("Vim技巧之四大模式_普通模式 - CSDN"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"https://www.freecodecamp.org/news/vim-editor-modes-explained/",target:"_blank",rel:"noopener noreferrer"}},[n._v("freecodecamp.Vim Editor Modes Explained"),t("OutboundLink")],1)]),n._v(" "),t("Vssue",{attrs:{title:"vim"}})],1)}),[],!1,null,null,null);t.default=v.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[114],{446:function(n,t,e){"use strict";e.r(t);var a=e(12),v=Object(a.a)({},(function(){var n=this,t=n._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":n.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[n._v("#")]),n._v(" 1.命令简介")]),n._v(" "),t("p",[n._v("vim 是 Linux 中最通用的全屏幕文本编辑器,是 vi 的增强版(vi iMproved),与 vi 完全兼容,且扩充了很多功能。")]),n._v(" "),t("p",[n._v("vim 编辑器支持编辑模式和命令模式,编辑模式下可以完成文本的编辑功能,命令模式下可以完成对文件的操作命令,要正确使用 vim 编辑器就必须熟练掌握这两种模式的切换。默认情况下,打开 vim 后自动进入命令模式。从编辑模式切换到命令模式使用 ESC 键,从命令模式切换到编辑模式使用 A、a、O、o、I、i 键。")]),n._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[n._v("#")]),n._v(" 2.命令格式")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v("vim [OPTIONS] [FILE...]\nvim [OPTIONS] -\nvim [OPTIONS] -t TAG\nvim [OPTIONS] -q [ERRORFILE]\n")])])]),t("p",[t("code",[n._v("[FILE...]")]),n._v("表示一系列使用 vim 编辑的文件,使用"),t("code",[n._v(":next")]),n._v("命令可以向前切换所编辑的文件,使用"),t("code",[n._v("--")]),n._v("可以向后切换,这是 vim 常用启动格式。")]),n._v(" "),t("p",[t("code",[n._v("-")]),n._v(":表示待编辑的文件从标准输入读取。")]),n._v(" "),t("p",[t("code",[n._v("-t TAG")]),n._v(":要编辑的文件和光标的初始位置取决于一个标签,一种 goto 标签。标签在标签文件中查找,与标签关联的文件成为当前文件并执行关联的命令。主要用于 C 程序,在这种情况下 TAG 可以是函数名,其结果是包含该函数的文件成为当前文件,并且光标位于函数的开头。参见:"),t("code",[n._v(":help tag-commands")]),n._v("。")]),n._v(" "),t("p",[t("code",[n._v("-q [ERRORFILE]")]),n._v(":使用 quickFix 模式启动 vim,文件 ERRORFILE 将被读取并显示第一个错误。如果 ERRORFILE 省略,则默认为 AztecC.Err(Amiga 系统)或 errors.err(其它系统)。关于 quickFix 模式说明,可以使用"),t("code",[n._v(":help quickfix")]),n._v("查看。")]),n._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[n._v("#")]),n._v(" 3.选项说明")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v("+NUM\n\t打开文件时光标跳转到由 NUM 指定的行首\n+/PAT\n\t打开文件时光标跳转到匹配的模式字符串 PAT\n+, -c CMD\n\t在完成对第一个文件的读取后,执行给出的指令\n-b\n\t以二进制模式打开文件,用于编辑二进制文件和可执行文件\n-C\n\t以兼容模式运行 vim,使 vim 的表现更像 vi,即使存在 .vimrc 文件\n-d\n\t以 diff 模式打开文件,当多个文件编辑时,显示文件差异部分\n-e\n\t进入 Ex 模式,即进入冒号开头的末行模式。ex是Unix编辑器\n-E\n\t进入增强 Ex 模式,就像执行命令 exim\n-l\n\t使用 lisp 模式,打开 lisp 和 showmatch\n-m\n\t取消写文件功能,重设 write 选项。你仍然可以修改缓冲内容,但是不可以写入文件\n-M\n\t关闭修改功能\n-N\n\t非兼容模式运行 vim,这会使 vim 表现的更好,但是可能会存在与 vi 不兼容的情况,即使存在 .vimrc 文件\n-n\n\t不使用 swap file,这可能会导致在 vim 意外崩溃的情况下无法恢复未保存的内容\n-o [N]\n\t以上下排列方式同时打开 N 个 vim 窗口,如果未指定 N ,则为每一个文件单独打开一个窗口\n-O [N]\n\t以左右下排列方式同时打开 N 个 vim 窗口,如果未指定 N ,则为每一个文件单独打开一个窗口\n-R\n\t以只读方式打开文件\n-r\n\t列出 swap file\n-r FILE\n\t以指定的交换文件来恢复崩溃的编辑会话。交换文件名后缀为.swp\n-s\n\t安静模式,与 -e 选项结合使用\n-u VIMRC\n\t使用指定的 vimrc 文件中的命令来初始化 vim,所有其它的初始化操作将被跳过。可以给定“NONE”来跳过所有的初始化\n-U GVIMRC\n\t使用指定的 gvimrc 文件中的命令来初始化 GUI,所有其它的 GUI 初始化操作将被跳过。可以给定 “NONE” 来跳过所有的 GUI 初始化\n-V [N]\n\t以冗余模式执行 vim,打印 vim 读取了哪些配置文件 vimrc。可选的数字 N 表示冗余级别,数值越大级别越高,取值范围是 0~10,默认是 10\n-x\n\t写文件时进行加密,会提示输入加密密钥\n-h, --help\n\t显示帮助信息并退出\n--version\n\t显示版本信息并退出\n")])])]),t("h2",{attrs:{id:"_4-内置命令"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-内置命令"}},[n._v("#")]),n._v(" 4.内置命令")]),n._v(" "),t("p",[n._v("vim 提供了丰富的内置命令,有些内置命令使用键盘组合键即可完成,有些内置命令则需要以冒号 : 开头输入。常用内置命令如下:")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v('Ctrl+u:向下滚动半屏\nCtrl+d:向上滚动半屏\nCtrl+f:向下滚动一屏\nCtrl+b:向上滚动一屏\nCtrl+e:向下滚动一行\nCtrl+y:向上滚动一行\nEnter:回车向下滚动一行\nEsc:从编辑模式切换到命令模式\nZZ:命令模式下保存当前文件所做的修改后退出 vim\n:[行号]:光标跳转到指定行的行首\n:$:光标跳转到最后一行的行首\ngg:跳转到首行;\nG:跳转到尾行\nCtrl+g:显示总行数\nx, X:删除一个字符或选中的内容。当删除一个字符时,x 删除光标后的,X 删除光标前的。删除即剪切\nd:删除选中的文本,删除即剪切\nD:删除从当前光标到光标所在行尾的全部字符。删除即剪切\ndd:删除光标所在行的整行内容。删除即剪切\nndd:删除当前行及其后n-1行,n为一个数字。删除即剪切\ny:复制选中的文本\ny0:复制光标前一个字符到行首的内容\ny$:复制光标后一个字符到行尾的内容\nyh:复制光标前的1个字符\nyl:复制光标后的1个字符\nnyh:复制光标前的n个字符,比如4yh复制光标前的4个字符\nnyl:复制光标后的n个字符,比如4yl复制光标后的4个字符\nyy:复制光标所在行\nnyy:复制当前行以及其后n-1行,n为一个数字;\np:小写p,粘贴文本操作,用于将缓存区的内容粘贴到当前光标所在位置的下方\nP:大写P,粘贴文本操作,用于将缓存区的内容粘贴到当前光标所在位置的上方;\n/[字符串]:向后搜索,支持正则表达式。用于从当前光标所在位置开始向文件尾部查找指定字符串的内容,查找的字符串会被加亮显示。键入字符 n 跳转到下一个,N 跳转到前一个\n?[字符串]:向前搜索,支持正则表达式。用于从当前光标所在位置开始向文件头部查找指定字符串的内容,查找的字符串会被加亮显示。键入字符 n 跳转到下一个,N 跳转到前一个\n:a,bs/F/T:替换文本操作,将a到b行之间第一个F换成T字符串。其中,":s/"表示进行替换操作。不指定a和b,则默认为当前行;如果b为$,表示替换到末行;如果是a,b为%,即:%s/F/T,表示从第一行替换至末行\n:a,bs/F/T/g:替换文本操作,替换第a行到b行,每一行所有F为T。a,b的取值规则同上一条;\na:在当前字符后添加文本\nA:在当前行末添加文本\ni:在当前字符前插入文本\nI:在当前行首插入文本\nno:在当前行后面插入n个空行,n为具体的数值\nnO:在当前行前面插入n个空行,n为具体的数值\n:wq:执行存盘退出操作\n:w:执行存盘操作\n:w!:执行强制存盘操作\n:q:执行退出操作\n:q!:执行强制退出操作\n:e [文件名]:打开并编辑指定名称的文件\n:n:如果同时打开多个文件,则继续编辑下一个文件\n:f:显示当前的文件名、文件总行数、光标所在行号占总行数的比例\n:set number:在最左端显示行号\n:set nonumber:在最左端不显示行号\njkhl或方向键:光标移动快捷键,分别为上下左右\nu:撤销\nctrl+r:反向撤销\nv+移动光标:使用v进行选择模式,移动光标可选择文本\nw:word,右移一个单词,光标停留在单词首部\ne:end,右移一个单词,光标停留单词的尾部\nb:back,左移一个单词,光标停留在单词首部\n^ 或 (:移至行头\n$ 或 ):移至行尾\ngd:高亮显示光标所在的单词\n')])])]),t("h2",{attrs:{id:"_5-vim-需知"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-vim-需知"}},[n._v("#")]),n._v(" 5.vim 需知")]),n._v(" "),t("h3",{attrs:{id:"_5-1-四大模式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-1-四大模式"}},[n._v("#")]),n._v(" 5.1 四大模式")]),n._v(" "),t("p",[n._v("众所周知,vim 里面最具特色的东西就是它可以切换模式,那什么是模式呢?可以简单的理解为在不同的模式下面按相同的键而得到不同的效果。比如 vim 在插入模式下面连按两次 d,那么就会在光标位置插入两个字母 d,如果在正常模式下面连按两次 d,那么光标所在当前行将会被删除。")]),n._v(" "),t("p",[n._v("既然说是 vim 的四大模式,那么 vim 到底有那四大模式呢?")]),n._v(" "),t("ul",[t("li",[n._v("正常模式(normal mode)")]),n._v(" "),t("li",[n._v("可视模式(visual mode)")]),n._v(" "),t("li",[n._v("插入模式(insert mode)")]),n._v(" "),t("li",[n._v("命令行模式(command-line mode)")])]),n._v(" "),t("p",[n._v("用户可以通过按 ESC 在各个模式之间进行切换。关于 vim 的模式说明,可以打开 vim 后键入 "),t("code",[n._v(":help mode")]),n._v(" 来查看。")]),n._v(" "),t("ul",[t("li",[t("strong",[n._v("正常模式 (command mode)")])])]),n._v(" "),t("p",[n._v("不管用户处于何种模式,只要按一下 ESC 键,即可进入正常模式。启动 vim 命令默认情况下进入正常模式。")]),n._v(" "),t("p",[n._v("在正常模式下,用户可以输入各种合法的 vim 命令,用于管理自己的文档。此时从键盘上输入的任何字符都被当做编辑命令来解释,若输入的字符是合法的 vim 命令,则 vim 在接受用户命令之后完成相应的动作。但需注意的是,所输入的命令并不在屏幕上显示出来。若输入的字符不是 vim 的合法命令,vim 会响铃报警。")]),n._v(" "),t("ul",[t("li",[t("strong",[n._v("可视模式(visual mode)")])])]),n._v(" "),t("p",[n._v("可视模式简单来说就是选中一块编辑区域,然后在上面执行一些操作,比如删除,替换,改变大小写等。")]),n._v(" "),t("p",[n._v("在正常模式按下 v(逐个字符选择文本)、 V(逐行选择文本)、Ctrl+v(按照块的方式选择文本),可以进入可视模式。可视模式中的操作有点像拿鼠标进行操作,选择文本的时候有一种鼠标选择的即视感,有时候会很方便。")]),n._v(" "),t("ul",[t("li",[t("strong",[n._v("插入模式 (insert mode)")])])]),n._v(" "),t("p",[n._v("在正常模式下输入插入命令 i(insert)、附加命令 a (append)、打开命令 o(open)、修改命令 c(change)、取代命令 r(replace)或替换命令 s(substitute)都可以进入插入模式。在该模式下,用户输入的任何字符都被Vi当做文件内容保存起来,并将其显示在屏幕上。在文本输入过程中,若想回到命令模式下,键入 ESC 键即可。")]),n._v(" "),t("ul",[t("li",[t("strong",[n._v("命令行模式 (command-line mode)")])])]),n._v(" "),t("p",[n._v("命令行模式又称为 ex 模式。ex 是 EXtended 的简称,是 Unix 系统上的纯文本编辑器。ex 命令可启动 vim,执行 ex 命令,键入 visual 就可以进入 vim 的正常模式。")]),n._v(" "),t("p",[n._v("vim 和 ex 编辑器的功能是相同的,二者主要区别是用户界面。在 vim 中,命令通常是单个键,例如 i、a、o 等;而在 ex 中,命令是以按回车键结束的行。在正常模式下,用户按冒号即可进入命令行模式,此时 vim 会在显示窗口的最后一行显示一个冒号作为命令行模式的提示符,等待用户输入命令。多数文件管理命令都是在此模式下执行的(如把编辑缓冲区的内容写到文件中等)。命令执行完后,vim 自动回到正常模式。")]),n._v(" "),t("h3",{attrs:{id:"_5-2-编码选项"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-2-编码选项"}},[n._v("#")]),n._v(" 5.2 编码选项")]),n._v(" "),t("p",[n._v("文件的编码和显示是一个令人头痛的东西,真希望这个世界上只存在 UTF8 编码,那就没那么痛苦了。vim编码配置涉及4个选项,分别是encoding 、fileencoding、fileencodings和termencoding,四者对应的简写分别为enc、fenc、fencs和tenc。")]),n._v(" "),t("p",[n._v("(1)encoding\nencoding 是 vim 内部使用的编码。vim 运行时,其菜单、标签、以及各个缓冲区统一使用 encoding 作为字符编码。")]),n._v(" "),t("p",[n._v("(2)fileencoding\nfileencoding为文件采用的编码方式。使用vim打开文件后,可以使用末行命令"),t("code",[n._v(":set fenc=utf-8")]),n._v("将文件编码方式更改为UTF-8,注意,前提是vim打开文件时已经正确识别出文件编码,即未出现乱码。")]),n._v(" "),t("p",[n._v("(3)fileencodings\nfileencodings用于vim在打开文件的时候进行解码的猜测列表。文件编码没有百分百正确的判断方法,所以vim只能猜测文件编码。~/.vimrc里面fileencodings的设置一般为")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v("set fileencodings=utf-8,gb18030,latin1\n")])])]),t("p",[n._v("(4)termencoding\n终端所使用的文本编码。这个选项的值用于告诉 vim 终端使用了哪种文本编码用于文本输入和显示。如果该值为空,那么它被设置为 encoding 的值。")]),n._v(" "),t("h3",{attrs:{id:"_5-3-读写文件时编码转换过程"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-3-读写文件时编码转换过程"}},[n._v("#")]),n._v(" 5.3 读写文件时编码转换过程")]),n._v(" "),t("p",[n._v("(1)读文件\nvim 打开文件时,需要将磁盘文件内容载入缓存,并将缓存中的字符转为换终端编码,通过网络传输的方式,传输到终端进行显示。两个转换环节,有一个出错都会出现乱码。")]),n._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[n._v("fileencoding -"),t("span",{pre:!0,attrs:{class:"token operator"}},[n._v(">")]),n._v(" encoding -"),t("span",{pre:!0,attrs:{class:"token operator"}},[n._v(">")]),n._v(" termencoding\n")])])]),t("p",[n._v("(2)写文件\n通过终端编辑文件时,字符编码转换过程是vim读文件的逆过程。")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v("termencoding -> encoding -> fileencoding \n")])])]),t("p",[n._v("注意:使用 vim 读写文件时为避免出现乱码,至关重要的一点就是终端,比如 SecureCRT 或 XShell 的编码设置要与 vim 的 termencoding 设置相同,如果不同还是还是会出现乱码,尽管 vim 已经采用正确的编码格式解析了文件。")]),n._v(" "),t("p",[n._v("比如将 XShell 设置为 UTF8。")]),n._v(" "),t("p",[t("img",{attrs:{src:"https://img-blog.csdn.net/20181012195217621",alt:"在这里插入图片描述"}})]),n._v(" "),t("h2",{attrs:{id:"_6-常见用法"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_6-常见用法"}},[n._v("#")]),n._v(" 6.常见用法")]),n._v(" "),t("ol",[t("li",[n._v("查看文件编码。")])]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v(":set fileencoding\n或者简写\n:set fenc\n")])])]),t("p",[n._v("可显示文件编码格式。这个命令有致命的缺点。原因是只有正常显示文件内容时,该命令显示的文件编码格式才是文件本身的编码格式。因为该命令显示的编码格式并不是文件本身的编码格式,而是当前打开该文件所使用的编码格式。因此,这个命令在网上的说明大都是不准确的,特此说明。")]),n._v(" "),t("ol",{attrs:{start:"2"}},[t("li",[n._v("修改编码类型。")])]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v(":set fileencoding=gbk\n#或者\n:set fenc=gbk\n")])])]),t("p",[n._v("还可以使用 iconv 修改文件编码类型。")]),n._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[n._v("iconv")]),n._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[n._v("-f")]),n._v(" encoding "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[n._v("-t")]),n._v(" encoding inputfile\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[n._v("# 比如将一个GBK编码的文件转换成 UTF8 编码")]),n._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[n._v("iconv")]),n._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[n._v("-f")]),n._v(" GBK "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[n._v("-t")]),n._v(" UTF-8 file1 "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[n._v("-o")]),n._v(" file2UTF-8\n")])])]),t("p",[n._v("iconv 参数说明:")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v("-f, --from-code=名称,原始文本编码\n-t, --to-code=名称,输出编码\n-l, --list 列举所有已知的字符集\n-c 从输出中忽略无效的字符\n-o, --output=FILE,输出文件\n-s, --silent,关闭警告\n--verbose,打印进度信息\n")])])]),t("ol",{attrs:{start:"3"}},[t("li",[n._v("指定编码类型浏览文件。")])]),n._v(" "),t("p",[n._v("如果知道了文件的编码类型,可显示指定编码类型来解析文件,而不用vim去猜测文件的编码类型,事实上猜测的往往是错误。命令如下:")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v('vim file_name -c "e ++enc=utf-8"\n')])])]),t("p",[n._v("或者在使用 vim 打开文件之后,在末行模式使用如下命令:")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v(":e ++enc=utf-8\n")])])]),t("ol",{attrs:{start:"4"}},[t("li",[n._v("新增空白行")])]),n._v(" "),t("p",[n._v("在命令行模式下输入 o。如果想添加三行的话,键入 3o ,如果想添加 n 行则键入 n 个 o。如果键入 3o 后立即退出插入模式的话,就可以添加三个空白行。如果输入一些内容再退出,可以添加三行相同的内容。")]),n._v(" "),t("p",[n._v("如果想在每一行执行相同的命令,在 vim 里可以用 :g 实现。一般的语法是:")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v(":g/pattern/cmd\n")])])]),t("p",[n._v("它表示在匹配 /pattern/ 这个正则表达式的行上执行 cmd 命令(也称冒号命令)。而 /^/ 这个表达式,用于匹配行首。因为任何一行都有行首,你的要求就很容易实现了。")]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v(":g/^/norm 3o\n")])])]),t("p",[n._v("norm 这个命令的意思是,把后面的参数看成是在普通模式下的按键,即命令模式下的按键。")]),n._v(" "),t("ol",{attrs:{start:"5"}},[t("li",[n._v("高亮显示选中的单词。")])]),n._v(" "),t("p",[n._v("将光标移到需要高亮显示的单词上,在命令模式下输入 gd,那么就可以将当前的单词在当前文本中全部高亮显示。")]),n._v(" "),t("p",[n._v("如下图所示,高亮显示 dwBeInvitedUinLen。\n"),t("img",{attrs:{src:"https://imgconvert.csdnimg.cn/aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTYwODAyMTYwNzMyMTMx",alt:"这里写图片描述"}})]),n._v(" "),t("ol",{attrs:{start:"6"}},[t("li",[n._v("输入特殊字符")])]),n._v(" "),t("p",[n._v("有三种方法,第一种是使用字符编码,第二种是使用二合字母(digraph),三是使用快捷键(Ctrl+字母)。")]),n._v(" "),t("ul",[t("li",[n._v("使用字符编码")])]),n._v(" "),t("p",[n._v("vim 可以用字符编码插入任意字符,使用此功能可以方便地输入键盘上找不到的字符。使用步骤如下:\n(1)编辑模式下按下 Ctrl+v;\n(2)如果是 ASCII 字符,则输入三位十进制 ASCII 码值,不足三位,前补0。比如输入大写字母 A,则输入 065;如果是 Unicode 字符,则输入“u+四位十六进制码值”。比如输入大写字母 A,则输入 u0041。")]),n._v(" "),t("p",[n._v("更多详情内容可参见 vim 帮助文档,末行模式输入"),t("code",[n._v(":h i_ctrl-v_digit")]),n._v("。")]),n._v(" "),t("ul",[t("li",[n._v("使用二合字母(digraph)")])]),n._v(" "),t("p",[n._v("二合字母顾名思义,使用两个字母的组合来标识特殊字符。使用步骤如下:\n(1)编辑模式下按下 Ctrl+K。\n(2)输入特殊字符对应的二合字母。可以使用"),t("code",[n._v(":dig")]),n._v("或"),t("code",[n._v(":h digraph-table")]),n._v("查看对应二合字母。比如回车符(Carriage Return) 的二合字母是 CR。")]),n._v(" "),t("ul",[t("li",[n._v("Ctrl+字母")])]),n._v(" "),t("p",[n._v("在 vim 中使用"),t("code",[n._v(":set list")]),n._v("显示所有字符时,经常会看到有"),t("code",[n._v("^I、^M")]),n._v("等符号,代表的字符可以使用"),t("code",[n._v(":h digraph-table")]),n._v("查看,特殊字符列表如下:")]),n._v(" "),t("p",[t("img",{attrs:{src:"https://img-blog.csdn.net/20180608145829247?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0szNDZLMzQ2/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70",alt:"这里写图片描述"}}),n._v('\n在 vim 的编辑模式下,可使用“Ctrl+字母”进行输入,例如使用"Ctrl+I"可以输入字符'),t("code",[n._v("^I")]),n._v('(Tab),使用"Ctrl+M"可以输入字符'),t("code",[n._v("^M")]),n._v("(回车)。")]),n._v(" "),t("ol",{attrs:{start:"7"}},[t("li",[n._v("其它常见操作")])]),n._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[n._v("#显示行号\n:set number\n\n#取消行号\n:set nonu\n\n#取消高亮显示查找后的字符串\n:nohl\n\n#显示换行符\n:set list\n\n#不显示换行符 \n:set nolist \n")])])]),t("h2",{attrs:{id:"_7-小结"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_7-小结"}},[n._v("#")]),n._v(" 7.小结")]),n._v(" "),t("p",[n._v("vim 仍有很多未知的东西等待我们去发现,如果 vim 使用过程中有问题,欢迎留言,一同探讨解决进步。")]),n._v(" "),t("hr"),n._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[n._v("#")]),n._v(" 参考文献")]),n._v(" "),t("p",[t("a",{attrs:{href:"https://www.linux.org/docs/man1/vim.html",target:"_blank",rel:"noopener noreferrer"}},[n._v("vim(1) manual - linux.org"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/vi.1p.html",target:"_blank",rel:"noopener noreferrer"}},[n._v("vi(1p) - Linux manual page - man7.org"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"http://man.linuxde.net/vi",target:"_blank",rel:"noopener noreferrer"}},[n._v("Linux命令大全.vi命令"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"http://blog.csdn.net/keepliving/article/details/5623362",target:"_blank",rel:"noopener noreferrer"}},[n._v("VIM乱码原因与解决方案"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/a627088424/article/details/38941589",target:"_blank",rel:"noopener noreferrer"}},[n._v("Vim如何插入特殊字符"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/smstong/article/details/51279810",target:"_blank",rel:"noopener noreferrer"}},[n._v("让VIM彻底告别乱码"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"https://www.jianshu.com/p/49b7281c18b6",target:"_blank",rel:"noopener noreferrer"}},[n._v("vim复制字符"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/ii1245712564/article/details/46768097",target:"_blank",rel:"noopener noreferrer"}},[n._v("Vim技巧之四大模式_普通模式 - CSDN"),t("OutboundLink")],1)]),n._v(" "),t("p",[t("a",{attrs:{href:"https://www.freecodecamp.org/news/vim-editor-modes-explained/",target:"_blank",rel:"noopener noreferrer"}},[n._v("freecodecamp.Vim Editor Modes Explained"),t("OutboundLink")],1)]),n._v(" "),t("Vssue",{attrs:{title:"vim"}})],1)}),[],!1,null,null,null);t.default=v.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/115.e6b44866.js b/docs/assets/js/115.4a46dbdc.js similarity index 99% rename from docs/assets/js/115.e6b44866.js rename to docs/assets/js/115.4a46dbdc.js index 11f535676..5e5bbb16c 100644 --- a/docs/assets/js/115.e6b44866.js +++ b/docs/assets/js/115.4a46dbdc.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[115],{450:function(t,v,e){"use strict";e.r(v);var _=e(12),a=Object(_.a)({},(function(){var t=this,v=t._self._c;return v("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[v("h2",{attrs:{id:"_1-命令简介"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),v("p",[t._v("df(Disk Free)命令用于查看 Linux 文件系统的磁盘空间占用情况。可以利用该命令来获取硬盘被占用了多少空间,以及剩余空间等信息,默认显示单位为 KB。")]),t._v(" "),v("p",[t._v("本文描述的是 GNU 版的 df,其它版本(如 POSIX 版)的实现会有所不同。")]),t._v(" "),v("h2",{attrs:{id:"_2-命令格式"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),v("div",{staticClass:"language- extra-class"},[v("pre",{pre:!0,attrs:{class:"language-text"}},[v("code",[t._v("df [OPTION]... [FILE]...\n")])])]),v("p",[t._v("参数 FILE 表示文件系统上的文件。如果给定参数 FILE,则 df 分别展示各个文件所在文件系统的信息,如果没有给定 FILE,则默认输出所有已挂载的文件系统的载信息。")]),t._v(" "),v("h2",{attrs:{id:"_3-选项说明"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),v("div",{staticClass:"language- extra-class"},[v("pre",{pre:!0,attrs:{class:"language-text"}},[v("code",[t._v("-a, --all\n\t显示所有的文件系统,包括虚拟文件系统\n-B, --block-size=SIZE\n\t使用指定的块大小\n-h, --human-readable\n\t以易读的方式显示磁盘空间已用与未用的大小\n--direct\n\t显示文件的统计信息,而不是挂载点\n--total\n\t显示所有文件系统总的使用情况\n-H, --si\n\t使用 1000 而非 1024 作为换算单位\n-i, --inodes\n\t显示索引节点 inode 信息,而非磁盘块的使用情况\n-k, --local\n\t同 --block-size=1K,即将块大小设置为 1KB\n-l, --local\n\t只输出本地文件系统信息\n-P\n\t输出格式为 POSIX\n-t , --type=TYPE\n\t显示指定的文件系统\n-T, --print-type\n\t显示文件系统类型\n-x, --exclude-type=TYPE\n\t显示指定的文件系统之外的文件系统\n--no-sync\n\t不进行磁盘同步,默认选项\n--help\n\t显示帮助信息并退出\n--version\n\t显示版本信息并退出\n")])])]),v("h2",{attrs:{id:"_4-常用示例"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),v("p",[t._v("(1)以易读方式显示文件系统空间使用情况,并输出文件系统类型。")]),t._v(" "),v("div",{staticClass:"language- extra-class"},[v("pre",{pre:!0,attrs:{class:"language-text"}},[v("code",[t._v("df -hT\nFilesystem Type Size Used Avail Use% Mounted on\n/dev/mapper/vg_mic-lv_root\n ext4 50G 16G 32G 33% /\ntmpfs tmpfs 16G 0 16G 0% /dev/shm\n/dev/sda1 ext4 485M 38M 422M 9% /boot\n/dev/mapper/vg_mic-lv_home\n ext4 210G 197G 2.7G 99% /home\n")])])]),v("p",[t._v("上面的示例输出信息表示的意思分别是:\n第一列:filesystem代表文件系统在哪个分区,所以列出设备名称。其中"),v("code",[t._v("/dev/mapper/vg_mic-lv_root")]),t._v("这行的意思是,你有一个VG (volume group,卷组)叫作vg_mic, vg_mic里面有一个LV(logical volume,逻辑卷)叫作lv_root。其实这个"),v("code",[t._v("/dev/mapper/vg_mic-lv_root")]),t._v("是一个连接文件,连接到/dev/dm-0的,可以用"),v("code",[t._v("ll /dev/mapper/vg_mic-lv_root")]),t._v("查看。实际上,可以将"),v("code",[t._v("vg_mic-lv_root")]),t._v("看作一个分区来对待就可以了。如果想查看实际的物理分区,可以使用命令pvdisplay$^{[1,2]}$。")]),t._v(" "),v("p",[t._v("第二列:Type代表文件系统类型。比如第三行的tmpfs是一种基于内存的文件系统,类似于ramdisk。tmpfs可以使用RAM,也可以使用swap分区来存储文件,提高文件的读写读写速度。再如第三行的/dev/sda1分区的文件系统是ext4。")]),t._v(" "),v("p",[t._v("第三列:Size 代表分区的大小。")]),t._v(" "),v("p",[t._v("第四列:Used表示已经使用的大小。")]),t._v(" "),v("p",[t._v("第五列:Avail表示可用的大小。")]),t._v(" "),v("p",[t._v("第六列:Use%表示以百分比显示已经使用的比例。")]),t._v(" "),v("p",[t._v("第七列:Mounted on表示磁盘分区挂载的目录,即挂载点。")]),t._v(" "),v("p",[t._v("这里列一下Linux系统中磁盘与其它外设的命名规则,以及磁盘分区的命名规则。常见的设备与其在Linux中的文件名如下表:")]),t._v(" "),v("table",[v("thead",[v("tr",[v("th",[t._v("设备")]),t._v(" "),v("th",[t._v("文件名")])])]),t._v(" "),v("tbody",[v("tr",[v("td",[t._v("IDE硬盘")]),t._v(" "),v("td",[t._v("/dev/hd[a-d]")])]),t._v(" "),v("tr",[v("td",[t._v("SCSI/SATA/USB硬盘与U盘")]),t._v(" "),v("td",[t._v("/dev/sd[a-p]")])]),t._v(" "),v("tr",[v("td",[t._v("软驱")]),t._v(" "),v("td",[t._v("/dev/fd[0-1]")])]),t._v(" "),v("tr",[v("td",[t._v("打印机")]),t._v(" "),v("td",[t._v("25针:/dev/lp[]0-2"),v("br"),t._v("USB:/dev/usb/lp[0-15]")])]),t._v(" "),v("tr",[v("td",[t._v("鼠标")]),t._v(" "),v("td",[t._v("USB:/dev/usb/mouse[0-15]"),v("br"),t._v("ps2:/dev/psaux")])]),t._v(" "),v("tr",[v("td",[t._v("当前CD ROM/DVD ROM")]),t._v(" "),v("td",[t._v("cdrom")])]),t._v(" "),v("tr",[v("td",[t._v("当前鼠标")]),t._v(" "),v("td",[t._v("/dev/mouse")])]),t._v(" "),v("tr",[v("td",[t._v("磁带机")]),t._v(" "),v("td",[t._v("IDE:/dev/ht0"),v("br"),t._v("SCSI:/dev/st0")])])])]),t._v(" "),v("p",[t._v("需要注意的是,每个磁盘驱动器的磁盘分区(partition)不同时,磁盘文件名还会改变。此外,磁带机的文件名,在某些不同的 Linux 发行版本中可能不一样。")]),t._v(" "),v("p",[t._v("IDE磁盘,一般可以接4个,磁盘名称分别是hda,hdb,hdc和hdd。以hda为例,如果分为四个分区,则四个分区的名称分别为hda1,hda2,hda3和hda4,其他三个磁盘的分区名称以此类推。")]),t._v(" "),v("p",[t._v("一个 IDE 磁盘、SATA磁盘和SCSI 磁盘主分区与扩展分区加在一起最多4个,扩展分区最多只有一个,扩展分区中再开辟逻辑分区。")]),t._v(" "),v("p",[t._v("IDE 磁盘最多可以分63个分区,59个逻辑分区。\nSATA硬盘最多15个分区,11个逻辑分区。\nSCSI硬盘最多16个分区,12个逻辑分区。")]),t._v(" "),v("p",[t._v("SATA 硬盘的分区名称与IDE磁盘的分区名称类似,以第一块 SATA 磁盘 sda 为例,那么各个分区的名称分别是 sda1,sda2,sda3...,以此类推。可见,IDE 磁盘与 SATA 磁盘的分区号均是从 1 开始的$^{[3]}$。")]),t._v(" "),v("p",[t._v("SCSI 硬盘的分区名称与 SATA 硬盘分区名称相同。")]),t._v(" "),v("p",[t._v("(2) 查看全部文件系统。")]),t._v(" "),v("div",{staticClass:"language- extra-class"},[v("pre",{pre:!0,attrs:{class:"language-text"}},[v("code",[t._v("df -a\nFilesystem 1K-blocks Used Available Use% Mounted on\nrootfs - - - - /\n/dev/vda1 30830592 9330332 19911116 32% /\ndevtmpfs 7569484 0 7569484 0% /dev\nsysfs 0 0 0 - /sys\nproc 0 0 0 - /proc\nsecurityfs 0 0 0 - /sys/kernel/security\ntmpfs 7570224 1232632 6337592 17% /dev/shm\n...\n")])])]),v("p",[t._v("系统里面存在很多特殊的文件系统,这些比较特殊的文件系统几乎都是在内存当中(如 /proc 挂载点),所以,这些特殊文件系统都不会占据硬盘空间。")]),t._v(" "),v("hr"),t._v(" "),v("h2",{attrs:{id:"参考文献"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),v("p",[v("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/df.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("df(1) - Linux manual page - man7.org"),v("OutboundLink")],1)]),t._v(" "),v("p",[t._v("马玉军.Linux指令范例速查手册.北京:科学出版社,2008.P330-331")]),t._v(" "),v("p",[v("a",{attrs:{href:"https://zhidao.baidu.com/question/416183903.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("vg_mic-lv_root是什么意思"),v("OutboundLink")],1)]),t._v(" "),v("p",[t._v("鸟哥.鸟哥的私房菜基础学习篇第三版[M].北京:人民邮电出版社,2010.P183-184")]),t._v(" "),v("Vssue",{attrs:{title:"df"}})],1)}),[],!1,null,null,null);v.default=a.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[115],{574:function(t,v,e){"use strict";e.r(v);var _=e(12),a=Object(_.a)({},(function(){var t=this,v=t._self._c;return v("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[v("h2",{attrs:{id:"_1-命令简介"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),v("p",[t._v("df(Disk Free)命令用于查看 Linux 文件系统的磁盘空间占用情况。可以利用该命令来获取硬盘被占用了多少空间,以及剩余空间等信息,默认显示单位为 KB。")]),t._v(" "),v("p",[t._v("本文描述的是 GNU 版的 df,其它版本(如 POSIX 版)的实现会有所不同。")]),t._v(" "),v("h2",{attrs:{id:"_2-命令格式"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),v("div",{staticClass:"language- extra-class"},[v("pre",{pre:!0,attrs:{class:"language-text"}},[v("code",[t._v("df [OPTION]... [FILE]...\n")])])]),v("p",[t._v("参数 FILE 表示文件系统上的文件。如果给定参数 FILE,则 df 分别展示各个文件所在文件系统的信息,如果没有给定 FILE,则默认输出所有已挂载的文件系统的载信息。")]),t._v(" "),v("h2",{attrs:{id:"_3-选项说明"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),v("div",{staticClass:"language- extra-class"},[v("pre",{pre:!0,attrs:{class:"language-text"}},[v("code",[t._v("-a, --all\n\t显示所有的文件系统,包括虚拟文件系统\n-B, --block-size=SIZE\n\t使用指定的块大小\n-h, --human-readable\n\t以易读的方式显示磁盘空间已用与未用的大小\n--direct\n\t显示文件的统计信息,而不是挂载点\n--total\n\t显示所有文件系统总的使用情况\n-H, --si\n\t使用 1000 而非 1024 作为换算单位\n-i, --inodes\n\t显示索引节点 inode 信息,而非磁盘块的使用情况\n-k, --local\n\t同 --block-size=1K,即将块大小设置为 1KB\n-l, --local\n\t只输出本地文件系统信息\n-P\n\t输出格式为 POSIX\n-t , --type=TYPE\n\t显示指定的文件系统\n-T, --print-type\n\t显示文件系统类型\n-x, --exclude-type=TYPE\n\t显示指定的文件系统之外的文件系统\n--no-sync\n\t不进行磁盘同步,默认选项\n--help\n\t显示帮助信息并退出\n--version\n\t显示版本信息并退出\n")])])]),v("h2",{attrs:{id:"_4-常用示例"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),v("p",[t._v("(1)以易读方式显示文件系统空间使用情况,并输出文件系统类型。")]),t._v(" "),v("div",{staticClass:"language- extra-class"},[v("pre",{pre:!0,attrs:{class:"language-text"}},[v("code",[t._v("df -hT\nFilesystem Type Size Used Avail Use% Mounted on\n/dev/mapper/vg_mic-lv_root\n ext4 50G 16G 32G 33% /\ntmpfs tmpfs 16G 0 16G 0% /dev/shm\n/dev/sda1 ext4 485M 38M 422M 9% /boot\n/dev/mapper/vg_mic-lv_home\n ext4 210G 197G 2.7G 99% /home\n")])])]),v("p",[t._v("上面的示例输出信息表示的意思分别是:\n第一列:filesystem代表文件系统在哪个分区,所以列出设备名称。其中"),v("code",[t._v("/dev/mapper/vg_mic-lv_root")]),t._v("这行的意思是,你有一个VG (volume group,卷组)叫作vg_mic, vg_mic里面有一个LV(logical volume,逻辑卷)叫作lv_root。其实这个"),v("code",[t._v("/dev/mapper/vg_mic-lv_root")]),t._v("是一个连接文件,连接到/dev/dm-0的,可以用"),v("code",[t._v("ll /dev/mapper/vg_mic-lv_root")]),t._v("查看。实际上,可以将"),v("code",[t._v("vg_mic-lv_root")]),t._v("看作一个分区来对待就可以了。如果想查看实际的物理分区,可以使用命令pvdisplay$^{[1,2]}$。")]),t._v(" "),v("p",[t._v("第二列:Type代表文件系统类型。比如第三行的tmpfs是一种基于内存的文件系统,类似于ramdisk。tmpfs可以使用RAM,也可以使用swap分区来存储文件,提高文件的读写读写速度。再如第三行的/dev/sda1分区的文件系统是ext4。")]),t._v(" "),v("p",[t._v("第三列:Size 代表分区的大小。")]),t._v(" "),v("p",[t._v("第四列:Used表示已经使用的大小。")]),t._v(" "),v("p",[t._v("第五列:Avail表示可用的大小。")]),t._v(" "),v("p",[t._v("第六列:Use%表示以百分比显示已经使用的比例。")]),t._v(" "),v("p",[t._v("第七列:Mounted on表示磁盘分区挂载的目录,即挂载点。")]),t._v(" "),v("p",[t._v("这里列一下Linux系统中磁盘与其它外设的命名规则,以及磁盘分区的命名规则。常见的设备与其在Linux中的文件名如下表:")]),t._v(" "),v("table",[v("thead",[v("tr",[v("th",[t._v("设备")]),t._v(" "),v("th",[t._v("文件名")])])]),t._v(" "),v("tbody",[v("tr",[v("td",[t._v("IDE硬盘")]),t._v(" "),v("td",[t._v("/dev/hd[a-d]")])]),t._v(" "),v("tr",[v("td",[t._v("SCSI/SATA/USB硬盘与U盘")]),t._v(" "),v("td",[t._v("/dev/sd[a-p]")])]),t._v(" "),v("tr",[v("td",[t._v("软驱")]),t._v(" "),v("td",[t._v("/dev/fd[0-1]")])]),t._v(" "),v("tr",[v("td",[t._v("打印机")]),t._v(" "),v("td",[t._v("25针:/dev/lp[]0-2"),v("br"),t._v("USB:/dev/usb/lp[0-15]")])]),t._v(" "),v("tr",[v("td",[t._v("鼠标")]),t._v(" "),v("td",[t._v("USB:/dev/usb/mouse[0-15]"),v("br"),t._v("ps2:/dev/psaux")])]),t._v(" "),v("tr",[v("td",[t._v("当前CD ROM/DVD ROM")]),t._v(" "),v("td",[t._v("cdrom")])]),t._v(" "),v("tr",[v("td",[t._v("当前鼠标")]),t._v(" "),v("td",[t._v("/dev/mouse")])]),t._v(" "),v("tr",[v("td",[t._v("磁带机")]),t._v(" "),v("td",[t._v("IDE:/dev/ht0"),v("br"),t._v("SCSI:/dev/st0")])])])]),t._v(" "),v("p",[t._v("需要注意的是,每个磁盘驱动器的磁盘分区(partition)不同时,磁盘文件名还会改变。此外,磁带机的文件名,在某些不同的 Linux 发行版本中可能不一样。")]),t._v(" "),v("p",[t._v("IDE磁盘,一般可以接4个,磁盘名称分别是hda,hdb,hdc和hdd。以hda为例,如果分为四个分区,则四个分区的名称分别为hda1,hda2,hda3和hda4,其他三个磁盘的分区名称以此类推。")]),t._v(" "),v("p",[t._v("一个 IDE 磁盘、SATA磁盘和SCSI 磁盘主分区与扩展分区加在一起最多4个,扩展分区最多只有一个,扩展分区中再开辟逻辑分区。")]),t._v(" "),v("p",[t._v("IDE 磁盘最多可以分63个分区,59个逻辑分区。\nSATA硬盘最多15个分区,11个逻辑分区。\nSCSI硬盘最多16个分区,12个逻辑分区。")]),t._v(" "),v("p",[t._v("SATA 硬盘的分区名称与IDE磁盘的分区名称类似,以第一块 SATA 磁盘 sda 为例,那么各个分区的名称分别是 sda1,sda2,sda3...,以此类推。可见,IDE 磁盘与 SATA 磁盘的分区号均是从 1 开始的$^{[3]}$。")]),t._v(" "),v("p",[t._v("SCSI 硬盘的分区名称与 SATA 硬盘分区名称相同。")]),t._v(" "),v("p",[t._v("(2) 查看全部文件系统。")]),t._v(" "),v("div",{staticClass:"language- extra-class"},[v("pre",{pre:!0,attrs:{class:"language-text"}},[v("code",[t._v("df -a\nFilesystem 1K-blocks Used Available Use% Mounted on\nrootfs - - - - /\n/dev/vda1 30830592 9330332 19911116 32% /\ndevtmpfs 7569484 0 7569484 0% /dev\nsysfs 0 0 0 - /sys\nproc 0 0 0 - /proc\nsecurityfs 0 0 0 - /sys/kernel/security\ntmpfs 7570224 1232632 6337592 17% /dev/shm\n...\n")])])]),v("p",[t._v("系统里面存在很多特殊的文件系统,这些比较特殊的文件系统几乎都是在内存当中(如 /proc 挂载点),所以,这些特殊文件系统都不会占据硬盘空间。")]),t._v(" "),v("hr"),t._v(" "),v("h2",{attrs:{id:"参考文献"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),v("p",[v("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/df.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("df(1) - Linux manual page - man7.org"),v("OutboundLink")],1)]),t._v(" "),v("p",[t._v("马玉军.Linux指令范例速查手册.北京:科学出版社,2008.P330-331")]),t._v(" "),v("p",[v("a",{attrs:{href:"https://zhidao.baidu.com/question/416183903.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("vg_mic-lv_root是什么意思"),v("OutboundLink")],1)]),t._v(" "),v("p",[t._v("鸟哥.鸟哥的私房菜基础学习篇第三版[M].北京:人民邮电出版社,2010.P183-184")]),t._v(" "),v("Vssue",{attrs:{title:"df"}})],1)}),[],!1,null,null,null);v.default=a.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/117.5bf674e0.js b/docs/assets/js/117.e03507a1.js similarity index 99% rename from docs/assets/js/117.5bf674e0.js rename to docs/assets/js/117.e03507a1.js index c64b873d1..143c65c9f 100644 --- a/docs/assets/js/117.5bf674e0.js +++ b/docs/assets/js/117.e03507a1.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[117],{448:function(e,t,n){"use strict";n.r(t);var s=n(12),a=Object(s.a)({},(function(){var e=this,t=e._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[e._v("#")]),e._v(" 1.命令简介")]),e._v(" "),t("p",[e._v("fdisk 命令用于创建和维护磁盘分区表。")]),e._v(" "),t("p",[e._v("它采用传统的问答式界面,而不是类似于 fdisk 的 cfdisk 的互动式操作界面,因此在使用上较为不便,但功能却丝毫不打折扣。它兼容 DOS 类型的分区表、BSD 或者 SUN 类型的磁盘列表。")]),e._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[e._v("#")]),e._v(" 2.命令格式")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("fdisk [-uc] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device\nfdisk -l [-u] [device...]\nfdisk -s partition...\nfdisk -v\nfdisk -h\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[e._v("#")]),e._v(" 3.选项说明")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("-b {sectorsize}\n\t指定硬盘扇区大小,可用数值为512, 1024, 2048 or 4096\n-c\n\t关闭DOS兼容模式\n-C {cyls}\n\t指定硬盘的柱面数(number of cylinders)\n-H {heads}\n\t指定硬盘的磁头数(number of heads),当然不是物理数值,而是作用于分区表。合理取值是255和16\n-S {sects}\n\t指定每个磁道的扇区数,当然不是物理数值,而是用于分区表。一个合理的数值是63;\n-l\n\t列出指定设备的分区表,然后退出。如果没有给定设备,则使用在/proc/partitions(如果存在)中提到的那些设备;\n-u\n\t在列出分区表时,给出扇区大小而不是柱面大小\n-s {partition}\n\t以块(block)为单位,显示指定分区的大小\n-v\n\t显示版本信息\n-h\n\t显示帮助信息\n")])])]),t("p",[e._v("阅读以上选项说明,需要注意以下几个问题:")]),e._v(" "),t("p",[e._v("(1)块(block)与扇区(sector)的区别。\n扇区是对硬盘而言,扇区是硬盘的最小存储单位,块是对文件系统而言,块是文件系统最小存取单位。一般而言,一个扇区大小为512B,一个块大小为4KB,一个block是由连续的8个sector组成。")]),e._v(" "),t("p",[e._v("(2)理解上面选项的含义,需了解磁盘的物理组成结构与相关概念,例如sector、cylinder、head等组成部件的具体含义,可参见"),t("a",{attrs:{href:"http://blog.chinaunix.net/uid-23069658-id-3413957.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("硬盘的存储原理和内部架构 "),t("OutboundLink")],1),e._v("。")]),e._v(" "),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[e._v("#")]),e._v(" 4.常用示例")]),e._v(" "),t("p",[e._v("(1)列出指定设备的分区情况。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("fdisk -l /dev/sda\n\nDisk /dev/sda: 300.0 GB, 299966445568 bytes\n255 heads, 63 sectors/track, 36468 cylinders\nUnits = cylinders of 16065 * 512 = 8225280 bytes\nSector size (logical/physical): 512 bytes / 512 bytes\nI/O size (minimum/optimal): 512 bytes / 512 bytes\nDisk identifier: 0x0009808c\n\n Device Boot Start End Blocks Id System\n/dev/sda1 * 1 1306 10485760 83 Linux\n/dev/sda2 1306 1566 2088960 82 Linux swap / Solaris\n/dev/sda3 1566 4177 20971520 83 Linux\n/dev/sda4 4177 36469 259387694 83 Linux\n")])])]),t("p",[e._v("对"),t("code",[e._v("fdisk -l")]),e._v("相关数值的解释如下:\n第一行中说明硬盘 /dev/sda 总大小为 300.0 GB;")]),e._v(" "),t("p",[e._v("第二行中 heads 表示硬盘磁头数,也是盘面数,因为磁头数等于盘面数。随后"),t("code",[e._v("63 sectors/track")]),e._v("说明每条磁道分63个扇区。共 36468 个柱面,柱面是分区的最小单位;")]),e._v(" "),t("p",[e._v("第三行说明每个柱面单位是 8225280 byets,"),t("code",[e._v("柱面单位大小=磁头数*每条磁道的扇区数*扇区大小=255*63*512B=8225280B")]),e._v(";")]),e._v(" "),t("p",[e._v("第四行说明扇区的大小是512B;")]),e._v(" "),t("p",[e._v("第五行说明硬盘最小与最佳的存储单位是512 bytes,等于扇区大小,因为扇区是硬盘的最小存储单位;")]),e._v(" "),t("p",[e._v("第六行说明硬盘标识符是 0x0009808c。")]),e._v(" "),t("p",[e._v("第七行表示每个分区相关参数的含义。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Device:分区名称;\nBoot:是否是活动分区。活动分区只能是主分区,一个硬盘只能有一个活动的主分区;一个硬盘的主分区与扩展分区总和不能超过4个。硬盘分区遵循着“主分区→扩展分区→逻辑分区”的次序原则,而删除分区则与之相反。\n\t主分区:一个硬盘可以划分多个主分区,但没必要划分那么多,一个足矣。\n\t扩展分区:主分区之外的硬盘空间就是扩展分区,\n\t逻辑分区:是对扩展分区再行划分得到的。\nStart:分区柱面的开始下标;\nEnd:分区柱面的结束下标;\nBlocks:该分区的块数量。当前文件系统block=2*sector,所以块数量=(End-Start)*柱面的扇区数/2=1305*255*63/2=10482412.5;\nId:各种分区的文件系统不同,如有ntfs分区,fat32分区,ext3分区,swap分区等。每一种文件系统都有一个代号,对应这里的Id。常见的文件系统ID有:\n\tf:FAT32 Extend,只限于扩展分区。\n\t86:NTFS。\n\t7:HPFS/NTFS\n\tb:FAT32。\n\t83:Linux Ext2。\n\t82:Linux 交换区。\nSystem:文件系统名称。\n")])])]),t("p",[t("strong",[e._v("总结:")])]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("一个磁盘的大小=一个柱面大小*柱面的总数=磁头数量*每个磁道上的扇区数*一个扇区大小*柱面总数\n")])])]),t("p",[e._v("即:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("磁盘大小=8225280*36468=299959511040 bytes=299GB=255*63*512*36468\n")])])]),t("p",[e._v("上例中显示出的硬盘大小与实际计算出来的有少许出入,这个不必太在意,Linux显示的这些数据不会十分精确。")]),e._v(" "),t("p",[e._v("(2)对指定设备进行分区并挂载。\n第一步,选择要进行操作的磁盘,进入问答式界面。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("fdisk /dev/sdb\n")])])]),t("p",[e._v("第二步,输入m列出可以执行的命令。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): m\nCommand action\n a toggle a bootable flag\n b edit bsd disklabel\n c toggle the dos compatibility flag\n d delete a partition\n l list known partition types\n m print this menu\n n add a new partition\n o create a new empty DOS partition table\n p print the partition table\n q quit without saving changes\n s create a new empty Sun disklabel\n t change a partition's system id\n u change display/entry units\n v verify the partition table\n w write table to disk and exit\n x extra functionality (experts only)\n")])])]),t("p",[e._v("第三步,输入p列出磁盘目前的分区情况。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Disk /dev/sda: 300.0 GB, 299966445568 bytes\n255 heads, 63 sectors/track, 36468 cylinders\nUnits = cylinders of 16065 * 512 = 8225280 bytes\nSector size (logical/physical): 512 bytes / 512 bytes\nI/O size (minimum/optimal): 512 bytes / 512 bytes\nDisk identifier: 0x0009808c\n\n Device Boot Start End Blocks Id System\n/dev/sda1 * 1 1306 10485760 83 Linux\n/dev/sda2 1306 1566 2088960 82 Linux swap / Solaris\n/dev/sda3 1566 4177 20971520 83 Linux\n/dev/sda4 4177 36469 259387694 83 Linux\n")])])]),t("p",[e._v("第四步,输入d然后选择分区,删除现有分区。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): d\nPartition number (1-4): 1\n\nCommand (m for help): d\nSelected partition 2\n\nCommand (m for help): d\nSelected partition 3\n\nCommand (m for help): d\nSelected partition 4\n")])])]),t("p",[e._v("第五步,输入n建立新的磁盘分区,首先建立两个主磁盘分区。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): n\nCommand action\n e extended\n p primary partition (1-4)\np //建立主分区\nPartition number (1-4): 1 //分区号\nFirst cylinder (1-391, default 1): //分区起始位置\nUsing default value 1\nlast cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100 //分区结束位置,单位为柱面\n\nCommand (m for help): n //再建立一个主分区\nCommand action\n e extended\n p primary partition (1-4)\np \nPartition number (1-4): 2 //分区号为2\nFirst cylinder (101-391, default 101):\nUsing default value 101\nLast cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M //分区结束位置,单位为M\n")])])]),t("p",[e._v("第七步,确认分区建立成功。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): p\n\nDisk /dev/sdb: 3221 MB, 3221225472 bytes\n255 heads, 63 sectors/track, 391 cylinders\nUnits = cylinders of 16065 * 512 = 8225280 bytes\n\n Device Boot Start End Blocks Id System\n/dev/sdb1 1 100 803218+ 83 Linux\n/dev/sdb2 101 125 200812+ 83 Linux\n")])])]),t("p",[e._v("第八步,再建立一个逻辑分区。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): n\nCommand action\n e extended\n p primary partition (1-4)\ne //选择扩展分区\nPartition number (1-4): 3\nFirst cylinder (126-391, default 126):\nUsing default value 126\nLast cylinder or +size or +sizeM or +sizeK (126-391, default 391):\nUsing default value 391\n")])])]),t("p",[e._v("第九步,确认扩展分区建立成功。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): p\n\nDisk /dev/sdb: 3221 MB, 3221225472 bytes\n255 heads, 63 sectors/track, 391 cylinders\nUnits = cylinders of 16065 * 512 = 8225280 bytes\n\n Device Boot Start End Blocks Id System\n/dev/sdb1 1 100 803218+ 83 Linux\n/dev/sdb2 101 125 200812+ 83 Linux\n/dev/sdb3 126 391 2136645 5 Extended\n")])])]),t("p",[e._v("第十步,在扩展分区上建立两个逻辑分区。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): n\nCommand action\n l logical (5 or over)\n p primary partition (1-4)\nl //选择逻辑分区\nFirst cylinder (126-391, default 126):\nUsing default value 126\nLast cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M \n\nCommand (m for help): n\nCommand action\n l logical (5 or over)\n p primary partition (1-4)\nl\nFirst cylinder (176-391, default 176):\nUsing default value 176\nLast cylinder or +size or +sizeM or +sizeK (176-391, default 391):\nUsing default value 391\n")])])]),t("p",[e._v("第十一步,确认逻辑分区建立成功。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): p\n\nDisk /dev/sdb: 3221 MB, 3221225472 bytes\n255 heads, 63 sectors/track, 391 cylinders\nUnits = cylinders of 16065 * 512 = 8225280 bytes\n\n Device Boot Start End Blocks Id System\n/dev/sdb1 1 100 803218+ 83 Linux\n/dev/sdb2 101 125 200812+ 83 Linux\n/dev/sdb3 126 391 2136645 5 Extended\n/dev/sdb5 126 175 401593+ 83 Linux\n/dev/sdb6 176 391 1734988+ 83 Linux\n\nCommand (m for help):\n")])])]),t("p",[e._v("从上面的结果我们可以看到,在硬盘 sdb 我们建立了 2 个主分区(sdb1,sdb2),1个扩展分区(sdb3),2 个逻辑分区(sdb5,sdb6)。")]),e._v(" "),t("p",[e._v("注意:主分区和扩展分区的磁盘号位1-4,也就是说最多有 4 个主分区或者扩展分区,逻辑分区开始的磁盘号为 5,因此在这个实验中是没有 sdb4 的。")]),e._v(" "),t("p",[e._v("最后对分区操作进行保存:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): w\nThe partition table has been altered!\n\nCalling ioctl() to re-read partition table.\nSyncing disks.\n")])])]),t("p",[e._v("建立好分区之后我们还需要对分区进行格式化才能在系统中使用磁盘。")]),e._v(" "),t("p",[e._v("在 sdb1 上建立 ext2 文件系统。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("[root@localhost ~]# mkfs.ext2 /dev/sdb1\nmke2fs 1.39 (29-May-2006)\nFilesystem label=\nOS type: Linux\nBlock size=4096 (log=2)\nFragment size=4096 (log=2)\n100576 inodes, 200804 blocks\n10040 blocks (5.00%) reserved for the super user\nFirst data block=0\nMaximum filesystem blocks=209715200\n7 block groups\n32768 blocks per group, 32768 fragments per group\n14368 inodes per group\nSuperblock backups stored on blocks:\n 32768, 98304, 163840\n\nWriting inode tables: done \nWriting superblocks and filesystem accounting information: done\n\nThis filesystem will be automatically checked every 32 mounts or\n180 days, whichever comes first. Use tune2fs -c or -i to override.\n")])])]),t("p",[e._v("在 sdb6 上建立 ext3 文件系统。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("[root@localhost ~]# mkfs.ext3 /dev/sdb6\nmke2fs 1.39 (29-May-2006)\nFilesystem label=\nOS type: Linux\nBlock size=4096 (log=2)\nFragment size=4096 (log=2)\n217280 inodes, 433747 blocks\n21687 blocks (5.00%) reserved for the super user\nFirst data block=0\nMaximum filesystem blocks=444596224\n14 block groups\n32768 blocks per group, 32768 fragments per group\n15520 inodes per group\nSuperblock backups stored on blocks:\n 32768, 98304, 163840, 229376, 294912\n\nWriting inode tables: done \nCreating journal (8192 blocks): done\nWriting superblocks and filesystem accounting information: done\n\nThis filesystem will be automatically checked every 32 mounts or\n180 days, whichever comes first. Use tune2fs -c or -i to override.\n[root@localhost ~]#\n")])])]),t("p",[e._v("建立两个目录/oracle和/web,将新建好的两个分区挂载到系统:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("[root@localhost ~]# mkdir /oracle\n[root@localhost ~]# mkdir /web\n[root@localhost ~]# mount /dev/sdb1 /oracle\n[root@localhost ~]# mount /dev/sdb6 /web\n")])])]),t("p",[e._v("查看分区挂载情况:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("[root@localhost ~]# df -h\n文件系统 容量 已用 可用 已用% 挂载点\n/dev/mapper/VolGroup00-LogVol00\n 6.7G 2.8G 3.6G 44% /\n/dev/sda1 99M 12M 82M 13% /boot\ntmpfs 125M 0 125M 0% /dev/shm\n/dev/sdb1 773M 808K 733M 1% /oracle\n/dev/sdb6 1.7G 35M 1.6G 3% /web\n")])])]),t("p",[e._v("如果需要每次开机自动挂载则需要修改/etc/fstab文件,加入两行配置:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("[root@localhost ~]# vim /etc/fstab\n\n/dev/VolGroup00/LogVol00 / ext3 defaults 1 1\nLABEL=/boot /boot ext3 defaults 1 2\ntmpfs /dev/shm tmpfs defaults 0 0\ndevpts /dev/pts devpts gid=5,mode=620 0 0\nsysfs /sys sysfs defaults 0 0\nproc /proc proc defaults 0 0\n/dev/VolGroup00/LogVol01 swap swap defaults 0 0\n/dev/sdb1 /oracle ext2 defaults 0 0\n/dev/sdb6 /web ext3 defaults 0 0\n")])])]),t("hr"),e._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[e._v("#")]),e._v(" 参考文献")]),e._v(" "),t("p",[t("a",{attrs:{href:"http://www.man7.org/linux/man-pages/man8/fdisk.8.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("fdisk(8) - Linux manual page - man7.org"),t("OutboundLink")],1)]),e._v(" "),t("p",[t("a",{attrs:{href:"http://man.linuxde.net/fdisk",target:"_blank",rel:"noopener noreferrer"}},[e._v("Linux命令大全.fdisk命令"),t("OutboundLink")],1)]),e._v(" "),t("p",[t("a",{attrs:{href:"http://blog.csdn.net/my_bai/article/details/73331360",target:"_blank",rel:"noopener noreferrer"}},[e._v("磁盘的块大小(Block Size)和扇区大小(Sector Size)"),t("OutboundLink")],1)]),e._v(" "),t("p",[t("a",{attrs:{href:"https://www.cnblogs.com/Dreama/articles/2106812.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("fdisk -l 命令详解"),t("OutboundLink")],1)]),e._v(" "),t("Vssue",{attrs:{title:"fdisk"}})],1)}),[],!1,null,null,null);t.default=a.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[117],{575:function(e,t,n){"use strict";n.r(t);var s=n(12),a=Object(s.a)({},(function(){var e=this,t=e._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[e._v("#")]),e._v(" 1.命令简介")]),e._v(" "),t("p",[e._v("fdisk 命令用于创建和维护磁盘分区表。")]),e._v(" "),t("p",[e._v("它采用传统的问答式界面,而不是类似于 fdisk 的 cfdisk 的互动式操作界面,因此在使用上较为不便,但功能却丝毫不打折扣。它兼容 DOS 类型的分区表、BSD 或者 SUN 类型的磁盘列表。")]),e._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[e._v("#")]),e._v(" 2.命令格式")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("fdisk [-uc] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device\nfdisk -l [-u] [device...]\nfdisk -s partition...\nfdisk -v\nfdisk -h\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[e._v("#")]),e._v(" 3.选项说明")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("-b {sectorsize}\n\t指定硬盘扇区大小,可用数值为512, 1024, 2048 or 4096\n-c\n\t关闭DOS兼容模式\n-C {cyls}\n\t指定硬盘的柱面数(number of cylinders)\n-H {heads}\n\t指定硬盘的磁头数(number of heads),当然不是物理数值,而是作用于分区表。合理取值是255和16\n-S {sects}\n\t指定每个磁道的扇区数,当然不是物理数值,而是用于分区表。一个合理的数值是63;\n-l\n\t列出指定设备的分区表,然后退出。如果没有给定设备,则使用在/proc/partitions(如果存在)中提到的那些设备;\n-u\n\t在列出分区表时,给出扇区大小而不是柱面大小\n-s {partition}\n\t以块(block)为单位,显示指定分区的大小\n-v\n\t显示版本信息\n-h\n\t显示帮助信息\n")])])]),t("p",[e._v("阅读以上选项说明,需要注意以下几个问题:")]),e._v(" "),t("p",[e._v("(1)块(block)与扇区(sector)的区别。\n扇区是对硬盘而言,扇区是硬盘的最小存储单位,块是对文件系统而言,块是文件系统最小存取单位。一般而言,一个扇区大小为512B,一个块大小为4KB,一个block是由连续的8个sector组成。")]),e._v(" "),t("p",[e._v("(2)理解上面选项的含义,需了解磁盘的物理组成结构与相关概念,例如sector、cylinder、head等组成部件的具体含义,可参见"),t("a",{attrs:{href:"http://blog.chinaunix.net/uid-23069658-id-3413957.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("硬盘的存储原理和内部架构 "),t("OutboundLink")],1),e._v("。")]),e._v(" "),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[e._v("#")]),e._v(" 4.常用示例")]),e._v(" "),t("p",[e._v("(1)列出指定设备的分区情况。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("fdisk -l /dev/sda\n\nDisk /dev/sda: 300.0 GB, 299966445568 bytes\n255 heads, 63 sectors/track, 36468 cylinders\nUnits = cylinders of 16065 * 512 = 8225280 bytes\nSector size (logical/physical): 512 bytes / 512 bytes\nI/O size (minimum/optimal): 512 bytes / 512 bytes\nDisk identifier: 0x0009808c\n\n Device Boot Start End Blocks Id System\n/dev/sda1 * 1 1306 10485760 83 Linux\n/dev/sda2 1306 1566 2088960 82 Linux swap / Solaris\n/dev/sda3 1566 4177 20971520 83 Linux\n/dev/sda4 4177 36469 259387694 83 Linux\n")])])]),t("p",[e._v("对"),t("code",[e._v("fdisk -l")]),e._v("相关数值的解释如下:\n第一行中说明硬盘 /dev/sda 总大小为 300.0 GB;")]),e._v(" "),t("p",[e._v("第二行中 heads 表示硬盘磁头数,也是盘面数,因为磁头数等于盘面数。随后"),t("code",[e._v("63 sectors/track")]),e._v("说明每条磁道分63个扇区。共 36468 个柱面,柱面是分区的最小单位;")]),e._v(" "),t("p",[e._v("第三行说明每个柱面单位是 8225280 byets,"),t("code",[e._v("柱面单位大小=磁头数*每条磁道的扇区数*扇区大小=255*63*512B=8225280B")]),e._v(";")]),e._v(" "),t("p",[e._v("第四行说明扇区的大小是512B;")]),e._v(" "),t("p",[e._v("第五行说明硬盘最小与最佳的存储单位是512 bytes,等于扇区大小,因为扇区是硬盘的最小存储单位;")]),e._v(" "),t("p",[e._v("第六行说明硬盘标识符是 0x0009808c。")]),e._v(" "),t("p",[e._v("第七行表示每个分区相关参数的含义。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Device:分区名称;\nBoot:是否是活动分区。活动分区只能是主分区,一个硬盘只能有一个活动的主分区;一个硬盘的主分区与扩展分区总和不能超过4个。硬盘分区遵循着“主分区→扩展分区→逻辑分区”的次序原则,而删除分区则与之相反。\n\t主分区:一个硬盘可以划分多个主分区,但没必要划分那么多,一个足矣。\n\t扩展分区:主分区之外的硬盘空间就是扩展分区,\n\t逻辑分区:是对扩展分区再行划分得到的。\nStart:分区柱面的开始下标;\nEnd:分区柱面的结束下标;\nBlocks:该分区的块数量。当前文件系统block=2*sector,所以块数量=(End-Start)*柱面的扇区数/2=1305*255*63/2=10482412.5;\nId:各种分区的文件系统不同,如有ntfs分区,fat32分区,ext3分区,swap分区等。每一种文件系统都有一个代号,对应这里的Id。常见的文件系统ID有:\n\tf:FAT32 Extend,只限于扩展分区。\n\t86:NTFS。\n\t7:HPFS/NTFS\n\tb:FAT32。\n\t83:Linux Ext2。\n\t82:Linux 交换区。\nSystem:文件系统名称。\n")])])]),t("p",[t("strong",[e._v("总结:")])]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("一个磁盘的大小=一个柱面大小*柱面的总数=磁头数量*每个磁道上的扇区数*一个扇区大小*柱面总数\n")])])]),t("p",[e._v("即:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("磁盘大小=8225280*36468=299959511040 bytes=299GB=255*63*512*36468\n")])])]),t("p",[e._v("上例中显示出的硬盘大小与实际计算出来的有少许出入,这个不必太在意,Linux显示的这些数据不会十分精确。")]),e._v(" "),t("p",[e._v("(2)对指定设备进行分区并挂载。\n第一步,选择要进行操作的磁盘,进入问答式界面。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("fdisk /dev/sdb\n")])])]),t("p",[e._v("第二步,输入m列出可以执行的命令。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): m\nCommand action\n a toggle a bootable flag\n b edit bsd disklabel\n c toggle the dos compatibility flag\n d delete a partition\n l list known partition types\n m print this menu\n n add a new partition\n o create a new empty DOS partition table\n p print the partition table\n q quit without saving changes\n s create a new empty Sun disklabel\n t change a partition's system id\n u change display/entry units\n v verify the partition table\n w write table to disk and exit\n x extra functionality (experts only)\n")])])]),t("p",[e._v("第三步,输入p列出磁盘目前的分区情况。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Disk /dev/sda: 300.0 GB, 299966445568 bytes\n255 heads, 63 sectors/track, 36468 cylinders\nUnits = cylinders of 16065 * 512 = 8225280 bytes\nSector size (logical/physical): 512 bytes / 512 bytes\nI/O size (minimum/optimal): 512 bytes / 512 bytes\nDisk identifier: 0x0009808c\n\n Device Boot Start End Blocks Id System\n/dev/sda1 * 1 1306 10485760 83 Linux\n/dev/sda2 1306 1566 2088960 82 Linux swap / Solaris\n/dev/sda3 1566 4177 20971520 83 Linux\n/dev/sda4 4177 36469 259387694 83 Linux\n")])])]),t("p",[e._v("第四步,输入d然后选择分区,删除现有分区。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): d\nPartition number (1-4): 1\n\nCommand (m for help): d\nSelected partition 2\n\nCommand (m for help): d\nSelected partition 3\n\nCommand (m for help): d\nSelected partition 4\n")])])]),t("p",[e._v("第五步,输入n建立新的磁盘分区,首先建立两个主磁盘分区。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): n\nCommand action\n e extended\n p primary partition (1-4)\np //建立主分区\nPartition number (1-4): 1 //分区号\nFirst cylinder (1-391, default 1): //分区起始位置\nUsing default value 1\nlast cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100 //分区结束位置,单位为柱面\n\nCommand (m for help): n //再建立一个主分区\nCommand action\n e extended\n p primary partition (1-4)\np \nPartition number (1-4): 2 //分区号为2\nFirst cylinder (101-391, default 101):\nUsing default value 101\nLast cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M //分区结束位置,单位为M\n")])])]),t("p",[e._v("第七步,确认分区建立成功。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): p\n\nDisk /dev/sdb: 3221 MB, 3221225472 bytes\n255 heads, 63 sectors/track, 391 cylinders\nUnits = cylinders of 16065 * 512 = 8225280 bytes\n\n Device Boot Start End Blocks Id System\n/dev/sdb1 1 100 803218+ 83 Linux\n/dev/sdb2 101 125 200812+ 83 Linux\n")])])]),t("p",[e._v("第八步,再建立一个逻辑分区。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): n\nCommand action\n e extended\n p primary partition (1-4)\ne //选择扩展分区\nPartition number (1-4): 3\nFirst cylinder (126-391, default 126):\nUsing default value 126\nLast cylinder or +size or +sizeM or +sizeK (126-391, default 391):\nUsing default value 391\n")])])]),t("p",[e._v("第九步,确认扩展分区建立成功。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): p\n\nDisk /dev/sdb: 3221 MB, 3221225472 bytes\n255 heads, 63 sectors/track, 391 cylinders\nUnits = cylinders of 16065 * 512 = 8225280 bytes\n\n Device Boot Start End Blocks Id System\n/dev/sdb1 1 100 803218+ 83 Linux\n/dev/sdb2 101 125 200812+ 83 Linux\n/dev/sdb3 126 391 2136645 5 Extended\n")])])]),t("p",[e._v("第十步,在扩展分区上建立两个逻辑分区。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): n\nCommand action\n l logical (5 or over)\n p primary partition (1-4)\nl //选择逻辑分区\nFirst cylinder (126-391, default 126):\nUsing default value 126\nLast cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M \n\nCommand (m for help): n\nCommand action\n l logical (5 or over)\n p primary partition (1-4)\nl\nFirst cylinder (176-391, default 176):\nUsing default value 176\nLast cylinder or +size or +sizeM or +sizeK (176-391, default 391):\nUsing default value 391\n")])])]),t("p",[e._v("第十一步,确认逻辑分区建立成功。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): p\n\nDisk /dev/sdb: 3221 MB, 3221225472 bytes\n255 heads, 63 sectors/track, 391 cylinders\nUnits = cylinders of 16065 * 512 = 8225280 bytes\n\n Device Boot Start End Blocks Id System\n/dev/sdb1 1 100 803218+ 83 Linux\n/dev/sdb2 101 125 200812+ 83 Linux\n/dev/sdb3 126 391 2136645 5 Extended\n/dev/sdb5 126 175 401593+ 83 Linux\n/dev/sdb6 176 391 1734988+ 83 Linux\n\nCommand (m for help):\n")])])]),t("p",[e._v("从上面的结果我们可以看到,在硬盘 sdb 我们建立了 2 个主分区(sdb1,sdb2),1个扩展分区(sdb3),2 个逻辑分区(sdb5,sdb6)。")]),e._v(" "),t("p",[e._v("注意:主分区和扩展分区的磁盘号位1-4,也就是说最多有 4 个主分区或者扩展分区,逻辑分区开始的磁盘号为 5,因此在这个实验中是没有 sdb4 的。")]),e._v(" "),t("p",[e._v("最后对分区操作进行保存:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("Command (m for help): w\nThe partition table has been altered!\n\nCalling ioctl() to re-read partition table.\nSyncing disks.\n")])])]),t("p",[e._v("建立好分区之后我们还需要对分区进行格式化才能在系统中使用磁盘。")]),e._v(" "),t("p",[e._v("在 sdb1 上建立 ext2 文件系统。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("[root@localhost ~]# mkfs.ext2 /dev/sdb1\nmke2fs 1.39 (29-May-2006)\nFilesystem label=\nOS type: Linux\nBlock size=4096 (log=2)\nFragment size=4096 (log=2)\n100576 inodes, 200804 blocks\n10040 blocks (5.00%) reserved for the super user\nFirst data block=0\nMaximum filesystem blocks=209715200\n7 block groups\n32768 blocks per group, 32768 fragments per group\n14368 inodes per group\nSuperblock backups stored on blocks:\n 32768, 98304, 163840\n\nWriting inode tables: done \nWriting superblocks and filesystem accounting information: done\n\nThis filesystem will be automatically checked every 32 mounts or\n180 days, whichever comes first. Use tune2fs -c or -i to override.\n")])])]),t("p",[e._v("在 sdb6 上建立 ext3 文件系统。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("[root@localhost ~]# mkfs.ext3 /dev/sdb6\nmke2fs 1.39 (29-May-2006)\nFilesystem label=\nOS type: Linux\nBlock size=4096 (log=2)\nFragment size=4096 (log=2)\n217280 inodes, 433747 blocks\n21687 blocks (5.00%) reserved for the super user\nFirst data block=0\nMaximum filesystem blocks=444596224\n14 block groups\n32768 blocks per group, 32768 fragments per group\n15520 inodes per group\nSuperblock backups stored on blocks:\n 32768, 98304, 163840, 229376, 294912\n\nWriting inode tables: done \nCreating journal (8192 blocks): done\nWriting superblocks and filesystem accounting information: done\n\nThis filesystem will be automatically checked every 32 mounts or\n180 days, whichever comes first. Use tune2fs -c or -i to override.\n[root@localhost ~]#\n")])])]),t("p",[e._v("建立两个目录/oracle和/web,将新建好的两个分区挂载到系统:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("[root@localhost ~]# mkdir /oracle\n[root@localhost ~]# mkdir /web\n[root@localhost ~]# mount /dev/sdb1 /oracle\n[root@localhost ~]# mount /dev/sdb6 /web\n")])])]),t("p",[e._v("查看分区挂载情况:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("[root@localhost ~]# df -h\n文件系统 容量 已用 可用 已用% 挂载点\n/dev/mapper/VolGroup00-LogVol00\n 6.7G 2.8G 3.6G 44% /\n/dev/sda1 99M 12M 82M 13% /boot\ntmpfs 125M 0 125M 0% /dev/shm\n/dev/sdb1 773M 808K 733M 1% /oracle\n/dev/sdb6 1.7G 35M 1.6G 3% /web\n")])])]),t("p",[e._v("如果需要每次开机自动挂载则需要修改/etc/fstab文件,加入两行配置:")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("[root@localhost ~]# vim /etc/fstab\n\n/dev/VolGroup00/LogVol00 / ext3 defaults 1 1\nLABEL=/boot /boot ext3 defaults 1 2\ntmpfs /dev/shm tmpfs defaults 0 0\ndevpts /dev/pts devpts gid=5,mode=620 0 0\nsysfs /sys sysfs defaults 0 0\nproc /proc proc defaults 0 0\n/dev/VolGroup00/LogVol01 swap swap defaults 0 0\n/dev/sdb1 /oracle ext2 defaults 0 0\n/dev/sdb6 /web ext3 defaults 0 0\n")])])]),t("hr"),e._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[e._v("#")]),e._v(" 参考文献")]),e._v(" "),t("p",[t("a",{attrs:{href:"http://www.man7.org/linux/man-pages/man8/fdisk.8.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("fdisk(8) - Linux manual page - man7.org"),t("OutboundLink")],1)]),e._v(" "),t("p",[t("a",{attrs:{href:"http://man.linuxde.net/fdisk",target:"_blank",rel:"noopener noreferrer"}},[e._v("Linux命令大全.fdisk命令"),t("OutboundLink")],1)]),e._v(" "),t("p",[t("a",{attrs:{href:"http://blog.csdn.net/my_bai/article/details/73331360",target:"_blank",rel:"noopener noreferrer"}},[e._v("磁盘的块大小(Block Size)和扇区大小(Sector Size)"),t("OutboundLink")],1)]),e._v(" "),t("p",[t("a",{attrs:{href:"https://www.cnblogs.com/Dreama/articles/2106812.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("fdisk -l 命令详解"),t("OutboundLink")],1)]),e._v(" "),t("Vssue",{attrs:{title:"fdisk"}})],1)}),[],!1,null,null,null);t.default=a.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/118.a163d30a.js b/docs/assets/js/118.76493d64.js similarity index 99% rename from docs/assets/js/118.a163d30a.js rename to docs/assets/js/118.76493d64.js index 8ac599151..c733696bf 100644 --- a/docs/assets/js/118.a163d30a.js +++ b/docs/assets/js/118.76493d64.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[118],{452:function(t,a,r){"use strict";r.r(a);var e=r(12),v=Object(e.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("chattr 用于改变文件属性。")]),t._v(" "),a("p",[t._v("与 chmod 命令相比,chmod 只改变文件的读写、执行权限,更底层的属性控制是由 chattr 来改变。")]),t._v(" "),a("p",[t._v("与之对应的命令是 lsattr,用于显示文件属性。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("chattr [ -RVf ] [ -v version ] [ mode ] files...\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-R\n\t递归地改变指定目录下文件的属性。此选项忽略符号链接;\n-V\n\t显示命令执行的详细信息;\n-f\n\t大部分错误信息不输出;\n-v\n\t设置文件版本号;\n+\n\t在原有参数设定基础上,追加参数;\n-\n\t在原有参数设定基础上,移除参数;\n=\n\t更新指定参数设定\n")])])]),a("p",[t._v("最关键的是 [mode] 部分,[mode] 部分由 + - = 和字符 [acdeijstuADST] 组合而成,这部分是用来控制文件的属性。")]),t._v(" "),a("p",[t._v("chattr 可以改变的文件系统属性有:")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("属性")]),t._v(" "),a("th",[t._v("含义")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("a")]),t._v(" "),a("td",[t._v("append only,只允许向文件追加数据,不允许删除和修改文件内容。如果目录有具有这个属性,系统将只允许在目录下简历和修改文件,不允许删除任何文件。只有root才能设置该属性")])]),t._v(" "),a("tr",[a("td",[t._v("c")]),t._v(" "),a("td",[t._v("compress,自动将文件压缩,在读取时自动解压缩")])]),t._v(" "),a("tr",[a("td",[t._v("d")]),t._v(" "),a("td",[t._v("No dump,在进行文件系统备份时,dump指令忽略此文件")])]),t._v(" "),a("tr",[a("td",[t._v("e")]),t._v(" "),a("td",[t._v("extent format,在ext文件系统中,表示该文件使用区段(extents)映射磁盘上的块")])]),t._v(" "),a("tr",[a("td",[t._v("i")]),t._v(" "),a("td",[t._v("immutable,不允许对文件进行任何的修改。对于目录而言,只能修改目录之下的文件,不允许建立和删除文件。只有root能设置此属性")])]),t._v(" "),a("tr",[a("td",[t._v("j")]),t._v(" "),a("td",[t._v("journal,设定此参数使得当通过mount参数:data=ordered 或者 data=writeback 挂 载的文件系统,文件在写入时会先被记录(在journal中)。如果filesystem被设定参数为 data=journal,则该参数自动失效")])]),t._v(" "),a("tr",[a("td",[t._v("s")]),t._v(" "),a("td",[t._v("secure deletion,系统在删除文件时,使用0填充文件所在的区域")])]),t._v(" "),a("tr",[a("td",[t._v("t")]),t._v(" "),a("td",[t._v("no tail-merging,文件拥有t属性时,与其它文件合并时末端不会存在局部块碎片")])]),t._v(" "),a("tr",[a("td",[t._v("u")]),t._v(" "),a("td",[t._v("undeletable,与s相反,删除文件时,文件内容其实还存在磁盘中,以便以后能够恢复删除的文件")])]),t._v(" "),a("tr",[a("td",[t._v("A")]),t._v(" "),a("td",[t._v("Atime,不能修改文件的最后访问时间")])]),t._v(" "),a("tr",[a("td",[t._v("D")]),t._v(" "),a("td",[t._v("如果一个目录设置了D属性,任何改变将同步到磁盘;这等价于mount命令中的dirsync选项,同步目录")])]),t._v(" "),a("tr",[a("td",[t._v("S")]),t._v(" "),a("td",[t._v("Sync,一旦应用程序对文件执行了写操作,则立刻将改动同步到磁盘")])]),t._v(" "),a("tr",[a("td",[t._v("T")]),t._v(" "),a("td",[t._v("目录设置T属性,Orlov块分配器将该目录视为目录层次结构的顶部,提示块分配器该目录下的子目录是无关的,将被分散的分配")])])])]),t._v(" "),a("p",[a("strong",[t._v("注意:")]),t._v("\nchattr 指令所修改的文件属性和 chmod 指令修改的文件属性是两个不同层次的属性,前者是底层文件系统来设定的,而 chmod 指令则是站在用户使用的角度来设定的。")]),t._v(" "),a("h2",{attrs:{id:"_4-常见示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常见示例"}},[t._v("#")]),t._v(" 4.常见示例")]),t._v(" "),a("p",[t._v("(1)用 chattr 命令防止系统中某个关键文件被修改:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("chattr +i /etc/resolv.conf\n")])])]),a("p",[t._v("然后用"),a("code",[t._v("mv /etc/resolv.conf")]),t._v("等命令作用于该文件,都会得到 Operation not permitted 的结果。vim 编辑该文件时会提示"),a("code",[t._v("W10: Warning: Changing a readonly file")]),t._v("错误。要想修改此文件需要把 i 属性去掉:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("chattr -i /etc/resolv.conf\n")])])]),a("p",[t._v("(2)让某个文件只能追加内容,不能删除或修改,一些日志文件适用于这种操作。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("chattr +a /data1/user_act.log\n")])])]),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/chattr.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("chattr(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/lsattr.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("lsattr(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"http://www.ha97.com/5172.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("(总结)Linux的chattr与lsattr命令详解"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"chattr"}})],1)}),[],!1,null,null,null);a.default=v.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[118],{450:function(t,a,r){"use strict";r.r(a);var e=r(12),v=Object(e.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("chattr 用于改变文件属性。")]),t._v(" "),a("p",[t._v("与 chmod 命令相比,chmod 只改变文件的读写、执行权限,更底层的属性控制是由 chattr 来改变。")]),t._v(" "),a("p",[t._v("与之对应的命令是 lsattr,用于显示文件属性。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("chattr [ -RVf ] [ -v version ] [ mode ] files...\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-R\n\t递归地改变指定目录下文件的属性。此选项忽略符号链接;\n-V\n\t显示命令执行的详细信息;\n-f\n\t大部分错误信息不输出;\n-v\n\t设置文件版本号;\n+\n\t在原有参数设定基础上,追加参数;\n-\n\t在原有参数设定基础上,移除参数;\n=\n\t更新指定参数设定\n")])])]),a("p",[t._v("最关键的是 [mode] 部分,[mode] 部分由 + - = 和字符 [acdeijstuADST] 组合而成,这部分是用来控制文件的属性。")]),t._v(" "),a("p",[t._v("chattr 可以改变的文件系统属性有:")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("属性")]),t._v(" "),a("th",[t._v("含义")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("a")]),t._v(" "),a("td",[t._v("append only,只允许向文件追加数据,不允许删除和修改文件内容。如果目录有具有这个属性,系统将只允许在目录下简历和修改文件,不允许删除任何文件。只有root才能设置该属性")])]),t._v(" "),a("tr",[a("td",[t._v("c")]),t._v(" "),a("td",[t._v("compress,自动将文件压缩,在读取时自动解压缩")])]),t._v(" "),a("tr",[a("td",[t._v("d")]),t._v(" "),a("td",[t._v("No dump,在进行文件系统备份时,dump指令忽略此文件")])]),t._v(" "),a("tr",[a("td",[t._v("e")]),t._v(" "),a("td",[t._v("extent format,在ext文件系统中,表示该文件使用区段(extents)映射磁盘上的块")])]),t._v(" "),a("tr",[a("td",[t._v("i")]),t._v(" "),a("td",[t._v("immutable,不允许对文件进行任何的修改。对于目录而言,只能修改目录之下的文件,不允许建立和删除文件。只有root能设置此属性")])]),t._v(" "),a("tr",[a("td",[t._v("j")]),t._v(" "),a("td",[t._v("journal,设定此参数使得当通过mount参数:data=ordered 或者 data=writeback 挂 载的文件系统,文件在写入时会先被记录(在journal中)。如果filesystem被设定参数为 data=journal,则该参数自动失效")])]),t._v(" "),a("tr",[a("td",[t._v("s")]),t._v(" "),a("td",[t._v("secure deletion,系统在删除文件时,使用0填充文件所在的区域")])]),t._v(" "),a("tr",[a("td",[t._v("t")]),t._v(" "),a("td",[t._v("no tail-merging,文件拥有t属性时,与其它文件合并时末端不会存在局部块碎片")])]),t._v(" "),a("tr",[a("td",[t._v("u")]),t._v(" "),a("td",[t._v("undeletable,与s相反,删除文件时,文件内容其实还存在磁盘中,以便以后能够恢复删除的文件")])]),t._v(" "),a("tr",[a("td",[t._v("A")]),t._v(" "),a("td",[t._v("Atime,不能修改文件的最后访问时间")])]),t._v(" "),a("tr",[a("td",[t._v("D")]),t._v(" "),a("td",[t._v("如果一个目录设置了D属性,任何改变将同步到磁盘;这等价于mount命令中的dirsync选项,同步目录")])]),t._v(" "),a("tr",[a("td",[t._v("S")]),t._v(" "),a("td",[t._v("Sync,一旦应用程序对文件执行了写操作,则立刻将改动同步到磁盘")])]),t._v(" "),a("tr",[a("td",[t._v("T")]),t._v(" "),a("td",[t._v("目录设置T属性,Orlov块分配器将该目录视为目录层次结构的顶部,提示块分配器该目录下的子目录是无关的,将被分散的分配")])])])]),t._v(" "),a("p",[a("strong",[t._v("注意:")]),t._v("\nchattr 指令所修改的文件属性和 chmod 指令修改的文件属性是两个不同层次的属性,前者是底层文件系统来设定的,而 chmod 指令则是站在用户使用的角度来设定的。")]),t._v(" "),a("h2",{attrs:{id:"_4-常见示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常见示例"}},[t._v("#")]),t._v(" 4.常见示例")]),t._v(" "),a("p",[t._v("(1)用 chattr 命令防止系统中某个关键文件被修改:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("chattr +i /etc/resolv.conf\n")])])]),a("p",[t._v("然后用"),a("code",[t._v("mv /etc/resolv.conf")]),t._v("等命令作用于该文件,都会得到 Operation not permitted 的结果。vim 编辑该文件时会提示"),a("code",[t._v("W10: Warning: Changing a readonly file")]),t._v("错误。要想修改此文件需要把 i 属性去掉:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("chattr -i /etc/resolv.conf\n")])])]),a("p",[t._v("(2)让某个文件只能追加内容,不能删除或修改,一些日志文件适用于这种操作。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("chattr +a /data1/user_act.log\n")])])]),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/chattr.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("chattr(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/lsattr.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("lsattr(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"http://www.ha97.com/5172.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("(总结)Linux的chattr与lsattr命令详解"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"chattr"}})],1)}),[],!1,null,null,null);a.default=v.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/12.a41deb34.js b/docs/assets/js/12.108d7764.js similarity index 99% rename from docs/assets/js/12.a41deb34.js rename to docs/assets/js/12.108d7764.js index 0516d91ce..0e80e426b 100644 --- a/docs/assets/js/12.a41deb34.js +++ b/docs/assets/js/12.108d7764.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[12],{346:function(t,a,e){"use strict";e.r(a);var v=e(12),_=Object(v.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("echo 显示一行文本。")]),t._v(" "),a("p",[t._v("echo 可用于打印 Shell 变量的值或直接输出指定字符串。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("echo [SHORT-OPTION]... [STRING]...\necho LONG-OPTION\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-n\n\t输出时不在行尾添加换行符。\n-e\n\t使反斜杠的转义功能生效。\n-E\n\t禁用反斜杠的转义功能,为默认选项。\n--help\n\t显示帮助信息并退出。\n--version\n\t显示版本信息并退出。\n")])])]),a("p",[t._v("使用 -e 选项时,若字符串中出现以下字符,则特别加以处理,而不会将它当成一般文字输出:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("\\\\:反斜杠;\n\\a:发出警告声;\n\\b:删除前一个字符;\n\\c:截断不输出\\c后面的内容;\n\\f:换行,但光标仍旧停留在原来的位置;\n\\n:换行且光标移至行首;\n\\r:光标移至行首,但不换行;\n\\t:插入tab;\n\\v:与\\f相同;\n\\nnn:插入nnn(八进制)所代表的ASCII字符;\n\\xHH:插入HH(十六进制)所代表的ASCII字符;\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("p",[t._v("(1)不换行输出。")]),t._v(" "),a("p",[t._v("echo 默认换行输出,使echo不换行输出有两种方法。")]),t._v(" "),a("p",[a("strong",[t._v("方法一:")]),t._v(" 使用命令选项-n禁止输出换行符。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("echo -n what you want to output\n")])])]),a("p",[a("strong",[t._v("方法二:")]),t._v(" 使用命令选项 -e 让 echo 识别转义字符 \\c,echo 默认是不识别转义字符的。转义字符 \\c 使用 man echo 查看 echo 的使用手册,其意思是 produce no further output,表示截断不输出 \\c 后面的内容。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("echo")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-e")]),t._v(" lalalala"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("\\")]),t._v("cend "),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 输出:lalalala")]),t._v("\n")])])]),a("p",[t._v("(2)使用 echo 打印带有颜色的字体。")]),t._v(" "),a("p",[t._v("Linux 终端下输出带颜色的文字只需在文字前面添加如下格式:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("\\033[显示方式;前景色;背景色m\n")])])]),a("p",[t._v("其中 \\033 是 ESC 健的八进制,"),a("code",[t._v("\\033[")]),t._v("即告诉终端后面是设置颜色的参数,显示方式,前景色,背景色均是数字。")]),t._v(" "),a("p",[t._v("数字含义如下:")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("显示方式")]),t._v(" "),a("th",[t._v("意义")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("0")]),t._v(" "),a("td",[t._v("终端默认设置")])]),t._v(" "),a("tr",[a("td",[t._v("1")]),t._v(" "),a("td",[t._v("高亮显示")])]),t._v(" "),a("tr",[a("td",[t._v("4")]),t._v(" "),a("td",[t._v("使用下划线")])]),t._v(" "),a("tr",[a("td",[t._v("5")]),t._v(" "),a("td",[t._v("闪烁")])]),t._v(" "),a("tr",[a("td",[t._v("7")]),t._v(" "),a("td",[t._v("反白显示")])]),t._v(" "),a("tr",[a("td",[t._v("8")]),t._v(" "),a("td",[t._v("不可见")])])])]),t._v(" "),a("p",[t._v("颜色数字代号如下:")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("前景色")]),t._v(" "),a("th",[t._v("背景色")]),t._v(" "),a("th",[t._v("颜色")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("30")]),t._v(" "),a("td",[t._v("40")]),t._v(" "),a("td",[t._v("黑色")])]),t._v(" "),a("tr",[a("td",[t._v("31")]),t._v(" "),a("td",[t._v("41")]),t._v(" "),a("td",[t._v("红色")])]),t._v(" "),a("tr",[a("td",[t._v("32")]),t._v(" "),a("td",[t._v("42")]),t._v(" "),a("td",[t._v("绿色")])]),t._v(" "),a("tr",[a("td",[t._v("33")]),t._v(" "),a("td",[t._v("43")]),t._v(" "),a("td",[t._v("黃色")])]),t._v(" "),a("tr",[a("td",[t._v("34")]),t._v(" "),a("td",[t._v("44")]),t._v(" "),a("td",[t._v("蓝色")])]),t._v(" "),a("tr",[a("td",[t._v("35")]),t._v(" "),a("td",[t._v("45")]),t._v(" "),a("td",[t._v("紫红色")])]),t._v(" "),a("tr",[a("td",[t._v("36")]),t._v(" "),a("td",[t._v("46")]),t._v(" "),a("td",[t._v("青蓝色")])]),t._v(" "),a("tr",[a("td",[t._v("37")]),t._v(" "),a("td",[t._v("47")]),t._v(" "),a("td",[t._v("白色")])])])]),t._v(" "),a("p",[t._v("(a)显示红色字体:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('echo -e "\\e[1;31mThis is red text\\e[0m"\n')])])]),a("p",[t._v("输出:")]),t._v(" "),a("p",[a("font",{attrs:{color:"#ff0000"}},[t._v(" This is red text ")])],1),t._v(" "),a("p",[t._v("其中,"),a("code",[t._v("\\e[0m")]),t._v("表示恢复终端默认设置。")]),t._v(" "),a("p",[t._v("(b)显示绿色背景字体。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('echo -e "\\e[1;42mGreen Background\\e[0m"\n')])])]),a("p",[t._v("输出:")]),t._v(" "),a("p",[a("img",{attrs:{src:"https://img-blog.csdnimg.cn/c388a7859bd948c99866a94d209cfce5.png",alt:"在这里插入图片描述"}})]),t._v(" "),a("p",[t._v("(c)文字闪动。")]),t._v(" "),a("p",[t._v("使用前景色31(红色),背景色42(绿色)闪动:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('echo -e "\\033[5;31;42mMySQL Server Stop...\\033[0m"\n')])])]),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/echo.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("echo(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"http://man.linuxde.net/echo",target:"_blank",rel:"noopener noreferrer"}},[t._v("echo命令 - Linux命令大全"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"https://www.cnblogs.com/linusflow/p/7399761.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("使用echo输出带颜色的字体"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"echo"}})],1)}),[],!1,null,null,null);a.default=_.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[12],{344:function(t,a,e){"use strict";e.r(a);var v=e(12),_=Object(v.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("echo 显示一行文本。")]),t._v(" "),a("p",[t._v("echo 可用于打印 Shell 变量的值或直接输出指定字符串。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("echo [SHORT-OPTION]... [STRING]...\necho LONG-OPTION\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-n\n\t输出时不在行尾添加换行符。\n-e\n\t使反斜杠的转义功能生效。\n-E\n\t禁用反斜杠的转义功能,为默认选项。\n--help\n\t显示帮助信息并退出。\n--version\n\t显示版本信息并退出。\n")])])]),a("p",[t._v("使用 -e 选项时,若字符串中出现以下字符,则特别加以处理,而不会将它当成一般文字输出:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("\\\\:反斜杠;\n\\a:发出警告声;\n\\b:删除前一个字符;\n\\c:截断不输出\\c后面的内容;\n\\f:换行,但光标仍旧停留在原来的位置;\n\\n:换行且光标移至行首;\n\\r:光标移至行首,但不换行;\n\\t:插入tab;\n\\v:与\\f相同;\n\\nnn:插入nnn(八进制)所代表的ASCII字符;\n\\xHH:插入HH(十六进制)所代表的ASCII字符;\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("p",[t._v("(1)不换行输出。")]),t._v(" "),a("p",[t._v("echo 默认换行输出,使echo不换行输出有两种方法。")]),t._v(" "),a("p",[a("strong",[t._v("方法一:")]),t._v(" 使用命令选项-n禁止输出换行符。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("echo -n what you want to output\n")])])]),a("p",[a("strong",[t._v("方法二:")]),t._v(" 使用命令选项 -e 让 echo 识别转义字符 \\c,echo 默认是不识别转义字符的。转义字符 \\c 使用 man echo 查看 echo 的使用手册,其意思是 produce no further output,表示截断不输出 \\c 后面的内容。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("echo")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-e")]),t._v(" lalalala"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("\\")]),t._v("cend "),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 输出:lalalala")]),t._v("\n")])])]),a("p",[t._v("(2)使用 echo 打印带有颜色的字体。")]),t._v(" "),a("p",[t._v("Linux 终端下输出带颜色的文字只需在文字前面添加如下格式:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("\\033[显示方式;前景色;背景色m\n")])])]),a("p",[t._v("其中 \\033 是 ESC 健的八进制,"),a("code",[t._v("\\033[")]),t._v("即告诉终端后面是设置颜色的参数,显示方式,前景色,背景色均是数字。")]),t._v(" "),a("p",[t._v("数字含义如下:")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("显示方式")]),t._v(" "),a("th",[t._v("意义")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("0")]),t._v(" "),a("td",[t._v("终端默认设置")])]),t._v(" "),a("tr",[a("td",[t._v("1")]),t._v(" "),a("td",[t._v("高亮显示")])]),t._v(" "),a("tr",[a("td",[t._v("4")]),t._v(" "),a("td",[t._v("使用下划线")])]),t._v(" "),a("tr",[a("td",[t._v("5")]),t._v(" "),a("td",[t._v("闪烁")])]),t._v(" "),a("tr",[a("td",[t._v("7")]),t._v(" "),a("td",[t._v("反白显示")])]),t._v(" "),a("tr",[a("td",[t._v("8")]),t._v(" "),a("td",[t._v("不可见")])])])]),t._v(" "),a("p",[t._v("颜色数字代号如下:")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("前景色")]),t._v(" "),a("th",[t._v("背景色")]),t._v(" "),a("th",[t._v("颜色")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("30")]),t._v(" "),a("td",[t._v("40")]),t._v(" "),a("td",[t._v("黑色")])]),t._v(" "),a("tr",[a("td",[t._v("31")]),t._v(" "),a("td",[t._v("41")]),t._v(" "),a("td",[t._v("红色")])]),t._v(" "),a("tr",[a("td",[t._v("32")]),t._v(" "),a("td",[t._v("42")]),t._v(" "),a("td",[t._v("绿色")])]),t._v(" "),a("tr",[a("td",[t._v("33")]),t._v(" "),a("td",[t._v("43")]),t._v(" "),a("td",[t._v("黃色")])]),t._v(" "),a("tr",[a("td",[t._v("34")]),t._v(" "),a("td",[t._v("44")]),t._v(" "),a("td",[t._v("蓝色")])]),t._v(" "),a("tr",[a("td",[t._v("35")]),t._v(" "),a("td",[t._v("45")]),t._v(" "),a("td",[t._v("紫红色")])]),t._v(" "),a("tr",[a("td",[t._v("36")]),t._v(" "),a("td",[t._v("46")]),t._v(" "),a("td",[t._v("青蓝色")])]),t._v(" "),a("tr",[a("td",[t._v("37")]),t._v(" "),a("td",[t._v("47")]),t._v(" "),a("td",[t._v("白色")])])])]),t._v(" "),a("p",[t._v("(a)显示红色字体:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('echo -e "\\e[1;31mThis is red text\\e[0m"\n')])])]),a("p",[t._v("输出:")]),t._v(" "),a("p",[a("font",{attrs:{color:"#ff0000"}},[t._v(" This is red text ")])],1),t._v(" "),a("p",[t._v("其中,"),a("code",[t._v("\\e[0m")]),t._v("表示恢复终端默认设置。")]),t._v(" "),a("p",[t._v("(b)显示绿色背景字体。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('echo -e "\\e[1;42mGreen Background\\e[0m"\n')])])]),a("p",[t._v("输出:")]),t._v(" "),a("p",[a("img",{attrs:{src:"https://img-blog.csdnimg.cn/c388a7859bd948c99866a94d209cfce5.png",alt:"在这里插入图片描述"}})]),t._v(" "),a("p",[t._v("(c)文字闪动。")]),t._v(" "),a("p",[t._v("使用前景色31(红色),背景色42(绿色)闪动:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('echo -e "\\033[5;31;42mMySQL Server Stop...\\033[0m"\n')])])]),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/echo.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("echo(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"http://man.linuxde.net/echo",target:"_blank",rel:"noopener noreferrer"}},[t._v("echo命令 - Linux命令大全"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"https://www.cnblogs.com/linusflow/p/7399761.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("使用echo输出带颜色的字体"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"echo"}})],1)}),[],!1,null,null,null);a.default=_.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/120.aa7bde68.js b/docs/assets/js/120.4ccea9a8.js similarity index 99% rename from docs/assets/js/120.aa7bde68.js rename to docs/assets/js/120.4ccea9a8.js index d88b50519..3e3de30aa 100644 --- a/docs/assets/js/120.aa7bde68.js +++ b/docs/assets/js/120.4ccea9a8.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[120],{454:function(s,t,a){"use strict";a.r(t);var e=a(12),r=Object(e.a)({},(function(){var s=this,t=s._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[s._v("#")]),s._v(" 1.命令简介")]),s._v(" "),t("p",[s._v("chmod 用来变更文件或目录的访问权限。")]),s._v(" "),t("p",[s._v("chmod 仅限文件属主和超级用户 root 使用。")]),s._v(" "),t("p",[s._v("Linux 文件与目录的权限有三种范围,属主(u,user)、属组(g,group)与其它(o,other),全部用户使用 a(all)表示。每个范围的权限由三个比特位表示,从左至右分别表示 r(read,读)、w(write,写)与 x(execute,可执行)。权限可以使用字符或八进制数字表示,r 对应数字 4,w 对应数字 2,x 对应数字 1。如果相应的权限位没有权限,使用"),t("code",[s._v("ls -l")]),s._v("命令查看时,显示为横杠-。如下图所示:\n"),t("img",{attrs:{src:"https://img-blog.csdnimg.cn/20191030210755294.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9kYWJsZWx2LmJsb2cuY3Nkbi5uZXQ=,size_16,color_FFFFFF,t_70",alt:"在这里插入图片描述"}}),s._v("\n注意:\n(1)当使用 chmod 改变符号链接的权限时,实际上改变的是目标文件的权限;chmod 无法更改其符号链接的权限,这不是一个 bug,因为符号链接的权限从未被使用过。\n(2)chmod 在递归时,遇到符号链接则会忽略之。")]),s._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("chmod [OPTION]... MODE[,MODE]... FILE...\nchmod [OPTION]... OCTAL-MODE FILE...\nchmod [OPTION]... --reference=RFILE FILE...\n")])])]),t("p",[s._v("其中 MODE 使用字符形式表示文件权限,格式为 [ugoa...][[+-=][perms...]...]。ugoa 任意字母组合指定权限范围,不指定默认为 a。+-= 分别表示增加、去除与赋予相应权限。权限 perms 可以是零也可以是 rwxXst 中的多个字符的组合,或者是 ugo 中的某一个字符。MODE 可以出现多次,由逗号隔开。rwxXst 分别表示 r(读)、w(写)、x(可执行)、X(可执行,已经有可执行权限或者目标是目录时使用,以示区分)、s(文件的特殊权限 SETUID 或 SETGID)和 t(粘滞位)。")]),s._v(" "),t("p",[s._v("OCTAL-MODE 为八进制数字表示权限比特位组成的数值。可以指定 1 到 4 个八进制数字(0-7)。从右至左,四个数字分别表示其它 o、用户组 g、属主 u 和文件的特殊权限 SETUID(4)、SETGID(2)和\nSBIT(1)。")]),s._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("-c, --changes\n\t类似 --verbose,但只在有更改生效时才显示结果\n-f, --silent, --quiet\n 去除大部份的错误信息\n-v, --verbose\n\t显示指令详细的执行过程\n--no-preserve-root\n\t不特殊对待根目录(默认)\n--preserve-root\n\t禁止对根目录进行递归操作\n--reference=RFILE\n\t使用指定参考文件的权限,而非自行指定\n-R, --recursive\n\t以递归方式更改所有文件及子目录\n--help\n\t显示帮助信息并退出。\n--version\n\t显示版本信息并退出。\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[s._v("#")]),s._v(" 4.常用示例")]),s._v(" "),t("p",[s._v("(1)增加全部用户对文件 test.sh 的执行权限。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" +x test.sh\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 或")]),s._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" a+x test.sh\n\nll test.sh\n-rwx-wx-wx "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":13 test.sh\n")])])]),t("p",[s._v("(2)减去全部用户对文件 test.sh 的执行权限。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-x")]),s._v(" test.sh\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 或")]),s._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" a-x test.sh\n\nll test.sh\n-rw--w--w- "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":13 test.sh\n")])])]),t("p",[s._v("(3)增加属主对文件 test.sh 的执行权限。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" u+x test.sh\n\nll test.sh\n-rwx-w--w- "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":13 test.sh\n")])])]),t("p",[s._v("(4)分别使用符号方式和数字方式为文件 test.sh 设置新的权限为 rwxr--r--。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 符号方式")]),s._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("a")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("rwx,g"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("r,o"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("r test.sh\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 数字方式")]),s._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" 0744 test.sh\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 或")]),s._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("744")]),s._v(" test.sh\n\nll test.sh\n-rwxr--r-- "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":13 test.sh\n")])])]),t("p",[s._v("(5)递归地将目录及其下所有文件和子目录加上读权限。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-R")]),s._v(" a+r "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("dir")]),s._v("\n\nll "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("dir")]),s._v("\ntotal "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("4")]),s._v("\ndrwxrwxrwx "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("4096")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":29 newdir\n-rw-rw-rw- "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":13 test.sh\n-rw-rw-rw- "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":26 test.txt\n")])])]),t("p",[s._v("(6)给文件 test.sh 增加 SETUID 权限。前提是属主对文件 test.sh 有执行权限。")]),s._v(" "),t("p",[s._v("SETUID(Set User ID)是一种特殊权限,它允许一个可执行文件在执行过程中暂时获取文件所有者的权限,而不是执行它的用户的权限。在某些情况下,这可以用于实现特定的权限管理需求。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" u+s test.sh\n\nll test.sh\n-rwsr--r-- "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":13 test.sh\n")])])]),t("h2",{attrs:{id:"_5-文件的特殊权限"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-文件的特殊权限"}},[s._v("#")]),s._v(" 5.文件的特殊权限")]),s._v(" "),t("h3",{attrs:{id:"setuid"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#setuid"}},[s._v("#")]),s._v(" SETUID")]),s._v(" "),t("p",[s._v("SETUID 使用小写字母 s 表示,出现在属主可执行权限位,具有 SUID 权限的文件会在其执行时,使调用者的有效身份临时变为该文件的拥有者,用于临时提升权限,使调用者暂时获得该文件拥有者的权限。")]),s._v(" "),t("p",[s._v("例如命令 passwd 的权限:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("ll /usr/bin/passwd\n-rwsr-xr-x 1 root root 27832 Jun 10 2014 /usr/bin/passwd\n")])])]),t("p",[s._v("在文件拥有者的执行位上出现 s 而不是 x,所以说 passwd 具有 SUID 权限。修改用户密码使用的是 passwd 这个命令,Linux 用户密码存储在文件 /etc/shadow 中。首先查看一下 /etc/shadow 文件的权限:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("ll /etc/shadow\n---------- 1 root root 853 Jan 4 14:56 /etc/shadow\n")])])]),t("p",[s._v("可见 root 没有读写权限,但是为什么 root 实际上可以读取和修改 shadow 呢?因为 Linux 的权限管理机制不能够限制神一样的 root。从 shadow 的权限列表可以看出,root 组用户和其他用户对 shadow 没有读写权限的,也就是只有 root 才能进行强制的读写操作。但是实际上普通用户是可以自行修改自己的密码的,这就是为什么呢?因为 /usr/bin/passwd 的属主 root 对其权限是 rws,而且其他用户的使用权限为 r-x,也就是说,别人在执行 passwd 时会暂时获得 passwd 的属主即 root 的权限。这就是 Linux 特有的 SUID 权限机制。")]),s._v(" "),t("h3",{attrs:{id:"setgid"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#setgid"}},[s._v("#")]),s._v(" SETGID")]),s._v(" "),t("p",[s._v("SETGID 与 SETUID类似,使用小写字母 s 表示,出现在用户组可执行权限位,具有 SETGID 权限的文件会在其执行时,使调用者的有效用户组临时变为该文件属主的用户组,用于临时提升权限,使调用者暂时获得该文件所属用户组的权限。")]),s._v(" "),t("p",[s._v("当 SGID 作用于可执行文件时,在执行该文件时,用户将获得该文件所属组的权限。")]),s._v(" "),t("p",[s._v("当 SGID 作用于目录时,当用户对某一目录有写和执行权限时,该用户可以在该目录下建立文件,如果该目录具有 SGID 权限,则该用户在该目录下建立的文件都属于这个目录所属的组。")]),s._v(" "),t("h3",{attrs:{id:"sbit"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#sbit"}},[s._v("#")]),s._v(" SBIT")]),s._v(" "),t("p",[s._v("SBIT(Sticky Bit)称为粘滞位,它出现在其他用户权限的执行位上,只能用来修饰一个目录,用于限制文件的删除。")]),s._v(" "),t("p",[s._v("当某一个目录拥有 SBIT 权限时,则任何一个能够在这个目录下建立文件的用户,该用户在这个目录下所建立的文件,只有该用户自己和 root 可以删除,其他用户均不可以。例如目录 /tmp 的权限如下:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("ll -d /tmp\ndrwxrwxrwt 14 root root 147456 2月 14 16:01 /tmp\n")])])]),t("p",[s._v("注意,如果目录的其他用户的权限执行位是 T,则表示 SBIT 权限无效。发生的情况是权限的执行位不是 x。")]),s._v(" "),t("h2",{attrs:{id:"_6-linux-文件分类"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_6-linux-文件分类"}},[s._v("#")]),s._v(" 6.Linux 文件分类")]),s._v(" "),t("p",[s._v("Linux 中一切皆文件,文件一般分为如下几种类型:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("- 普通文件\nd 目录\nb 块设备\nc 字符设备\np 命名管道\nl 符号链接\ns 套接字\n")])])]),t("p",[s._v("如果文件是目录,其 rwx 权限的作用如下:\n(1)目录读权限位意味着可以列出其中的内容;\n(2)目录写权限位意味着可以在该目录中创建、删除、更名或移动文件,前提是目录需要有执行权限;\n(3)目录执行权限位则意味着可以进入该目录进行搜索。因此在创建目录的时候一般都具有可执行权限。")]),s._v(" "),t("hr"),s._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/chmod.1.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("chmod(1) - Linux manual page - Michael Kerrisk"),t("OutboundLink")],1)]),s._v(" "),t("p",[t("a",{attrs:{href:"https://dablelv.blog.csdn.net/article/details/87280503",target:"_blank",rel:"noopener noreferrer"}},[s._v("Linux 文件特殊权限 SUID、SGID 与 SBIT"),t("OutboundLink")],1)]),s._v(" "),t("Vssue",{attrs:{title:"chmod"}})],1)}),[],!1,null,null,null);t.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[120],{452:function(s,t,a){"use strict";a.r(t);var e=a(12),r=Object(e.a)({},(function(){var s=this,t=s._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[s._v("#")]),s._v(" 1.命令简介")]),s._v(" "),t("p",[s._v("chmod 用来变更文件或目录的访问权限。")]),s._v(" "),t("p",[s._v("chmod 仅限文件属主和超级用户 root 使用。")]),s._v(" "),t("p",[s._v("Linux 文件与目录的权限有三种范围,属主(u,user)、属组(g,group)与其它(o,other),全部用户使用 a(all)表示。每个范围的权限由三个比特位表示,从左至右分别表示 r(read,读)、w(write,写)与 x(execute,可执行)。权限可以使用字符或八进制数字表示,r 对应数字 4,w 对应数字 2,x 对应数字 1。如果相应的权限位没有权限,使用"),t("code",[s._v("ls -l")]),s._v("命令查看时,显示为横杠-。如下图所示:\n"),t("img",{attrs:{src:"https://img-blog.csdnimg.cn/20191030210755294.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9kYWJsZWx2LmJsb2cuY3Nkbi5uZXQ=,size_16,color_FFFFFF,t_70",alt:"在这里插入图片描述"}}),s._v("\n注意:\n(1)当使用 chmod 改变符号链接的权限时,实际上改变的是目标文件的权限;chmod 无法更改其符号链接的权限,这不是一个 bug,因为符号链接的权限从未被使用过。\n(2)chmod 在递归时,遇到符号链接则会忽略之。")]),s._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("chmod [OPTION]... MODE[,MODE]... FILE...\nchmod [OPTION]... OCTAL-MODE FILE...\nchmod [OPTION]... --reference=RFILE FILE...\n")])])]),t("p",[s._v("其中 MODE 使用字符形式表示文件权限,格式为 [ugoa...][[+-=][perms...]...]。ugoa 任意字母组合指定权限范围,不指定默认为 a。+-= 分别表示增加、去除与赋予相应权限。权限 perms 可以是零也可以是 rwxXst 中的多个字符的组合,或者是 ugo 中的某一个字符。MODE 可以出现多次,由逗号隔开。rwxXst 分别表示 r(读)、w(写)、x(可执行)、X(可执行,已经有可执行权限或者目标是目录时使用,以示区分)、s(文件的特殊权限 SETUID 或 SETGID)和 t(粘滞位)。")]),s._v(" "),t("p",[s._v("OCTAL-MODE 为八进制数字表示权限比特位组成的数值。可以指定 1 到 4 个八进制数字(0-7)。从右至左,四个数字分别表示其它 o、用户组 g、属主 u 和文件的特殊权限 SETUID(4)、SETGID(2)和\nSBIT(1)。")]),s._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("-c, --changes\n\t类似 --verbose,但只在有更改生效时才显示结果\n-f, --silent, --quiet\n 去除大部份的错误信息\n-v, --verbose\n\t显示指令详细的执行过程\n--no-preserve-root\n\t不特殊对待根目录(默认)\n--preserve-root\n\t禁止对根目录进行递归操作\n--reference=RFILE\n\t使用指定参考文件的权限,而非自行指定\n-R, --recursive\n\t以递归方式更改所有文件及子目录\n--help\n\t显示帮助信息并退出。\n--version\n\t显示版本信息并退出。\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[s._v("#")]),s._v(" 4.常用示例")]),s._v(" "),t("p",[s._v("(1)增加全部用户对文件 test.sh 的执行权限。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" +x test.sh\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 或")]),s._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" a+x test.sh\n\nll test.sh\n-rwx-wx-wx "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":13 test.sh\n")])])]),t("p",[s._v("(2)减去全部用户对文件 test.sh 的执行权限。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-x")]),s._v(" test.sh\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 或")]),s._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" a-x test.sh\n\nll test.sh\n-rw--w--w- "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":13 test.sh\n")])])]),t("p",[s._v("(3)增加属主对文件 test.sh 的执行权限。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" u+x test.sh\n\nll test.sh\n-rwx-w--w- "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":13 test.sh\n")])])]),t("p",[s._v("(4)分别使用符号方式和数字方式为文件 test.sh 设置新的权限为 rwxr--r--。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 符号方式")]),s._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("a")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("rwx,g"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("r,o"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("r test.sh\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 数字方式")]),s._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" 0744 test.sh\n\n"),t("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 或")]),s._v("\n"),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("744")]),s._v(" test.sh\n\nll test.sh\n-rwxr--r-- "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":13 test.sh\n")])])]),t("p",[s._v("(5)递归地将目录及其下所有文件和子目录加上读权限。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-R")]),s._v(" a+r "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("dir")]),s._v("\n\nll "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("dir")]),s._v("\ntotal "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("4")]),s._v("\ndrwxrwxrwx "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("4096")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":29 newdir\n-rw-rw-rw- "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":13 test.sh\n-rw-rw-rw- "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":26 test.txt\n")])])]),t("p",[s._v("(6)给文件 test.sh 增加 SETUID 权限。前提是属主对文件 test.sh 有执行权限。")]),s._v(" "),t("p",[s._v("SETUID(Set User ID)是一种特殊权限,它允许一个可执行文件在执行过程中暂时获取文件所有者的权限,而不是执行它的用户的权限。在某些情况下,这可以用于实现特定的权限管理需求。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("chmod")]),s._v(" u+s test.sh\n\nll test.sh\n-rwsr--r-- "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("30")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(":13 test.sh\n")])])]),t("h2",{attrs:{id:"_5-文件的特殊权限"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-文件的特殊权限"}},[s._v("#")]),s._v(" 5.文件的特殊权限")]),s._v(" "),t("h3",{attrs:{id:"setuid"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#setuid"}},[s._v("#")]),s._v(" SETUID")]),s._v(" "),t("p",[s._v("SETUID 使用小写字母 s 表示,出现在属主可执行权限位,具有 SUID 权限的文件会在其执行时,使调用者的有效身份临时变为该文件的拥有者,用于临时提升权限,使调用者暂时获得该文件拥有者的权限。")]),s._v(" "),t("p",[s._v("例如命令 passwd 的权限:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("ll /usr/bin/passwd\n-rwsr-xr-x 1 root root 27832 Jun 10 2014 /usr/bin/passwd\n")])])]),t("p",[s._v("在文件拥有者的执行位上出现 s 而不是 x,所以说 passwd 具有 SUID 权限。修改用户密码使用的是 passwd 这个命令,Linux 用户密码存储在文件 /etc/shadow 中。首先查看一下 /etc/shadow 文件的权限:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("ll /etc/shadow\n---------- 1 root root 853 Jan 4 14:56 /etc/shadow\n")])])]),t("p",[s._v("可见 root 没有读写权限,但是为什么 root 实际上可以读取和修改 shadow 呢?因为 Linux 的权限管理机制不能够限制神一样的 root。从 shadow 的权限列表可以看出,root 组用户和其他用户对 shadow 没有读写权限的,也就是只有 root 才能进行强制的读写操作。但是实际上普通用户是可以自行修改自己的密码的,这就是为什么呢?因为 /usr/bin/passwd 的属主 root 对其权限是 rws,而且其他用户的使用权限为 r-x,也就是说,别人在执行 passwd 时会暂时获得 passwd 的属主即 root 的权限。这就是 Linux 特有的 SUID 权限机制。")]),s._v(" "),t("h3",{attrs:{id:"setgid"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#setgid"}},[s._v("#")]),s._v(" SETGID")]),s._v(" "),t("p",[s._v("SETGID 与 SETUID类似,使用小写字母 s 表示,出现在用户组可执行权限位,具有 SETGID 权限的文件会在其执行时,使调用者的有效用户组临时变为该文件属主的用户组,用于临时提升权限,使调用者暂时获得该文件所属用户组的权限。")]),s._v(" "),t("p",[s._v("当 SGID 作用于可执行文件时,在执行该文件时,用户将获得该文件所属组的权限。")]),s._v(" "),t("p",[s._v("当 SGID 作用于目录时,当用户对某一目录有写和执行权限时,该用户可以在该目录下建立文件,如果该目录具有 SGID 权限,则该用户在该目录下建立的文件都属于这个目录所属的组。")]),s._v(" "),t("h3",{attrs:{id:"sbit"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#sbit"}},[s._v("#")]),s._v(" SBIT")]),s._v(" "),t("p",[s._v("SBIT(Sticky Bit)称为粘滞位,它出现在其他用户权限的执行位上,只能用来修饰一个目录,用于限制文件的删除。")]),s._v(" "),t("p",[s._v("当某一个目录拥有 SBIT 权限时,则任何一个能够在这个目录下建立文件的用户,该用户在这个目录下所建立的文件,只有该用户自己和 root 可以删除,其他用户均不可以。例如目录 /tmp 的权限如下:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("ll -d /tmp\ndrwxrwxrwt 14 root root 147456 2月 14 16:01 /tmp\n")])])]),t("p",[s._v("注意,如果目录的其他用户的权限执行位是 T,则表示 SBIT 权限无效。发生的情况是权限的执行位不是 x。")]),s._v(" "),t("h2",{attrs:{id:"_6-linux-文件分类"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_6-linux-文件分类"}},[s._v("#")]),s._v(" 6.Linux 文件分类")]),s._v(" "),t("p",[s._v("Linux 中一切皆文件,文件一般分为如下几种类型:")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("- 普通文件\nd 目录\nb 块设备\nc 字符设备\np 命名管道\nl 符号链接\ns 套接字\n")])])]),t("p",[s._v("如果文件是目录,其 rwx 权限的作用如下:\n(1)目录读权限位意味着可以列出其中的内容;\n(2)目录写权限位意味着可以在该目录中创建、删除、更名或移动文件,前提是目录需要有执行权限;\n(3)目录执行权限位则意味着可以进入该目录进行搜索。因此在创建目录的时候一般都具有可执行权限。")]),s._v(" "),t("hr"),s._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/chmod.1.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("chmod(1) - Linux manual page - Michael Kerrisk"),t("OutboundLink")],1)]),s._v(" "),t("p",[t("a",{attrs:{href:"https://dablelv.blog.csdn.net/article/details/87280503",target:"_blank",rel:"noopener noreferrer"}},[s._v("Linux 文件特殊权限 SUID、SGID 与 SBIT"),t("OutboundLink")],1)]),s._v(" "),t("Vssue",{attrs:{title:"chmod"}})],1)}),[],!1,null,null,null);t.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/121.4da0a457.js b/docs/assets/js/121.2cc770c1.js similarity index 99% rename from docs/assets/js/121.4da0a457.js rename to docs/assets/js/121.2cc770c1.js index 55d7f6ab1..4374dffd9 100644 --- a/docs/assets/js/121.4da0a457.js +++ b/docs/assets/js/121.2cc770c1.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[121],{455:function(a,t,e){"use strict";e.r(t);var s=e(12),n=Object(s.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("chown 用来改变文件或目录的属主(owner)和所属用户组(group)。")]),a._v(" "),t("p",[a._v("chown 仅限超级用户 root 使用,普通用户没有权限改变文件属主及所属组。")]),a._v(" "),t("p",[a._v("该命令通过改变文件的属主或所属用户组可以向某个用户授权。属主可以是用户名或用户 ID,用户组可以是组名或组 ID。文件名是由空格分隔的文件列表,在文件名中可以包含通配符。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("chown [OPTION]... [OWNER][:[GROUP]] FILE...\nchown [OPTION]... --reference=RFILE FILE...\n")])])]),t("p",[a._v("在指定属主与所属用户组时有如下几种情况:\n(1)如果只指定了属主,则只改变每个给定文件的属主,不会更改文件的用户组;\n(2)如果属主后面跟一个冒号和用户组,则文件所属的用户组也将被更改;\n(3)如果用户名后面有冒号但没有组名,则该用户将成为文件的属主,并且文件属组将更改为该用户的登录组;\n(4)如果给定冒号和组名,但省略了属主,则只更改所属组。这种情况,chown 的功能等同于 chgrp;\n(5)如果只给定一个冒号,或者整个操作数为空,则属主和用户组都不会更改。")]),a._v(" "),t("p",[a._v("注意,OWNER 与 GROUP 之间的冒号可以使用点号替代。")]),a._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-c, --changes\n\t 输出效果类似 verbose 模式,但只在有更改生效时才显示。\n-f, --silent, --quiet\n\t忽略大部分错误信息。\n-v, --verbose\n\t显示指令详细的执行过程\n--dereference\n\t修改符号链接指向的实际文件的属主和所属用户组,而不是符号链接文件本身。为默认选项\n-h, --no-dereference\n\t修改符号链接文件本身的属主和所属用户组。作用与 --dereference 相反\n--from=CURRENT_OWNER:CURRENT_GROUP\n\t只有当文件的属主和所属组符合选项所指定的才更改。CURRENT_OWNER 和 CURRENT_GROUP 可以省略,这时省略的属性就不需要进行匹配\n--no-preserve-root\n\t不特殊对待根目录 /。为默认选项\n--preserve-root\n\t不允许在根目录 /上递归操作\n--reference=RFILE\n\t使用指定的文件 RFILE 的属主和所属用户组,而非指定值\n-R, --recursive\n\t递归处理所有的文件及子目录\n\t\n以下三个选项 -H、-L 和 -P 与 -R 配合使用,用于递归操作时确定遍历的方式:\n-H\n\t如果命令行参数是一个符号链接指向一个目录,则遍历它\n-L\n\t遍历每一个符号链接指向的目录\n-P\n\t不遍历任何符号链接(缺省选项)。\n\n--help\n\t显示帮助信息\n--version\n\t显示版本信息\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("(1)只修改文件属主为 root。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("chown")]),a._v(" root FILE\n")])])]),t("p",[a._v("注意,指定的属主必须是系统合法用户,可以查看文件 /etc/passwd 确定当前系统有哪些用户。")]),a._v(" "),t("p",[a._v("(2)修改文件属主和用户组均为 root。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("chown")]),a._v(" root:root FILE\n")])])]),t("p",[a._v("(3)只修改文件所属组为 root。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("chown")]),a._v(" :root FILE\n")])])]),t("p",[a._v("(4)递归修改所有的文件及子目录属主和所属组为 root。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("chown")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-R")]),a._v(" root:root /DIR\n")])])]),t("p",[a._v("(5)显示修改的动作,使用 -v 冗余模式输出。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("chown")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-vR")]),a._v(" root:root /DIR\n")])])]),t("h2",{attrs:{id:"_5-用户与组相关配置文件"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-用户与组相关配置文件"}},[a._v("#")]),a._v(" 5.用户与组相关配置文件")]),a._v(" "),t("p",[a._v("Linux 与用户和组的定义相关的配置文件有:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("/etc/passwd 用户信息\n/etc/shadow 用户口令及其相关属性\n/etc/group 用户组信息\n/etc/gshadow 用户组口令及其相关属性\n")])])]),t("h3",{attrs:{id:"etc-passwd-7-列"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#etc-passwd-7-列"}},[a._v("#")]),a._v(" /etc/passwd(7 列)")]),a._v(" "),t("p",[a._v("/etc/passwd 用来保存用户名称、ID、属组 ID、家目录等信息。")]),a._v(" "),t("p",[a._v("每行格式如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("用户名:口令:用户标识号:组标识号:注释性描述:主目录:默认Shell\n")])])]),t("p",[a._v("示例内容如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("cat /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\n...\n")])])]),t("p",[a._v("在 passwd 文件中,第一行内容是超级用户 root 行,可以看到它的 uid 和 gid 都为 0。为了方便理解,下面给出各字段的描述:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v('字段1:用户名,这是用户登录时使用的账户名称,在系统中是唯一的,不能重名\n字段2:密码占位符 x;早期的 Unix 系统中,该字段是存放账户密码的,由于安全原因,后来把这个密码字段内容移到 /etc/shadow 中了\n字段3:UID;范围是 0-65535\n字段4:用户主组的 ID,范围是 0-65535。当添加用户时,默认情况下会同时建立一个与用户同名且 GID 与 UID 相同的组。用户所属的其它用户组定义在文件 /etc/group\n字段5:用户说明;这个字段是对这个账户的说明\n字段6:宿主目录;用户登录后首先进入的目录,一般为 "/home/用户名" 这样的目录\n字段7:登录 Shell 当前用户登录后所使用的 Shell,在 Centos/RHEL 系统中,默认的 Shell 是 Bash;如果不希望用户登登系统,可以通过 usermod 或者手动修改 passwd 设置,将该字段设置为 /sbin/nologin 即可。出于安全考虑,大多数内置系统账户都是 /sbin/nologin,表示禁止登录系统\n')])])]),t("h3",{attrs:{id:"etc-shadow-9-列"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#etc-shadow-9-列"}},[a._v("#")]),a._v(" /etc/shadow(9 列)")]),a._v(" "),t("p",[a._v("/etc/shadow 用于保存加密后的用户口令相关信息,只有 root 用户拥有读写权限。")]),a._v(" "),t("p",[a._v("每行格式如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("用户名:加密口令:最后一次修改时间:最小时间间隔:最大时间间隔:警告时间:不活动时间:失效时间:保留字段\n")])])]),t("p",[a._v("示例内容如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("root:$6$25KI3rub$BK5ef2iaxtl0Jn7lofKk9xZDrOU6aamefgIDKlHUycqUvU/lF1XdcQa4Bz53vGmnTh/kV/T1DLtdIRxxVKj8M.:17403:0:99999:7:::\nbin:*:16973:0:99999:7:::\ndaemon:*:16973:0:99999:7:::\nadm:*:16973:0:99999:7:::\n...\n")])])]),t("p",[a._v("下面是每个字段的详细含义:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("第一列:用户名。与 /etc/passwd 文件中的用户名有相同的含义\n第二列:加密口令。存放的是加密后的用户口令字串,如果此字段是“*”、“!”、“x”等字符,则对应的用户不能登录系统\n第三列:最后一次修改时间。表示从某个时间起,到用户最近一次修改口令的间隔天数。可以通过 passwd 来修改用户的密码,然后查看 /etc/shadow 中此字段的变化\n第四列:最小时间间隔。 表示两次修改密码之间的最小时间间隔。\n第五列:最大时间间隔。表示两次修改密码之间的最大时间间隔,这个设置能增强管理员管理用户的时效性。\n第六列:警告时间。表示从系统开始警告用户到密码正式失效之间的天数。\n第七列:不活动时间。此字段表示用户口令作废多少天后,系统会禁用此用户,也就是说系统不再让此用户登录,也不会提示用户过期,是完全禁用。\n第八列:失效时间。表示该用户的帐号生存期,超过这个设定时间,帐号失效,用户就无法登录系统了。如果这个字段的值为空,帐号永久可用。\n第九列:保留字段: linux的保留字段,目前为空,以备linux日后发展之用。\n")])])]),t("h3",{attrs:{id:"etc-group-4-列"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#etc-group-4-列"}},[a._v("#")]),a._v(" /etc/group(4 列)")]),a._v(" "),t("p",[a._v("/etc/group 保存了用户组的相关信息。通过查询该文件,可查看某个用户属于哪些组。")]),a._v(" "),t("p",[a._v("每行格式如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("组名:口令:组标识号:组内用户列表\n")])])]),t("p",[a._v("示例内容如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("root:x:0:\nbin:x:1:\ndaemon:x:2:\n...\n")])])]),t("p",[a._v("每个字段的详细含义:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("组名:用户组的名称,由字母或数字构成。与 /etc/passwd 中的用户名一样,组名不能重复。\n口令:存放的是用户组加密后的口令字串,密码默认设置在 /etc/gshadow 文件中,而在这里用 “x” 代替,linux 系统下默认的用户组都没有口令,可以通过 gpasswd 来给用户组添加密码。\n组标识号:即 GID,与 /etc/passwd 中的组标识号对应。\n组内用户列表: 显示属于这个组的所有用户,多个用户之间用逗号分隔。\n")])])]),t("h3",{attrs:{id:"etc-gshdow-4-列"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#etc-gshdow-4-列"}},[a._v("#")]),a._v(" /etc/gshdow(4 列)")]),a._v(" "),t("p",[a._v("/etc/gshdow 保存了组密码及其相关属性。")]),a._v(" "),t("p",[a._v("每行格式如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("群组名称:群组密码:组管理员列表:以当前组为附加组的用户列表\n")])])]),t("p",[a._v("示例内容如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("root:::\nbin:::\ndaemon:::\ntcpdump:!::\nmysql:!::\n...\n")])])]),t("p",[a._v("各个字段详细含义如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("组名称: 组名称,不能重复\n组密码:为空,表示只有组内用户可以获取组权限。为 ! 或者 * 表示用户无法通过组密码获取组权限\n组管理员列表: 组管理员的列表,能够更改组密码和成员\n以当前组为附加组的用户列表: 以逗号分隔的用户名列表,如果为空,表示用户名与组名相同,即该组是同名用户的主组\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/chown.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("chown(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://man7.org/linux/man-pages/man5/passwd.5.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("passwd(5) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://man7.org/linux/man-pages/man5/shadow.5.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("shadow(5) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://man7.org/linux/man-pages/man5/group.5.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("group(5) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://man7.org/linux/man-pages/man5/gshadow.5.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("gshadow(5) - Linux manual page -man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/98666179",target:"_blank",rel:"noopener noreferrer"}},[a._v("【Linux】一步一步学Linux——chown命令(112)"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://www.cnblogs.com/zhongguiyao/p/9165917.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("Linux系统的用户和用户组管理"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/humanking7/article/details/84001125#11__etcpasswd__17_24",target:"_blank",rel:"noopener noreferrer"}},[a._v("[Linux]用户和组相关配置文件介绍(共7个文件)"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"chown"}})],1)}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[121],{453:function(a,t,e){"use strict";e.r(t);var s=e(12),n=Object(s.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("chown 用来改变文件或目录的属主(owner)和所属用户组(group)。")]),a._v(" "),t("p",[a._v("chown 仅限超级用户 root 使用,普通用户没有权限改变文件属主及所属组。")]),a._v(" "),t("p",[a._v("该命令通过改变文件的属主或所属用户组可以向某个用户授权。属主可以是用户名或用户 ID,用户组可以是组名或组 ID。文件名是由空格分隔的文件列表,在文件名中可以包含通配符。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("chown [OPTION]... [OWNER][:[GROUP]] FILE...\nchown [OPTION]... --reference=RFILE FILE...\n")])])]),t("p",[a._v("在指定属主与所属用户组时有如下几种情况:\n(1)如果只指定了属主,则只改变每个给定文件的属主,不会更改文件的用户组;\n(2)如果属主后面跟一个冒号和用户组,则文件所属的用户组也将被更改;\n(3)如果用户名后面有冒号但没有组名,则该用户将成为文件的属主,并且文件属组将更改为该用户的登录组;\n(4)如果给定冒号和组名,但省略了属主,则只更改所属组。这种情况,chown 的功能等同于 chgrp;\n(5)如果只给定一个冒号,或者整个操作数为空,则属主和用户组都不会更改。")]),a._v(" "),t("p",[a._v("注意,OWNER 与 GROUP 之间的冒号可以使用点号替代。")]),a._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-c, --changes\n\t 输出效果类似 verbose 模式,但只在有更改生效时才显示。\n-f, --silent, --quiet\n\t忽略大部分错误信息。\n-v, --verbose\n\t显示指令详细的执行过程\n--dereference\n\t修改符号链接指向的实际文件的属主和所属用户组,而不是符号链接文件本身。为默认选项\n-h, --no-dereference\n\t修改符号链接文件本身的属主和所属用户组。作用与 --dereference 相反\n--from=CURRENT_OWNER:CURRENT_GROUP\n\t只有当文件的属主和所属组符合选项所指定的才更改。CURRENT_OWNER 和 CURRENT_GROUP 可以省略,这时省略的属性就不需要进行匹配\n--no-preserve-root\n\t不特殊对待根目录 /。为默认选项\n--preserve-root\n\t不允许在根目录 /上递归操作\n--reference=RFILE\n\t使用指定的文件 RFILE 的属主和所属用户组,而非指定值\n-R, --recursive\n\t递归处理所有的文件及子目录\n\t\n以下三个选项 -H、-L 和 -P 与 -R 配合使用,用于递归操作时确定遍历的方式:\n-H\n\t如果命令行参数是一个符号链接指向一个目录,则遍历它\n-L\n\t遍历每一个符号链接指向的目录\n-P\n\t不遍历任何符号链接(缺省选项)。\n\n--help\n\t显示帮助信息\n--version\n\t显示版本信息\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("(1)只修改文件属主为 root。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("chown")]),a._v(" root FILE\n")])])]),t("p",[a._v("注意,指定的属主必须是系统合法用户,可以查看文件 /etc/passwd 确定当前系统有哪些用户。")]),a._v(" "),t("p",[a._v("(2)修改文件属主和用户组均为 root。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("chown")]),a._v(" root:root FILE\n")])])]),t("p",[a._v("(3)只修改文件所属组为 root。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("chown")]),a._v(" :root FILE\n")])])]),t("p",[a._v("(4)递归修改所有的文件及子目录属主和所属组为 root。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("chown")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-R")]),a._v(" root:root /DIR\n")])])]),t("p",[a._v("(5)显示修改的动作,使用 -v 冗余模式输出。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("chown")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-vR")]),a._v(" root:root /DIR\n")])])]),t("h2",{attrs:{id:"_5-用户与组相关配置文件"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-用户与组相关配置文件"}},[a._v("#")]),a._v(" 5.用户与组相关配置文件")]),a._v(" "),t("p",[a._v("Linux 与用户和组的定义相关的配置文件有:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("/etc/passwd 用户信息\n/etc/shadow 用户口令及其相关属性\n/etc/group 用户组信息\n/etc/gshadow 用户组口令及其相关属性\n")])])]),t("h3",{attrs:{id:"etc-passwd-7-列"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#etc-passwd-7-列"}},[a._v("#")]),a._v(" /etc/passwd(7 列)")]),a._v(" "),t("p",[a._v("/etc/passwd 用来保存用户名称、ID、属组 ID、家目录等信息。")]),a._v(" "),t("p",[a._v("每行格式如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("用户名:口令:用户标识号:组标识号:注释性描述:主目录:默认Shell\n")])])]),t("p",[a._v("示例内容如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("cat /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\n...\n")])])]),t("p",[a._v("在 passwd 文件中,第一行内容是超级用户 root 行,可以看到它的 uid 和 gid 都为 0。为了方便理解,下面给出各字段的描述:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v('字段1:用户名,这是用户登录时使用的账户名称,在系统中是唯一的,不能重名\n字段2:密码占位符 x;早期的 Unix 系统中,该字段是存放账户密码的,由于安全原因,后来把这个密码字段内容移到 /etc/shadow 中了\n字段3:UID;范围是 0-65535\n字段4:用户主组的 ID,范围是 0-65535。当添加用户时,默认情况下会同时建立一个与用户同名且 GID 与 UID 相同的组。用户所属的其它用户组定义在文件 /etc/group\n字段5:用户说明;这个字段是对这个账户的说明\n字段6:宿主目录;用户登录后首先进入的目录,一般为 "/home/用户名" 这样的目录\n字段7:登录 Shell 当前用户登录后所使用的 Shell,在 Centos/RHEL 系统中,默认的 Shell 是 Bash;如果不希望用户登登系统,可以通过 usermod 或者手动修改 passwd 设置,将该字段设置为 /sbin/nologin 即可。出于安全考虑,大多数内置系统账户都是 /sbin/nologin,表示禁止登录系统\n')])])]),t("h3",{attrs:{id:"etc-shadow-9-列"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#etc-shadow-9-列"}},[a._v("#")]),a._v(" /etc/shadow(9 列)")]),a._v(" "),t("p",[a._v("/etc/shadow 用于保存加密后的用户口令相关信息,只有 root 用户拥有读写权限。")]),a._v(" "),t("p",[a._v("每行格式如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("用户名:加密口令:最后一次修改时间:最小时间间隔:最大时间间隔:警告时间:不活动时间:失效时间:保留字段\n")])])]),t("p",[a._v("示例内容如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("root:$6$25KI3rub$BK5ef2iaxtl0Jn7lofKk9xZDrOU6aamefgIDKlHUycqUvU/lF1XdcQa4Bz53vGmnTh/kV/T1DLtdIRxxVKj8M.:17403:0:99999:7:::\nbin:*:16973:0:99999:7:::\ndaemon:*:16973:0:99999:7:::\nadm:*:16973:0:99999:7:::\n...\n")])])]),t("p",[a._v("下面是每个字段的详细含义:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("第一列:用户名。与 /etc/passwd 文件中的用户名有相同的含义\n第二列:加密口令。存放的是加密后的用户口令字串,如果此字段是“*”、“!”、“x”等字符,则对应的用户不能登录系统\n第三列:最后一次修改时间。表示从某个时间起,到用户最近一次修改口令的间隔天数。可以通过 passwd 来修改用户的密码,然后查看 /etc/shadow 中此字段的变化\n第四列:最小时间间隔。 表示两次修改密码之间的最小时间间隔。\n第五列:最大时间间隔。表示两次修改密码之间的最大时间间隔,这个设置能增强管理员管理用户的时效性。\n第六列:警告时间。表示从系统开始警告用户到密码正式失效之间的天数。\n第七列:不活动时间。此字段表示用户口令作废多少天后,系统会禁用此用户,也就是说系统不再让此用户登录,也不会提示用户过期,是完全禁用。\n第八列:失效时间。表示该用户的帐号生存期,超过这个设定时间,帐号失效,用户就无法登录系统了。如果这个字段的值为空,帐号永久可用。\n第九列:保留字段: linux的保留字段,目前为空,以备linux日后发展之用。\n")])])]),t("h3",{attrs:{id:"etc-group-4-列"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#etc-group-4-列"}},[a._v("#")]),a._v(" /etc/group(4 列)")]),a._v(" "),t("p",[a._v("/etc/group 保存了用户组的相关信息。通过查询该文件,可查看某个用户属于哪些组。")]),a._v(" "),t("p",[a._v("每行格式如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("组名:口令:组标识号:组内用户列表\n")])])]),t("p",[a._v("示例内容如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("root:x:0:\nbin:x:1:\ndaemon:x:2:\n...\n")])])]),t("p",[a._v("每个字段的详细含义:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("组名:用户组的名称,由字母或数字构成。与 /etc/passwd 中的用户名一样,组名不能重复。\n口令:存放的是用户组加密后的口令字串,密码默认设置在 /etc/gshadow 文件中,而在这里用 “x” 代替,linux 系统下默认的用户组都没有口令,可以通过 gpasswd 来给用户组添加密码。\n组标识号:即 GID,与 /etc/passwd 中的组标识号对应。\n组内用户列表: 显示属于这个组的所有用户,多个用户之间用逗号分隔。\n")])])]),t("h3",{attrs:{id:"etc-gshdow-4-列"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#etc-gshdow-4-列"}},[a._v("#")]),a._v(" /etc/gshdow(4 列)")]),a._v(" "),t("p",[a._v("/etc/gshdow 保存了组密码及其相关属性。")]),a._v(" "),t("p",[a._v("每行格式如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("群组名称:群组密码:组管理员列表:以当前组为附加组的用户列表\n")])])]),t("p",[a._v("示例内容如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("root:::\nbin:::\ndaemon:::\ntcpdump:!::\nmysql:!::\n...\n")])])]),t("p",[a._v("各个字段详细含义如下:")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("组名称: 组名称,不能重复\n组密码:为空,表示只有组内用户可以获取组权限。为 ! 或者 * 表示用户无法通过组密码获取组权限\n组管理员列表: 组管理员的列表,能够更改组密码和成员\n以当前组为附加组的用户列表: 以逗号分隔的用户名列表,如果为空,表示用户名与组名相同,即该组是同名用户的主组\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/chown.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("chown(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://man7.org/linux/man-pages/man5/passwd.5.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("passwd(5) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://man7.org/linux/man-pages/man5/shadow.5.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("shadow(5) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://man7.org/linux/man-pages/man5/group.5.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("group(5) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"http://man7.org/linux/man-pages/man5/gshadow.5.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("gshadow(5) - Linux manual page -man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/98666179",target:"_blank",rel:"noopener noreferrer"}},[a._v("【Linux】一步一步学Linux——chown命令(112)"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://www.cnblogs.com/zhongguiyao/p/9165917.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("Linux系统的用户和用户组管理"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/humanking7/article/details/84001125#11__etcpasswd__17_24",target:"_blank",rel:"noopener noreferrer"}},[a._v("[Linux]用户和组相关配置文件介绍(共7个文件)"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"chown"}})],1)}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/122.05bd848b.js b/docs/assets/js/122.cc695705.js similarity index 99% rename from docs/assets/js/122.05bd848b.js rename to docs/assets/js/122.cc695705.js index dc7c29113..f9caec314 100644 --- a/docs/assets/js/122.05bd848b.js +++ b/docs/assets/js/122.cc695705.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[122],{457:function(t,a,e){"use strict";e.r(a);var s=e(12),r=Object(s.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("getfacl(get file acess control lists)获取文件访问控制列表。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("getfacl "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-aceEsRLPtpndvh"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("file"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(".\ngetfacl "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-aceEsRLPtpndvh"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" -\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-a, --access\n\t仅显示文件访问控制列表。\n-d, --default\n\t仅显示默认的访问控制列表。\n-c, --omit-header\n\t不显示注释表头。\n-e, --all-effective\n\t打印所有有效权限注释,即使与 ACL 条目定义的权限相同。\n-E, --no-effective\n\t显示无效权限。\n-s, --skip-base\n\t跳过仅包含基本 ACL 条目(owner、group 和 others)的文件。\n-R, --recursive\n\t递归显示子目录。\n-L, --logical\n\t逻辑遍历(跟随符号链接)。\n-P, --physical\n\t物理遍历(不跟随符号链接)。\n-t, --tabular\n\t使用制表符分隔的输出格式。\n-n, --numeric\n\t显示数字的用户/组标识。\n-p, --absolute-names\n\t不去除路径前的 '/' 符号。\n-v, --version\n\t显示版本并退出。\n-h, --help\n\t显示帮助信息并退出。\n--\n\t命令行选项结束符。所有剩余参数都被解释为文件名,即使它们以连字符开头。\n-\n\t如果文件名参数是单连字符,getfacl 将从标准输入读取文件列表。\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("p",[t._v("(1)获取文件访问控制列表。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("getfacl test.txt\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# file: test.txt")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# owner: root")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# group: root")]),t._v("\nuser::rw-\ngroup::r--\nother::r--\n")])])]),a("p",[t._v("文件访问控制列表默认为空,我们可以使用 setfacl 为文件设置 ACL。比如给文件 test.txt 添加针对用户 alice 的 rw 权限。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-m")]),t._v(" user:alice:rw- test.txt\n\ngetfacl test.txt\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# file: test.txt")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# owner: root")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# group: root")]),t._v("\nuser::rw-\nuser:alice:rw-\ngroup::r--\nmask::rw-\nother::r--\n")])])]),a("p",[t._v("从输出结果 user:alice:rw- 可以看出,用户 alice 对文件 test.txt 拥有了 rw 权限。")]),t._v(" "),a("p",[t._v("(2)不显示注释表头。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("getfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-c")]),t._v(" test.txt\nuser::rw-\nuser:alice:rw-\ngroup::r--\nmask::rw-\nother::r--\n")])])]),a("p",[t._v("(3)打印所有有效权限注释,即使与 ACL 条目定义的权限相同。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("getfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-e")]),t._v(" test.txt\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# file: test.txt")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# owner: root")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# group: root")]),t._v("\nuser::rw-\nuser:alice:rw-\t\t"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#effective:rw-")]),t._v("\ngroup::r--\t\t\t"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#effective:r--")]),t._v("\nmask::rw-\nother::r--\n")])])]),a("p",[t._v("(4)仅显示默认的访问控制列表。")]),t._v(" "),a("p",[t._v("默认的访问控制列表只针对目录有效。假设我们有一个名为 testdir 的目录。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("getfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-d")]),t._v(" testdir\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# file: test.txt")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# owner: root")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# group: root")]),t._v("\n")])])]),a("p",[t._v("可见目录缺省是没有默认的访问控制列表。下面通过 serfacl 命令给目录添加默认的访问控制列表。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-m")]),t._v(" d:u:alice:rwx testdir\n\ngetfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-d")]),t._v(" testdir\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# file: testdir")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# owner: root")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# group: root")]),t._v("\nuser::rwx\nuser:alice:rwx\ngroup::r-x\nmask::rwx\nother::r-x\n")])])]),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/getfacl.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("getfacl(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"getfacl"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[122],{455:function(t,a,e){"use strict";e.r(a);var s=e(12),r=Object(s.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("getfacl(get file acess control lists)获取文件访问控制列表。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("getfacl "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-aceEsRLPtpndvh"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("file"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(".\ngetfacl "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-aceEsRLPtpndvh"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" -\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-a, --access\n\t仅显示文件访问控制列表。\n-d, --default\n\t仅显示默认的访问控制列表。\n-c, --omit-header\n\t不显示注释表头。\n-e, --all-effective\n\t打印所有有效权限注释,即使与 ACL 条目定义的权限相同。\n-E, --no-effective\n\t显示无效权限。\n-s, --skip-base\n\t跳过仅包含基本 ACL 条目(owner、group 和 others)的文件。\n-R, --recursive\n\t递归显示子目录。\n-L, --logical\n\t逻辑遍历(跟随符号链接)。\n-P, --physical\n\t物理遍历(不跟随符号链接)。\n-t, --tabular\n\t使用制表符分隔的输出格式。\n-n, --numeric\n\t显示数字的用户/组标识。\n-p, --absolute-names\n\t不去除路径前的 '/' 符号。\n-v, --version\n\t显示版本并退出。\n-h, --help\n\t显示帮助信息并退出。\n--\n\t命令行选项结束符。所有剩余参数都被解释为文件名,即使它们以连字符开头。\n-\n\t如果文件名参数是单连字符,getfacl 将从标准输入读取文件列表。\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("p",[t._v("(1)获取文件访问控制列表。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("getfacl test.txt\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# file: test.txt")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# owner: root")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# group: root")]),t._v("\nuser::rw-\ngroup::r--\nother::r--\n")])])]),a("p",[t._v("文件访问控制列表默认为空,我们可以使用 setfacl 为文件设置 ACL。比如给文件 test.txt 添加针对用户 alice 的 rw 权限。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-m")]),t._v(" user:alice:rw- test.txt\n\ngetfacl test.txt\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# file: test.txt")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# owner: root")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# group: root")]),t._v("\nuser::rw-\nuser:alice:rw-\ngroup::r--\nmask::rw-\nother::r--\n")])])]),a("p",[t._v("从输出结果 user:alice:rw- 可以看出,用户 alice 对文件 test.txt 拥有了 rw 权限。")]),t._v(" "),a("p",[t._v("(2)不显示注释表头。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("getfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-c")]),t._v(" test.txt\nuser::rw-\nuser:alice:rw-\ngroup::r--\nmask::rw-\nother::r--\n")])])]),a("p",[t._v("(3)打印所有有效权限注释,即使与 ACL 条目定义的权限相同。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("getfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-e")]),t._v(" test.txt\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# file: test.txt")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# owner: root")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# group: root")]),t._v("\nuser::rw-\nuser:alice:rw-\t\t"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#effective:rw-")]),t._v("\ngroup::r--\t\t\t"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#effective:r--")]),t._v("\nmask::rw-\nother::r--\n")])])]),a("p",[t._v("(4)仅显示默认的访问控制列表。")]),t._v(" "),a("p",[t._v("默认的访问控制列表只针对目录有效。假设我们有一个名为 testdir 的目录。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("getfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-d")]),t._v(" testdir\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# file: test.txt")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# owner: root")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# group: root")]),t._v("\n")])])]),a("p",[t._v("可见目录缺省是没有默认的访问控制列表。下面通过 serfacl 命令给目录添加默认的访问控制列表。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-m")]),t._v(" d:u:alice:rwx testdir\n\ngetfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-d")]),t._v(" testdir\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# file: testdir")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# owner: root")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# group: root")]),t._v("\nuser::rwx\nuser:alice:rwx\ngroup::r-x\nmask::rwx\nother::r-x\n")])])]),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/getfacl.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("getfacl(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"getfacl"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/123.06a1a423.js b/docs/assets/js/123.4a43f0a6.js similarity index 97% rename from docs/assets/js/123.06a1a423.js rename to docs/assets/js/123.4a43f0a6.js index 215a63a7c..8f85e57d3 100644 --- a/docs/assets/js/123.06a1a423.js +++ b/docs/assets/js/123.4a43f0a6.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[123],{456:function(t,a,r){"use strict";r.r(a);var e=r(12),s=Object(e.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("lsattr 用于显示文件属性。")]),t._v(" "),a("p",[t._v("与之对应的命令是 chattr,用于改变文件属性。与 chmod 命令相比,chmod 只改变文件的读写、执行权限,更底层的属性控制是由 chattr 来改变。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("lsattr [ -RVadv ] [ files... ]\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-R\n\t递归列出子目录及其文件的属性\n-V\n\t显示lsattr版本信息\n-a\n\t显示所有隐藏的文件属性\n-d\n\t如果是目录,则只显示目录本身的属性,而非目录内的文件名\n-v\n\t显示文件版本号\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("lsattr -vV\nlsattr 1.41.12 (17-May-2010)\n18446744072009275534 --------------- ./demo\n18446744072009481631 --------------- ./inputFile.txt\n18446744072009374382 -----a--------- ./input_file.txt\n")])])]),a("p",[t._v("第一行为 lsattr 版本信息,第一列为文件版本号,最后一个文件 input_file.txt 属性 a,表示只追加属性。")]),t._v(" "),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/lsattr.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("lsattr(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/chattr.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("chattr(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"http://www.ha97.com/5172.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("(总结)Linux的chattr与lsattr命令详解"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"lsattr"}})],1)}),[],!1,null,null,null);a.default=s.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[123],{454:function(t,a,r){"use strict";r.r(a);var e=r(12),s=Object(e.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("lsattr 用于显示文件属性。")]),t._v(" "),a("p",[t._v("与之对应的命令是 chattr,用于改变文件属性。与 chmod 命令相比,chmod 只改变文件的读写、执行权限,更底层的属性控制是由 chattr 来改变。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("lsattr [ -RVadv ] [ files... ]\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-R\n\t递归列出子目录及其文件的属性\n-V\n\t显示lsattr版本信息\n-a\n\t显示所有隐藏的文件属性\n-d\n\t如果是目录,则只显示目录本身的属性,而非目录内的文件名\n-v\n\t显示文件版本号\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("lsattr -vV\nlsattr 1.41.12 (17-May-2010)\n18446744072009275534 --------------- ./demo\n18446744072009481631 --------------- ./inputFile.txt\n18446744072009374382 -----a--------- ./input_file.txt\n")])])]),a("p",[t._v("第一行为 lsattr 版本信息,第一列为文件版本号,最后一个文件 input_file.txt 属性 a,表示只追加属性。")]),t._v(" "),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/lsattr.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("lsattr(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/chattr.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("chattr(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"http://www.ha97.com/5172.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("(总结)Linux的chattr与lsattr命令详解"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"lsattr"}})],1)}),[],!1,null,null,null);a.default=s.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/124.15db04e3.js b/docs/assets/js/124.15286044.js similarity index 99% rename from docs/assets/js/124.15db04e3.js rename to docs/assets/js/124.15286044.js index 27f9790a1..b20600844 100644 --- a/docs/assets/js/124.15db04e3.js +++ b/docs/assets/js/124.15286044.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[124],{458:function(s,a,t){"use strict";t.r(a);var e=t(12),r=Object(e.a)({},(function(){var s=this,a=s._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[s._v("#")]),s._v(" 1.命令简介")]),s._v(" "),a("p",[s._v("setfacl(set file access control lists)设置文件访问控制列表。")]),s._v(" "),a("p",[s._v("setfacl 可以更精确的控制权限的分配,比如让某一个用户对某一个文件具有某种权限。")]),s._v(" "),a("p",[s._v("ACL 指文件的所有者、所属组、其他人的读/写/执行之外的特殊的权限, 对于需要特殊权限的使用状况有一定帮助。 如某一个文件,不让单一的某个用户访问。")]),s._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("-bkndRLPvh"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("-m"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("|")]),s._v("-x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("acl_spec"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("-M"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("|")]),s._v("-X"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("acl_file"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("file")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("..")]),s._v(".\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("-m, --modify=\n\t更改文件的访问控制列表。\n-M, --modify-file=\n\t从文件读取访问控制列表条目更改。\n-x, --remove=\n\t根据文件中访问控制列表移除条目。\n-X, --remove-file=\n\t从文件读取访问控制列表条目并删除。\n-b, --remove-all\n\t删除所有扩展访问控制列表条目。\n-k, --remove-default\n\t移除默认访问控制列表。\n--set=acl\n\t设定替换当前的文件访问控制列表。\n--set-file=\n\t从文件中读取访问控制列表条目设定。\n--mask\n\t重新计算有效权限掩码。\n-n, --no-mask\n\t不重新计算有效权限掩码。\n-d, --default\n\t应用到默认访问控制列表的操作。\n-R, --recursive\n\t递归操作子目录。\n-L, --logical\n\t依照系统逻辑,跟随符号链接。\n-P, --physical\n\t依照自然逻辑,不跟随符号链接。\n--restore=\n\t恢复访问控制列表,和 “getfacl -R” 作用相反。\n--test\n\t测试模式。列出 ACL,而不是更改任何文件的 ACL。\n-v, --version\n\t显示版本并退出。\n-h, --help\n\t显示本帮助信息。\n")])])]),a("h2",{attrs:{id:"_4-acl"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-acl"}},[s._v("#")]),s._v(" 4.ACL")]),s._v(" "),a("h3",{attrs:{id:"_4-1-acl-组成"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-1-acl-组成"}},[s._v("#")]),s._v(" 4.1 ACL 组成")]),s._v(" "),a("p",[s._v("ACL 是由一系列的 Access Entry 所组成的,每一条 Access Entry 定义了特定的类别可以对文件拥有的操作权限。Access Entry 有三个组成部分:")]),s._v(" "),a("ul",[a("li",[s._v("Entry tag type")]),s._v(" "),a("li",[s._v("Qualifier (optional)")]),s._v(" "),a("li",[s._v("Permission")])]),s._v(" "),a("p",[s._v("我们先来看一下最重要的 Entry tag type,它有以下几个类型:")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("ACL_USER_OBJ:相当于 Linux 里 file owner 的 permission。 \nACL_USER:定义了额外的用户可以对此文件拥有的 permission。 \nACL_GROUP_OBJ:相当于 Linux 里 group 的 permission。 \nACL_GROUP:定义了额外的组可以对此文件拥有的 permission。 \nACL_MASK:定义了 ACL_USER, ACL_GROUP_OBJ 和 ACL_GROUP 的最大权限。 \nACL_OTHER:相当于 Linux 里 other 的 permission。 \n")])])]),a("p",[s._v("首先我们还是要讲一下设置 ACL 文件的格式。")]),s._v(" "),a("p",[s._v("每一个 Access Entry 都是由三个被 : 号分隔开的字段所组成,第一个就是 Entry tag type。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("user\t对应了 ACL_USER_OBJ 和 ACL_USER\ngroup\t对应了 ACL_GROUP_OBJ 和 ACL_GROUP\nmask\t对应了 ACL_MASK\nother\t对应了 ACL_OTHER\n")])])]),a("p",[s._v("第二个字段称之为 qualifier,为用户名或组名,它定义了特定用户和组对于文件的权限。注意,只有 user 和 group 才有 qualifier,其他的都为空。")]),s._v(" "),a("p",[s._v("第三个字段就是我们熟悉的 permission 了。它和 Linux 的 permission 一样定义,这里就不多讲了。")]),s._v(" "),a("h3",{attrs:{id:"_4-2-acl-设置"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-2-acl-设置"}},[s._v("#")]),s._v(" 4.2 ACL 设置")]),s._v(" "),a("p",[s._v("下面我们就来看一下怎么设置 test.txt 这个文件的 ACL 让它来达到我们上面的要求。")]),s._v(" "),a("p",[s._v("一开始文件没有 ACL 的额外属性:")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v(" test.txt\n-rw-r--r-- "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("27")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(":37 test.txt\n\ngetfacl --omit-header test.txt\nuser::rw-\ngroup::r--\nother::r--\n")])])]),a("p",[s._v("我们先让用户 alice 拥有对 test.txt 文件的读写权限。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" user:alice:rw- ./test.txt\n")])])]),a("p",[s._v("我们再查看一下 test.txt 的 ACL。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("getfacl --omit-header ./test.txt\nuser::rw-\nuser:alice:rw-\ngroup::r--\nmask::rw-\nother::r--\n")])])]),a("p",[s._v("这时我们就可以看到 alice 用户在 ACL 里面已经拥有了对文件的读写权。这个时候如果我们查看一下 Linux 的 permission 我们还会发现一个不一样的地方。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v(" ./test.txt\n-rw-rw-r--+ "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("27")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(":37 test.txt\n")])])]),a("p",[s._v("在文件 permission 的最后多了一个 + 号,当任何一个文件拥有了 ACL_USER 或者 ACL_GROUP 的值以后我们就可以称它为 ACL 文件,这个 + 号就是用来提示我们的。我们还可以发现当一个文件拥有了 ACL_USER 或者 ACL_GROUP 的值时 ACL_MASK 同时也会被定义。")]),s._v(" "),a("p",[s._v("接下来我们来设置 alice 组拥有 read permission:")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" group:alice:r-- ./test.txt\n\ngetfacl --omit-header ./test.txt\nuser::rw-\nuser:alice:rw-\ngroup::r--\ngroup:alice:r--\nmask::rw-\nother::r--\n")])])]),a("h3",{attrs:{id:"_4-3-acl-mask-和-effective-permission"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-3-acl-mask-和-effective-permission"}},[s._v("#")]),s._v(" 4.3 ACL_MASK 和 Effective permission")]),s._v(" "),a("p",[s._v("这里需要重点讲一下 ACL_MASK,因为这是掌握 ACL 的另一个关键,在 Linux file permission 里面大家都知道比如对于"),a("code",[s._v("rw-rw-r--")]),s._v("来说, 当中的那个"),a("code",[s._v("rw-")]),s._v("是指文件组的permission。但是在 ACL 里面这种情况只是在 ACL_MASK 不存在的情况下成立。如果文件有 ACL_MASK 值,那么当中那个"),a("code",[s._v("rw-")]),s._v("代表的就是 mask 值而不再是 group permission了。")]),s._v(" "),a("p",[s._v("让我们来看下面这个例子:")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v("\n-rwxrw-r-- "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root admin "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Jul "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("23")]),s._v(":10 test.sh\n")])])]),a("p",[s._v("这里说明 test.sh 文件只有文件属主 root 拥有 rwx 权限。admin 组只有 rw 权限。现在我们想让用户 alice 也对 test.sh 具有和 root 一样的 permission。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" user:alice:rwx ./test.sh\n\ngetfacl --omit-header ./test.sh\nuser::rwx user:alice:rwx\ngroup::rw-\nmask::rwx\nother::r--\n")])])]),a("p",[s._v("这里我们看到 alice 已经拥有了 rwx 权限,mask 值也被设定为 rwx,那是因为它规定了 ACL_USER,ACL_GROUP 和 ACL_GROUP_OBJ 的最大值。现在我们再来看 test.sh 的 Linux permission,它已经变成了:")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v("\n-rwxrwxr--+ "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root admin "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Jul "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("23")]),s._v(":10 test.sh\n")])])]),a("p",[s._v("那么如果现在 admin 组的用户想要执行 test.sh 的程序会发生什么情况呢?它会被permission deny。原因在于实际上 admin 组的用户只有 rw 权限,这里当中显示的 rwx 是ACL_MASK 的值而不是 group 的 permission。")]),s._v(" "),a("p",[s._v("所以从这里我们就可以知道,如果一个文件后面有 + 标记,我们都需要用 getfacl 来确认它的 permission,以免发生混淆。")]),s._v(" "),a("p",[s._v("下面我们再来继续看一个例子,假如现在我们设置 test.sh 的 mask 为 read only,那么 admin 组的用户还会有 write permission 吗?")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" mask::r-- ./test.sh\n\ngetfacl --omit-header ./test.sh\nuser::rwx\nuser:alice:rwx "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("#effective:r--")]),s._v("\ngroup::rw- "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("#effective:r--")]),s._v("\nmask::r--\nother::r--\n")])])]),a("p",[s._v("这时候我们可以看到 ACL_USER 和 ACL_GROUP_OBJ 旁边多了个"),a("code",[s._v("#effective:r–")]),s._v(",这是什么意思呢?")]),s._v(" "),a("p",[s._v("让我们再来回顾一下 ACL_MASK 的定义。它规定了 ACL_USER,ACL_GROUP_OBJ 和 ACL_GROUP 的最大权限。那么在我们这个例子中他们的最大权限也就是 read only。虽然我们这里给 ACL_USER 和 ACL_GROUP_OBJ 设置了其他权限,但是他们真正有效果的只有 read 权限。")]),s._v(" "),a("p",[s._v("这时我们再来查看 test.sh 的 Linux file permission 时它的 group permission 也会显示其 mask 的值 r--。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v("\n-rwxr--r--+ "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root admin "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Jul "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("23")]),s._v(":10 test.sh\n")])])]),a("h3",{attrs:{id:"_4-4-default-acl"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-4-default-acl"}},[s._v("#")]),s._v(" 4.4 Default ACL")]),s._v(" "),a("p",[s._v("上面我们所有讲的都是 Access ACL,也就是对文件而言。下面简单讲一下 Default ACL。")]),s._v(" "),a("p",[s._v("Default ACL 是指对于一个目录进行 Default ACL 设置,并且在此目录下建立的文件都将继承此目录的 ACL。")]),s._v(" "),a("p",[s._v("同样我们来做一个试验说明,比如现在 root 用户建立了一个 dir 目录:")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("mkdir")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("dir")]),s._v("\n")])])]),a("p",[s._v("他希望所有在此目录下建立的文件都可以被 alice 用户所访问,那么我们就应该对 dir 目录设置 Default ACL。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-d")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" user:alice:rw ./dir\n\ngetfacl --omit-header ./dir\nuser::rwx\ngroup::rwx\nother::r-x\ndefault:user::rwx\ndefault:user:alice:rwx\ndefault:group::rwx\ndefault:mask::rwx\ndefault: other::r-x\n")])])]),a("p",[s._v("这里我们可以看到 ACL 定义了 default 选项,alice 用户拥有了 default 的 rwx 权限。所有没有定义的 default 都将从 file permission 里 copy 过来。现在 root 用户在 dir 下建立一个 test.txt 文件。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("touch")]),s._v(" ./dir/test.txt\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v(" ./dir/test.txt\n-rw-rw-r--+ "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Jul "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("23")]),s._v(":46 ./dir/test.txt\n\ngetfacl --omit-header ./dir/test.txt\nuser::rw-\nuser:alice:rw-\ngroup::rwx "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("#effective:rw-")]),s._v("\nmask::rw-\nother::r--\n")])])]),a("p",[s._v("这里我们看到在 dir 下建立的文件 alice 用户自动就有了 rw 权限。")]),s._v(" "),a("h3",{attrs:{id:"_4-5-acl-相关命令"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-5-acl-相关命令"}},[s._v("#")]),s._v(" 4.5 ACL 相关命令")]),s._v(" "),a("p",[s._v("前面的例子中我们都注意到了 getfacl 命令是用来读取文件的 ACL,setfacl 是用来设定文件的 Acess ACL。这里还有一个 chacl 是用来改变文件和目录的 Access ACL and Default ACL,它的具体参数大家可以去看 man page。我只想提及一下 chacl -B。它可以彻底删除文件或者目录的 ACL 属性(包括 Default ACL),比如你即使用了 setfacl -x 删除了所有文件的 ACL 属性,那个 + 号还是会出现在文件的末尾,所以正确的删除方法应该是用chacl -B用cp来复制文件的时候我们现在可以加上-p选项。这样在拷贝文件的时候也将拷贝文件的 ACL 属性,对于不能拷贝的 ACL 属性将给出警告。")]),s._v(" "),a("p",[s._v("mv 命令将会默认地移动文件的 ACL 属性,同样如果操作不允许的情况下会给出警告。")]),s._v(" "),a("h2",{attrs:{id:"_5-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_5-常用示例"}},[s._v("#")]),s._v(" 5.常用示例")]),s._v(" "),a("p",[s._v("(1)修改一个文件的 ACL 权限。")]),s._v(" "),a("ul",[a("li",[s._v("比如给一个用户 alice 添加对文件 test 的 rw 权限。")])]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" user:alice:rw- "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("test")]),s._v("\n")])])]),a("ul",[a("li",[s._v("比如给一个用户组 alice 添加对文件 test 的 rw 权限。")])]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" group:alice:rw- "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("test")]),s._v("\n")])])]),a("p",[s._v("(2)设置目录的默认 ACL 权限。")]),s._v(" "),a("p",[s._v("默认的访问控制列表只针对目录有效。假设我们有一个名为 testdir 的目录。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" d:u:alice:rwx testdir\n")])])]),a("p",[s._v("一个目录设置过递归 ACL 权限后,假如又添加了些新文件,那么这个默认 ACL 权限就会把新添的文件全部继承这个目录的 ACL 权限。")]),s._v(" "),a("p",[s._v("(3)清除指定用户对文件的 ACL 规则。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-x")]),s._v(" u:alice "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("test")]),s._v("\n")])])]),a("p",[s._v("(4)清除指定用户组对文件的 ACL 规则。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-x")]),s._v(" g:alice "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("test")]),s._v("\n")])])]),a("p",[s._v("(5)清除文件的所有 ACL。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-b")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("test")]),s._v("\n")])])]),a("hr"),s._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/setfacl.1.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("setfacl(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),s._v(" "),a("p",[a("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/98896132",target:"_blank",rel:"noopener noreferrer"}},[s._v("【Linux】一步一步学Linux——setfacl命令(117)"),a("OutboundLink")],1)]),s._v(" "),a("Vssue",{attrs:{title:"setfacl"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[124],{456:function(s,a,t){"use strict";t.r(a);var e=t(12),r=Object(e.a)({},(function(){var s=this,a=s._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[s._v("#")]),s._v(" 1.命令简介")]),s._v(" "),a("p",[s._v("setfacl(set file access control lists)设置文件访问控制列表。")]),s._v(" "),a("p",[s._v("setfacl 可以更精确的控制权限的分配,比如让某一个用户对某一个文件具有某种权限。")]),s._v(" "),a("p",[s._v("ACL 指文件的所有者、所属组、其他人的读/写/执行之外的特殊的权限, 对于需要特殊权限的使用状况有一定帮助。 如某一个文件,不让单一的某个用户访问。")]),s._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("-bkndRLPvh"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("-m"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("|")]),s._v("-x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("acl_spec"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("-M"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("|")]),s._v("-X"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("acl_file"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("file")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("..")]),s._v(".\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("-m, --modify=\n\t更改文件的访问控制列表。\n-M, --modify-file=\n\t从文件读取访问控制列表条目更改。\n-x, --remove=\n\t根据文件中访问控制列表移除条目。\n-X, --remove-file=\n\t从文件读取访问控制列表条目并删除。\n-b, --remove-all\n\t删除所有扩展访问控制列表条目。\n-k, --remove-default\n\t移除默认访问控制列表。\n--set=acl\n\t设定替换当前的文件访问控制列表。\n--set-file=\n\t从文件中读取访问控制列表条目设定。\n--mask\n\t重新计算有效权限掩码。\n-n, --no-mask\n\t不重新计算有效权限掩码。\n-d, --default\n\t应用到默认访问控制列表的操作。\n-R, --recursive\n\t递归操作子目录。\n-L, --logical\n\t依照系统逻辑,跟随符号链接。\n-P, --physical\n\t依照自然逻辑,不跟随符号链接。\n--restore=\n\t恢复访问控制列表,和 “getfacl -R” 作用相反。\n--test\n\t测试模式。列出 ACL,而不是更改任何文件的 ACL。\n-v, --version\n\t显示版本并退出。\n-h, --help\n\t显示本帮助信息。\n")])])]),a("h2",{attrs:{id:"_4-acl"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-acl"}},[s._v("#")]),s._v(" 4.ACL")]),s._v(" "),a("h3",{attrs:{id:"_4-1-acl-组成"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-1-acl-组成"}},[s._v("#")]),s._v(" 4.1 ACL 组成")]),s._v(" "),a("p",[s._v("ACL 是由一系列的 Access Entry 所组成的,每一条 Access Entry 定义了特定的类别可以对文件拥有的操作权限。Access Entry 有三个组成部分:")]),s._v(" "),a("ul",[a("li",[s._v("Entry tag type")]),s._v(" "),a("li",[s._v("Qualifier (optional)")]),s._v(" "),a("li",[s._v("Permission")])]),s._v(" "),a("p",[s._v("我们先来看一下最重要的 Entry tag type,它有以下几个类型:")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("ACL_USER_OBJ:相当于 Linux 里 file owner 的 permission。 \nACL_USER:定义了额外的用户可以对此文件拥有的 permission。 \nACL_GROUP_OBJ:相当于 Linux 里 group 的 permission。 \nACL_GROUP:定义了额外的组可以对此文件拥有的 permission。 \nACL_MASK:定义了 ACL_USER, ACL_GROUP_OBJ 和 ACL_GROUP 的最大权限。 \nACL_OTHER:相当于 Linux 里 other 的 permission。 \n")])])]),a("p",[s._v("首先我们还是要讲一下设置 ACL 文件的格式。")]),s._v(" "),a("p",[s._v("每一个 Access Entry 都是由三个被 : 号分隔开的字段所组成,第一个就是 Entry tag type。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("user\t对应了 ACL_USER_OBJ 和 ACL_USER\ngroup\t对应了 ACL_GROUP_OBJ 和 ACL_GROUP\nmask\t对应了 ACL_MASK\nother\t对应了 ACL_OTHER\n")])])]),a("p",[s._v("第二个字段称之为 qualifier,为用户名或组名,它定义了特定用户和组对于文件的权限。注意,只有 user 和 group 才有 qualifier,其他的都为空。")]),s._v(" "),a("p",[s._v("第三个字段就是我们熟悉的 permission 了。它和 Linux 的 permission 一样定义,这里就不多讲了。")]),s._v(" "),a("h3",{attrs:{id:"_4-2-acl-设置"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-2-acl-设置"}},[s._v("#")]),s._v(" 4.2 ACL 设置")]),s._v(" "),a("p",[s._v("下面我们就来看一下怎么设置 test.txt 这个文件的 ACL 让它来达到我们上面的要求。")]),s._v(" "),a("p",[s._v("一开始文件没有 ACL 的额外属性:")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v(" test.txt\n-rw-r--r-- "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("27")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(":37 test.txt\n\ngetfacl --omit-header test.txt\nuser::rw-\ngroup::r--\nother::r--\n")])])]),a("p",[s._v("我们先让用户 alice 拥有对 test.txt 文件的读写权限。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" user:alice:rw- ./test.txt\n")])])]),a("p",[s._v("我们再查看一下 test.txt 的 ACL。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("getfacl --omit-header ./test.txt\nuser::rw-\nuser:alice:rw-\ngroup::r--\nmask::rw-\nother::r--\n")])])]),a("p",[s._v("这时我们就可以看到 alice 用户在 ACL 里面已经拥有了对文件的读写权。这个时候如果我们查看一下 Linux 的 permission 我们还会发现一个不一样的地方。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v(" ./test.txt\n-rw-rw-r--+ "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Oct "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("27")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(":37 test.txt\n")])])]),a("p",[s._v("在文件 permission 的最后多了一个 + 号,当任何一个文件拥有了 ACL_USER 或者 ACL_GROUP 的值以后我们就可以称它为 ACL 文件,这个 + 号就是用来提示我们的。我们还可以发现当一个文件拥有了 ACL_USER 或者 ACL_GROUP 的值时 ACL_MASK 同时也会被定义。")]),s._v(" "),a("p",[s._v("接下来我们来设置 alice 组拥有 read permission:")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" group:alice:r-- ./test.txt\n\ngetfacl --omit-header ./test.txt\nuser::rw-\nuser:alice:rw-\ngroup::r--\ngroup:alice:r--\nmask::rw-\nother::r--\n")])])]),a("h3",{attrs:{id:"_4-3-acl-mask-和-effective-permission"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-3-acl-mask-和-effective-permission"}},[s._v("#")]),s._v(" 4.3 ACL_MASK 和 Effective permission")]),s._v(" "),a("p",[s._v("这里需要重点讲一下 ACL_MASK,因为这是掌握 ACL 的另一个关键,在 Linux file permission 里面大家都知道比如对于"),a("code",[s._v("rw-rw-r--")]),s._v("来说, 当中的那个"),a("code",[s._v("rw-")]),s._v("是指文件组的permission。但是在 ACL 里面这种情况只是在 ACL_MASK 不存在的情况下成立。如果文件有 ACL_MASK 值,那么当中那个"),a("code",[s._v("rw-")]),s._v("代表的就是 mask 值而不再是 group permission了。")]),s._v(" "),a("p",[s._v("让我们来看下面这个例子:")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v("\n-rwxrw-r-- "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root admin "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Jul "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("23")]),s._v(":10 test.sh\n")])])]),a("p",[s._v("这里说明 test.sh 文件只有文件属主 root 拥有 rwx 权限。admin 组只有 rw 权限。现在我们想让用户 alice 也对 test.sh 具有和 root 一样的 permission。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" user:alice:rwx ./test.sh\n\ngetfacl --omit-header ./test.sh\nuser::rwx user:alice:rwx\ngroup::rw-\nmask::rwx\nother::r--\n")])])]),a("p",[s._v("这里我们看到 alice 已经拥有了 rwx 权限,mask 值也被设定为 rwx,那是因为它规定了 ACL_USER,ACL_GROUP 和 ACL_GROUP_OBJ 的最大值。现在我们再来看 test.sh 的 Linux permission,它已经变成了:")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v("\n-rwxrwxr--+ "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root admin "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Jul "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("23")]),s._v(":10 test.sh\n")])])]),a("p",[s._v("那么如果现在 admin 组的用户想要执行 test.sh 的程序会发生什么情况呢?它会被permission deny。原因在于实际上 admin 组的用户只有 rw 权限,这里当中显示的 rwx 是ACL_MASK 的值而不是 group 的 permission。")]),s._v(" "),a("p",[s._v("所以从这里我们就可以知道,如果一个文件后面有 + 标记,我们都需要用 getfacl 来确认它的 permission,以免发生混淆。")]),s._v(" "),a("p",[s._v("下面我们再来继续看一个例子,假如现在我们设置 test.sh 的 mask 为 read only,那么 admin 组的用户还会有 write permission 吗?")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" mask::r-- ./test.sh\n\ngetfacl --omit-header ./test.sh\nuser::rwx\nuser:alice:rwx "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("#effective:r--")]),s._v("\ngroup::rw- "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("#effective:r--")]),s._v("\nmask::r--\nother::r--\n")])])]),a("p",[s._v("这时候我们可以看到 ACL_USER 和 ACL_GROUP_OBJ 旁边多了个"),a("code",[s._v("#effective:r–")]),s._v(",这是什么意思呢?")]),s._v(" "),a("p",[s._v("让我们再来回顾一下 ACL_MASK 的定义。它规定了 ACL_USER,ACL_GROUP_OBJ 和 ACL_GROUP 的最大权限。那么在我们这个例子中他们的最大权限也就是 read only。虽然我们这里给 ACL_USER 和 ACL_GROUP_OBJ 设置了其他权限,但是他们真正有效果的只有 read 权限。")]),s._v(" "),a("p",[s._v("这时我们再来查看 test.sh 的 Linux file permission 时它的 group permission 也会显示其 mask 的值 r--。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v("\n-rwxr--r--+ "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root admin "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Jul "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("23")]),s._v(":10 test.sh\n")])])]),a("h3",{attrs:{id:"_4-4-default-acl"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-4-default-acl"}},[s._v("#")]),s._v(" 4.4 Default ACL")]),s._v(" "),a("p",[s._v("上面我们所有讲的都是 Access ACL,也就是对文件而言。下面简单讲一下 Default ACL。")]),s._v(" "),a("p",[s._v("Default ACL 是指对于一个目录进行 Default ACL 设置,并且在此目录下建立的文件都将继承此目录的 ACL。")]),s._v(" "),a("p",[s._v("同样我们来做一个试验说明,比如现在 root 用户建立了一个 dir 目录:")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("mkdir")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("dir")]),s._v("\n")])])]),a("p",[s._v("他希望所有在此目录下建立的文件都可以被 alice 用户所访问,那么我们就应该对 dir 目录设置 Default ACL。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-d")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" user:alice:rw ./dir\n\ngetfacl --omit-header ./dir\nuser::rwx\ngroup::rwx\nother::r-x\ndefault:user::rwx\ndefault:user:alice:rwx\ndefault:group::rwx\ndefault:mask::rwx\ndefault: other::r-x\n")])])]),a("p",[s._v("这里我们可以看到 ACL 定义了 default 选项,alice 用户拥有了 default 的 rwx 权限。所有没有定义的 default 都将从 file permission 里 copy 过来。现在 root 用户在 dir 下建立一个 test.txt 文件。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("touch")]),s._v(" ./dir/test.txt\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v(" ./dir/test.txt\n-rw-rw-r--+ "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" Jul "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("23")]),s._v(":46 ./dir/test.txt\n\ngetfacl --omit-header ./dir/test.txt\nuser::rw-\nuser:alice:rw-\ngroup::rwx "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("#effective:rw-")]),s._v("\nmask::rw-\nother::r--\n")])])]),a("p",[s._v("这里我们看到在 dir 下建立的文件 alice 用户自动就有了 rw 权限。")]),s._v(" "),a("h3",{attrs:{id:"_4-5-acl-相关命令"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-5-acl-相关命令"}},[s._v("#")]),s._v(" 4.5 ACL 相关命令")]),s._v(" "),a("p",[s._v("前面的例子中我们都注意到了 getfacl 命令是用来读取文件的 ACL,setfacl 是用来设定文件的 Acess ACL。这里还有一个 chacl 是用来改变文件和目录的 Access ACL and Default ACL,它的具体参数大家可以去看 man page。我只想提及一下 chacl -B。它可以彻底删除文件或者目录的 ACL 属性(包括 Default ACL),比如你即使用了 setfacl -x 删除了所有文件的 ACL 属性,那个 + 号还是会出现在文件的末尾,所以正确的删除方法应该是用chacl -B用cp来复制文件的时候我们现在可以加上-p选项。这样在拷贝文件的时候也将拷贝文件的 ACL 属性,对于不能拷贝的 ACL 属性将给出警告。")]),s._v(" "),a("p",[s._v("mv 命令将会默认地移动文件的 ACL 属性,同样如果操作不允许的情况下会给出警告。")]),s._v(" "),a("h2",{attrs:{id:"_5-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_5-常用示例"}},[s._v("#")]),s._v(" 5.常用示例")]),s._v(" "),a("p",[s._v("(1)修改一个文件的 ACL 权限。")]),s._v(" "),a("ul",[a("li",[s._v("比如给一个用户 alice 添加对文件 test 的 rw 权限。")])]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" user:alice:rw- "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("test")]),s._v("\n")])])]),a("ul",[a("li",[s._v("比如给一个用户组 alice 添加对文件 test 的 rw 权限。")])]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" group:alice:rw- "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("test")]),s._v("\n")])])]),a("p",[s._v("(2)设置目录的默认 ACL 权限。")]),s._v(" "),a("p",[s._v("默认的访问控制列表只针对目录有效。假设我们有一个名为 testdir 的目录。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" d:u:alice:rwx testdir\n")])])]),a("p",[s._v("一个目录设置过递归 ACL 权限后,假如又添加了些新文件,那么这个默认 ACL 权限就会把新添的文件全部继承这个目录的 ACL 权限。")]),s._v(" "),a("p",[s._v("(3)清除指定用户对文件的 ACL 规则。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-x")]),s._v(" u:alice "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("test")]),s._v("\n")])])]),a("p",[s._v("(4)清除指定用户组对文件的 ACL 规则。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-x")]),s._v(" g:alice "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("test")]),s._v("\n")])])]),a("p",[s._v("(5)清除文件的所有 ACL。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("setfacl "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-b")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("test")]),s._v("\n")])])]),a("hr"),s._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/setfacl.1.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("setfacl(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),s._v(" "),a("p",[a("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/98896132",target:"_blank",rel:"noopener noreferrer"}},[s._v("【Linux】一步一步学Linux——setfacl命令(117)"),a("OutboundLink")],1)]),s._v(" "),a("Vssue",{attrs:{title:"setfacl"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/125.65fa3d3b.js b/docs/assets/js/125.dae362bc.js similarity index 98% rename from docs/assets/js/125.65fa3d3b.js rename to docs/assets/js/125.dae362bc.js index 464c50773..48668ed14 100644 --- a/docs/assets/js/125.65fa3d3b.js +++ b/docs/assets/js/125.dae362bc.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[125],{460:function(s,a,t){"use strict";t.r(a);var e=t(12),r=Object(e.a)({},(function(){var s=this,a=s._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[s._v("#")]),s._v(" 1.命令简介")]),s._v(" "),a("p",[s._v("su 用于临时切换身份到另一个指定的用户,未指定用户名默认为 root。")]),s._v(" "),a("p",[s._v("使用 su 切换用户身份后,默认情况下不改变当前工作目录,但会改变 HOME、SHELL、USER、LOGNAME 等 Shell 的环境变量。")]),s._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("su [OPTIONS] [-] [USER [ARG...]]\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("-c, --command=CMD\n\t执行完指定命令后,立即恢复原来的用户身份\n--session-command=CMD\n\t等同于选项 -c,但不创建新会话\n-, -l, --login\n\t切换用户身份时启动一个新的 Shell。此选项可同时改变工作目录和 HOME、SHELL、USER、LOGNAME 等环境变量,也包括环境变量 PATH\n-f, --fast\n\t不必读启动文件(如 csh.cshrc 等),仅用于 csh 或 tcsh 两种 Shell\n-m, --preserve-environment\n\t保留原用户的 Shell 环境变量\n-p\n\t同 -m\n-s, --shell=SHELL\n\t指定使用的 Shell\n-h, --help\n\t显示帮助信息并退出\n-v, --version\n\t显示版本信息并退出\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[s._v("#")]),s._v(" 4.常用示例")]),s._v(" "),a("p",[s._v("(1)不指定目标用户,缺省切换到 root。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("su")]),s._v("\n")])])]),a("p",[s._v("(2)切换到指定的用户。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("su")]),s._v(" foo\n")])])]),a("p",[s._v("(3)切换用户身份时同时切换 Shell 环境。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("su")]),s._v(" - root\n")])])]),a("p",[s._v("(4)切换用户后执行指定命令,执行后返回原用户。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("su")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-c")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" root\n")])])]),a("h2",{attrs:{id:"_5-su-和-sudo-命令的区别"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_5-su-和-sudo-命令的区别"}},[s._v("#")]),s._v(" 5.su 和 sudo 命令的区别")]),s._v(" "),a("p",[s._v("su 用来长时间切换用户,常见用法是"),a("code",[s._v("su USERNAME")]),s._v(",未指定 USERNAME 默认切换至 root。")]),s._v(" "),a("p",[s._v("sudo 允许被授权的用户以其他用户或者管理员身份来执行命令,可以使用 -u 选项来指明需要使用的用户身份,默认是 root。sudo 使一般用户不需要知道超级用户的密码即可获得权限。首先超级用户将普通用户的名字、可以执行的特定命令、按照哪种用户或用户组的身份执行等信息,登记在特殊的文件中(通常是 /etc/sudoers),即完成对该用户的授权(此时该用户称为 sudoer)。若其未经授权的用户企图使用 sudo,则会发出警告的邮件给管理员。用户使用 sudo 时,必须先输入当前用户密码,如果当前用户是 root 或者当前用户与目标用户一致,无需输入密码,之后的一段时间内(默认为 5 分钟,可在 /etc/sudoers 配置),使用 sudo 不需要再次输入密码。")]),s._v(" "),a("hr"),s._v(" "),a("h1",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),a("p",[a("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/su.1.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("su(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),s._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/sudo.8.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("sudo(8) - Linux manual page - man7.org"),a("OutboundLink")],1)]),s._v(" "),a("Vssue",{attrs:{title:"su"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[125],{458:function(s,a,t){"use strict";t.r(a);var e=t(12),r=Object(e.a)({},(function(){var s=this,a=s._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[s._v("#")]),s._v(" 1.命令简介")]),s._v(" "),a("p",[s._v("su 用于临时切换身份到另一个指定的用户,未指定用户名默认为 root。")]),s._v(" "),a("p",[s._v("使用 su 切换用户身份后,默认情况下不改变当前工作目录,但会改变 HOME、SHELL、USER、LOGNAME 等 Shell 的环境变量。")]),s._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("su [OPTIONS] [-] [USER [ARG...]]\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("-c, --command=CMD\n\t执行完指定命令后,立即恢复原来的用户身份\n--session-command=CMD\n\t等同于选项 -c,但不创建新会话\n-, -l, --login\n\t切换用户身份时启动一个新的 Shell。此选项可同时改变工作目录和 HOME、SHELL、USER、LOGNAME 等环境变量,也包括环境变量 PATH\n-f, --fast\n\t不必读启动文件(如 csh.cshrc 等),仅用于 csh 或 tcsh 两种 Shell\n-m, --preserve-environment\n\t保留原用户的 Shell 环境变量\n-p\n\t同 -m\n-s, --shell=SHELL\n\t指定使用的 Shell\n-h, --help\n\t显示帮助信息并退出\n-v, --version\n\t显示版本信息并退出\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[s._v("#")]),s._v(" 4.常用示例")]),s._v(" "),a("p",[s._v("(1)不指定目标用户,缺省切换到 root。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("su")]),s._v("\n")])])]),a("p",[s._v("(2)切换到指定的用户。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("su")]),s._v(" foo\n")])])]),a("p",[s._v("(3)切换用户身份时同时切换 Shell 环境。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("su")]),s._v(" - root\n")])])]),a("p",[s._v("(4)切换用户后执行指定命令,执行后返回原用户。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("su")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-c")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" root\n")])])]),a("h2",{attrs:{id:"_5-su-和-sudo-命令的区别"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_5-su-和-sudo-命令的区别"}},[s._v("#")]),s._v(" 5.su 和 sudo 命令的区别")]),s._v(" "),a("p",[s._v("su 用来长时间切换用户,常见用法是"),a("code",[s._v("su USERNAME")]),s._v(",未指定 USERNAME 默认切换至 root。")]),s._v(" "),a("p",[s._v("sudo 允许被授权的用户以其他用户或者管理员身份来执行命令,可以使用 -u 选项来指明需要使用的用户身份,默认是 root。sudo 使一般用户不需要知道超级用户的密码即可获得权限。首先超级用户将普通用户的名字、可以执行的特定命令、按照哪种用户或用户组的身份执行等信息,登记在特殊的文件中(通常是 /etc/sudoers),即完成对该用户的授权(此时该用户称为 sudoer)。若其未经授权的用户企图使用 sudo,则会发出警告的邮件给管理员。用户使用 sudo 时,必须先输入当前用户密码,如果当前用户是 root 或者当前用户与目标用户一致,无需输入密码,之后的一段时间内(默认为 5 分钟,可在 /etc/sudoers 配置),使用 sudo 不需要再次输入密码。")]),s._v(" "),a("hr"),s._v(" "),a("h1",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),a("p",[a("a",{attrs:{href:"http://man7.org/linux/man-pages/man1/su.1.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("su(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),s._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/sudo.8.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("sudo(8) - Linux manual page - man7.org"),a("OutboundLink")],1)]),s._v(" "),a("Vssue",{attrs:{title:"su"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/126.f92f3a36.js b/docs/assets/js/126.25f9c22e.js similarity index 99% rename from docs/assets/js/126.f92f3a36.js rename to docs/assets/js/126.25f9c22e.js index cc556b1e4..c2f68a800 100644 --- a/docs/assets/js/126.f92f3a36.js +++ b/docs/assets/js/126.25f9c22e.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[126],{459:function(s,t,a){"use strict";a.r(t);var n=a(12),e=Object(n.a)({},(function(){var s=this,t=s._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[s._v("#")]),s._v(" 1.命令简介")]),s._v(" "),t("p",[s._v("sudo 可以用指定的用户身份执行指定的指令,而无需输入指定用户的密码,只需要输入当前用户的密码。未指定用户名默认为 root。")]),s._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("sudo [OPTIONS] [CMD]\n")])])]),t("p",[s._v("没有选项与命令单独执行 sudo,将列出 sudo 简要使用方法。")]),s._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("-A\n\t使用辅助程序(可能是图形化界面的程序)读取用户的密码并将密码输出到标准输出。如果设置了环境变量 SUDO_ASKPASS,它会指定辅助程序的路径,否则,由配置文件 /etc/sudo.conf 的 askpass 选项来指定辅助程序的路径。如果没有可用的辅助程序,sudo 将错误退出\n-b\n\t选项 -b(background)把 sudo 所要运行的命令放到后台运行\n-E\n\t选项 -E(preserve Environment)向安全策略指示用户希望保存他们现有的环境变量。如果指定了 -E 选项,且用户没有保留环境变量的权限,则安全策略可能返回错误\n-H\n\t选项 -H(Home)将 HOME 环境变量设置为目标用户的家目录,目标用户默认为 root\n-h\n\t选项 -h(help)显示帮助信息并退出\n-i [CMD]\n\t选项 -i(simulate initial login)将模拟初始登录,即启动目标用户在 /etc/passwd 中配置的 Shell,相关的资源文件将被读取并执行,比如 ~/.profile 和 ~/.login。如果后跟命令 CMD,则 CMD 将被传递给 Shell 并被执行\n-K\n\t选项 -K(sure Kill)类似于 -k,它只用于删除了用户的缓存凭据,不能与命令或其他选项一起使用\n-k [CMD]\n\t单独使用 -k(kill)选项时,使密码缓存失效,也就是下次执行 sudo 时需要输入密码。如果后跟命令,表示忽略缓存密码,需要用户重新输入密码 ,新输入的密码不会更新密码缓存\n-l[l] [CMD]\n\t如果选项 -l(list)后不跟命令,则列出 sudo 允许当前用户(或使用 -U 指定的其他用户)执行的指令和无法执行的指令。如果指定了命令并被安全策略所允许,则将显示该命令绝对路径以及命令参数。如果指定了命令不被允许,sudo 以状态码 1 退出。如果使用 -ll 或多次指定 -l 选项,则使用长格式输出\n-n\n\t选项 -n(non-interactive)表示以非交互模式执行 sudo,阻止 sudo 向用户询问密码。如果执行命令时需要密码,则 sudo 将报错误信息并退出\n-p PROMPT\n\t改变询问密码的提示符号\n-s [CMD]\n\t选项 -s(shell)执行环境变量 SHELL 表示的 Shell,如果 SHELL 没有值,则执行目标用户在配置文件 /etc/passwd 中配置的 Shell。如果选项后跟命令,则传递给 Shell 执行,如果没有指定命令,则执行交互式 Shell\n-U USER\n\t选项 -U(other user)与 -l 选项一起使用,以指定应列出其权限的用户。sudoers 策略仅允许 root 用户或当前主机上具有 ALL 权限的用户使用此选项\n-u USER\n\t选项 -u(user)指定执行命令时使用的用户身份,默认为 root。如果使用 uid 则使用 #uid 表示用户\n-V, --version\n\t显示版本信息并退出。\n-v, --validate\n\t更新用户的缓存凭据,使密码有效期延长 5 分钟。\n")])])]),t("p",[t("strong",[s._v("注意:")]),s._v("\nsudo 运行时要参照配置文件 /etc/sudousers ,该文件配置了用户能够执行的命令。")]),s._v(" "),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[s._v("#")]),s._v(" 4.常用示例")]),s._v(" "),t("p",[s._v("(1)查看此当前用户拥有的权限。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("sudo")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v("\nMatching Defaults entries "),t("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" lvlv on jumper02:\n env_reset, mail_badpass, "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("secure_path")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("/usr/local/sbin"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("\\")]),s._v(":/usr/local/bin"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("\\")]),s._v(":/usr/sbin"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("\\")]),s._v(":/usr/bin"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("\\")]),s._v(":/sbin"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("\\")]),s._v(":/bin"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("\\")]),s._v(":/snap/bin\n\nUser lvlv may run the following commands on jumper02:\n "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("ALL"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" NOPASSWD: ALL\n")])])]),t("p",[s._v("(2)以指定用户身份执行命令。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("sudo")]),s._v(" –u USERNAME CMD\n")])])]),t("p",[s._v("(3)结束密码有效期,也就是下次执行 sudo 时需要输入密码。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("sudo")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-k")]),s._v("\n")])])]),t("p",[s._v("(4)以指定用户创建一个文件,缺省为 root 用户。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("sudo")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("touch")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("file")]),s._v("\n\n"),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("file")]),s._v("\n-rw-r--r-- "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("5")]),s._v("月 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("14")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("19")]),s._v(":10 "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("file")]),s._v("\n")])])]),t("p",[s._v("(5)显示版本信息并退出。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("sudo")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-V")]),s._v("\nSudo version "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1.8")]),s._v(".21p2\nSudoers policy plugin version "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1.8")]),s._v(".21p2\nSudoers "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("file")]),s._v(" grammar version "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("46")]),s._v("\nSudoers I/O plugin version "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1.8")]),s._v(".21p2\n")])])]),t("hr"),s._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/sudo.8.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("sudo(8) - Linux manual page - man7.org"),t("OutboundLink")],1)]),s._v(" "),t("p",[t("a",{attrs:{href:"https://man.linuxde.net/sudo",target:"_blank",rel:"noopener noreferrer"}},[s._v("sudo命令 - Linux 命令大全"),t("OutboundLink")],1)]),s._v(" "),t("Vssue",{attrs:{title:"sudo"}})],1)}),[],!1,null,null,null);t.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[126],{457:function(s,t,a){"use strict";a.r(t);var n=a(12),e=Object(n.a)({},(function(){var s=this,t=s._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[s._v("#")]),s._v(" 1.命令简介")]),s._v(" "),t("p",[s._v("sudo 可以用指定的用户身份执行指定的指令,而无需输入指定用户的密码,只需要输入当前用户的密码。未指定用户名默认为 root。")]),s._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("sudo [OPTIONS] [CMD]\n")])])]),t("p",[s._v("没有选项与命令单独执行 sudo,将列出 sudo 简要使用方法。")]),s._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("-A\n\t使用辅助程序(可能是图形化界面的程序)读取用户的密码并将密码输出到标准输出。如果设置了环境变量 SUDO_ASKPASS,它会指定辅助程序的路径,否则,由配置文件 /etc/sudo.conf 的 askpass 选项来指定辅助程序的路径。如果没有可用的辅助程序,sudo 将错误退出\n-b\n\t选项 -b(background)把 sudo 所要运行的命令放到后台运行\n-E\n\t选项 -E(preserve Environment)向安全策略指示用户希望保存他们现有的环境变量。如果指定了 -E 选项,且用户没有保留环境变量的权限,则安全策略可能返回错误\n-H\n\t选项 -H(Home)将 HOME 环境变量设置为目标用户的家目录,目标用户默认为 root\n-h\n\t选项 -h(help)显示帮助信息并退出\n-i [CMD]\n\t选项 -i(simulate initial login)将模拟初始登录,即启动目标用户在 /etc/passwd 中配置的 Shell,相关的资源文件将被读取并执行,比如 ~/.profile 和 ~/.login。如果后跟命令 CMD,则 CMD 将被传递给 Shell 并被执行\n-K\n\t选项 -K(sure Kill)类似于 -k,它只用于删除了用户的缓存凭据,不能与命令或其他选项一起使用\n-k [CMD]\n\t单独使用 -k(kill)选项时,使密码缓存失效,也就是下次执行 sudo 时需要输入密码。如果后跟命令,表示忽略缓存密码,需要用户重新输入密码 ,新输入的密码不会更新密码缓存\n-l[l] [CMD]\n\t如果选项 -l(list)后不跟命令,则列出 sudo 允许当前用户(或使用 -U 指定的其他用户)执行的指令和无法执行的指令。如果指定了命令并被安全策略所允许,则将显示该命令绝对路径以及命令参数。如果指定了命令不被允许,sudo 以状态码 1 退出。如果使用 -ll 或多次指定 -l 选项,则使用长格式输出\n-n\n\t选项 -n(non-interactive)表示以非交互模式执行 sudo,阻止 sudo 向用户询问密码。如果执行命令时需要密码,则 sudo 将报错误信息并退出\n-p PROMPT\n\t改变询问密码的提示符号\n-s [CMD]\n\t选项 -s(shell)执行环境变量 SHELL 表示的 Shell,如果 SHELL 没有值,则执行目标用户在配置文件 /etc/passwd 中配置的 Shell。如果选项后跟命令,则传递给 Shell 执行,如果没有指定命令,则执行交互式 Shell\n-U USER\n\t选项 -U(other user)与 -l 选项一起使用,以指定应列出其权限的用户。sudoers 策略仅允许 root 用户或当前主机上具有 ALL 权限的用户使用此选项\n-u USER\n\t选项 -u(user)指定执行命令时使用的用户身份,默认为 root。如果使用 uid 则使用 #uid 表示用户\n-V, --version\n\t显示版本信息并退出。\n-v, --validate\n\t更新用户的缓存凭据,使密码有效期延长 5 分钟。\n")])])]),t("p",[t("strong",[s._v("注意:")]),s._v("\nsudo 运行时要参照配置文件 /etc/sudousers ,该文件配置了用户能够执行的命令。")]),s._v(" "),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[s._v("#")]),s._v(" 4.常用示例")]),s._v(" "),t("p",[s._v("(1)查看此当前用户拥有的权限。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("sudo")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v("\nMatching Defaults entries "),t("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" lvlv on jumper02:\n env_reset, mail_badpass, "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("secure_path")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("/usr/local/sbin"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("\\")]),s._v(":/usr/local/bin"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("\\")]),s._v(":/usr/sbin"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("\\")]),s._v(":/usr/bin"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("\\")]),s._v(":/sbin"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("\\")]),s._v(":/bin"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("\\")]),s._v(":/snap/bin\n\nUser lvlv may run the following commands on jumper02:\n "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("ALL"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" NOPASSWD: ALL\n")])])]),t("p",[s._v("(2)以指定用户身份执行命令。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("sudo")]),s._v(" –u USERNAME CMD\n")])])]),t("p",[s._v("(3)结束密码有效期,也就是下次执行 sudo 时需要输入密码。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("sudo")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-k")]),s._v("\n")])])]),t("p",[s._v("(4)以指定用户创建一个文件,缺省为 root 用户。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("sudo")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("touch")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("file")]),s._v("\n\n"),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("ls")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("file")]),s._v("\n-rw-r--r-- "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" root root "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("5")]),s._v("月 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("14")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("19")]),s._v(":10 "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("file")]),s._v("\n")])])]),t("p",[s._v("(5)显示版本信息并退出。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("sudo")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-V")]),s._v("\nSudo version "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1.8")]),s._v(".21p2\nSudoers policy plugin version "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1.8")]),s._v(".21p2\nSudoers "),t("span",{pre:!0,attrs:{class:"token function"}},[s._v("file")]),s._v(" grammar version "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("46")]),s._v("\nSudoers I/O plugin version "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1.8")]),s._v(".21p2\n")])])]),t("hr"),s._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/sudo.8.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("sudo(8) - Linux manual page - man7.org"),t("OutboundLink")],1)]),s._v(" "),t("p",[t("a",{attrs:{href:"https://man.linuxde.net/sudo",target:"_blank",rel:"noopener noreferrer"}},[s._v("sudo命令 - Linux 命令大全"),t("OutboundLink")],1)]),s._v(" "),t("Vssue",{attrs:{title:"sudo"}})],1)}),[],!1,null,null,null);t.default=e.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/127.93f65539.js b/docs/assets/js/127.1ede57c6.js similarity index 98% rename from docs/assets/js/127.93f65539.js rename to docs/assets/js/127.1ede57c6.js index c64135781..bfeb82380 100644 --- a/docs/assets/js/127.93f65539.js +++ b/docs/assets/js/127.1ede57c6.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[127],{461:function(a,t,s){"use strict";s.r(t);var r=s(12),e=Object(r.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("umask 为 Shell 内建命令,用于设置创建文件时的权限掩码。")]),a._v(" "),t("p",[a._v("权限掩码由 3 个八进制数字组成,将 777(八进制)减掉权限掩码后,即可得到新建文件的默认权限。它与 chmod 的效果刚好相反。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("umask [-p] [-S] [MODE]\n")])])]),t("p",[a._v("后不跟任何选项与参数单独执行 umask,则以八进制格式显示当前权限掩码。")]),a._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-p [MODE]\n\t以八进制数字形式显示或设置权限掩码。当 MODE 没有提供时,显示当前权限掩码。为默认选项\n-S [MODE]\n\t以字符形式显示或设置新建文件的默认权限。当 MODE 没有提供时,显示新建文件的默认权限\n")])])]),t("p",[a._v("注意:出于安全的考虑,文件的执行权限不能通过权限掩码来设置,必须手工修改。")]),a._v(" "),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("(1)显示当前权限掩码。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("umask\n0022\n")])])]),t("p",[a._v("(2)以字符形式显示新建文件的默认权限。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("umask -S\nu=rwx,g=rx,o=rx\n")])])]),t("p",[a._v("等于八进制权限位 0777 减去掩码 0022,即 0755,以字符形式显示为 u=rwx,g=rx,o=rx。")]),a._v(" "),t("p",[a._v("(3)设置权限掩码并查看。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("#设置权限掩码\numask 044\n\n#查看权限掩码\numask\n044\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://www.linux.org/docs/man1/umask.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("umask(1) manual - linux.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/umask.1p.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("umask(1p) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"umask-builtin"}})],1)}),[],!1,null,null,null);t.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[127],{459:function(a,t,s){"use strict";s.r(t);var r=s(12),e=Object(r.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("umask 为 Shell 内建命令,用于设置创建文件时的权限掩码。")]),a._v(" "),t("p",[a._v("权限掩码由 3 个八进制数字组成,将 777(八进制)减掉权限掩码后,即可得到新建文件的默认权限。它与 chmod 的效果刚好相反。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("umask [-p] [-S] [MODE]\n")])])]),t("p",[a._v("后不跟任何选项与参数单独执行 umask,则以八进制格式显示当前权限掩码。")]),a._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-p [MODE]\n\t以八进制数字形式显示或设置权限掩码。当 MODE 没有提供时,显示当前权限掩码。为默认选项\n-S [MODE]\n\t以字符形式显示或设置新建文件的默认权限。当 MODE 没有提供时,显示新建文件的默认权限\n")])])]),t("p",[a._v("注意:出于安全的考虑,文件的执行权限不能通过权限掩码来设置,必须手工修改。")]),a._v(" "),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("(1)显示当前权限掩码。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("umask\n0022\n")])])]),t("p",[a._v("(2)以字符形式显示新建文件的默认权限。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("umask -S\nu=rwx,g=rx,o=rx\n")])])]),t("p",[a._v("等于八进制权限位 0777 减去掩码 0022,即 0755,以字符形式显示为 u=rwx,g=rx,o=rx。")]),a._v(" "),t("p",[a._v("(3)设置权限掩码并查看。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("#设置权限掩码\numask 044\n\n#查看权限掩码\numask\n044\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://www.linux.org/docs/man1/umask.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("umask(1) manual - linux.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/umask.1p.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("umask(1p) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"umask-builtin"}})],1)}),[],!1,null,null,null);t.default=e.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/128.05bf72b6.js b/docs/assets/js/128.a9e3863d.js similarity index 99% rename from docs/assets/js/128.05bf72b6.js rename to docs/assets/js/128.a9e3863d.js index 89cfbec08..bb7c80b56 100644 --- a/docs/assets/js/128.05bf72b6.js +++ b/docs/assets/js/128.a9e3863d.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[128],{462:function(s,a,t){"use strict";t.r(a);var e=t(12),r=Object(e.a)({},(function(){var s=this,a=s._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[s._v("#")]),s._v(" 1.命令简介")]),s._v(" "),a("p",[s._v("visudo 安全地编辑 sudoers 文件。")]),s._v(" "),a("p",[s._v("sudoers 文件的默认权限是 440,即默认无法修改;通过 visudo 可以在不更改 sudoers 文件权限的情况下,直接修改 sudoers 文件;默认编辑 /etc/sudoers 文件。")]),s._v(" "),a("p",[s._v("注意:需要超级用户权限。")]),s._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("visudo "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("-chqsV"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("-f"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" sudoers"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("-c, --check\n\t启用仅检查模式。将检查现有的 sudoers 文件(以及它包含的任何其他文件)是否存在语法错误。\n-f, --file=\n\t指定 sudoers 文件的位置。\n-h, --help\n\t显示帮助信息并退出。\n-q, --quiet\n\t启用安静模式。在此模式下,不会打印有关语法错误的详细信息。此选项仅在与 -c 选项结合使用时才有用。\n-s, --strict\n\t严格语法检查。\n-V, --version\n\t显示版本信息并退出。\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[s._v("#")]),s._v(" 4.常用示例")]),s._v(" "),a("p",[s._v("(1)编辑 /etc/sudoers 文件。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("visudo\n")])])]),a("p",[s._v("如将 tom 用户设置为拥有所有权限。")]),s._v(" "),a("p",[s._v("仿照现有 root 的例子就行,我们在下面加一行。")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("## Allow root to run any commands anywhere\nroot ALL=(ALL) ALL\ntom ALL=(ALL) ALL\n")])])]),a("p",[s._v("第一个ALL是指网络中的主机。第二个括号里的ALL是指目标用户,也就是以谁的身份去执行命令。最后一个ALL当然就是指命令名了。")]),s._v(" "),a("p",[s._v("再如我们想让 tom 用户在 linux 主机上以 foo 或 bar 的身份执行 kill 命令,这样编写配置文件:")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("tom "),a("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("linux")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("foo,bar"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" /bin/kill\n")])])]),a("p",[s._v("但这还有个问题,tom 到底以 foo 还是 bar 的身份执行?")]),s._v(" "),a("p",[s._v("这时我们应该想到了 sudo -u 了,它正是用在这种时候。 tom可以使用 sudo -u foo kill PID 或 sudo -u bar kill PID,但这样挺麻烦,其实我们可以不必每次加-u,把 foo 或 bar 设为默认的目标用户即可。")]),s._v(" "),a("p",[s._v("再在上面加一行:")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("Defaults:foobar runas_default=itcast\n")])])]),a("p",[s._v("Defaults 后面如果有冒号,是对后面用户的默认,如果没有,则是对所有用户的默认。就像配置文件中自带的一行:")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("Defaults env_reset\n")])])]),a("p",[s._v("(2)取消执行 sudo 时输入密码。")]),s._v(" "),a("p",[s._v("很多时候,我们本来就登录了,每次使用 sudo 还要输入密码就显得烦琐了。我们可不可以不再输入密码呢?")]),s._v(" "),a("p",[s._v("当然可以,我们这样修改配置文件:")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("tom localhost=NOPASSWD: /bin/cat, /bin/ls\n")])])]),a("p",[s._v("(2)检查语法等错误(不编辑)。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("visudo "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-c")]),s._v("\n")])])]),a("p",[s._v("(3)显示版本信息并退出。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("visudo "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-V")]),s._v("\nvisudo version "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1.8")]),s._v(".21p2\nvisudo grammar version "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("46")]),s._v("\n")])])]),a("hr"),s._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/visudo.8.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("visudo(8) - Linux manual page - man7.org"),a("OutboundLink")],1)]),s._v(" "),a("Vssue",{attrs:{title:"visudo"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[128],{461:function(s,a,t){"use strict";t.r(a);var e=t(12),r=Object(e.a)({},(function(){var s=this,a=s._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[s._v("#")]),s._v(" 1.命令简介")]),s._v(" "),a("p",[s._v("visudo 安全地编辑 sudoers 文件。")]),s._v(" "),a("p",[s._v("sudoers 文件的默认权限是 440,即默认无法修改;通过 visudo 可以在不更改 sudoers 文件权限的情况下,直接修改 sudoers 文件;默认编辑 /etc/sudoers 文件。")]),s._v(" "),a("p",[s._v("注意:需要超级用户权限。")]),s._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("visudo "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("-chqsV"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("-f"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" sudoers"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("-c, --check\n\t启用仅检查模式。将检查现有的 sudoers 文件(以及它包含的任何其他文件)是否存在语法错误。\n-f, --file=\n\t指定 sudoers 文件的位置。\n-h, --help\n\t显示帮助信息并退出。\n-q, --quiet\n\t启用安静模式。在此模式下,不会打印有关语法错误的详细信息。此选项仅在与 -c 选项结合使用时才有用。\n-s, --strict\n\t严格语法检查。\n-V, --version\n\t显示版本信息并退出。\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[s._v("#")]),s._v(" 4.常用示例")]),s._v(" "),a("p",[s._v("(1)编辑 /etc/sudoers 文件。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("visudo\n")])])]),a("p",[s._v("如将 tom 用户设置为拥有所有权限。")]),s._v(" "),a("p",[s._v("仿照现有 root 的例子就行,我们在下面加一行。")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("## Allow root to run any commands anywhere\nroot ALL=(ALL) ALL\ntom ALL=(ALL) ALL\n")])])]),a("p",[s._v("第一个ALL是指网络中的主机。第二个括号里的ALL是指目标用户,也就是以谁的身份去执行命令。最后一个ALL当然就是指命令名了。")]),s._v(" "),a("p",[s._v("再如我们想让 tom 用户在 linux 主机上以 foo 或 bar 的身份执行 kill 命令,这样编写配置文件:")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("tom "),a("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("linux")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("foo,bar"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" /bin/kill\n")])])]),a("p",[s._v("但这还有个问题,tom 到底以 foo 还是 bar 的身份执行?")]),s._v(" "),a("p",[s._v("这时我们应该想到了 sudo -u 了,它正是用在这种时候。 tom可以使用 sudo -u foo kill PID 或 sudo -u bar kill PID,但这样挺麻烦,其实我们可以不必每次加-u,把 foo 或 bar 设为默认的目标用户即可。")]),s._v(" "),a("p",[s._v("再在上面加一行:")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("Defaults:foobar runas_default=itcast\n")])])]),a("p",[s._v("Defaults 后面如果有冒号,是对后面用户的默认,如果没有,则是对所有用户的默认。就像配置文件中自带的一行:")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("Defaults env_reset\n")])])]),a("p",[s._v("(2)取消执行 sudo 时输入密码。")]),s._v(" "),a("p",[s._v("很多时候,我们本来就登录了,每次使用 sudo 还要输入密码就显得烦琐了。我们可不可以不再输入密码呢?")]),s._v(" "),a("p",[s._v("当然可以,我们这样修改配置文件:")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("tom localhost=NOPASSWD: /bin/cat, /bin/ls\n")])])]),a("p",[s._v("(2)检查语法等错误(不编辑)。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("visudo "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-c")]),s._v("\n")])])]),a("p",[s._v("(3)显示版本信息并退出。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("visudo "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-V")]),s._v("\nvisudo version "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1.8")]),s._v(".21p2\nvisudo grammar version "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("46")]),s._v("\n")])])]),a("hr"),s._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/visudo.8.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("visudo(8) - Linux manual page - man7.org"),a("OutboundLink")],1)]),s._v(" "),a("Vssue",{attrs:{title:"visudo"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/129.f9495992.js b/docs/assets/js/129.fda77f12.js similarity index 99% rename from docs/assets/js/129.f9495992.js rename to docs/assets/js/129.fda77f12.js index aeb1b7d07..0d286a5ed 100644 --- a/docs/assets/js/129.f9495992.js +++ b/docs/assets/js/129.fda77f12.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[129],{463:function(a,t,s){"use strict";s.r(t);var e=s(12),n=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("ac(accounting)打印有关用户连接时间的统计信息。")]),a._v(" "),t("p",[a._v("ac 命令根据当前的 /var/log/wtmp 文件中的登录进入和退出来报告用户连接的时间(小时)。如果不使用标志,则报告总的时间,也就是统计用户的在线时间。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[a._v("ac "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("OPTIONS"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-d, --daily-totals\n\t按每天的统计数据打印。 \n-f, --file \n\t读取指定文件而不是系统的 wtmp 文件。\n--complain\n\t当 wtmp 文件出现问题(时间扭曲、丢失记录或其他)时,打印出相应的错误。\n-y, --print-year\n\t在显示日期的时候输出年份。 \n-p, --individual-totals\n\t打印每个账号的总的连接时间。 \n-z, --print-zeros\n\t如果任何类别的总计(除了总计)为零,则打印它。默认值是禁止打印。\n--debug\n\t打印详细的内部信息。\n-V, --version\n\t打印版本号打印到标准输出并退出。\n-h, --help\n\t将使用字符串和系统文件的默认位置打印到标准输出并退出。\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("(1)输出用户连接时间。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[a._v("ac\n\ttotal "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("18817.91")]),a._v("\n")])])]),t("p",[a._v("(2)按每天的统计数据打印。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("ac -d\nNov 8 total 0.20\nNov 7 total 3.48\nNov 9 total 52.51\nNov 14 total 1.52\nNov 15 total 48.03\nNov 18 total 18.10\nNov 19 total 64.61\n")])])]),t("p",[a._v("(3)根据日期(含年份)显示所有用户的登录总时间")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[a._v("ac "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-d")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-y")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("8")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("2022")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("0.20")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("7")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("2022")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("3.48")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("9")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("2022")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("52.51")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("14")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("2022")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("1.52")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("15")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("2022")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("48.03")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("18")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("2022")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("18.10")]),a._v("\n")])])]),t("p",[a._v("(4)按天显示指定用户的登录总时间。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[a._v("ac "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-d")]),a._v(" root\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("8")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("0.14")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("7")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("3.48")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("9")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("44.60")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("14")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("1.52")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("15")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("47.84")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("18")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("18.10")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("19")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("64.61")]),a._v("\n")])])]),t("p",[a._v("(5)查看每个用户的登录总时间。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[a._v("ac "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-p")]),a._v("\n\tdeng "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("15822.55")]),a._v("\n\toracle "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("349.49")]),a._v("\n\troot "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("2646.22")]),a._v("\n\titcast "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("0.06")]),a._v("\n\ttotal "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("18818.32")]),a._v("\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/ac.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("ac(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"ac"}})],1)}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[129],{460:function(a,t,s){"use strict";s.r(t);var e=s(12),n=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("ac(accounting)打印有关用户连接时间的统计信息。")]),a._v(" "),t("p",[a._v("ac 命令根据当前的 /var/log/wtmp 文件中的登录进入和退出来报告用户连接的时间(小时)。如果不使用标志,则报告总的时间,也就是统计用户的在线时间。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[a._v("ac "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("OPTIONS"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-d, --daily-totals\n\t按每天的统计数据打印。 \n-f, --file \n\t读取指定文件而不是系统的 wtmp 文件。\n--complain\n\t当 wtmp 文件出现问题(时间扭曲、丢失记录或其他)时,打印出相应的错误。\n-y, --print-year\n\t在显示日期的时候输出年份。 \n-p, --individual-totals\n\t打印每个账号的总的连接时间。 \n-z, --print-zeros\n\t如果任何类别的总计(除了总计)为零,则打印它。默认值是禁止打印。\n--debug\n\t打印详细的内部信息。\n-V, --version\n\t打印版本号打印到标准输出并退出。\n-h, --help\n\t将使用字符串和系统文件的默认位置打印到标准输出并退出。\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("(1)输出用户连接时间。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[a._v("ac\n\ttotal "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("18817.91")]),a._v("\n")])])]),t("p",[a._v("(2)按每天的统计数据打印。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("ac -d\nNov 8 total 0.20\nNov 7 total 3.48\nNov 9 total 52.51\nNov 14 total 1.52\nNov 15 total 48.03\nNov 18 total 18.10\nNov 19 total 64.61\n")])])]),t("p",[a._v("(3)根据日期(含年份)显示所有用户的登录总时间")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[a._v("ac "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-d")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-y")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("8")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("2022")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("0.20")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("7")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("2022")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("3.48")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("9")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("2022")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("52.51")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("14")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("2022")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("1.52")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("15")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("2022")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("48.03")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("18")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("2022")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("18.10")]),a._v("\n")])])]),t("p",[a._v("(4)按天显示指定用户的登录总时间。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[a._v("ac "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-d")]),a._v(" root\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("8")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("0.14")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("7")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("3.48")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("9")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("44.60")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("14")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("1.52")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("15")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("47.84")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("18")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("18.10")]),a._v("\nNov "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("19")]),a._v(" total "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("64.61")]),a._v("\n")])])]),t("p",[a._v("(5)查看每个用户的登录总时间。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[a._v("ac "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-p")]),a._v("\n\tdeng "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("15822.55")]),a._v("\n\toracle "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("349.49")]),a._v("\n\troot "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("2646.22")]),a._v("\n\titcast "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("0.06")]),a._v("\n\ttotal "),t("span",{pre:!0,attrs:{class:"token number"}},[a._v("18818.32")]),a._v("\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/ac.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("ac(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"ac"}})],1)}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/130.75667145.js b/docs/assets/js/130.5496fa86.js similarity index 99% rename from docs/assets/js/130.75667145.js rename to docs/assets/js/130.5496fa86.js index 6d20f2246..1bc82b006 100644 --- a/docs/assets/js/130.75667145.js +++ b/docs/assets/js/130.5496fa86.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[130],{464:function(a,s,t){"use strict";t.r(s);var e=t(12),r=Object(e.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),s("p",[a._v("adduser 创建新用户或更新创建新用户时的默认信息。")]),a._v(" "),s("p",[a._v("adduser 用于创建的新的用户。用户帐号建好后,再用 passwd 设定帐号的密码。而可用 userdel 删除帐号。使用 adduser 所建立的帐号,实际上是保存在 /etc/passwd 文本文件中。")]),a._v(" "),s("p",[a._v("在 Centos 和 Redhat 中,adduser 实际上是 useradd 的软链接,所以 adduser 用法和 useradd 用法一样。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("adduser "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<")]),a._v("options"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<")]),a._v("LOGIN"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),a._v("\nadduser "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v("\nadduser "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<")]),a._v("options"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n")])])]),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("-b, --base-dir BASE_DIR\n\t新账户的主目录的基目录\n-c, --comment COMMENT\n\t新账户的备注信息,备注信息保存在 /etc/passwd 的备注栏中\n-d, --home-dir HOME_DIR\n\t新账户的主目录\n-D, --defaults\n\t显示或更改默认的 useradd 配置\n-e, --expiredate EXPIRE_DATE\n\t新账户的过期日期,日期格式为 YYYY-MM-DD。如果未指定,useradd 将使用在 /etc/default/useradd 中指定的到期日期 EXPIRE,或默认情况下使用空字符串(无过期)\n-f, --inactive INACTIVE\n\t指定在密码过期后多少天即关闭该账号。如果为 0 账号立即被停用;如果为 -1 则账号一直可用。默认值为 -1\n-g, --gid GROUP\n\t指定用户所属的主组。主组必须已经存在\n-G, --groups GROUPS\n\t指定用户所属的附加组,多个组使用逗号分隔\n-h, --help\n 显示帮助信息并推出\n-k, --skel SKEL_DIR\n\t指定用户的骨架目录。与选项 -m (或 --create-home)联用,骨架目录包含要复制到用户主目录中的文件和目录\n-K, --key KEY=VALUE\n\t不使用 /etc/login.defs 中的默认值(UID_MIN、UID_MAX、UMASK、PASS_MAX_DAYS 等)\n-l, --no-log-init\n\t不要将此用户添加到最近登录和登录失败数据库\n-m, --create-home\n\t创建用户的家目录。useradd 默认会创建 home 目录,除非 /etc/login.defs 中的 CREATE_HOME 设置为no\n-M, --no-create-home\n\t不创建用户的主目录。即使 /etc/login.defs 中的 CREATE_HOME 设置为 yes\n-N, --no-user-group\n\t不创建同名的组\n-o, --non-unique\n \t允许使用重复的 UID 创建用户\n-p, --password PASSWORD \n \t设置账户密码,注意是使用 crypt(3) 加密后的用户密码,不是密码的明文。默认是用户密码不可用。推荐使用 passwd 命令给用户设置密码\n-r, --system\n \t创建一个系统账户\n-R, --root CHROOT_DIR\n\t设置根目录。在 Linux 系统中,系统默认的根目录是 /\n-s, --shell SHELL \n\t新账户的登录 Shell\n-u, --uid UID\n\t新账户的用户 ID\n-U, --user-group\n\t创建与用户同名的组,并将用户添加到此组中。为默认动作,除非 /etc/login.defs 中 USERGROUPS_ENAB 被设置为 no 或显示使用选项 -N, --no-user-group。\n-Z, --selinux-user SEUSER\n\t为 SELinux 用户映射使用指定 SEUSER。\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)添加新用户。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("adduser dablelv\n")])])]),s("p",[a._v("默认在创建用户时的同时会创建一个同名的用户主组和在 /home 目录下同名的家目录,除非在配置文件 /etc/login.defs 中 USERGROUPS_ENAB 和 CREATE_HOME 被设置为 no。")]),a._v(" "),s("p",[a._v("(2)添加新用户时,显示指明家目录和所属的主组。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("adduser "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-d")]),a._v(" /home/dablelvH "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-g")]),a._v(" root dablelv\n")])])]),s("p",[a._v("添加用户成功后,我们可以使用 "),s("a",{attrs:{href:"https://dablelv.blog.csdn.net/article/details/102845312",target:"_blank",rel:"noopener noreferrer"}},[a._v("id"),s("OutboundLink")],1),a._v(" 命令查看用户 dablelv 的用户 ID、主组和附加组。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("id")]),a._v(" dablelv\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("uid")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1000")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("dablelv"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("gid")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("root"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("groups")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("root"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v("\n")])])]),s("p",[a._v("(3)添加新用户后,并使用 passwd 给用户设置密码。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("adduser dablelv\n"),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("passwd")]),a._v(" dablelv\n")])])]),s("p",[a._v("(4)添加用户,并给用户设置有效期。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("adduser "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-e")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("2020")]),a._v("-12-31 dablelv\n")])])]),s("p",[a._v("(5)使用 useradd -D 查看创建新用户时的默认信息,或直接 cat /etc/default/useradd。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("adduser "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("GROUP")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("100")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s("span",{pre:!0,attrs:{class:"token environment constant"}},[a._v("HOME")])]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/home\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("INACTIVE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("-1\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("EXPIRE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s("span",{pre:!0,attrs:{class:"token environment constant"}},[a._v("SHELL")])]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/bin/bash\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("SKEL")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/etc/skel\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("CREATE_MAIL_SPOOL")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("yes\n")])])]),s("p",[a._v("(6)修改创建新用户时的默认信息。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-f")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 查看是否修改成功")]),a._v("\nadduser "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("grep")]),a._v(" INACTIVE\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("INACTIVE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v("\n")])])]),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://www.commandlinux.com/man-page/man8/adduser.8.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("adduser linux command man page"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/useradd.8.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("useradd(8) - Linux manual page - man7.org"),s("OutboundLink")],1)]),a._v(" "),s("Vssue",{attrs:{title:"adduser"}})],1)}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[130],{462:function(a,s,t){"use strict";t.r(s);var e=t(12),r=Object(e.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),s("p",[a._v("adduser 创建新用户或更新创建新用户时的默认信息。")]),a._v(" "),s("p",[a._v("adduser 用于创建的新的用户。用户帐号建好后,再用 passwd 设定帐号的密码。而可用 userdel 删除帐号。使用 adduser 所建立的帐号,实际上是保存在 /etc/passwd 文本文件中。")]),a._v(" "),s("p",[a._v("在 Centos 和 Redhat 中,adduser 实际上是 useradd 的软链接,所以 adduser 用法和 useradd 用法一样。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("adduser "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<")]),a._v("options"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<")]),a._v("LOGIN"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),a._v("\nadduser "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v("\nadduser "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<")]),a._v("options"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n")])])]),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("-b, --base-dir BASE_DIR\n\t新账户的主目录的基目录\n-c, --comment COMMENT\n\t新账户的备注信息,备注信息保存在 /etc/passwd 的备注栏中\n-d, --home-dir HOME_DIR\n\t新账户的主目录\n-D, --defaults\n\t显示或更改默认的 useradd 配置\n-e, --expiredate EXPIRE_DATE\n\t新账户的过期日期,日期格式为 YYYY-MM-DD。如果未指定,useradd 将使用在 /etc/default/useradd 中指定的到期日期 EXPIRE,或默认情况下使用空字符串(无过期)\n-f, --inactive INACTIVE\n\t指定在密码过期后多少天即关闭该账号。如果为 0 账号立即被停用;如果为 -1 则账号一直可用。默认值为 -1\n-g, --gid GROUP\n\t指定用户所属的主组。主组必须已经存在\n-G, --groups GROUPS\n\t指定用户所属的附加组,多个组使用逗号分隔\n-h, --help\n 显示帮助信息并推出\n-k, --skel SKEL_DIR\n\t指定用户的骨架目录。与选项 -m (或 --create-home)联用,骨架目录包含要复制到用户主目录中的文件和目录\n-K, --key KEY=VALUE\n\t不使用 /etc/login.defs 中的默认值(UID_MIN、UID_MAX、UMASK、PASS_MAX_DAYS 等)\n-l, --no-log-init\n\t不要将此用户添加到最近登录和登录失败数据库\n-m, --create-home\n\t创建用户的家目录。useradd 默认会创建 home 目录,除非 /etc/login.defs 中的 CREATE_HOME 设置为no\n-M, --no-create-home\n\t不创建用户的主目录。即使 /etc/login.defs 中的 CREATE_HOME 设置为 yes\n-N, --no-user-group\n\t不创建同名的组\n-o, --non-unique\n \t允许使用重复的 UID 创建用户\n-p, --password PASSWORD \n \t设置账户密码,注意是使用 crypt(3) 加密后的用户密码,不是密码的明文。默认是用户密码不可用。推荐使用 passwd 命令给用户设置密码\n-r, --system\n \t创建一个系统账户\n-R, --root CHROOT_DIR\n\t设置根目录。在 Linux 系统中,系统默认的根目录是 /\n-s, --shell SHELL \n\t新账户的登录 Shell\n-u, --uid UID\n\t新账户的用户 ID\n-U, --user-group\n\t创建与用户同名的组,并将用户添加到此组中。为默认动作,除非 /etc/login.defs 中 USERGROUPS_ENAB 被设置为 no 或显示使用选项 -N, --no-user-group。\n-Z, --selinux-user SEUSER\n\t为 SELinux 用户映射使用指定 SEUSER。\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)添加新用户。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("adduser dablelv\n")])])]),s("p",[a._v("默认在创建用户时的同时会创建一个同名的用户主组和在 /home 目录下同名的家目录,除非在配置文件 /etc/login.defs 中 USERGROUPS_ENAB 和 CREATE_HOME 被设置为 no。")]),a._v(" "),s("p",[a._v("(2)添加新用户时,显示指明家目录和所属的主组。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("adduser "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-d")]),a._v(" /home/dablelvH "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-g")]),a._v(" root dablelv\n")])])]),s("p",[a._v("添加用户成功后,我们可以使用 "),s("a",{attrs:{href:"https://dablelv.blog.csdn.net/article/details/102845312",target:"_blank",rel:"noopener noreferrer"}},[a._v("id"),s("OutboundLink")],1),a._v(" 命令查看用户 dablelv 的用户 ID、主组和附加组。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("id")]),a._v(" dablelv\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("uid")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1000")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("dablelv"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("gid")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("root"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("groups")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("root"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v("\n")])])]),s("p",[a._v("(3)添加新用户后,并使用 passwd 给用户设置密码。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("adduser dablelv\n"),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("passwd")]),a._v(" dablelv\n")])])]),s("p",[a._v("(4)添加用户,并给用户设置有效期。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("adduser "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-e")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("2020")]),a._v("-12-31 dablelv\n")])])]),s("p",[a._v("(5)使用 useradd -D 查看创建新用户时的默认信息,或直接 cat /etc/default/useradd。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("adduser "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("GROUP")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("100")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s("span",{pre:!0,attrs:{class:"token environment constant"}},[a._v("HOME")])]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/home\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("INACTIVE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("-1\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("EXPIRE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s("span",{pre:!0,attrs:{class:"token environment constant"}},[a._v("SHELL")])]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/bin/bash\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("SKEL")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/etc/skel\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("CREATE_MAIL_SPOOL")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("yes\n")])])]),s("p",[a._v("(6)修改创建新用户时的默认信息。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-f")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 查看是否修改成功")]),a._v("\nadduser "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("grep")]),a._v(" INACTIVE\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("INACTIVE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v("\n")])])]),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://www.commandlinux.com/man-page/man8/adduser.8.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("adduser linux command man page"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/useradd.8.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("useradd(8) - Linux manual page - man7.org"),s("OutboundLink")],1)]),a._v(" "),s("Vssue",{attrs:{title:"adduser"}})],1)}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/131.8450cab7.js b/docs/assets/js/131.cc21dc48.js similarity index 99% rename from docs/assets/js/131.8450cab7.js rename to docs/assets/js/131.cc21dc48.js index 26cce0576..aae49232b 100644 --- a/docs/assets/js/131.8450cab7.js +++ b/docs/assets/js/131.cc21dc48.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[131],{465:function(a,s,e){"use strict";e.r(s);var t=e(12),r=Object(t.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),s("p",[a._v("chage(change)修改用户密码过期信息。")]),a._v(" "),s("p",[a._v("chage 可以更改密码修改之间的天数和上次更改密码的日期。系统使用此信息来确定用户何时必须修改其密码。")]),a._v(" "),s("p",[a._v("chage 也可以设置帐户的过期时间。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("options"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" LOGIN\n")])])]),s("p",[a._v("LOGIN 为用户名。")]),a._v(" "),s("p",[a._v("如果没有选择任何选项,chage 将以交互方式运行,提示用户所有字段的当前值。 输入新值以更改字段,或将该行留空以使用当前值。 当前值显示在中括号 [] 内。")]),a._v(" "),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("-d, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--lastday")]),a._v(" LAST_DAY\n 将最近一次密码设置时间设为 LAST_DAY。LAST_DAY 可以是距离 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1970")]),a._v(" 年 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1")]),a._v(" 月 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1")]),a._v(" 日后的天数,也可以是 YYYY-MM-DD 格式的日期。如果 LAST_DAY 为 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v(" 表示用户在下次登录时必须更改密码。\n-E, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--expiredate")]),a._v(" EXPIRE_DATE\n 将帐户过期时间设为指定日期。EXPIRE_DATE 可以是距离 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1970")]),a._v(" 年 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1")]),a._v(" 月 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1")]),a._v(" 日后的天数,也可以是 YYYY-MM-DD 格式的日期。如果 EXPIRE_DATE 为 "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-1")]),a._v(" 则表示账户永不过期。\n-h, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--help")]),a._v("\n 显示此帮助信息并退出。\n-i, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--iso8601")]),a._v("\n 打印日期时,使用 YYYY-MM-DD 格式。\n-I, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--inactive")]),a._v(" INACITVE\n 设置密码过期后帐户被锁定前不活动的天数。如果 INACITVE 为 -1,表示账户永不会被锁定。\n-l, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--list")]),a._v("\n 显示帐户年龄信息。\n-m, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--mindays")]),a._v(" MIN_DAYS\n 将两次改变密码之间相距的最小天数设为 MIN_DAYS。此字段为 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v(" 表示用户可以随时更改其密码。\n-M, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--maxdays")]),a._v(" MAX_DAYS\n 将两次改变密码之间相距的最大天数设为 MAX_DAYS。此字段为 "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-1")]),a._v(" 表示取消检查密码的有效性。\n-R, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--root")]),a._v(" CHROOT_DIR\n 在 CHROOT_DIR 目录中应用更改并使用 CHROOT_DIR 目录中的配置文件。 仅支持绝对路径。\n-W, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--warndays")]),a._v(" WARN_DAYS\n 将密码过期警告天数设为 WARN_DAYS。\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)显示账户年龄信息。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-l")]),a._v(" root\nLast password change "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v(":")]),a._v(" Nov "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("27")]),a._v(", "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("2022")]),a._v("\nPassword expires "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v(":")]),a._v(" never\nPassword inactive "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v(":")]),a._v(" never\nAccount expires "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v(":")]),a._v(" never\nMinimum number of days between password change "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v(":")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v("\nMaximum number of days between password change "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v(":")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("99999")]),a._v("\nNumber of days of warning before password expires "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v(":")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("7")]),a._v("\n")])])]),s("p",[a._v("(2)设置两次更改密码之间相距的最大天数。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-M")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("180")]),a._v(" root\n")])])]),s("p",[a._v("(3)设置两次改变密码之间相距的最小天数。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-m")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("30")]),a._v(" root\n")])])]),s("p",[a._v("(4)强制用户登录时修改口令。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-d")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v(" tom\n")])])]),s("p",[a._v("-d 后面如果接数字的话是从1970年1月1日累加,如"),s("code",[a._v("chage -d 5 tom")]),a._v("修改时间就变成1970年1月6日。也可以直接接日期如"),s("code",[a._v("chage -d 2023-02-18 tom")]),a._v("密码修改时间就变成了2023年2月18日。")]),a._v(" "),s("p",[a._v("-d 后面如果接 0 表示用户在下次登录时必须更改密码。")]),a._v(" "),s("p",[a._v("(5)设置账户的过期时间。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-E")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[a._v("'2023-09-30'")]),a._v(" tom\n")])])]),s("p",[a._v("如果想设置为永久有效,则 -E 后跟 -1。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-E")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-1")]),a._v(" tom\n")])])]),s("p",[a._v("(6)设置密码过期前多少天开始提醒。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-W")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("7")]),a._v(" tom\n")])])]),s("p",[a._v("(7)设置账户密码过期后账户被锁定前的不活跃天数。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-I")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("5")]),a._v(" tom\n")])])]),s("p",[a._v("(8)一个综合实例。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-m")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-M")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("90")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-W")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("15")]),a._v(" tom\n")])])]),s("p",[a._v("设置用户随时都可修改密码且密码最高有效期为 90 天。在密码失效前,提前 15 天发出警告提醒。")]),a._v(" "),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/chage.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("chage(1) - Linux manual page - man7.org"),s("OutboundLink")],1)]),a._v(" "),s("Vssue",{attrs:{title:"chage"}})],1)}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[131],{463:function(a,s,e){"use strict";e.r(s);var t=e(12),r=Object(t.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),s("p",[a._v("chage(change)修改用户密码过期信息。")]),a._v(" "),s("p",[a._v("chage 可以更改密码修改之间的天数和上次更改密码的日期。系统使用此信息来确定用户何时必须修改其密码。")]),a._v(" "),s("p",[a._v("chage 也可以设置帐户的过期时间。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("options"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" LOGIN\n")])])]),s("p",[a._v("LOGIN 为用户名。")]),a._v(" "),s("p",[a._v("如果没有选择任何选项,chage 将以交互方式运行,提示用户所有字段的当前值。 输入新值以更改字段,或将该行留空以使用当前值。 当前值显示在中括号 [] 内。")]),a._v(" "),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("-d, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--lastday")]),a._v(" LAST_DAY\n 将最近一次密码设置时间设为 LAST_DAY。LAST_DAY 可以是距离 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1970")]),a._v(" 年 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1")]),a._v(" 月 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1")]),a._v(" 日后的天数,也可以是 YYYY-MM-DD 格式的日期。如果 LAST_DAY 为 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v(" 表示用户在下次登录时必须更改密码。\n-E, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--expiredate")]),a._v(" EXPIRE_DATE\n 将帐户过期时间设为指定日期。EXPIRE_DATE 可以是距离 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1970")]),a._v(" 年 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1")]),a._v(" 月 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1")]),a._v(" 日后的天数,也可以是 YYYY-MM-DD 格式的日期。如果 EXPIRE_DATE 为 "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-1")]),a._v(" 则表示账户永不过期。\n-h, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--help")]),a._v("\n 显示此帮助信息并退出。\n-i, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--iso8601")]),a._v("\n 打印日期时,使用 YYYY-MM-DD 格式。\n-I, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--inactive")]),a._v(" INACITVE\n 设置密码过期后帐户被锁定前不活动的天数。如果 INACITVE 为 -1,表示账户永不会被锁定。\n-l, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--list")]),a._v("\n 显示帐户年龄信息。\n-m, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--mindays")]),a._v(" MIN_DAYS\n 将两次改变密码之间相距的最小天数设为 MIN_DAYS。此字段为 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v(" 表示用户可以随时更改其密码。\n-M, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--maxdays")]),a._v(" MAX_DAYS\n 将两次改变密码之间相距的最大天数设为 MAX_DAYS。此字段为 "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-1")]),a._v(" 表示取消检查密码的有效性。\n-R, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--root")]),a._v(" CHROOT_DIR\n 在 CHROOT_DIR 目录中应用更改并使用 CHROOT_DIR 目录中的配置文件。 仅支持绝对路径。\n-W, "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("--warndays")]),a._v(" WARN_DAYS\n 将密码过期警告天数设为 WARN_DAYS。\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)显示账户年龄信息。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-l")]),a._v(" root\nLast password change "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v(":")]),a._v(" Nov "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("27")]),a._v(", "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("2022")]),a._v("\nPassword expires "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v(":")]),a._v(" never\nPassword inactive "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v(":")]),a._v(" never\nAccount expires "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v(":")]),a._v(" never\nMinimum number of days between password change "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v(":")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v("\nMaximum number of days between password change "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v(":")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("99999")]),a._v("\nNumber of days of warning before password expires "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v(":")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("7")]),a._v("\n")])])]),s("p",[a._v("(2)设置两次更改密码之间相距的最大天数。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-M")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("180")]),a._v(" root\n")])])]),s("p",[a._v("(3)设置两次改变密码之间相距的最小天数。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-m")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("30")]),a._v(" root\n")])])]),s("p",[a._v("(4)强制用户登录时修改口令。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-d")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v(" tom\n")])])]),s("p",[a._v("-d 后面如果接数字的话是从1970年1月1日累加,如"),s("code",[a._v("chage -d 5 tom")]),a._v("修改时间就变成1970年1月6日。也可以直接接日期如"),s("code",[a._v("chage -d 2023-02-18 tom")]),a._v("密码修改时间就变成了2023年2月18日。")]),a._v(" "),s("p",[a._v("-d 后面如果接 0 表示用户在下次登录时必须更改密码。")]),a._v(" "),s("p",[a._v("(5)设置账户的过期时间。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-E")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[a._v("'2023-09-30'")]),a._v(" tom\n")])])]),s("p",[a._v("如果想设置为永久有效,则 -E 后跟 -1。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-E")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-1")]),a._v(" tom\n")])])]),s("p",[a._v("(6)设置密码过期前多少天开始提醒。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-W")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("7")]),a._v(" tom\n")])])]),s("p",[a._v("(7)设置账户密码过期后账户被锁定前的不活跃天数。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-I")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("5")]),a._v(" tom\n")])])]),s("p",[a._v("(8)一个综合实例。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[a._v("chage "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-m")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-M")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("90")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-W")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("15")]),a._v(" tom\n")])])]),s("p",[a._v("设置用户随时都可修改密码且密码最高有效期为 90 天。在密码失效前,提前 15 天发出警告提醒。")]),a._v(" "),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/chage.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("chage(1) - Linux manual page - man7.org"),s("OutboundLink")],1)]),a._v(" "),s("Vssue",{attrs:{title:"chage"}})],1)}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/133.bace3ca3.js b/docs/assets/js/133.8a8dfb99.js similarity index 99% rename from docs/assets/js/133.bace3ca3.js rename to docs/assets/js/133.8a8dfb99.js index 86d142341..8a5f972b5 100644 --- a/docs/assets/js/133.bace3ca3.js +++ b/docs/assets/js/133.8a8dfb99.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[133],{467:function(t,s,a){"use strict";a.r(s);var n=a(12),e=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),s("p",[t._v("last 列出登录系统的用户列表。")]),t._v(" "),s("p",[t._v("last 用于显示用户最近登录信息。单独执行 last 命令,它会读取/var/log/wtmp的文件,并把该给文件的内容记录的登入系统的用户名单全部显示出来。")]),t._v(" "),s("p",[t._v("last 的作用是显示近期用户或终端的登录情况,通过查看系统记录的日志文件内容,进而使管理员可以获知谁曾经或企图连接系统。")]),t._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("last "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-R"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-n")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-adFiowx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("file")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-t")]),t._v(" YYYYMMDDHHMMSS "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v("."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("tty"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v("."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("-a\n\t把从何处登入系统的主机名称或ip地址,显示在最后一行。\n-d\n\t将 IP 地址转换成主机名称。\n-f \n\t指定要搜索的文件,而不是 /var/log/wtmp。\n-n , -\n\t设置列出名单的显示行数。\n-R\n\t不显示登入系统的主机名称或IP地址。\n-x\n\t显示系统关机,重新开机,以及执行等级的改变等信息。\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),s("p",[t._v("(1)显示近期用户或终端的登录情况。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("last\nroot pts/2 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("11")]),t._v(":18 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/1 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),t._v(":39 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" 09:36 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/3 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":46 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:23"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":17 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:52"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot pts/2 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".5.238 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("15")]),t._v(":22 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":59 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:37"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot pts/1 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".5.238 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("15")]),t._v(":09 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("19")]),t._v(":11 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("04:01"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(".\n")])])]),s("p",[t._v("第一列:用户名。")]),t._v(" "),s("p",[t._v("第二列:终端位置。pts:意味着从 SSH 或 TELNET 的远程连接用户。​tty:意味着直接连接到计算机或者本地连接用户。除了重启,所有状态会在启动时显示。")]),t._v(" "),s("p",[t._v("第三列:登录 IP 或者内核。0.0 或者什么都没有的话,意味着用户通过本地终端连接重启活动,会显示内核版本。")]),t._v(" "),s("p",[t._v("第四列:开始时间。")]),t._v(" "),s("p",[t._v("第五列:结束时间。still log in:还在登录。down:直到正常关机。crash:直到强制关机。")]),t._v(" "),s("p",[t._v("第六列:持续时间。")]),t._v(" "),s("p",[t._v("(2)指定显示的行数。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("last "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-5")]),t._v("\nroot pts/2 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("11")]),t._v(":18 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/1 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),t._v(":39 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" 09:36 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/3 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":46 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:23"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":17 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:52"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \n\nwtmp begins Sun Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("16")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v(":39:53 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v("\n")])])]),s("p",[t._v("(3)最后一列显示主机 IP 地址。")]),t._v(" "),s("p",[t._v("把从何处登入系统的主机名称或ip地址,显示在最后一行。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("last "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-5a")]),t._v("\nroot pts/2 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("11")]),t._v(":18 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91\nroot pts/1 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),t._v(":39 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91\nroot pts/0 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" 09:36 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91\nroot pts/3 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":46 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:23"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91\nroot pts/0 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":17 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:52"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91\n\nwtmp begins Sun Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("16")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v(":39:53 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v("\n")])])]),s("p",[t._v("(4)显示指定用户的登录记录。")]),t._v(" "),s("p",[t._v("比如查看 root 用户最近的 5 条记录。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("last "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-5")]),t._v(" root\nroot pts/2 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("11")]),t._v(":18 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/1 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),t._v(":39 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" 09:36 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/3 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":46 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:23"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":17 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:52"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \n\nwtmp begins Sun Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("16")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v(":39:53 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v("\n")])])]),s("p",[t._v("(5)指定登录记录文件。")]),t._v(" "),s("p",[t._v("/var/log/btmp 该文件比较详细,可以显示 ssh 远程登录的信息。")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("last -5 -f /var/log/btmp\nlast -5 -f /var/log/btmp\nadmin ssh:notty 92.255.85.113 Thu Oct 27 13:43 gone - no logout \nadmin ssh:notty 92.255.85.113 Thu Oct 27 13:43 - 13:43 (00:00) \ntest ssh:notty 92.255.85.113 Thu Oct 27 13:38 - 13:43 (00:05) \ntest ssh:notty 92.255.85.113 Thu Oct 27 13:38 - 13:38 (00:00) \nguest ssh:notty 92.255.85.113 Thu Oct 27 13:33 - 13:38 (00:04) \n\nbtmp begins Mon Oct 17 03:43:01 2022\n")])])]),s("p",[t._v("(6)显示完整登录和登出信息。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("last "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-F")]),t._v("\nroot pts/2 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("11")]),t._v(":18:16 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v(" still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/1 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),t._v(":39:21 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v(" still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" 09:36:20 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v(" still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/3 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":46:50 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v(" - Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10:24 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:23"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":17:53 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v(" - Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10:24 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:52"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),s("h2",{attrs:{id:"_5-utmp、wtmp-与-btmp-文件"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_5-utmp、wtmp-与-btmp-文件"}},[t._v("#")]),t._v(" 5.utmp、wtmp 与 btmp 文件")]),t._v(" "),s("p",[t._v("Linux 用户登录信息放在三个文件中:")]),t._v(" "),s("ul",[s("li",[s("p",[t._v("/var/run/utmp:记录当前正在登录系统的用户信息,默认由 who 和w 记录当前登录用户的信息,uptime 记录系统启动时间。")])]),t._v(" "),s("li",[s("p",[t._v("/var/log/wtmp:记录当前正在登录和历史登录系统的用户信息,默认由last命令查看;")])]),t._v(" "),s("li",[s("p",[t._v("/var/log/btmp:记录失败的登录尝试信息,默认由 lastb 命令查看。")])])]),t._v(" "),s("p",[t._v("这三个文件都是二进制数据文件,并且三个文件结构完全相同,是由 /usr/include/bits/utmp.h 文件定义了这三个文件的结构体。")]),t._v(" "),s("p",[t._v("默认情况下文件的日志信息会通过 logrotate 日志管理工具定期清理。logrotate 的配置文件是 /etc/logrotate.conf,此处是 logrotate 的缺省设置,通常不需要对它进行修改。日志文件的轮循压缩等设置存放在独立的配置文件中,它(们)放在 /etc/logrotate.d/ 目录下,它会覆盖缺省设置。")]),t._v(" "),s("p",[t._v("如果不想记录相关信息,则可以直接将相关文件删除即可。如果系统不存在该文件,则需要在此路径 touch 一个文件就可以继续记录相关信息了。")]),t._v(" "),s("hr"),t._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),s("p",[s("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/last.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("last(1) — Linux manual page - man7.org"),s("OutboundLink")],1)]),t._v(" "),s("Vssue",{attrs:{title:"last"}})],1)}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[133],{464:function(t,s,a){"use strict";a.r(s);var n=a(12),e=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),s("p",[t._v("last 列出登录系统的用户列表。")]),t._v(" "),s("p",[t._v("last 用于显示用户最近登录信息。单独执行 last 命令,它会读取/var/log/wtmp的文件,并把该给文件的内容记录的登入系统的用户名单全部显示出来。")]),t._v(" "),s("p",[t._v("last 的作用是显示近期用户或终端的登录情况,通过查看系统记录的日志文件内容,进而使管理员可以获知谁曾经或企图连接系统。")]),t._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("last "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-R"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-n")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-adFiowx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("file")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-t")]),t._v(" YYYYMMDDHHMMSS "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v("."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("tty"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v("."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("-a\n\t把从何处登入系统的主机名称或ip地址,显示在最后一行。\n-d\n\t将 IP 地址转换成主机名称。\n-f \n\t指定要搜索的文件,而不是 /var/log/wtmp。\n-n , -\n\t设置列出名单的显示行数。\n-R\n\t不显示登入系统的主机名称或IP地址。\n-x\n\t显示系统关机,重新开机,以及执行等级的改变等信息。\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),s("p",[t._v("(1)显示近期用户或终端的登录情况。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("last\nroot pts/2 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("11")]),t._v(":18 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/1 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),t._v(":39 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" 09:36 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/3 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":46 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:23"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":17 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:52"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot pts/2 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".5.238 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("15")]),t._v(":22 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":59 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:37"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot pts/1 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".5.238 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("15")]),t._v(":09 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("19")]),t._v(":11 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("04:01"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(".\n")])])]),s("p",[t._v("第一列:用户名。")]),t._v(" "),s("p",[t._v("第二列:终端位置。pts:意味着从 SSH 或 TELNET 的远程连接用户。​tty:意味着直接连接到计算机或者本地连接用户。除了重启,所有状态会在启动时显示。")]),t._v(" "),s("p",[t._v("第三列:登录 IP 或者内核。0.0 或者什么都没有的话,意味着用户通过本地终端连接重启活动,会显示内核版本。")]),t._v(" "),s("p",[t._v("第四列:开始时间。")]),t._v(" "),s("p",[t._v("第五列:结束时间。still log in:还在登录。down:直到正常关机。crash:直到强制关机。")]),t._v(" "),s("p",[t._v("第六列:持续时间。")]),t._v(" "),s("p",[t._v("(2)指定显示的行数。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("last "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-5")]),t._v("\nroot pts/2 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("11")]),t._v(":18 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/1 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),t._v(":39 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" 09:36 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/3 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":46 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:23"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":17 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:52"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \n\nwtmp begins Sun Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("16")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v(":39:53 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v("\n")])])]),s("p",[t._v("(3)最后一列显示主机 IP 地址。")]),t._v(" "),s("p",[t._v("把从何处登入系统的主机名称或ip地址,显示在最后一行。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("last "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-5a")]),t._v("\nroot pts/2 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("11")]),t._v(":18 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91\nroot pts/1 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),t._v(":39 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91\nroot pts/0 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" 09:36 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91\nroot pts/3 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":46 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:23"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91\nroot pts/0 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":17 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:52"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91\n\nwtmp begins Sun Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("16")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v(":39:53 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v("\n")])])]),s("p",[t._v("(4)显示指定用户的登录记录。")]),t._v(" "),s("p",[t._v("比如查看 root 用户最近的 5 条记录。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("last "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-5")]),t._v(" root\nroot pts/2 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("11")]),t._v(":18 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/1 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),t._v(":39 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" 09:36 still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/3 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":46 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:23"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":17 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:52"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \n\nwtmp begins Sun Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("16")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v(":39:53 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v("\n")])])]),s("p",[t._v("(5)指定登录记录文件。")]),t._v(" "),s("p",[t._v("/var/log/btmp 该文件比较详细,可以显示 ssh 远程登录的信息。")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("last -5 -f /var/log/btmp\nlast -5 -f /var/log/btmp\nadmin ssh:notty 92.255.85.113 Thu Oct 27 13:43 gone - no logout \nadmin ssh:notty 92.255.85.113 Thu Oct 27 13:43 - 13:43 (00:00) \ntest ssh:notty 92.255.85.113 Thu Oct 27 13:38 - 13:43 (00:05) \ntest ssh:notty 92.255.85.113 Thu Oct 27 13:38 - 13:38 (00:00) \nguest ssh:notty 92.255.85.113 Thu Oct 27 13:33 - 13:38 (00:04) \n\nbtmp begins Mon Oct 17 03:43:01 2022\n")])])]),s("p",[t._v("(6)显示完整登录和登出信息。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("last "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-F")]),t._v("\nroot pts/2 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("11")]),t._v(":18:16 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v(" still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/1 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),t._v(":39:21 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v(" still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" 09:36:20 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v(" still logged "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" \nroot pts/3 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":46:50 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v(" - Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10:24 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:23"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot pts/0 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("223.73")]),t._v(".1.91 Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(":17:53 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v(" - Wed Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("26")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),t._v(":10:24 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("03:52"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),s("h2",{attrs:{id:"_5-utmp、wtmp-与-btmp-文件"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_5-utmp、wtmp-与-btmp-文件"}},[t._v("#")]),t._v(" 5.utmp、wtmp 与 btmp 文件")]),t._v(" "),s("p",[t._v("Linux 用户登录信息放在三个文件中:")]),t._v(" "),s("ul",[s("li",[s("p",[t._v("/var/run/utmp:记录当前正在登录系统的用户信息,默认由 who 和w 记录当前登录用户的信息,uptime 记录系统启动时间。")])]),t._v(" "),s("li",[s("p",[t._v("/var/log/wtmp:记录当前正在登录和历史登录系统的用户信息,默认由last命令查看;")])]),t._v(" "),s("li",[s("p",[t._v("/var/log/btmp:记录失败的登录尝试信息,默认由 lastb 命令查看。")])])]),t._v(" "),s("p",[t._v("这三个文件都是二进制数据文件,并且三个文件结构完全相同,是由 /usr/include/bits/utmp.h 文件定义了这三个文件的结构体。")]),t._v(" "),s("p",[t._v("默认情况下文件的日志信息会通过 logrotate 日志管理工具定期清理。logrotate 的配置文件是 /etc/logrotate.conf,此处是 logrotate 的缺省设置,通常不需要对它进行修改。日志文件的轮循压缩等设置存放在独立的配置文件中,它(们)放在 /etc/logrotate.d/ 目录下,它会覆盖缺省设置。")]),t._v(" "),s("p",[t._v("如果不想记录相关信息,则可以直接将相关文件删除即可。如果系统不存在该文件,则需要在此路径 touch 一个文件就可以继续记录相关信息了。")]),t._v(" "),s("hr"),t._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),s("p",[s("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/last.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("last(1) — Linux manual page - man7.org"),s("OutboundLink")],1)]),t._v(" "),s("Vssue",{attrs:{title:"last"}})],1)}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/134.10ea39ce.js b/docs/assets/js/134.9fa951a4.js similarity index 99% rename from docs/assets/js/134.10ea39ce.js rename to docs/assets/js/134.9fa951a4.js index 96b596c35..721c8aafe 100644 --- a/docs/assets/js/134.10ea39ce.js +++ b/docs/assets/js/134.9fa951a4.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[134],{468:function(t,s,a){"use strict";a.r(s);var n=a(12),e=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),s("p",[t._v("lastb 用于显示用户错误的登录列表。")]),t._v(" "),s("p",[t._v("lastb 可以发现系统的登录异常。单独执行 lastb 命令,它会读取位于 /var/log 目录下名为 btmp 的文件,并把该文件内容记录的登入失败的用户名单,全部显示出来。")]),t._v(" "),s("p",[t._v("实际上 lastb 是 last 的一个软链,所以 lastb 功能均可由 last 实现。唯一与 last 不同之处在于其默认读取的日志文件是 /var/log/btmp,其中包含所有错误的登录尝试。")]),t._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("lastb "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-R"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-n")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("file")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-adFiowx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v("."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("tty"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v("."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("-n , - \n\t显示最近登录信息的行数。\n-t \n\t根据登录的时间显示指定用户的登录状态。\n-R\n\t禁止显示主机名字段。\n-a\n\t在最后一列显示主机名称。\n-d\n\t对于非本地登录的用户,将显示的 IP 地址转换为主机名。\n-i\n\t类似于 “-d” 的选项,将显示的主机名称转换为 IP 地址。\n-o\n\t读取旧的类型的 wtmp 文件。\n-x\n\t显示系统登录等级。\n--help\n\t显示帮助信息。\n--version\n\t显示版本显示。\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),s("p",[t._v("(1)列出登入失败的用户记录。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("lastb "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-5")]),t._v("\nadmin ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nadmin ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \noperator ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":24 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":24 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1234")]),t._v(" ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":20 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":20 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1234")]),t._v(" ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":20 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":20 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\nbtmp begins Mon Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("17")]),t._v(" 03:43:01 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v("\n")])])]),s("p",[t._v("lastb 指令,它会读取位于 /var/log/btmp 的文件,并把该文件内容记录的登入系统失败的用户名单,全部显示出来。btmp 是二进制文件,所以用 last -f /var/log/btmp 结果一样。")]),t._v(" "),s("p",[t._v("(2)使用 -a 选项把来源 IP 显示在最后列。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("lastb "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-a5")]),t._v("\nadmin ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":33 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":33 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113\nadmin ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":33 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":33 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113\nadmin ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113\nadmin ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113\noperator ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":24 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":24 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113\n\nbtmp begins Mon Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("17")]),t._v(" 03:43:01 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v("\n")])])]),s("p",[t._v("(3)不显示主机名字段。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("lastb "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-5")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-R")]),t._v("\njeremias ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \njeremias ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nmatthew ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":39 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":39 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \n\nbtmp begins Mon Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("17")]),t._v(" 03:43:01 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v("\n")])])]),s("p",[t._v("(4)显示指定用户登录失败记录。")]),t._v(" "),s("p",[t._v("比如显示 root 用户登录失败记录。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("lastb "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-n")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),t._v(" root\nroot ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("147.182")]),t._v(".179.237 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":44 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":44 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":42 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":42 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("61.177")]),t._v(".172.145 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("61.177")]),t._v(".172.145 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":38 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":38 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \n\nbtmp begins Mon Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("17")]),t._v(" 03:43:01 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v("\n")])])]),s("hr"),t._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),s("p",[s("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/lastb.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("lastb(1) — Linux manual page - man7.org"),s("OutboundLink")],1)]),t._v(" "),s("Vssue",{attrs:{title:"lastb"}})],1)}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[134],{465:function(t,s,a){"use strict";a.r(s);var n=a(12),e=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),s("p",[t._v("lastb 用于显示用户错误的登录列表。")]),t._v(" "),s("p",[t._v("lastb 可以发现系统的登录异常。单独执行 lastb 命令,它会读取位于 /var/log 目录下名为 btmp 的文件,并把该文件内容记录的登入失败的用户名单,全部显示出来。")]),t._v(" "),s("p",[t._v("实际上 lastb 是 last 的一个软链,所以 lastb 功能均可由 last 实现。唯一与 last 不同之处在于其默认读取的日志文件是 /var/log/btmp,其中包含所有错误的登录尝试。")]),t._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("lastb "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-R"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-n")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("file")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-adFiowx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v("."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("tty"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v("."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("-n , - \n\t显示最近登录信息的行数。\n-t \n\t根据登录的时间显示指定用户的登录状态。\n-R\n\t禁止显示主机名字段。\n-a\n\t在最后一列显示主机名称。\n-d\n\t对于非本地登录的用户,将显示的 IP 地址转换为主机名。\n-i\n\t类似于 “-d” 的选项,将显示的主机名称转换为 IP 地址。\n-o\n\t读取旧的类型的 wtmp 文件。\n-x\n\t显示系统登录等级。\n--help\n\t显示帮助信息。\n--version\n\t显示版本显示。\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),s("p",[t._v("(1)列出登入失败的用户记录。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("lastb "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-5")]),t._v("\nadmin ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nadmin ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \noperator ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":24 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":24 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1234")]),t._v(" ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":20 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":20 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \n"),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1234")]),t._v(" ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":20 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":20 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\nbtmp begins Mon Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("17")]),t._v(" 03:43:01 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v("\n")])])]),s("p",[t._v("lastb 指令,它会读取位于 /var/log/btmp 的文件,并把该文件内容记录的登入系统失败的用户名单,全部显示出来。btmp 是二进制文件,所以用 last -f /var/log/btmp 结果一样。")]),t._v(" "),s("p",[t._v("(2)使用 -a 选项把来源 IP 显示在最后列。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("lastb "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-a5")]),t._v("\nadmin ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":33 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":33 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113\nadmin ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":33 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":33 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113\nadmin ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113\nadmin ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":29 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113\noperator ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":24 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":24 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113\n\nbtmp begins Mon Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("17")]),t._v(" 03:43:01 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v("\n")])])]),s("p",[t._v("(3)不显示主机名字段。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("lastb "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-5")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-R")]),t._v("\njeremias ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \njeremias ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nmatthew ssh:notty Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":39 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":39 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \n\nbtmp begins Mon Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("17")]),t._v(" 03:43:01 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v("\n")])])]),s("p",[t._v("(4)显示指定用户登录失败记录。")]),t._v(" "),s("p",[t._v("比如显示 root 用户登录失败记录。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[t._v("lastb "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-n")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),t._v(" root\nroot ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("147.182")]),t._v(".179.237 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":44 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":44 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":42 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":42 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("61.177")]),t._v(".172.145 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("61.177")]),t._v(".172.145 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":40 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nroot ssh:notty "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("92.255")]),t._v(".85.113 Thu Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("27")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":38 - "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v(":38 "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("00:00"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \n\nbtmp begins Mon Oct "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("17")]),t._v(" 03:43:01 "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2022")]),t._v("\n")])])]),s("hr"),t._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),s("p",[s("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/lastb.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("lastb(1) — Linux manual page - man7.org"),s("OutboundLink")],1)]),t._v(" "),s("Vssue",{attrs:{title:"lastb"}})],1)}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/135.e22176d1.js b/docs/assets/js/135.494e2786.js similarity index 99% rename from docs/assets/js/135.e22176d1.js rename to docs/assets/js/135.494e2786.js index 973760bd5..d0a3cf8a1 100644 --- a/docs/assets/js/135.e22176d1.js +++ b/docs/assets/js/135.494e2786.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[135],{470:function(e,a,s){"use strict";s.r(a);var t=s(12),r=Object(t.a)({},(function(){var e=this,a=e._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[e._v("#")]),e._v(" 1.命令简介")]),e._v(" "),a("p",[e._v("lastlog 用于显示系统中所有用户最近一次登录信息。")]),e._v(" "),a("p",[e._v("lastlog 命令格式化输出上次登录日志 /var/log/lastlog 的内容。它根据 UID 排序显示登录名、终端(tty)和上次登录时间。如果一个用户从未登录过,lastlog 显示 "),a("code",[e._v("**Never logged in**")]),e._v("。")]),e._v(" "),a("p",[e._v("注意需要以 root 身份运行该命令。")]),e._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[e._v("#")]),e._v(" 2.命令格式")]),e._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[e._v("lastlog "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("[")]),e._v("OPTIONS"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("]")]),e._v("\n")])])]),a("p",[e._v("无选项单独执行 lastlog 将打印 lastlog 日志中的条目,并按其在 /etc/passwd 中的顺序进行排序。")]),e._v(" "),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[e._v("#")]),e._v(" 3.选项说明")]),e._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[e._v("-b, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("--before")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v("<")]),e._v("DAYS"),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v(">")]),e._v("\n\t仅打印早于 DAYS 的最近登录记录。\n-C, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("--clear")]),e._v("\n\t清除用户的 lastlog 记录(仅与-u一起使用)。\n-h, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("--help")]),e._v("\n\t显示此帮助信息并退出。\n-R, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("--root")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v("<")]),e._v("CHROOT_DIR"),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v(">")]),e._v("\n\t在 CHROOT_DIR 目录中应用更改并使用 CHROOT_DIR 目录中的配置文件。\n-S, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("--set")]),e._v("\n\t将 lastlog 记录设置为当前时间(仅与 "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("-u")]),e._v(" 一起使用)。\n-t, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("--time")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v("<")]),e._v("DAYS"),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v(">")]),e._v("\n\t仅打印晚于 DAYS 的最近登录记录。\n-u, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("--user")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v("<")]),e._v("LOGIN"),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v(">")]),e._v("\n\t打印 LOGIN 用户的最近登录记录。\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[e._v("#")]),e._v(" 4.常用示例")]),e._v(" "),a("p",[e._v("(1) 显示系统中所有用户最近一次登录信息。")]),e._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[e._v("Username Port From Latest\nroot pts/4 "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("223.73")]),e._v(".1.91 Thu Oct "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("27")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("15")]),e._v(":49:23 +0800 "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("2022")]),e._v("\nbin **Never logged in**\ndaemon **Never logged in**\nadm **Never logged in**\nlp **Never logged in**\n"),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("sync")]),e._v(" **Never logged in**\n"),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("shutdown")]),e._v(" **Never logged in**\n"),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("halt")]),e._v(" **Never logged in**\nmail **Never logged in**\noperator **Never logged in**\ngames **Never logged in**\n"),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("ftp")]),e._v(" **Never logged in**\nnobody **Never logged in**\nsystemd-network **Never logged in**\ndbus **Never logged in**\npolkitd **Never logged in**\nlibstoragemgmt **Never logged in**\nrpc **Never logged in**\nntp **Never logged in**\nabrt **Never logged in**\nsshd **Never logged in**\npostfix **Never logged in**\nchrony **Never logged in**\ntcpdump **Never logged in**\nsyslog **Never logged in**\nwww **Never logged in**\nlighthouse **Never logged in**\ntss **Never logged in**\n")])])]),a("p",[e._v("(2)显示指定用户的最近登录信息。")]),e._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[e._v("lastlog "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("-u")]),e._v(" root\nUsername Port From Latest\nroot pts/4 "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("223.73")]),e._v(".1.91 Thu Oct "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("27")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("15")]),e._v(":49:23 +0800 "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("2022")]),e._v("\n")])])]),a("p",[e._v("(3)显示指定天数前的登录信息。")]),e._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[e._v("lastlog "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("-b")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("7")]),e._v("\nUsername Port From Latest\nbin **Never logged in**\ndaemon **Never logged in**\nadm **Never logged in**\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("..")]),e._v(".\n")])])]),a("p",[e._v("(4)显示指定天数以来的登录信息。")]),e._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[e._v("lastlog "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("-b")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("7")]),e._v("\nUsername Port From Latest\nroot pts/4 "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("223.73")]),e._v(".1.91 Thu Oct "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("27")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("15")]),e._v(":49:23 +0800 "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("2022")]),e._v("\n")])])]),a("p",[e._v("(5)清除指定用户的登录信息。")]),e._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[e._v("lastlog "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("-C")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("-u")]),e._v(" root\n\nlastlog "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("-u")]),e._v(" root\nUsername Port From Latest\nroot **Never logged in**\n")])])]),a("hr"),e._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[e._v("#")]),e._v(" 参考文献")]),e._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/lastlog.8.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("lastlog(8) - Linux manual page - man7.org"),a("OutboundLink")],1)]),e._v(" "),a("Vssue",{attrs:{title:"lastlog"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[135],{467:function(e,a,s){"use strict";s.r(a);var t=s(12),r=Object(t.a)({},(function(){var e=this,a=e._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[e._v("#")]),e._v(" 1.命令简介")]),e._v(" "),a("p",[e._v("lastlog 用于显示系统中所有用户最近一次登录信息。")]),e._v(" "),a("p",[e._v("lastlog 命令格式化输出上次登录日志 /var/log/lastlog 的内容。它根据 UID 排序显示登录名、终端(tty)和上次登录时间。如果一个用户从未登录过,lastlog 显示 "),a("code",[e._v("**Never logged in**")]),e._v("。")]),e._v(" "),a("p",[e._v("注意需要以 root 身份运行该命令。")]),e._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[e._v("#")]),e._v(" 2.命令格式")]),e._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[e._v("lastlog "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("[")]),e._v("OPTIONS"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("]")]),e._v("\n")])])]),a("p",[e._v("无选项单独执行 lastlog 将打印 lastlog 日志中的条目,并按其在 /etc/passwd 中的顺序进行排序。")]),e._v(" "),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[e._v("#")]),e._v(" 3.选项说明")]),e._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[e._v("-b, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("--before")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v("<")]),e._v("DAYS"),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v(">")]),e._v("\n\t仅打印早于 DAYS 的最近登录记录。\n-C, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("--clear")]),e._v("\n\t清除用户的 lastlog 记录(仅与-u一起使用)。\n-h, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("--help")]),e._v("\n\t显示此帮助信息并退出。\n-R, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("--root")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v("<")]),e._v("CHROOT_DIR"),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v(">")]),e._v("\n\t在 CHROOT_DIR 目录中应用更改并使用 CHROOT_DIR 目录中的配置文件。\n-S, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("--set")]),e._v("\n\t将 lastlog 记录设置为当前时间(仅与 "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("-u")]),e._v(" 一起使用)。\n-t, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("--time")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v("<")]),e._v("DAYS"),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v(">")]),e._v("\n\t仅打印晚于 DAYS 的最近登录记录。\n-u, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("--user")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v("<")]),e._v("LOGIN"),a("span",{pre:!0,attrs:{class:"token operator"}},[e._v(">")]),e._v("\n\t打印 LOGIN 用户的最近登录记录。\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[e._v("#")]),e._v(" 4.常用示例")]),e._v(" "),a("p",[e._v("(1) 显示系统中所有用户最近一次登录信息。")]),e._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[e._v("Username Port From Latest\nroot pts/4 "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("223.73")]),e._v(".1.91 Thu Oct "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("27")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("15")]),e._v(":49:23 +0800 "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("2022")]),e._v("\nbin **Never logged in**\ndaemon **Never logged in**\nadm **Never logged in**\nlp **Never logged in**\n"),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("sync")]),e._v(" **Never logged in**\n"),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("shutdown")]),e._v(" **Never logged in**\n"),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("halt")]),e._v(" **Never logged in**\nmail **Never logged in**\noperator **Never logged in**\ngames **Never logged in**\n"),a("span",{pre:!0,attrs:{class:"token function"}},[e._v("ftp")]),e._v(" **Never logged in**\nnobody **Never logged in**\nsystemd-network **Never logged in**\ndbus **Never logged in**\npolkitd **Never logged in**\nlibstoragemgmt **Never logged in**\nrpc **Never logged in**\nntp **Never logged in**\nabrt **Never logged in**\nsshd **Never logged in**\npostfix **Never logged in**\nchrony **Never logged in**\ntcpdump **Never logged in**\nsyslog **Never logged in**\nwww **Never logged in**\nlighthouse **Never logged in**\ntss **Never logged in**\n")])])]),a("p",[e._v("(2)显示指定用户的最近登录信息。")]),e._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[e._v("lastlog "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("-u")]),e._v(" root\nUsername Port From Latest\nroot pts/4 "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("223.73")]),e._v(".1.91 Thu Oct "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("27")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("15")]),e._v(":49:23 +0800 "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("2022")]),e._v("\n")])])]),a("p",[e._v("(3)显示指定天数前的登录信息。")]),e._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[e._v("lastlog "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("-b")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("7")]),e._v("\nUsername Port From Latest\nbin **Never logged in**\ndaemon **Never logged in**\nadm **Never logged in**\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[e._v("..")]),e._v(".\n")])])]),a("p",[e._v("(4)显示指定天数以来的登录信息。")]),e._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[e._v("lastlog "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("-b")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("7")]),e._v("\nUsername Port From Latest\nroot pts/4 "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("223.73")]),e._v(".1.91 Thu Oct "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("27")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("15")]),e._v(":49:23 +0800 "),a("span",{pre:!0,attrs:{class:"token number"}},[e._v("2022")]),e._v("\n")])])]),a("p",[e._v("(5)清除指定用户的登录信息。")]),e._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[e._v("lastlog "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("-C")]),e._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("-u")]),e._v(" root\n\nlastlog "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[e._v("-u")]),e._v(" root\nUsername Port From Latest\nroot **Never logged in**\n")])])]),a("hr"),e._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[e._v("#")]),e._v(" 参考文献")]),e._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/lastlog.8.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("lastlog(8) - Linux manual page - man7.org"),a("OutboundLink")],1)]),e._v(" "),a("Vssue",{attrs:{title:"lastlog"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/136.43aeda3b.js b/docs/assets/js/136.a86e4246.js similarity index 96% rename from docs/assets/js/136.43aeda3b.js rename to docs/assets/js/136.a86e4246.js index f175f6137..21ed186b6 100644 --- a/docs/assets/js/136.43aeda3b.js +++ b/docs/assets/js/136.a86e4246.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[136],{471:function(a,t,s){"use strict";s.r(t);var e=s(12),r=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("logname 打印当前用户的登录名。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("logname [OPTION]\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("--help\n\t显示帮助信息然后退出。\n--version\n\t显示版本信息然后退出。\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("显示当前用户登录名。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("logname\nroot\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/logname.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("logname(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"logname"}})],1)}),[],!1,null,null,null);t.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[136],{468:function(a,t,s){"use strict";s.r(t);var e=s(12),r=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("logname 打印当前用户的登录名。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("logname [OPTION]\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("--help\n\t显示帮助信息然后退出。\n--version\n\t显示版本信息然后退出。\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("显示当前用户登录名。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("logname\nroot\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/logname.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("logname(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"logname"}})],1)}),[],!1,null,null,null);t.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/137.5c4aa035.js b/docs/assets/js/137.846df3d9.js similarity index 98% rename from docs/assets/js/137.5c4aa035.js rename to docs/assets/js/137.846df3d9.js index f7165984f..a74f39e60 100644 --- a/docs/assets/js/137.5c4aa035.js +++ b/docs/assets/js/137.846df3d9.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[137],{469:function(a,s,t){"use strict";t.r(s);var e=t(12),r=Object(e.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),s("p",[a._v("passwd 令用于设置用户的认证信息,包括用户密码、账户锁定、密码失效等。")]),a._v(" "),s("p",[a._v("系统管理员能用它管理系统用户的密码,只有管理员可以指定用户名称,一般用户只能变更自己的密码。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd [OPTIONS] [USERNAME]\n")])])]),s("p",[a._v("不带任何选项和参数直接运行 passwd 表示修改当前用户的登录密码,这也是 passwd 最常见的用法。")]),a._v(" "),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("p",[a._v("注意,长选项的必须参数对于短选项也是必须的。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("-k, --keep\n\t保持身份验证令牌不过期\n-d, --delete\n 删除已命名帐号的密码(仅限 root 用户)\n-l, --lock\n\t锁定指定帐户的密码(仅限 root 用户)。锁定是在密码加密字符串前面加上 ! 使得密码校验不通过。注意,帐户没有完全锁定,用户仍然可以通过其他身份验证方式登录,如 ssh 公钥身份验证\n-u, --unlock\n\t解锁指定账户的密码(仅限 root 用户)\n-e, --expire\n\t终止指定帐户的密码(仅限 root 用户)\n-f, --force\n\t强制执行操作\n-x, --maximum=DAYS\n\t密码的最长有效时限(仅限 root 用户)\n-n, --minimum=DAYS\n\t密码的最短有效时限(仅限 root 用户)\n-w, --warning=DAYS\n\t在密码过期前多少天开始提醒用户(仅限 root 用户)\n-i, --inactive=DAYS\n\t当密码过期后经过多少天该帐号会被禁用(仅限 root 用户)\n-S, --status\n\t报告已命名帐号的密码状态(仅限 root 用户)\n--stdin\n\t从标准输入读取令牌(仅限 root 用户)\n-?, --help\n \t显示帮助信息并退出\n--usage\n\t显示简要使用信息\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)修改当前登陆的账户密码。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd\n")])])]),s("p",[a._v('注意,设置用户密码时一定要遵守"复杂性、易记忆性、时效性"的密码规范。简单来讲就是密码要大于 8 位,包含大小写字母、数字和特殊符号,并且容易记忆和定期更换。')]),a._v(" "),s("p",[a._v("(2)修改其他用户密码,需要管理员权限。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd USERNAME\n")])])]),s("p",[a._v("(3)锁定指定帐户的密码,使得用户通过密码无法登录。需要管理员权限。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd -l USERNAME\n")])])]),s("p",[a._v("(4)解锁指定帐户的密码。需要管理员权限。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd -u USERNAME\n")])])]),s("p",[a._v("(5)终止指定帐户的密码,使用户下次登陆强制改密码。需要管理员权限。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd -e USERNAME\n")])])]),s("p",[a._v("(6)清除登录密码,使得用户无需通过密码即可登录。需要管理员权限,风险极大,不推荐使用。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd -d USERNAME\n")])])]),s("p",[a._v("(7)查询帐号的密码状态。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd -S dablelv\ndablelv PS 2020-03-08 0 90 7 -1 (Password set, SHA512 crypt.)\n")])])]),s("p",[a._v("显示账户状态信息,共有7个字段,分别是登录名、密码、上次修改时间、密码修改间隔时间(0)、密码有效期(90)、警告时间(7)、密码不失效(-1),单位都是天。")]),a._v(" "),s("p",[a._v("(8)设置密码的最小和最大有效天数。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd -x 100 -n 30 dablelv\n\n#查看是否设置成功\npasswd -S dablelv\ndablelv PS 2020-03-08 30 100 7 -1 (Password set, SHA512 crypt.)\n")])])]),s("p",[a._v("(9) 在密码过期前多少天开始提醒用户。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd -w 7 dablelv\n")])])]),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://linux.die.net/man/1/passwd",target:"_blank",rel:"noopener noreferrer"}},[a._v("passwd(1) manual"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/97966163",target:"_blank",rel:"noopener noreferrer"}},[a._v("CSDN.【Linux】一步一步学Linux——passwd命令(85)"),s("OutboundLink")],1)]),a._v(" "),s("Vssue",{attrs:{title:"passwd"}})],1)}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[137],{470:function(a,s,t){"use strict";t.r(s);var e=t(12),r=Object(e.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),s("p",[a._v("passwd 令用于设置用户的认证信息,包括用户密码、账户锁定、密码失效等。")]),a._v(" "),s("p",[a._v("系统管理员能用它管理系统用户的密码,只有管理员可以指定用户名称,一般用户只能变更自己的密码。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd [OPTIONS] [USERNAME]\n")])])]),s("p",[a._v("不带任何选项和参数直接运行 passwd 表示修改当前用户的登录密码,这也是 passwd 最常见的用法。")]),a._v(" "),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("p",[a._v("注意,长选项的必须参数对于短选项也是必须的。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("-k, --keep\n\t保持身份验证令牌不过期\n-d, --delete\n 删除已命名帐号的密码(仅限 root 用户)\n-l, --lock\n\t锁定指定帐户的密码(仅限 root 用户)。锁定是在密码加密字符串前面加上 ! 使得密码校验不通过。注意,帐户没有完全锁定,用户仍然可以通过其他身份验证方式登录,如 ssh 公钥身份验证\n-u, --unlock\n\t解锁指定账户的密码(仅限 root 用户)\n-e, --expire\n\t终止指定帐户的密码(仅限 root 用户)\n-f, --force\n\t强制执行操作\n-x, --maximum=DAYS\n\t密码的最长有效时限(仅限 root 用户)\n-n, --minimum=DAYS\n\t密码的最短有效时限(仅限 root 用户)\n-w, --warning=DAYS\n\t在密码过期前多少天开始提醒用户(仅限 root 用户)\n-i, --inactive=DAYS\n\t当密码过期后经过多少天该帐号会被禁用(仅限 root 用户)\n-S, --status\n\t报告已命名帐号的密码状态(仅限 root 用户)\n--stdin\n\t从标准输入读取令牌(仅限 root 用户)\n-?, --help\n \t显示帮助信息并退出\n--usage\n\t显示简要使用信息\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)修改当前登陆的账户密码。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd\n")])])]),s("p",[a._v('注意,设置用户密码时一定要遵守"复杂性、易记忆性、时效性"的密码规范。简单来讲就是密码要大于 8 位,包含大小写字母、数字和特殊符号,并且容易记忆和定期更换。')]),a._v(" "),s("p",[a._v("(2)修改其他用户密码,需要管理员权限。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd USERNAME\n")])])]),s("p",[a._v("(3)锁定指定帐户的密码,使得用户通过密码无法登录。需要管理员权限。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd -l USERNAME\n")])])]),s("p",[a._v("(4)解锁指定帐户的密码。需要管理员权限。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd -u USERNAME\n")])])]),s("p",[a._v("(5)终止指定帐户的密码,使用户下次登陆强制改密码。需要管理员权限。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd -e USERNAME\n")])])]),s("p",[a._v("(6)清除登录密码,使得用户无需通过密码即可登录。需要管理员权限,风险极大,不推荐使用。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd -d USERNAME\n")])])]),s("p",[a._v("(7)查询帐号的密码状态。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd -S dablelv\ndablelv PS 2020-03-08 0 90 7 -1 (Password set, SHA512 crypt.)\n")])])]),s("p",[a._v("显示账户状态信息,共有7个字段,分别是登录名、密码、上次修改时间、密码修改间隔时间(0)、密码有效期(90)、警告时间(7)、密码不失效(-1),单位都是天。")]),a._v(" "),s("p",[a._v("(8)设置密码的最小和最大有效天数。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd -x 100 -n 30 dablelv\n\n#查看是否设置成功\npasswd -S dablelv\ndablelv PS 2020-03-08 30 100 7 -1 (Password set, SHA512 crypt.)\n")])])]),s("p",[a._v("(9) 在密码过期前多少天开始提醒用户。")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("passwd -w 7 dablelv\n")])])]),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://linux.die.net/man/1/passwd",target:"_blank",rel:"noopener noreferrer"}},[a._v("passwd(1) manual"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/97966163",target:"_blank",rel:"noopener noreferrer"}},[a._v("CSDN.【Linux】一步一步学Linux——passwd命令(85)"),s("OutboundLink")],1)]),a._v(" "),s("Vssue",{attrs:{title:"passwd"}})],1)}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/138.5589ca34.js b/docs/assets/js/138.ff2bcc5b.js similarity index 99% rename from docs/assets/js/138.5589ca34.js rename to docs/assets/js/138.ff2bcc5b.js index 123f56971..edf4ae08b 100644 --- a/docs/assets/js/138.5589ca34.js +++ b/docs/assets/js/138.ff2bcc5b.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[138],{472:function(a,s,t){"use strict";t.r(s);var e=t(12),n=Object(e.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),s("p",[a._v("useradd 用来创建新用户或更新创建新用户时的默认信息。")]),a._v(" "),s("p",[a._v("如果在创建用户时没有指定密码,用户的默认密码是不可用的。所以 useradd 一般与 passwd 命令成对使用,在创建用户后给用户设置密码。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("OPTIONS"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" LOGIN\n"),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("OPTIONS"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n")])])]),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("-b, --base-dir BASE_DIR\n\t新账户的主目录的基目录\n-c, --comment COMMENT\n\t新账户的备注信息,备注信息保存在 /etc/passwd 的备注栏中\n-d, --home-dir HOME_DIR\n\t新账户的主目录\n-D, --defaults\n\t显示或更改默认的 useradd 配置\n-e, --expiredate EXPIRE_DATE\n\t新账户的过期日期,日期格式为 YYYY-MM-DD。如果未指定,useradd 将使用在 /etc/default/useradd 中指定的到期日期 EXPIRE,或默认情况下使用空字符串(无过期)\n-f, --inactive INACTIVE\n\t指定在密码过期后多少天即关闭该账号。如果为 0 账号立即被停用;如果为 -1 则账号一直可用。默认值为 -1\n-g, --gid GROUP\n\t指定用户所属的主组。主组必须已经存在\n-G, --groups GROUPS\n\t指定用户所属的附加组,多个组使用逗号分隔\n-h, --help\n 显示帮助信息并推出\n-k, --skel SKEL_DIR\n\t指定用户的骨架目录。与选项 -m (或 --create-home)联用,骨架目录包含要复制到用户主目录中的文件和目录\n-K, --key KEY=VALUE\n\t不使用 /etc/login.defs 中的默认值(UID_MIN、UID_MAX、UMASK、PASS_MAX_DAYS 等)\n-l, --no-log-init\n\t不要将此用户添加到最近登录和登录失败数据库\n-m, --create-home\n\t创建用户的家目录。useradd 默认会创建 home 目录,除非 /etc/login.defs 中的 CREATE_HOME 设置为no\n-M, --no-create-home\n\t不创建用户的主目录。即使 /etc/login.defs 中的 CREATE_HOME 设置为 yes\n-N, --no-user-group\n\t不创建同名的组\n-o, --non-unique\n \t允许使用重复的 UID 创建用户\n-p, --password PASSWORD \n \t设置账户密码,注意是使用 crypt(3) 加密后的用户密码,不是密码的明文。默认是用户密码不可用。推荐使用 passwd 命令给用户设置密码\n-r, --system\n \t创建一个系统账户\n-R, --root CHROOT_DIR\n\t设置根目录。在 Linux 系统中,系统默认的根目录是 /\n-s, --shell SHELL \n\t新账户的登录 Shell\n-u, --uid UID\n\t新账户的用户 ID\n-U, --user-group\n\t创建与用户同名的组,并将用户添加到此组中。为默认动作,除非 /etc/login.defs 中 USERGROUPS_ENAB 被设置为 no 或显示使用选项 -N, --no-user-group\n-Z, --selinux-user SEUSER\n\t为 SELinux 用户映射使用指定 SEUSER\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)添加新用户。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" dablelv\n")])])]),s("p",[a._v("默认在创建用户时的同时会创建一个同名的用户主组和在 /home 目录下同名的家目录,除非在配置文件 /etc/login.defs 中 USERGROUPS_ENAB 和 CREATE_HOME 被设置为 no。")]),a._v(" "),s("p",[a._v("(2)添加新用户时,显示指明家目录和所属的主组。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-d")]),a._v(" /home/dablelvH "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-g")]),a._v(" root dablelv\n")])])]),s("p",[a._v("添加用户成功后,我们可以使用 "),s("a",{attrs:{href:"https://dablelv.blog.csdn.net/article/details/102845312",target:"_blank",rel:"noopener noreferrer"}},[a._v("id"),s("OutboundLink")],1),a._v(" 命令查看用户 dablelv 的用户 ID、主组和附加组。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("id")]),a._v(" dablelv\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("uid")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1000")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("dablelv"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("gid")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("root"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("groups")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("root"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v("\n")])])]),s("p",[a._v("(3)添加新用户后,并使用 passwd 给用户设置密码。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" dablelv\n"),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("passwd")]),a._v(" dablelv\n")])])]),s("p",[a._v("(4)添加用户,并给用户设置有效期。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-e")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("2020")]),a._v("-12-31 dablelv\n")])])]),s("p",[a._v("(5)使用 useradd -D 查看创建新用户时的默认信息,或直接 cat /etc/default/useradd。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("GROUP")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("100")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s("span",{pre:!0,attrs:{class:"token environment constant"}},[a._v("HOME")])]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/home\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("INACTIVE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("-1\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("EXPIRE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s("span",{pre:!0,attrs:{class:"token environment constant"}},[a._v("SHELL")])]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/bin/bash\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("SKEL")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/etc/skel\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("CREATE_MAIL_SPOOL")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("yes\n")])])]),s("p",[a._v("(6)修改创建新用户时的默认信息。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-f")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 查看是否修改成功")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("grep")]),a._v(" INACTIVE\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("INACTIVE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v("\n")])])]),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/useradd.8.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("useradd(8) - Linux manual page - man7.org"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"https://www.cnblogs.com/diantong/p/9430258.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("Linux命令之useradd - 博客园"),s("OutboundLink")],1)]),a._v(" "),s("Vssue",{attrs:{title:"useradd"}})],1)}),[],!1,null,null,null);s.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[138],{469:function(a,s,t){"use strict";t.r(s);var e=t(12),n=Object(e.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),s("p",[a._v("useradd 用来创建新用户或更新创建新用户时的默认信息。")]),a._v(" "),s("p",[a._v("如果在创建用户时没有指定密码,用户的默认密码是不可用的。所以 useradd 一般与 passwd 命令成对使用,在创建用户后给用户设置密码。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("OPTIONS"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v(" LOGIN\n"),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("OPTIONS"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n")])])]),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("-b, --base-dir BASE_DIR\n\t新账户的主目录的基目录\n-c, --comment COMMENT\n\t新账户的备注信息,备注信息保存在 /etc/passwd 的备注栏中\n-d, --home-dir HOME_DIR\n\t新账户的主目录\n-D, --defaults\n\t显示或更改默认的 useradd 配置\n-e, --expiredate EXPIRE_DATE\n\t新账户的过期日期,日期格式为 YYYY-MM-DD。如果未指定,useradd 将使用在 /etc/default/useradd 中指定的到期日期 EXPIRE,或默认情况下使用空字符串(无过期)\n-f, --inactive INACTIVE\n\t指定在密码过期后多少天即关闭该账号。如果为 0 账号立即被停用;如果为 -1 则账号一直可用。默认值为 -1\n-g, --gid GROUP\n\t指定用户所属的主组。主组必须已经存在\n-G, --groups GROUPS\n\t指定用户所属的附加组,多个组使用逗号分隔\n-h, --help\n 显示帮助信息并推出\n-k, --skel SKEL_DIR\n\t指定用户的骨架目录。与选项 -m (或 --create-home)联用,骨架目录包含要复制到用户主目录中的文件和目录\n-K, --key KEY=VALUE\n\t不使用 /etc/login.defs 中的默认值(UID_MIN、UID_MAX、UMASK、PASS_MAX_DAYS 等)\n-l, --no-log-init\n\t不要将此用户添加到最近登录和登录失败数据库\n-m, --create-home\n\t创建用户的家目录。useradd 默认会创建 home 目录,除非 /etc/login.defs 中的 CREATE_HOME 设置为no\n-M, --no-create-home\n\t不创建用户的主目录。即使 /etc/login.defs 中的 CREATE_HOME 设置为 yes\n-N, --no-user-group\n\t不创建同名的组\n-o, --non-unique\n \t允许使用重复的 UID 创建用户\n-p, --password PASSWORD \n \t设置账户密码,注意是使用 crypt(3) 加密后的用户密码,不是密码的明文。默认是用户密码不可用。推荐使用 passwd 命令给用户设置密码\n-r, --system\n \t创建一个系统账户\n-R, --root CHROOT_DIR\n\t设置根目录。在 Linux 系统中,系统默认的根目录是 /\n-s, --shell SHELL \n\t新账户的登录 Shell\n-u, --uid UID\n\t新账户的用户 ID\n-U, --user-group\n\t创建与用户同名的组,并将用户添加到此组中。为默认动作,除非 /etc/login.defs 中 USERGROUPS_ENAB 被设置为 no 或显示使用选项 -N, --no-user-group\n-Z, --selinux-user SEUSER\n\t为 SELinux 用户映射使用指定 SEUSER\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)添加新用户。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" dablelv\n")])])]),s("p",[a._v("默认在创建用户时的同时会创建一个同名的用户主组和在 /home 目录下同名的家目录,除非在配置文件 /etc/login.defs 中 USERGROUPS_ENAB 和 CREATE_HOME 被设置为 no。")]),a._v(" "),s("p",[a._v("(2)添加新用户时,显示指明家目录和所属的主组。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-d")]),a._v(" /home/dablelvH "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-g")]),a._v(" root dablelv\n")])])]),s("p",[a._v("添加用户成功后,我们可以使用 "),s("a",{attrs:{href:"https://dablelv.blog.csdn.net/article/details/102845312",target:"_blank",rel:"noopener noreferrer"}},[a._v("id"),s("OutboundLink")],1),a._v(" 命令查看用户 dablelv 的用户 ID、主组和附加组。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("id")]),a._v(" dablelv\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("uid")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1000")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("dablelv"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("gid")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("root"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("groups")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("(")]),a._v("root"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(")")]),a._v("\n")])])]),s("p",[a._v("(3)添加新用户后,并使用 passwd 给用户设置密码。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" dablelv\n"),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("passwd")]),a._v(" dablelv\n")])])]),s("p",[a._v("(4)添加用户,并给用户设置有效期。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-e")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("2020")]),a._v("-12-31 dablelv\n")])])]),s("p",[a._v("(5)使用 useradd -D 查看创建新用户时的默认信息,或直接 cat /etc/default/useradd。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("GROUP")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("100")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s("span",{pre:!0,attrs:{class:"token environment constant"}},[a._v("HOME")])]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/home\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("INACTIVE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("-1\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("EXPIRE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s("span",{pre:!0,attrs:{class:"token environment constant"}},[a._v("SHELL")])]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/bin/bash\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("SKEL")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("/etc/skel\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("CREATE_MAIL_SPOOL")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("yes\n")])])]),s("p",[a._v("(6)修改创建新用户时的默认信息。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-f")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# 查看是否修改成功")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("useradd")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-D")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("grep")]),a._v(" INACTIVE\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("INACTIVE")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v("\n")])])]),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/useradd.8.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("useradd(8) - Linux manual page - man7.org"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"https://www.cnblogs.com/diantong/p/9430258.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("Linux命令之useradd - 博客园"),s("OutboundLink")],1)]),a._v(" "),s("Vssue",{attrs:{title:"useradd"}})],1)}),[],!1,null,null,null);s.default=n.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/139.4b5140ac.js b/docs/assets/js/139.b59d345e.js similarity index 98% rename from docs/assets/js/139.4b5140ac.js rename to docs/assets/js/139.b59d345e.js index a83e7d9f3..ea278e9ab 100644 --- a/docs/assets/js/139.4b5140ac.js +++ b/docs/assets/js/139.b59d345e.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[139],{473:function(e,t,a){"use strict";a.r(t);var s=a(12),r=Object(s.a)({},(function(){var e=this,t=e._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[e._v("#")]),e._v(" 1.命令简介")]),e._v(" "),t("p",[e._v("userdel(user delete) 命令是系统管理员命令,用于删除用户账户和相关文件。")]),e._v(" "),t("p",[e._v("其实 userdel 命令实际上是修改了系统的用户账号文件 /etc/passwd、/etc/shadow 以及 /etc/group 文件,这与 Linux 系统“一切操作皆文件”的思想正好吻合。")]),e._v(" "),t("p",[e._v("值得注意的是,如果有该要删除用户相关的进程正在运行,userdel 命令通常不会删除一个用户账号。如果确实必须要删除,可以先终止用户进程,然后再执行userdel命令进行删除。但是 userdel 命令也提供了一个面对该种情况的参数,即 -f 选项。")]),e._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[e._v("#")]),e._v(" 2.命令格式")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("userdel [options] LOGIN\n")])])]),t("p",[e._v("若不加选项,则仅删除用户帐号,而不删除相关文件。")]),e._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[e._v("#")]),e._v(" 3.选项说明")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("-f, --force\n\t\t强制删除用户,即使用户当前已登录\n-h, --help\n\t显示帮助信息并推出\n-r, --remove\n\t删除用户的同时删除与用户相关的所有文件,比如删除主目录和邮件池\n-R, --root CHROOT_DIR\n \t在 CHROOT_DIR 目录中应用更改并使用 CHROOT_DIR 目录中的配置文件\n-Z, --selinux-user\n\t为用户删除所有的 SELinux 用户映射\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[e._v("#")]),e._v(" 4.常用示例")]),e._v(" "),t("p",[e._v("(1)删除用户,但不删除其家目录及文件。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("userdel tom\n")])])]),t("p",[e._v("(2)删除用户,删除主目录和邮件池。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("userdel -r tom\n")])])]),t("p",[e._v("请不要轻易用 -r 选项,它会删除用户的同时删除用户所有的文件和目录,切记如果用户目录下有重要的文件,在删除前请备份。")]),e._v(" "),t("p",[e._v("(3)强制删除用户。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("userdel -f tom\n")])])]),t("hr"),e._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[e._v("#")]),e._v(" 参考文献")]),e._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/userdel.8.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("userdel(8) - Linux manual page - man7.org"),t("OutboundLink")],1)]),e._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/97963550",target:"_blank",rel:"noopener noreferrer"}},[e._v("CSDN.【Linux】一步一步学Linux——userdel命令(84)"),t("OutboundLink")],1)]),e._v(" "),t("Vssue",{attrs:{title:"userdel"}})],1)}),[],!1,null,null,null);t.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[139],{471:function(e,t,a){"use strict";a.r(t);var s=a(12),r=Object(s.a)({},(function(){var e=this,t=e._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[e._v("#")]),e._v(" 1.命令简介")]),e._v(" "),t("p",[e._v("userdel(user delete) 命令是系统管理员命令,用于删除用户账户和相关文件。")]),e._v(" "),t("p",[e._v("其实 userdel 命令实际上是修改了系统的用户账号文件 /etc/passwd、/etc/shadow 以及 /etc/group 文件,这与 Linux 系统“一切操作皆文件”的思想正好吻合。")]),e._v(" "),t("p",[e._v("值得注意的是,如果有该要删除用户相关的进程正在运行,userdel 命令通常不会删除一个用户账号。如果确实必须要删除,可以先终止用户进程,然后再执行userdel命令进行删除。但是 userdel 命令也提供了一个面对该种情况的参数,即 -f 选项。")]),e._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[e._v("#")]),e._v(" 2.命令格式")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("userdel [options] LOGIN\n")])])]),t("p",[e._v("若不加选项,则仅删除用户帐号,而不删除相关文件。")]),e._v(" "),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[e._v("#")]),e._v(" 3.选项说明")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("-f, --force\n\t\t强制删除用户,即使用户当前已登录\n-h, --help\n\t显示帮助信息并推出\n-r, --remove\n\t删除用户的同时删除与用户相关的所有文件,比如删除主目录和邮件池\n-R, --root CHROOT_DIR\n \t在 CHROOT_DIR 目录中应用更改并使用 CHROOT_DIR 目录中的配置文件\n-Z, --selinux-user\n\t为用户删除所有的 SELinux 用户映射\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[e._v("#")]),e._v(" 4.常用示例")]),e._v(" "),t("p",[e._v("(1)删除用户,但不删除其家目录及文件。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("userdel tom\n")])])]),t("p",[e._v("(2)删除用户,删除主目录和邮件池。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("userdel -r tom\n")])])]),t("p",[e._v("请不要轻易用 -r 选项,它会删除用户的同时删除用户所有的文件和目录,切记如果用户目录下有重要的文件,在删除前请备份。")]),e._v(" "),t("p",[e._v("(3)强制删除用户。")]),e._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[e._v("userdel -f tom\n")])])]),t("hr"),e._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[e._v("#")]),e._v(" 参考文献")]),e._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/userdel.8.html",target:"_blank",rel:"noopener noreferrer"}},[e._v("userdel(8) - Linux manual page - man7.org"),t("OutboundLink")],1)]),e._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/97963550",target:"_blank",rel:"noopener noreferrer"}},[e._v("CSDN.【Linux】一步一步学Linux——userdel命令(84)"),t("OutboundLink")],1)]),e._v(" "),t("Vssue",{attrs:{title:"userdel"}})],1)}),[],!1,null,null,null);t.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/14.245e8c8c.js b/docs/assets/js/14.d33ddaf5.js similarity index 98% rename from docs/assets/js/14.245e8c8c.js rename to docs/assets/js/14.d33ddaf5.js index d13ac7b36..ebfc26992 100644 --- a/docs/assets/js/14.245e8c8c.js +++ b/docs/assets/js/14.d33ddaf5.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[14],{348:function(a,s,t){"use strict";t.r(s);var e=t(12),n=Object(e.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),s("p",[a._v("eval(evaluate)连接参数构造命令并执行,为内建命令。")]),a._v(" "),s("p",[a._v("使用空格分隔每个参数,如果参数中含有变量,则替换为变量值,然后再将构造的命令交由 Shell 解释执行。它通常用于动态生成和执行命令,或者将字符串解释为可执行的 Shell 代码。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("eval")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("ARG"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),a._v("."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n")])])]),s("p",[a._v("eval 的返回值是其后面命令的退出状态。如果没有参数或只有空参数,eval 返回 0。")]),a._v(" "),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("p",[a._v("None。")]),a._v(" "),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)回显简单变量。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("NAME")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("foo\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$NAME")]),a._v("\nfoo\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# echo 前添加 eval 也可以")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("eval")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$NAME")]),a._v("\nfoo\n")])])]),s("p",[a._v("(2)先替换变量再执行命令。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" test.txt\nHello World"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("!")]),a._v("\n\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("command")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"cat test.txt"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(";")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$command")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" test.txt\n\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("eval")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$command")]),a._v("\nHello World"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("!")]),a._v("\n")])])]),s("p",[a._v("(3)获取传给脚本或函数的最后一个参数。")]),a._v(" "),s("p",[a._v("使用特殊字符 "),s("code",[a._v("$#")]),a._v(" 表示传递给脚本或函数的参数个数,使用"),s("code",[a._v("$n")]),a._v("获取参数,n 为数字,"),s("code",[a._v("$1")]),a._v(" 表示第一个参数,"),s("code",[a._v("$2")]),a._v(" 表示第二个参数,所以"),s("code",[a._v("$$#")]),a._v("表示最后一个参数。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" test.sh\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#!/usr/bin/bash")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("\\")]),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$$")]),a._v("#\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("eval")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("\\")]),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$$")]),a._v("#\n\n./test.sh firstarg lastarg\n"),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$2")]),a._v("\nlastarg\n")])])]),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://www.man7.org/linux/man-pages/man1/bash.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("bash(1) - Linux manual page - man7.org"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"https://blog.csdn.net/baidu_37964071/article/details/80930704",target:"_blank",rel:"noopener noreferrer"}},[a._v("``和$()的区别及eval详解 - CSDN"),s("OutboundLink")],1)]),a._v(" "),s("Vssue",{attrs:{title:"eval-builtin"}})],1)}),[],!1,null,null,null);s.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[14],{347:function(a,s,t){"use strict";t.r(s);var e=t(12),n=Object(e.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),s("p",[a._v("eval(evaluate)连接参数构造命令并执行,为内建命令。")]),a._v(" "),s("p",[a._v("使用空格分隔每个参数,如果参数中含有变量,则替换为变量值,然后再将构造的命令交由 Shell 解释执行。它通常用于动态生成和执行命令,或者将字符串解释为可执行的 Shell 代码。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("eval")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),a._v("ARG"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),a._v("."),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),a._v("\n")])])]),s("p",[a._v("eval 的返回值是其后面命令的退出状态。如果没有参数或只有空参数,eval 返回 0。")]),a._v(" "),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("p",[a._v("None。")]),a._v(" "),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)回显简单变量。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("NAME")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),a._v("foo\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$NAME")]),a._v("\nfoo\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("# echo 前添加 eval 也可以")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("eval")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$NAME")]),a._v("\nfoo\n")])])]),s("p",[a._v("(2)先替换变量再执行命令。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" test.txt\nHello World"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("!")]),a._v("\n\n"),s("span",{pre:!0,attrs:{class:"token assign-left variable"}},[a._v("command")]),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("=")]),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"cat test.txt"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(";")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$command")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" test.txt\n\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("eval")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$command")]),a._v("\nHello World"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("!")]),a._v("\n")])])]),s("p",[a._v("(3)获取传给脚本或函数的最后一个参数。")]),a._v(" "),s("p",[a._v("使用特殊字符 "),s("code",[a._v("$#")]),a._v(" 表示传递给脚本或函数的参数个数,使用"),s("code",[a._v("$n")]),a._v("获取参数,n 为数字,"),s("code",[a._v("$1")]),a._v(" 表示第一个参数,"),s("code",[a._v("$2")]),a._v(" 表示第二个参数,所以"),s("code",[a._v("$$#")]),a._v("表示最后一个参数。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("cat")]),a._v(" test.sh\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[a._v("#!/usr/bin/bash")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("\\")]),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$$")]),a._v("#\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("eval")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("echo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("\\")]),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$$")]),a._v("#\n\n./test.sh firstarg lastarg\n"),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$2")]),a._v("\nlastarg\n")])])]),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://www.man7.org/linux/man-pages/man1/bash.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("bash(1) - Linux manual page - man7.org"),s("OutboundLink")],1)]),a._v(" "),s("p",[s("a",{attrs:{href:"https://blog.csdn.net/baidu_37964071/article/details/80930704",target:"_blank",rel:"noopener noreferrer"}},[a._v("``和$()的区别及eval详解 - CSDN"),s("OutboundLink")],1)]),a._v(" "),s("Vssue",{attrs:{title:"eval-builtin"}})],1)}),[],!1,null,null,null);s.default=n.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/140.e405a89e.js b/docs/assets/js/140.cac581cd.js similarity index 98% rename from docs/assets/js/140.e405a89e.js rename to docs/assets/js/140.cac581cd.js index 8663d5c6f..da5382c93 100644 --- a/docs/assets/js/140.e405a89e.js +++ b/docs/assets/js/140.cac581cd.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[140],{474:function(a,t,e){"use strict";e.r(t);var s=e(12),r=Object(s.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("usermod(user modify)是系统管理员命令,用于修改用户账号。")]),a._v(" "),t("p",[a._v("usermod 可用来修改用户账号的各项设定,通过修改系统账号文件让命令行指定的变化生效。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod [OPTIONS] LOGIN\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-a, --append\n\t将用户添加到补充组。仅与 -G 选项一起使用。\n-c, --comment\n\t添加备信息\n-d, --home HOME_DIR\n\t用户的新主目录\n-e, --expiredate EXPIRE_DATE\n\t设定帐户过期的日期\n-f, --inactive INACTIVE\n\t过期 INACTIVE 天数后,设定密码为失效状态\n-g, --gid GROUP\n\t强制使用 GROUP 为新主组\n-G, --groups GROUPS\n\t新的附加组列表 GROUPS\n-a, --append GROUP\n\t将用户追加至上边 -G 中提到的附加组中,并不从其它组中删除此用户\n-h, --help\n\t显示此帮助信息并推出\n-l, --login LOGIN\n\t新的登录名称\n-L, --lock\n\t锁定用户帐号\n-m, --move-home\n\t将家目录内容移至新位置 (仅于 -d 一起使用)\n-o, --non-unique\n\t允许使用重复的(非唯一的) UID\n-p, --password PASSWORD\n\t将加密过的密码 (PASSWORD) 设为新密码\n-s, --shell SHELL\n\t该用户帐号的新登录 shell\n-u, --uid UID\n \t用户帐号的新 UID\n-U, --unlock\n\t解锁用户帐号\n-Z, --selinux-user SEUSER\n\t用户账户的新 SELinux 用户映射\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("(1)修改用户的家目录。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -d /home/tom tom\n")])])]),t("p",[a._v("(2)改变用户的 uid。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -u 888 tom\n")])])]),t("p",[a._v("(3)修改用户名为 jerry。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -l jerry tom\n")])])]),t("p",[a._v("(4)锁定 tom 用户。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -L tom\n")])])]),t("p",[a._v("(5)解锁 tom 用户。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -U tom\n")])])]),t("p",[a._v("(6)添加新的附加组。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -G deng tom\n")])])]),t("p",[a._v("(7)修改用户登录 Shell。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -s /bin/sh tom\n")])])]),t("p",[a._v("(8)修改用户的 GID。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -g 1003 tom\n")])])]),t("p",[a._v("(9)指定帐号过期日期。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -e 2020-12-31 tom\n")])])]),t("p",[a._v("(10)指定用户帐号密码过期多少天后,禁用该帐号。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -f 3 tom\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/usermod.8.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("usermod(8) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/97970997",target:"_blank",rel:"noopener noreferrer"}},[a._v("CSDN.【Linux】一步一步学Linux——usermod命令(86)"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"usermod"}})],1)}),[],!1,null,null,null);t.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[140],{472:function(a,t,e){"use strict";e.r(t);var s=e(12),r=Object(s.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("usermod(user modify)是系统管理员命令,用于修改用户账号。")]),a._v(" "),t("p",[a._v("usermod 可用来修改用户账号的各项设定,通过修改系统账号文件让命令行指定的变化生效。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod [OPTIONS] LOGIN\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-a, --append\n\t将用户添加到补充组。仅与 -G 选项一起使用。\n-c, --comment\n\t添加备信息\n-d, --home HOME_DIR\n\t用户的新主目录\n-e, --expiredate EXPIRE_DATE\n\t设定帐户过期的日期\n-f, --inactive INACTIVE\n\t过期 INACTIVE 天数后,设定密码为失效状态\n-g, --gid GROUP\n\t强制使用 GROUP 为新主组\n-G, --groups GROUPS\n\t新的附加组列表 GROUPS\n-a, --append GROUP\n\t将用户追加至上边 -G 中提到的附加组中,并不从其它组中删除此用户\n-h, --help\n\t显示此帮助信息并推出\n-l, --login LOGIN\n\t新的登录名称\n-L, --lock\n\t锁定用户帐号\n-m, --move-home\n\t将家目录内容移至新位置 (仅于 -d 一起使用)\n-o, --non-unique\n\t允许使用重复的(非唯一的) UID\n-p, --password PASSWORD\n\t将加密过的密码 (PASSWORD) 设为新密码\n-s, --shell SHELL\n\t该用户帐号的新登录 shell\n-u, --uid UID\n \t用户帐号的新 UID\n-U, --unlock\n\t解锁用户帐号\n-Z, --selinux-user SEUSER\n\t用户账户的新 SELinux 用户映射\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("(1)修改用户的家目录。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -d /home/tom tom\n")])])]),t("p",[a._v("(2)改变用户的 uid。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -u 888 tom\n")])])]),t("p",[a._v("(3)修改用户名为 jerry。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -l jerry tom\n")])])]),t("p",[a._v("(4)锁定 tom 用户。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -L tom\n")])])]),t("p",[a._v("(5)解锁 tom 用户。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -U tom\n")])])]),t("p",[a._v("(6)添加新的附加组。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -G deng tom\n")])])]),t("p",[a._v("(7)修改用户登录 Shell。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -s /bin/sh tom\n")])])]),t("p",[a._v("(8)修改用户的 GID。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -g 1003 tom\n")])])]),t("p",[a._v("(9)指定帐号过期日期。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -e 2020-12-31 tom\n")])])]),t("p",[a._v("(10)指定用户帐号密码过期多少天后,禁用该帐号。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("usermod -f 3 tom\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/usermod.8.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("usermod(8) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/97970997",target:"_blank",rel:"noopener noreferrer"}},[a._v("CSDN.【Linux】一步一步学Linux——usermod命令(86)"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"usermod"}})],1)}),[],!1,null,null,null);t.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/141.b15c1fd4.js b/docs/assets/js/141.e5a8f71e.js similarity index 97% rename from docs/assets/js/141.b15c1fd4.js rename to docs/assets/js/141.e5a8f71e.js index d4145bb99..adf513fc2 100644 --- a/docs/assets/js/141.b15c1fd4.js +++ b/docs/assets/js/141.e5a8f71e.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[141],{475:function(t,s,a){"use strict";a.r(s);var r=a(12),e=Object(r.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),s("p",[t._v("users 打印当前登录的用户名列表。")]),t._v(" "),s("p",[t._v("每个显示的用户名对应一个登录会话。如果一个用户有不止一个登录会话,那他的用户名将重复显示对应的次数。")]),t._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("users")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("OPTION"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(". "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("FILE"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("--help\n\t显示此帮助信息并退出。\n--version\n\t显示版本信息并退出。\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),s("p",[t._v("显示系统当前登录的用户名。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("users")]),t._v("\nroot root root\n")])])]),s("hr"),t._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),s("p",[s("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/users.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("users(1) — Linux manual page - man7.org"),s("OutboundLink")],1)]),t._v(" "),s("Vssue",{attrs:{title:"users"}})],1)}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[141],{474:function(t,s,a){"use strict";a.r(s);var r=a(12),e=Object(r.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),s("p",[t._v("users 打印当前登录的用户名列表。")]),t._v(" "),s("p",[t._v("每个显示的用户名对应一个登录会话。如果一个用户有不止一个登录会话,那他的用户名将重复显示对应的次数。")]),t._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("users")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("OPTION"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(". "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("FILE"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("--help\n\t显示此帮助信息并退出。\n--version\n\t显示版本信息并退出。\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),s("p",[t._v("显示系统当前登录的用户名。")]),t._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("users")]),t._v("\nroot root root\n")])])]),s("hr"),t._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),s("p",[s("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/users.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("users(1) — Linux manual page - man7.org"),s("OutboundLink")],1)]),t._v(" "),s("Vssue",{attrs:{title:"users"}})],1)}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/142.89f0916e.js b/docs/assets/js/142.658ca8d7.js similarity index 99% rename from docs/assets/js/142.89f0916e.js rename to docs/assets/js/142.658ca8d7.js index c58014145..35e841b5d 100644 --- a/docs/assets/js/142.89f0916e.js +++ b/docs/assets/js/142.658ca8d7.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[142],{476:function(s,a,t){"use strict";t.r(a);var r=t(12),e=Object(r.a)({},(function(){var s=this,a=s._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[s._v("#")]),s._v(" 1.命令简介")]),s._v(" "),a("p",[s._v("w 显示谁已登录以及他们正在做什么。")]),s._v(" "),a("p",[s._v("w 用于显示已经登录系统的用户列表,并显示用户正在执行的指令。执行这个命令可得知目前有哪些用户登录系统,以及他们正在执行的程序。单独执行 w 会显示所有用户,您也可指定用户名称,仅显示某个用户的相关信息。")]),s._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("w "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("options"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("user"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("..")]),s._v("."),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("-h, --no-header\n\t不打印头信息。\n-u, --no-current\n\t当显示当前进程和 CPU 时间时忽略用户名。\n-s, --short\n\t使用短输出格式。\n-f, --from\n\t显示用户从哪登录。\n--help\n\t显示帮助信息然后退出。\n-i, --ip-addr\n\t显示 from 字段的 IP 地址而不是主机名。\n-V, --version\n\t显示版本信息。\n-o, --old-style\n\t老式输出。空闲时间少于一分钟打印空白。\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[s._v("#")]),s._v(" 4.常用示例")]),s._v(" "),a("p",[s._v("(1)显示已经登录系统的用户列表,并显示用户正在执行的指令。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("w\n "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("12")]),s._v(":26:14 up "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(" days, "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("14")]),s._v(":36, "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" users, load average: "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0.19")]),s._v(", "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0.18")]),s._v(", "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0.11")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token environment constant"}},[s._v("USER")]),s._v(" TTY FROM LOGIN@ IDLE JCPU PCPU WHAT\nroot pts/0 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 09:36 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("7")]),s._v(":42 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\nroot pts/1 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(":39 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("6")]),s._v(".00s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\nroot pts/2 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("11")]),s._v(":18 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(":06m "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\n")])])]),a("p",[s._v("w 显示系统中当前用户的 信息,以及他们的进程。第一行中依次显示当前时间,系统的持续运行时间,登录的用户数和最近 1, 5, 15分钟的系统平均负载(load average)。")]),s._v(" "),a("p",[s._v("接下来的条目显示每位用户的:登录名、tty名、远程主机、登录时间、空闲时间、JCPU、PCPU 以及他们当前进程的命令行。")]),s._v(" "),a("p",[s._v("JCPU 时间指某个 tty 所有进程用掉的时间,不包括过去的后台任务,但是包括正在运行的后台任务。")]),s._v(" "),a("p",[s._v("PCPU 时间指当前进程用掉的时间,可以在 what 域看到当前进程。")]),s._v(" "),a("p",[s._v("(2)不打印头信息。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("w "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-h")]),s._v("\nroot pts/0 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 09:36 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("15")]),s._v(":13 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\nroot pts/1 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(":39 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(".00s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\nroot pts/2 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("11")]),s._v(":18 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(":13m "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\n")])])]),a("p",[s._v("(3)使用短输出格式。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("w "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-s")]),s._v("\n "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("12")]),s._v(":36:50 up "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(" days, "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("14")]),s._v(":46, "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" users, load average: "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0.00")]),s._v(", "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0.07")]),s._v(", "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0.11")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token environment constant"}},[s._v("USER")]),s._v(" TTY FROM IDLE WHAT\nroot pts/0 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("18")]),s._v(":18 "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\nroot pts/1 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),s._v(".00s "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\nroot pts/2 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(":16m "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\n")])])]),a("hr"),s._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/w.1.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("w(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),s._v(" "),a("Vssue",{attrs:{title:"w"}})],1)}),[],!1,null,null,null);a.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[142],{478:function(s,a,t){"use strict";t.r(a);var r=t(12),e=Object(r.a)({},(function(){var s=this,a=s._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[s._v("#")]),s._v(" 1.命令简介")]),s._v(" "),a("p",[s._v("w 显示谁已登录以及他们正在做什么。")]),s._v(" "),a("p",[s._v("w 用于显示已经登录系统的用户列表,并显示用户正在执行的指令。执行这个命令可得知目前有哪些用户登录系统,以及他们正在执行的程序。单独执行 w 会显示所有用户,您也可指定用户名称,仅显示某个用户的相关信息。")]),s._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("w "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("options"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("user"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("..")]),s._v("."),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[s._v("-h, --no-header\n\t不打印头信息。\n-u, --no-current\n\t当显示当前进程和 CPU 时间时忽略用户名。\n-s, --short\n\t使用短输出格式。\n-f, --from\n\t显示用户从哪登录。\n--help\n\t显示帮助信息然后退出。\n-i, --ip-addr\n\t显示 from 字段的 IP 地址而不是主机名。\n-V, --version\n\t显示版本信息。\n-o, --old-style\n\t老式输出。空闲时间少于一分钟打印空白。\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[s._v("#")]),s._v(" 4.常用示例")]),s._v(" "),a("p",[s._v("(1)显示已经登录系统的用户列表,并显示用户正在执行的指令。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("w\n "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("12")]),s._v(":26:14 up "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(" days, "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("14")]),s._v(":36, "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" users, load average: "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0.19")]),s._v(", "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0.18")]),s._v(", "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0.11")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token environment constant"}},[s._v("USER")]),s._v(" TTY FROM LOGIN@ IDLE JCPU PCPU WHAT\nroot pts/0 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 09:36 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("7")]),s._v(":42 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\nroot pts/1 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(":39 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("6")]),s._v(".00s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\nroot pts/2 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("11")]),s._v(":18 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(":06m "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\n")])])]),a("p",[s._v("w 显示系统中当前用户的 信息,以及他们的进程。第一行中依次显示当前时间,系统的持续运行时间,登录的用户数和最近 1, 5, 15分钟的系统平均负载(load average)。")]),s._v(" "),a("p",[s._v("接下来的条目显示每位用户的:登录名、tty名、远程主机、登录时间、空闲时间、JCPU、PCPU 以及他们当前进程的命令行。")]),s._v(" "),a("p",[s._v("JCPU 时间指某个 tty 所有进程用掉的时间,不包括过去的后台任务,但是包括正在运行的后台任务。")]),s._v(" "),a("p",[s._v("PCPU 时间指当前进程用掉的时间,可以在 what 域看到当前进程。")]),s._v(" "),a("p",[s._v("(2)不打印头信息。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("w "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-h")]),s._v("\nroot pts/0 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 09:36 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("15")]),s._v(":13 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\nroot pts/1 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(":39 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(".00s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\nroot pts/2 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("11")]),s._v(":18 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(":13m "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(".02s "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\n")])])]),a("p",[s._v("(3)使用短输出格式。")]),s._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[s._v("w "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-s")]),s._v("\n "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("12")]),s._v(":36:50 up "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(" days, "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("14")]),s._v(":46, "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" users, load average: "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0.00")]),s._v(", "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0.07")]),s._v(", "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0.11")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token environment constant"}},[s._v("USER")]),s._v(" TTY FROM IDLE WHAT\nroot pts/0 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("18")]),s._v(":18 "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\nroot pts/1 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),s._v(".00s "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\nroot pts/2 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(":16m "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-bash")]),s._v("\n")])])]),a("hr"),s._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/w.1.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("w(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),s._v(" "),a("Vssue",{attrs:{title:"w"}})],1)}),[],!1,null,null,null);a.default=e.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/143.72bd88d7.js b/docs/assets/js/143.f790b313.js similarity index 99% rename from docs/assets/js/143.72bd88d7.js rename to docs/assets/js/143.f790b313.js index 5b8281ef0..807a27fe8 100644 --- a/docs/assets/js/143.72bd88d7.js +++ b/docs/assets/js/143.f790b313.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[143],{477:function(s,t,a){"use strict";a.r(t);var n=a(12),e=Object(n.a)({},(function(){var s=this,t=s._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[s._v("#")]),s._v(" 1.命令简介")]),s._v(" "),t("p",[s._v("who 显示当前谁登录了系统。")]),s._v(" "),t("p",[s._v("who 命令用来打印当前登录的用户信息,包含了系统的启动时间 、 活动进程 、 使用者 ID、使用终端等信息,是系统管理员了解系统运行状态的常用命令。")]),s._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("who")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("OPTION"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("..")]),s._v(". "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("FILE"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("|")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("ARG"),t("span",{pre:!0,attrs:{class:"token operator"}},[t("span",{pre:!0,attrs:{class:"token file-descriptor important"}},[s._v("1")]),s._v(">")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("ARG"),t("span",{pre:!0,attrs:{class:"token operator"}},[t("span",{pre:!0,attrs:{class:"token file-descriptor important"}},[s._v("2")]),s._v(">")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("-a, --all\n \t等于 -b -d --login -p -r -t -T -u 选项的组合。\n-b, --boot\n\t上次系统启动时间。\n-d, --dead\n \t显示已死的进程。\n-H, --heading\n\t输出头部的标题列。\n-l,--login\n\t显示系统登录进程。\n--lookup\n\t尝试通过 DNS 查验主机名。\n-m\n\t只面对和标准输入有直接交互的主机和用户。\n-p, --process\n\t显示由 init 进程衍生的活动进程。\n-q, --count\n\t列出所有已登录用户的登录名与用户数量。\n-r, --runlevel\n\t显示当前的运行级别。\n-s, --short\n\t只显示名称、线路和时间(默认)。\n-T, -w, --mesg\n\t用 +,- 或 ? 标注用户消息状态。\n-u, --users\n\t列出已登录的用户。\n--message\n\t等于 -T。\n--writable\n\t等于 -T。\n--help\n\t显示此帮助信息并退出。\n--version\n\t显示版本信息并退出。\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[s._v("#")]),s._v(" 4.常用示例")]),s._v(" "),t("p",[s._v("(1)显示当前已登录的用户信息。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("who")]),s._v("\nroot pts/0 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 09:36 "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nroot pts/1 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(":39 "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])])]),t("p",[s._v("第一列:显示用户名称。\n第二列:显示用户连接方式。tty 表示用户直连主机,pts 表示远程登录。\n第三列:显示用户登录日期。\n第四列:显示用户登录时间。\n第五列:显示用户登录的 IP 地址。")]),s._v(" "),t("p",[s._v("(2)输出头部的标题列。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("who")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-H")]),s._v("\nNAME LINE TIME COMMENT\nroot pts/0 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 09:36 "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nroot pts/1 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(":39 "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])])]),t("p",[s._v("(3)显示目前登入系统的用户详细信息。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("who")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-a")]),s._v("\n system boot "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-16 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(":50\n run-level "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-16 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(":50\nLOGIN ttyS0 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-16 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(":50 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1371")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("id")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("tyS0\nLOGIN tty1 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-16 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(":50 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1370")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("id")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("tty1\nroot + pts/0 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 09:36 00:20 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("9391")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nroot + pts/1 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(":39 "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v(".")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("21685")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n pts/2 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-26 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("18")]),s._v(":59 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("27651")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("id")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("ts/2 "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("term")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("exit")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v("\n pts/3 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-26 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("22")]),s._v(":10 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("4638")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("id")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("ts/3 "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("term")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("exit")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v("\n")])])]),t("p",[s._v("(4)显示已死的进程。")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("who -d\n pts/2 2022-10-26 18:59 27651 id=ts/2 term=0 exit=0\n pts/3 2022-10-26 22:10 4638 id=ts/3 term=0 exit=0\n")])])]),t("p",[s._v("(5)列出已登录的用户。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("who")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-uH")]),s._v("\nNAME LINE TIME IDLE PID COMMENT\nroot pts/0 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 09:36 "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v(".")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("9391")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nroot pts/1 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(":39 "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v(".")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("21685")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])])]),t("hr"),s._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/who.1.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("who(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),s._v(" "),t("Vssue",{attrs:{title:"who"}})],1)}),[],!1,null,null,null);t.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[143],{473:function(s,t,a){"use strict";a.r(t);var n=a(12),e=Object(n.a)({},(function(){var s=this,t=s._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[s._v("#")]),s._v(" 1.命令简介")]),s._v(" "),t("p",[s._v("who 显示当前谁登录了系统。")]),s._v(" "),t("p",[s._v("who 命令用来打印当前登录的用户信息,包含了系统的启动时间 、 活动进程 、 使用者 ID、使用终端等信息,是系统管理员了解系统运行状态的常用命令。")]),s._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[s._v("#")]),s._v(" 2.命令格式")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("who")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("OPTION"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("..")]),s._v(". "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("FILE"),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("|")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("ARG"),t("span",{pre:!0,attrs:{class:"token operator"}},[t("span",{pre:!0,attrs:{class:"token file-descriptor important"}},[s._v("1")]),s._v(">")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("ARG"),t("span",{pre:!0,attrs:{class:"token operator"}},[t("span",{pre:!0,attrs:{class:"token file-descriptor important"}},[s._v("2")]),s._v(">")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[s._v("#")]),s._v(" 3.选项说明")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("-a, --all\n \t等于 -b -d --login -p -r -t -T -u 选项的组合。\n-b, --boot\n\t上次系统启动时间。\n-d, --dead\n \t显示已死的进程。\n-H, --heading\n\t输出头部的标题列。\n-l,--login\n\t显示系统登录进程。\n--lookup\n\t尝试通过 DNS 查验主机名。\n-m\n\t只面对和标准输入有直接交互的主机和用户。\n-p, --process\n\t显示由 init 进程衍生的活动进程。\n-q, --count\n\t列出所有已登录用户的登录名与用户数量。\n-r, --runlevel\n\t显示当前的运行级别。\n-s, --short\n\t只显示名称、线路和时间(默认)。\n-T, -w, --mesg\n\t用 +,- 或 ? 标注用户消息状态。\n-u, --users\n\t列出已登录的用户。\n--message\n\t等于 -T。\n--writable\n\t等于 -T。\n--help\n\t显示此帮助信息并退出。\n--version\n\t显示版本信息并退出。\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[s._v("#")]),s._v(" 4.常用示例")]),s._v(" "),t("p",[s._v("(1)显示当前已登录的用户信息。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("who")]),s._v("\nroot pts/0 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 09:36 "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nroot pts/1 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(":39 "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])])]),t("p",[s._v("第一列:显示用户名称。\n第二列:显示用户连接方式。tty 表示用户直连主机,pts 表示远程登录。\n第三列:显示用户登录日期。\n第四列:显示用户登录时间。\n第五列:显示用户登录的 IP 地址。")]),s._v(" "),t("p",[s._v("(2)输出头部的标题列。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("who")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-H")]),s._v("\nNAME LINE TIME COMMENT\nroot pts/0 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 09:36 "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nroot pts/1 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(":39 "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])])]),t("p",[s._v("(3)显示目前登入系统的用户详细信息。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("who")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-a")]),s._v("\n system boot "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-16 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(":50\n run-level "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-16 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(":50\nLOGIN ttyS0 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-16 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(":50 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1371")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("id")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("tyS0\nLOGIN tty1 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-16 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(":50 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("1370")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("id")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("tty1\nroot + pts/0 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 09:36 00:20 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("9391")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nroot + pts/1 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(":39 "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v(".")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("21685")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n pts/2 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-26 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("18")]),s._v(":59 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("27651")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("id")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("ts/2 "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("term")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("exit")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v("\n pts/3 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-26 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("22")]),s._v(":10 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("4638")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("id")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("ts/3 "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("term")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token assign-left variable"}},[s._v("exit")]),t("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v("\n")])])]),t("p",[s._v("(4)显示已死的进程。")]),s._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[s._v("who -d\n pts/2 2022-10-26 18:59 27651 id=ts/2 term=0 exit=0\n pts/3 2022-10-26 22:10 4638 id=ts/3 term=0 exit=0\n")])])]),t("p",[s._v("(5)列出已登录的用户。")]),s._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[s._v("who")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-uH")]),s._v("\nNAME LINE TIME IDLE PID COMMENT\nroot pts/0 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 09:36 "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v(".")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("9391")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nroot pts/1 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("2022")]),s._v("-10-27 "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(":39 "),t("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v(".")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("21685")]),s._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),t("span",{pre:!0,attrs:{class:"token number"}},[s._v("223.73")]),s._v(".1.91"),t("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])])]),t("hr"),s._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[s._v("#")]),s._v(" 参考文献")]),s._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/who.1.html",target:"_blank",rel:"noopener noreferrer"}},[s._v("who(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),s._v(" "),t("Vssue",{attrs:{title:"who"}})],1)}),[],!1,null,null,null);t.default=e.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/144.6ed48227.js b/docs/assets/js/144.7ad6227b.js similarity index 97% rename from docs/assets/js/144.6ed48227.js rename to docs/assets/js/144.7ad6227b.js index f16803946..48951bc59 100644 --- a/docs/assets/js/144.6ed48227.js +++ b/docs/assets/js/144.7ad6227b.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[144],{478:function(a,t,s){"use strict";s.r(t);var e=s(12),r=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("whoami 打印当前用户名。")]),a._v(" "),t("p",[a._v("whoami 打印与当前有效用户 ID 关联的用户名。与 id -un 相同。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("whoami")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<")]),a._v("OPTION"),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),a._v(".\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("--help\n\t显示此帮助信息并退出。\n--version\n\t显示版本信息并退出。\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("查询当前登录的用户名。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("whoami")]),a._v("\nroot\n")])])]),t("p",[a._v("或者")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("id")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-un")]),a._v("\nroot\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/whoami.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("whoami(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"whoami"}})],1)}),[],!1,null,null,null);t.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[144],{475:function(a,t,s){"use strict";s.r(t);var e=s(12),r=Object(e.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("whoami 打印当前用户名。")]),a._v(" "),t("p",[a._v("whoami 打印与当前有效用户 ID 关联的用户名。与 id -un 相同。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("whoami")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("[")]),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<")]),a._v("OPTION"),t("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("]")]),t("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("..")]),a._v(".\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("--help\n\t显示此帮助信息并退出。\n--version\n\t显示版本信息并退出。\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("查询当前登录的用户名。")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("whoami")]),a._v("\nroot\n")])])]),t("p",[a._v("或者")]),a._v(" "),t("div",{staticClass:"language-shell extra-class"},[t("pre",{pre:!0,attrs:{class:"language-shell"}},[t("code",[t("span",{pre:!0,attrs:{class:"token function"}},[a._v("id")]),a._v(" "),t("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-un")]),a._v("\nroot\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/whoami.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("whoami(1) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"whoami"}})],1)}),[],!1,null,null,null);t.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/145.8eddf90e.js b/docs/assets/js/145.e5347c51.js similarity index 98% rename from docs/assets/js/145.8eddf90e.js rename to docs/assets/js/145.e5347c51.js index cd3388ff5..521b818d5 100644 --- a/docs/assets/js/145.8eddf90e.js +++ b/docs/assets/js/145.e5347c51.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[145],{480:function(t,a,s){"use strict";s.r(a);var e=s(12),r=Object(e.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("gpasswd 命令用于管理 /etc/group 和 /etc/gshadow。")]),t._v(" "),a("p",[t._v("每个组都可以有管理员、成员和密码。")]),t._v(" "),a("p",[t._v("系统管理员可以使用 -a 选项定义组管理员,使用 -m 选项定义成员。由组管理员用组名调用 gpasswd 会提示输入组的新密码,以此修改组密码。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("gpasswd [OPTIONS] GROUP\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-a, --add USER\n\t向组 GROUP 中添加用户 USER。\n-d, --delete USER\n\t从组 GROUP 中添加或删除用户\n-h, --help\n\t显示此帮助信息并退出\n-r, --delete-password\n\t删除组密码\n-R, --restric\tt\n\t向其成员限制访问组 GROUP\n-M, --members USER,...\n\t设置组 GROUP 的成员列表\n-A, --administrators ,...\n\t设置组的管理员列表。\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("p",[t._v("(1)向组 test 中添加用户 itcast。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("gpasswd -a itcast test\n")])])]),a("p",[t._v("(2)从组 test 中删除用户。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("gpasswd -d itcast test\n")])])]),a("p",[t._v("(3)移除组 test 的密码。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("gpasswd -r test\n")])])]),a("p",[t._v("(4)设置组的管理员列表。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("gpasswd -A deng test\n")])])]),a("p",[t._v("(5)给用户组创建密码。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("gpasswd test\n")])])]),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/gpasswd.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("gpasswd(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/98104598",target:"_blank",rel:"noopener noreferrer"}},[t._v("CSDN.【Linux】一步一步学Linux——gpasswd命令(90)"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"gpasswd"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[145],{476:function(t,a,s){"use strict";s.r(a);var e=s(12),r=Object(e.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("gpasswd 命令用于管理 /etc/group 和 /etc/gshadow。")]),t._v(" "),a("p",[t._v("每个组都可以有管理员、成员和密码。")]),t._v(" "),a("p",[t._v("系统管理员可以使用 -a 选项定义组管理员,使用 -m 选项定义成员。由组管理员用组名调用 gpasswd 会提示输入组的新密码,以此修改组密码。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("gpasswd [OPTIONS] GROUP\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-a, --add USER\n\t向组 GROUP 中添加用户 USER。\n-d, --delete USER\n\t从组 GROUP 中添加或删除用户\n-h, --help\n\t显示此帮助信息并退出\n-r, --delete-password\n\t删除组密码\n-R, --restric\tt\n\t向其成员限制访问组 GROUP\n-M, --members USER,...\n\t设置组 GROUP 的成员列表\n-A, --administrators ,...\n\t设置组的管理员列表。\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("p",[t._v("(1)向组 test 中添加用户 itcast。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("gpasswd -a itcast test\n")])])]),a("p",[t._v("(2)从组 test 中删除用户。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("gpasswd -d itcast test\n")])])]),a("p",[t._v("(3)移除组 test 的密码。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("gpasswd -r test\n")])])]),a("p",[t._v("(4)设置组的管理员列表。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("gpasswd -A deng test\n")])])]),a("p",[t._v("(5)给用户组创建密码。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("gpasswd test\n")])])]),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/gpasswd.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("gpasswd(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("p",[a("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/98104598",target:"_blank",rel:"noopener noreferrer"}},[t._v("CSDN.【Linux】一步一步学Linux——gpasswd命令(90)"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"gpasswd"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/146.5be02a31.js b/docs/assets/js/146.ad8248af.js similarity index 98% rename from docs/assets/js/146.5be02a31.js rename to docs/assets/js/146.ad8248af.js index e176d42a4..981bd8e52 100644 --- a/docs/assets/js/146.5be02a31.js +++ b/docs/assets/js/146.ad8248af.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[146],{479:function(a,t,e){"use strict";e.r(t);var s=e(12),r=Object(s.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("groupadd 是系统管理员命令,用于创建一个新组。")]),a._v(" "),t("p",[a._v("groupadd 命令使用命令行上指定的值以及系统中的默认值创建一个新的组帐户。新组将根据需要被添加到系统文件中。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupadd [OPTIONS] GROUP\n")])])]),t("h2",{attrs:{id:"_3-常用选项"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-常用选项"}},[a._v("#")]),a._v(" 3.常用选项")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v(" -f, --force\n \t如果组已经存在则成功退出并且如果 GID 已经存在则取消 -g\n -g, --gid GID\n \t为新组使用 GID\n -h, --help\n \t显示帮助信息并推出\n -K, --key KEY=VALUE\n \t不使用 /etc/login.defs 中的默认值\n -o, --non-unique\n \t允许创建有重复 GID 的组\n -p, --password PASSWORD\n \t为新组使用加密过的密码\n -r, --system\n \t创建一个系统组\n")])])]),t("h2",{attrs:{id:"_4-参考示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-参考示例"}},[a._v("#")]),a._v(" 4.参考示例")]),a._v(" "),t("p",[a._v("(1)添加一个用户组。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupadd g1\n")])])]),t("p",[a._v("(2)添加一个用户组并指定GID。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupadd -g 888 g2\n")])])]),t("p",[a._v("(3)使用 -r 创建系统工作组。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupadd -r -g 889 g3\n")])])]),t("p",[a._v("(4)允许创建有重复 GID 的组。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupadd -o -r -g 889 g4\n\n#查看新创建的用户组\ntail -n 3 /etc/group\ng2:x:888:\ng3:x:889:\ng4:x:889:\n")])])]),t("p",[a._v("(5)为新组使用加密过的密码。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupadd -p $6$6B3fQyRr$DWk9/i2ly/8IFNA8lNReCAve6eODSGuvOD2Y2q/NGZXGgaQ9j/APs0TpA3b5nPg2VcuDyHVCz.d8zpeJYJar./ g5\n")])])]),t("h2",{attrs:{id:"_5-相关文件"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-相关文件"}},[a._v("#")]),a._v(" 5.相关文件")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("/etc/group\t\t#群组信息\n/etc/gshadow\t#群组加密信息\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/groupadd.8.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("groupadd(8) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/97973193",target:"_blank",rel:"noopener noreferrer"}},[a._v("CSDN.【Linux】一步一步学Linux——groupadd命令(87)"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"groupadd"}})],1)}),[],!1,null,null,null);t.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[146],{477:function(a,t,e){"use strict";e.r(t);var s=e(12),r=Object(s.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("groupadd 是系统管理员命令,用于创建一个新组。")]),a._v(" "),t("p",[a._v("groupadd 命令使用命令行上指定的值以及系统中的默认值创建一个新的组帐户。新组将根据需要被添加到系统文件中。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupadd [OPTIONS] GROUP\n")])])]),t("h2",{attrs:{id:"_3-常用选项"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-常用选项"}},[a._v("#")]),a._v(" 3.常用选项")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v(" -f, --force\n \t如果组已经存在则成功退出并且如果 GID 已经存在则取消 -g\n -g, --gid GID\n \t为新组使用 GID\n -h, --help\n \t显示帮助信息并推出\n -K, --key KEY=VALUE\n \t不使用 /etc/login.defs 中的默认值\n -o, --non-unique\n \t允许创建有重复 GID 的组\n -p, --password PASSWORD\n \t为新组使用加密过的密码\n -r, --system\n \t创建一个系统组\n")])])]),t("h2",{attrs:{id:"_4-参考示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-参考示例"}},[a._v("#")]),a._v(" 4.参考示例")]),a._v(" "),t("p",[a._v("(1)添加一个用户组。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupadd g1\n")])])]),t("p",[a._v("(2)添加一个用户组并指定GID。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupadd -g 888 g2\n")])])]),t("p",[a._v("(3)使用 -r 创建系统工作组。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupadd -r -g 889 g3\n")])])]),t("p",[a._v("(4)允许创建有重复 GID 的组。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupadd -o -r -g 889 g4\n\n#查看新创建的用户组\ntail -n 3 /etc/group\ng2:x:888:\ng3:x:889:\ng4:x:889:\n")])])]),t("p",[a._v("(5)为新组使用加密过的密码。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupadd -p $6$6B3fQyRr$DWk9/i2ly/8IFNA8lNReCAve6eODSGuvOD2Y2q/NGZXGgaQ9j/APs0TpA3b5nPg2VcuDyHVCz.d8zpeJYJar./ g5\n")])])]),t("h2",{attrs:{id:"_5-相关文件"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_5-相关文件"}},[a._v("#")]),a._v(" 5.相关文件")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("/etc/group\t\t#群组信息\n/etc/gshadow\t#群组加密信息\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/groupadd.8.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("groupadd(8) - Linux manual page - man7.org"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/97973193",target:"_blank",rel:"noopener noreferrer"}},[a._v("CSDN.【Linux】一步一步学Linux——groupadd命令(87)"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"groupadd"}})],1)}),[],!1,null,null,null);t.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/147.7649e895.js b/docs/assets/js/147.4861d28f.js similarity index 97% rename from docs/assets/js/147.7649e895.js rename to docs/assets/js/147.4861d28f.js index 2a5f79a43..1483367b3 100644 --- a/docs/assets/js/147.7649e895.js +++ b/docs/assets/js/147.4861d28f.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[147],{482:function(t,a,e){"use strict";e.r(a);var s=e(12),r=Object(s.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("groupdel(group delete)命令是系统管理员命令,用于删除一个组。")]),t._v(" "),a("p",[t._v("groupdel 命令用于删除指定的工作组,本命令要修改的系统文件包括 /ect/group 和 /ect/gshadow。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("groupdel [OPTIONS] GROUP\n")])])]),a("h2",{attrs:{id:"_3-常用选项"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-常用选项"}},[t._v("#")]),t._v(" 3.常用选项")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-h, --help\n \t显示此帮助信息并推出\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("p",[t._v("(1)删除用户组")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("groupdel g1\n")])])]),a("p",[t._v("(2)查看帮助信息。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("groupdel -h\n")])])]),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"https://linux.die.net/man/8/groupdel",target:"_blank",rel:"noopener noreferrer"}},[t._v("groupdel(8) manual"),a("OutboundLink")],1)]),t._v(" "),a("p",[t._v("CSDN.【Linux】一步一步学Linux——groupdel命令(88)](https://blog.csdn.net/dengjin20104042056/article/details/98095658)")]),t._v(" "),a("Vssue",{attrs:{title:"groupdel"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[147],{479:function(t,a,e){"use strict";e.r(a);var s=e(12),r=Object(s.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("groupdel(group delete)命令是系统管理员命令,用于删除一个组。")]),t._v(" "),a("p",[t._v("groupdel 命令用于删除指定的工作组,本命令要修改的系统文件包括 /ect/group 和 /ect/gshadow。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("groupdel [OPTIONS] GROUP\n")])])]),a("h2",{attrs:{id:"_3-常用选项"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-常用选项"}},[t._v("#")]),t._v(" 3.常用选项")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-h, --help\n \t显示此帮助信息并推出\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("p",[t._v("(1)删除用户组")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("groupdel g1\n")])])]),a("p",[t._v("(2)查看帮助信息。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("groupdel -h\n")])])]),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"https://linux.die.net/man/8/groupdel",target:"_blank",rel:"noopener noreferrer"}},[t._v("groupdel(8) manual"),a("OutboundLink")],1)]),t._v(" "),a("p",[t._v("CSDN.【Linux】一步一步学Linux——groupdel命令(88)](https://blog.csdn.net/dengjin20104042056/article/details/98095658)")]),t._v(" "),a("Vssue",{attrs:{title:"groupdel"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/148.f17bd9ae.js b/docs/assets/js/148.88d4453e.js similarity index 98% rename from docs/assets/js/148.f17bd9ae.js rename to docs/assets/js/148.88d4453e.js index 545649368..8594e5761 100644 --- a/docs/assets/js/148.f17bd9ae.js +++ b/docs/assets/js/148.88d4453e.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[148],{483:function(a,t,e){"use strict";e.r(t);var r=e(12),s=Object(r.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("groupmod(group modify)是系统管理员命令,用于更改群组识别码或名称。")]),a._v(" "),t("p",[a._v("不过大家还是要注意,用户名不要随意修改,组名和 GID 也不要随意修改,因为非常容易导致管理员逻辑混乱。如果非要修改用户名或组名,则建议大家先删除旧的,再建立新的。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupmod [OPTIONS] GROUP\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-g, --gid GID\n\t将组 ID 改为 GID\n-h, --help\n\t显示此帮助信息并推出\n-n, --new-name NEW_GROUP\n\t改名为 NEW_GROUP\n-o, --non-unique\n\t允许使用重复的 GID\n-p, --password PASSWORD\n\t将密码更改为(加密过的) PASSWORD\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("(1)改用户组 ID。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupmod -g 8888 g5\n\n#参看是否修改成功\ntail -3 /etc/group\ng3:x:889:\ng4:x:889:\ng5:x:8888:\n")])])]),t("p",[a._v("(2)更改用户组名。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupmod -n heima g5\n\n#查看是否修改成功\ntail -5 /etc/group\ng3:x:889:\ng4:x:889:\nheima:x:8888:\n")])])]),t("p",[a._v("(3)更改用户组密码。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupmod -p $6$6B3fQyRr$DWk9/i2ly/8IFNA8lNReCAve6eODSGuvOD2Y2q/NGZXGgaQ9j/APs0TpA3b5nPg2VcuDyHVCz.d8zpeJYJar./ heima\n")])])]),t("p",[a._v("(4)允许使用重复的 GID。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupmod -g 8888 -o g4\n\n#查看是否修改成功\ntail -3 /etc/group\ng3:x:889:\ng4:x:8888:\nheima:x:8888:\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/groupmod.8.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("groupmod(8) manual"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/98098710",target:"_blank",rel:"noopener noreferrer"}},[a._v("CSDN.【Linux】一步一步学Linux——groupmod命令(89)"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"groupmod"}})],1)}),[],!1,null,null,null);t.default=s.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[148],{480:function(a,t,e){"use strict";e.r(t);var r=e(12),s=Object(r.a)({},(function(){var a=this,t=a._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[t("h2",{attrs:{id:"_1-命令简介"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),t("p",[a._v("groupmod(group modify)是系统管理员命令,用于更改群组识别码或名称。")]),a._v(" "),t("p",[a._v("不过大家还是要注意,用户名不要随意修改,组名和 GID 也不要随意修改,因为非常容易导致管理员逻辑混乱。如果非要修改用户名或组名,则建议大家先删除旧的,再建立新的。")]),a._v(" "),t("h2",{attrs:{id:"_2-命令格式"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupmod [OPTIONS] GROUP\n")])])]),t("h2",{attrs:{id:"_3-选项说明"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("-g, --gid GID\n\t将组 ID 改为 GID\n-h, --help\n\t显示此帮助信息并推出\n-n, --new-name NEW_GROUP\n\t改名为 NEW_GROUP\n-o, --non-unique\n\t允许使用重复的 GID\n-p, --password PASSWORD\n\t将密码更改为(加密过的) PASSWORD\n")])])]),t("h2",{attrs:{id:"_4-常用示例"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),t("p",[a._v("(1)改用户组 ID。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupmod -g 8888 g5\n\n#参看是否修改成功\ntail -3 /etc/group\ng3:x:889:\ng4:x:889:\ng5:x:8888:\n")])])]),t("p",[a._v("(2)更改用户组名。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupmod -n heima g5\n\n#查看是否修改成功\ntail -5 /etc/group\ng3:x:889:\ng4:x:889:\nheima:x:8888:\n")])])]),t("p",[a._v("(3)更改用户组密码。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupmod -p $6$6B3fQyRr$DWk9/i2ly/8IFNA8lNReCAve6eODSGuvOD2Y2q/NGZXGgaQ9j/APs0TpA3b5nPg2VcuDyHVCz.d8zpeJYJar./ heima\n")])])]),t("p",[a._v("(4)允许使用重复的 GID。")]),a._v(" "),t("div",{staticClass:"language- extra-class"},[t("pre",{pre:!0,attrs:{class:"language-text"}},[t("code",[a._v("groupmod -g 8888 -o g4\n\n#查看是否修改成功\ntail -3 /etc/group\ng3:x:889:\ng4:x:8888:\nheima:x:8888:\n")])])]),t("hr"),a._v(" "),t("h2",{attrs:{id:"参考文献"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),t("p",[t("a",{attrs:{href:"https://man7.org/linux/man-pages/man8/groupmod.8.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("groupmod(8) manual"),t("OutboundLink")],1)]),a._v(" "),t("p",[t("a",{attrs:{href:"https://blog.csdn.net/dengjin20104042056/article/details/98098710",target:"_blank",rel:"noopener noreferrer"}},[a._v("CSDN.【Linux】一步一步学Linux——groupmod命令(89)"),t("OutboundLink")],1)]),a._v(" "),t("Vssue",{attrs:{title:"groupmod"}})],1)}),[],!1,null,null,null);t.default=s.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/15.00908673.js b/docs/assets/js/15.58042256.js similarity index 98% rename from docs/assets/js/15.00908673.js rename to docs/assets/js/15.58042256.js index 9c9fb186a..0cedc6325 100644 --- a/docs/assets/js/15.00908673.js +++ b/docs/assets/js/15.58042256.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[15],{347:function(a,s,t){"use strict";t.r(s);var e=t(12),r=Object(e.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),s("p",[a._v("exec 执行指定命令,并替换当前 Shell 进程。")]),a._v(" "),s("p",[a._v("exec 命令通常用在 Shell 脚本程序中,可以调用其他的命令。如果在当前终端中使用命令,则当指定的命令执行完毕后会立即退出终端。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("exec [-cl] [-a name] [command [arguments]]\n")])])]),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-a")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<")]),a._v("name"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),a._v("\n\t作为第 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v(" 个参数传递给 COMMAND 命令。\n"),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-c")]),a._v(" \n\t在一个空环境中执行 COMMAND 命令。\n"),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-l")]),a._v("\n\t在 COMMAND 命令的第 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v(" 个参数中加一个短线。\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)执行 Shell 命令。")]),a._v(" "),s("p",[a._v("命令执行完后,然后退出当前终端。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("exec")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("ls")]),a._v("\n")])])]),s("p",[a._v("(2)在一个空环境中执行命令。")]),a._v(" "),s("p",[a._v("命令执行完后,然后退出当前终端。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("exec")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-c")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("ls")]),a._v("\n")])])]),s("p",[a._v("(3)find 和 exec 综合使用。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("find")]),a._v(" ./ "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-name")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"test.txt"')]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-exec")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("ls")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-l")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("}")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("\\")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(";")]),a._v("\n-rw-rw-r--+ "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1")]),a._v(" root root "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("6")]),a._v(" Nov "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("24")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("17")]),a._v(":59 ./test/test.txt\n")])])]),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://www.man7.org/linux/man-pages/man1/bash.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("bash(1) - Linux manual page - man7.org"),s("OutboundLink")],1)]),a._v(" "),s("Vssue",{attrs:{title:"exec-builtin"}})],1)}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[15],{348:function(a,s,t){"use strict";t.r(s);var e=t(12),r=Object(e.a)({},(function(){var a=this,s=a._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h2",{attrs:{id:"_1-命令简介"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[a._v("#")]),a._v(" 1.命令简介")]),a._v(" "),s("p",[a._v("exec 执行指定命令,并替换当前 Shell 进程。")]),a._v(" "),s("p",[a._v("exec 命令通常用在 Shell 脚本程序中,可以调用其他的命令。如果在当前终端中使用命令,则当指定的命令执行完毕后会立即退出终端。")]),a._v(" "),s("h2",{attrs:{id:"_2-命令格式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[a._v("#")]),a._v(" 2.命令格式")]),a._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[a._v("exec [-cl] [-a name] [command [arguments]]\n")])])]),s("h2",{attrs:{id:"_3-选项说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[a._v("#")]),a._v(" 3.选项说明")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-a")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<")]),a._v("name"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),a._v("\n\t作为第 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v(" 个参数传递给 COMMAND 命令。\n"),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-c")]),a._v(" \n\t在一个空环境中执行 COMMAND 命令。\n"),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-l")]),a._v("\n\t在 COMMAND 命令的第 "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("0")]),a._v(" 个参数中加一个短线。\n")])])]),s("h2",{attrs:{id:"_4-常用示例"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[a._v("#")]),a._v(" 4.常用示例")]),a._v(" "),s("p",[a._v("(1)执行 Shell 命令。")]),a._v(" "),s("p",[a._v("命令执行完后,然后退出当前终端。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("exec")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("ls")]),a._v("\n")])])]),s("p",[a._v("(2)在一个空环境中执行命令。")]),a._v(" "),s("p",[a._v("命令执行完后,然后退出当前终端。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("exec")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-c")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("ls")]),a._v("\n")])])]),s("p",[a._v("(3)find 和 exec 综合使用。")]),a._v(" "),s("div",{staticClass:"language-shell extra-class"},[s("pre",{pre:!0,attrs:{class:"language-shell"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("find")]),a._v(" ./ "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-name")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"test.txt"')]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-exec")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("ls")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token parameter variable"}},[a._v("-l")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("}")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v("\\")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[a._v(";")]),a._v("\n-rw-rw-r--+ "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("1")]),a._v(" root root "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("6")]),a._v(" Nov "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("24")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[a._v("17")]),a._v(":59 ./test/test.txt\n")])])]),s("hr"),a._v(" "),s("h2",{attrs:{id:"参考文献"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[a._v("#")]),a._v(" 参考文献")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://www.man7.org/linux/man-pages/man1/bash.1.html",target:"_blank",rel:"noopener noreferrer"}},[a._v("bash(1) - Linux manual page - man7.org"),s("OutboundLink")],1)]),a._v(" "),s("Vssue",{attrs:{title:"exec-builtin"}})],1)}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/150.6330a13d.js b/docs/assets/js/150.1f8cacf9.js similarity index 97% rename from docs/assets/js/150.6330a13d.js rename to docs/assets/js/150.1f8cacf9.js index c39caf4dd..2527425e5 100644 --- a/docs/assets/js/150.6330a13d.js +++ b/docs/assets/js/150.1f8cacf9.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[150],{484:function(t,a,s){"use strict";s.r(a);var e=s(12),r=Object(e.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("newgrp(new group)登录到一个新组。")]),t._v(" "),a("p",[t._v("newgrp 将当前的实际组 ID 更改为指定的组,如果没有给出组名,则更改为 /etc/passwd 中列出的默认组。")]),t._v(" "),a("p",[t._v("newgrp 类似 login 指令,但它是以相同的帐号,另一个组名,再次登入系统。欲使用 newgrp 切换群组,用户必须是该群组的用户,否则将无法登入指定的群组。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("newgrp "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GROUP"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-\n\t如果给出该选项,则用户的环境将被重新初始化,就像用户已登录一样。否则,当前环境(包括当前工作目录)保持不变。\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("p",[t._v("将群组切换到 test 组。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("newgrp test\n")])])]),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/newgrp.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("newgrp(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"newgrp"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[150],{482:function(t,a,s){"use strict";s.r(a);var e=s(12),r=Object(e.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"_1-命令简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-命令简介"}},[t._v("#")]),t._v(" 1.命令简介")]),t._v(" "),a("p",[t._v("newgrp(new group)登录到一个新组。")]),t._v(" "),a("p",[t._v("newgrp 将当前的实际组 ID 更改为指定的组,如果没有给出组名,则更改为 /etc/passwd 中列出的默认组。")]),t._v(" "),a("p",[t._v("newgrp 类似 login 指令,但它是以相同的帐号,另一个组名,再次登入系统。欲使用 newgrp 切换群组,用户必须是该群组的用户,否则将无法登入指定的群组。")]),t._v(" "),a("h2",{attrs:{id:"_2-命令格式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-命令格式"}},[t._v("#")]),t._v(" 2.命令格式")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("newgrp "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("GROUP"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),a("h2",{attrs:{id:"_3-选项说明"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-选项说明"}},[t._v("#")]),t._v(" 3.选项说明")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-\n\t如果给出该选项,则用户的环境将被重新初始化,就像用户已登录一样。否则,当前环境(包括当前工作目录)保持不变。\n")])])]),a("h2",{attrs:{id:"_4-常用示例"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-常用示例"}},[t._v("#")]),t._v(" 4.常用示例")]),t._v(" "),a("p",[t._v("将群组切换到 test 组。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("newgrp test\n")])])]),a("hr"),t._v(" "),a("h2",{attrs:{id:"参考文献"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#参考文献"}},[t._v("#")]),t._v(" 参考文献")]),t._v(" "),a("p",[a("a",{attrs:{href:"https://man7.org/linux/man-pages/man1/newgrp.1.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("newgrp(1) - Linux manual page - man7.org"),a("OutboundLink")],1)]),t._v(" "),a("Vssue",{attrs:{title:"newgrp"}})],1)}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file diff --git a/docs/assets/js/151.ff7359bc.js b/docs/assets/js/151.227dfadb.js similarity index 99% rename from docs/assets/js/151.ff7359bc.js rename to docs/assets/js/151.227dfadb.js index d977fba41..1a36b9a82 100644 --- a/docs/assets/js/151.ff7359bc.js +++ b/docs/assets/js/151.227dfadb.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[151],{486:function(t,a,e){"use strict";e.r(a);var s=e(12),r=Object(s.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("p",[a("img",{attrs:{src:"https://img-blog.csdnimg.cn/20201214105406191.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0szNDZLMzQ2,size_16,color_FFFFFF,t_70",alt:"在这里插入图片描述"}})]),t._v(" "),a("h2",{attrs:{id:"导语"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#导语"}},[t._v("#")]),t._v(" 导语")]),t._v(" "),a("p",[t._v("这里记录本人使用 Git 的点滴,以需要完成的功能为切入点来讲解需要使用的命令,供大家参考。当然,再结合官方文档 "),a("a",{attrs:{href:"https://git-scm.com/docs",target:"_blank",rel:"noopener noreferrer"}},[t._v("Git Reference"),a("OutboundLink")],1),t._v(" 及"),a("a",{attrs:{href:"http://blog.csdn.net/dengsilinming/article/details/8000622",target:"_blank",rel:"noopener noreferrer"}},[t._v(" Git 常用命令大全"),a("OutboundLink")],1),t._v("这类较全面的 Git 命令介绍的文章,能帮助我们更好地掌握 Git 的使用。")]),t._v(" "),a("h2",{attrs:{id:"_1-git-简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-git-简介"}},[t._v("#")]),t._v(" 1.Git 简介")]),t._v(" "),a("p",[t._v("Git 是一款由 Linux 之父 Linus Torvalds 开发的免费、开源的分布式源码管理(SCM,Source Code Management)工具,也称为版本控制系统(VCS,Version Control System),用于敏捷高效地处理任何或小或大的项目。Git 相比于其它的 SCM 工具,比如 Subversion(SVN)、Mercurial、CVS、Perforce 和 ClearCase,因其高效的性能、便捷的分支管理、免费开源等优秀特性,自 2005 年诞生以来,迅速成为最流行的分布式版本控制系统,没有之一。")]),t._v(" "),a("h2",{attrs:{id:"_2-git-客户端下载安装"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-git-客户端下载安装"}},[t._v("#")]),t._v(" 2.Git 客户端下载安装")]),t._v(" "),a("p",[t._v("Windows下主要有三款客户端:")]),t._v(" "),a("ul",[a("li",[a("a",{attrs:{href:"https://git-for-windows.github.io/",target:"_blank",rel:"noopener noreferrer"}},[t._v("git for windows"),a("OutboundLink")],1)]),t._v(" "),a("li",[a("a",{attrs:{href:"https://desktop.github.com/",target:"_blank",rel:"noopener noreferrer"}},[t._v("GitHub Desktop"),a("OutboundLink")],1)]),t._v(" "),a("li",[a("a",{attrs:{href:"https://tortoisegit.org/",target:"_blank",rel:"noopener noreferrer"}},[t._v("TortoiseGit "),a("OutboundLink")],1)])]),t._v(" "),a("p",[t._v("本文使用的是 GitHub Desktop,可以下载"),a("a",{attrs:{href:"http://download.csdn.net/detail/lyg468088/8723039",target:"_blank",rel:"noopener noreferrer"}},[t._v("离线安装包"),a("OutboundLink")],1),t._v("。")]),t._v(" "),a("p",[t._v("双击安装,这里不再赘述,安装成功后,打开 Git Shell 就可以执行 Git 命令了。需要注意一点,安装好 GitHub Desktop 后,桌面会出现两个图标:")]),t._v(" "),a("p",[a("img",{attrs:{src:"https://imgconvert.csdnimg.cn/aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTYxMjI0MTExNjExMTc0",alt:""}})]),t._v(" "),a("p",[t._v("首先需要打开 GitHub 图标,使用 GitHub 账号登陆,让 GitHub Desktop 帮助我们创建 SSH Key,并以邮件的方式通知我们。如果使用 git for windows,需要手动安装 SSH Key,安装教程见:"),a("a",{attrs:{href:"http://blog.csdn.net/wfdtxz/article/details/8678982",target:"_blank",rel:"noopener noreferrer"}},[t._v("git使用SSH密钥"),a("OutboundLink")],1),t._v("。git for windows 每次更新远程仓库时,都需要输入 GitHub 用户名和密码,解决办法见:"),a("a",{attrs:{href:"http://blog.csdn.net/collonn/article/details/52848784",target:"_blank",rel:"noopener noreferrer"}},[t._v("git for windows 总是提示输入用户名和秘密"),a("OutboundLink")],1),t._v("。")]),t._v(" "),a("h2",{attrs:{id:"_3-设置和配置-setup-and-config"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-设置和配置-setup-and-config"}},[t._v("#")]),t._v(" 3.设置和配置(Setup and Config)")]),t._v(" "),a("h3",{attrs:{id:"git-config"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-config"}},[t._v("#")]),t._v(" git config")]),t._v(" "),a("p",[t._v("(1)简介")]),t._v(" "),a("p",[t._v("安装完 Git 后,需要对 Git 环境进行一次配置,且只需要配置一次。程序升级时会保留配置信息。 你可以在任何时候再次通过运行命令来修改它们。")]),t._v(" "),a("p",[t._v("Git 自带一个 git config 的工具来设置控制 Git 外观和行为的配置变量,这些变量按照不同的作用级别默认存储在四个不同的文件中。 可以使用 --file 选项来显示指明配置文件的路径。")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("文件路径")]),t._v(" "),a("th",[t._v("级别")]),t._v(" "),a("th",[t._v("说明")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("/etc/gitconfig")]),t._v(" "),a("td",[t._v("系统级别")]),t._v(" "),a("td",[t._v("包含系统上每一个用户及他们仓库的通用配置。 如果使用带有 --system 选项 Git 会读写此文件")])]),t._v(" "),a("tr",[a("td",[t._v("~/.config/git/config")]),t._v(" "),a("td",[t._v("用户级别")]),t._v(" "),a("td",[t._v("针对当前用户。 使用 --global 选项 Git 会读写此文件")])]),t._v(" "),a("tr",[a("td",[t._v("~/.gitconfig")]),t._v(" "),a("td",[t._v("用户级别")]),t._v(" "),a("td",[t._v("针对当前用户。 使用 --global 选项 Git 会读写此文件。较新版本的 Git 会使用此配置文件")])]),t._v(" "),a("tr",[a("td",[t._v("仓库目录/.gitconfig")]),t._v(" "),a("td",[t._v("仓库级别")]),t._v(" "),a("td",[t._v("对当前仓库有效。使用 --local 选项 Git 会读写此文件,为默认选项")])])])]),t._v(" "),a("p",[t._v("从下到上,每一个级别会覆盖上一级别的配置,优先级如下:")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("仓库目录/.git/config "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" ~/.gitconfig "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" /etc/gitconfig\n")])])]),a("p",[t._v("(2)格式")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" config "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("options"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),a("p",[t._v("(3)选项")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[t._v("配置文件路径(Config "),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("file")]),t._v(" location)\n"),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--system")]),t._v("\n\t使用系统级别的配置文件\n"),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--global")]),t._v("\n\t使用当前用户全局配置文件\n"),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--local")]),t._v("\n\t使用当前仓库的配置文件,为默认选项\n-f, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--file")]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("file"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n\t显示指定配置文件路径\n\n动作(Action)\n-l, "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--list")]),t._v("\n\t列出所有配置\n"),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--unset")]),t._v("\n\t从配置文件中删除变量名匹配的某一行\n--unset-all\n\t从配置文件中删除变量名匹配的所有行\n")])])]),a("p",[t._v("(4)示例")]),t._v(" "),a("ul",[a("li",[t._v("配置用户信息。")])]),t._v(" "),a("p",[t._v("当安装完 Git 应该做的第一件事就是设置你的用户名称与邮件地址。这样做很重要,因为每一个 Git 的提交都会使用这些信息,并且它会写入到你的每一次提交中。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('git config --global user.name "John Doe"\ngit config --global user.email "johndoe@example.com"\n')])])]),a("ul",[a("li",[t._v("配置文本编辑器。")])]),t._v(" "),a("p",[t._v("当 Git 需要你输入信息时会调用文本编辑器。 如果未配置,Git 会使用操作系统默认的文本编辑器,通常是 Vim。 如果你想使用不同的文本编辑器,例如 Emacs,可以这样做:")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--global")]),t._v(" core.editor emacs\n")])])]),a("ul",[a("li",[t._v("让 Git 记住用户名和密码。")])]),t._v(" "),a("p",[t._v("每次使用 HTTP 协议与 Git 远端交互时均需要输入用户名和密码,为了避免如此繁琐的操作,可以使用 Git 凭证系统来处理这个事情。 下面有一些 Git 的选项:\n(1)默认所有都不缓存。 每一次连接都会询问你的用户名和密码。\n(2)cache 模式会将凭证存放在内存中一段时间。 密码永远不会被存储在磁盘中,并且在15分钟后从内存中清除。\n(3)store 模式会将凭证用明文的形式存放在磁盘中,并且永不过期。 这意味着除非你修改了你在 Git 服务器上的密码,否则你永远不需要再次输入你的凭证信息。 这种方式的缺点是你的密码是用明文的方式存放在你的 home 目录下。\n(4)如果你使用的是 Mac,Git 还有一种 osxkeychain 模式,它会将凭证缓存到你系统用户的钥匙串中。 这种方式将凭证存放在磁盘中,并且永不过期,但是是被加密的,这种加密方式与存放 HTTPS 凭证以及 Safari 的自动填写是相同的。\n(5)如果你使用的是 Windows,你可以安装一个叫做 Git Credential Manager for Windows 的辅助工具。 这和上面说的 osxkeychain 十分类似,但是是使用 Windows Credential Store 来控制敏感信息。 可以在 "),a("a",{attrs:{href:"https://github.com/Microsoft/Git-Credential-Manager-for-Windows",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),a("OutboundLink")],1),t._v(" 下载。")]),t._v(" "),a("p",[t._v("其中部分辅助工具有一些选项。如 store 模式可以接受一个 "),a("code",[t._v("--file ")]),t._v(" 参数,可以自定义存放密码的文件路径(默认 ~/.git-credentials )。cache 模式有 "),a("code",[t._v("--timeout ")]),t._v(" 参数,可以设置凭证存放在内存的存活时间(默认是 900,也就是 15 分钟)。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 设置记住密码(默认15分钟)")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--global")]),t._v(" credential.helper cache\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 设置记住密码,自定义有效时长,比如一小时后失效")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--global")]),t._v(" credential.helper "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v("'cache --timeout=3600'")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 长期存储用户名和密码")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--global")]),t._v(" credential.helper store\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 长期存储用户名和密码,指定用户名密码存储位置")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--global")]),t._v(" credential.helper "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v("'store --file ~/.git-credentials'")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 不记住用户名密码,以 HTTP 协议的 clone、pull、push 等每次请求,都需要输入用户名和密码")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--global")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--unset")]),t._v(" credential.helper\n")])])]),a("p",[t._v("如果变更了用户名或密码,只需要清除存放密码的文件(默认 ~/.git-credentials ),会提示重新输入。")]),t._v(" "),a("ul",[a("li",[t._v("协议替换")])]),t._v(" "),a("p",[t._v("当你想去克隆一个别人 Github 上的 repository 时,如果使用 HTTPS 协议无法访问,那么可以变更协议采用 SSH 来访问。除了在 clone 时显示变更协议,我们也可以通过配置,让 git 自动进行协议替换。")]),t._v(" "),a("p",[t._v("例如将 HTTPS 协议变更为 SSH 协议。在终端中输入:")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--global")]),t._v(" url.https://github.com/.insteadOf git@github.com:\n")])])]),a("p",[t._v("一顿操作之后,你的 .gitconfig 中会多出一行参数设置:")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("url "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://github.com/"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\tinsteadOf "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" git@github.com:\n")])])]),a("p",[t._v("设置之后,使用 git 进行 clone 时,资源 url 中协议和域名部分"),a("code",[t._v("git@github.com:")]),t._v("将被替换为"),a("code",[t._v("https://github.com/")]),t._v("。")]),t._v(" "),a("ul",[a("li",[t._v("core.autocrlf 的配置。")])]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#提交时转换为 LF,检出时转换为 CRLF")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--global")]),t._v(" core.autocrlf "),a("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),t._v(" \n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#提交时转换为 LF,检出时不转换")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--global")]),t._v(" core.autocrlf input\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("#提交检出均不转换")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--global")]),t._v(" core.autocrlf "),a("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),t._v("\n")])])]),a("p",[t._v("建议设置为最后一种,提交检出均不转换。")]),t._v(" "),a("ul",[a("li",[t._v("查看配置信息。")])]),t._v(" "),a("p",[t._v("使用"),a("code",[t._v("git config -l, --list")]),t._v("命令可以列出 Git 当前所有配置。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-l")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token assign-left variable"}},[t._v("user.name")]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("John Doe\n"),a("span",{pre:!0,attrs:{class:"token assign-left variable"}},[t._v("user.email")]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("johndoe@example.com\n"),a("span",{pre:!0,attrs:{class:"token assign-left variable"}},[t._v("color.status")]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("auto\n"),a("span",{pre:!0,attrs:{class:"token assign-left variable"}},[t._v("color.branch")]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("auto\n"),a("span",{pre:!0,attrs:{class:"token assign-left variable"}},[t._v("color.interactive")]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("auto\n"),a("span",{pre:!0,attrs:{class:"token assign-left variable"}},[t._v("color.diff")]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("auto\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("..")]),t._v(".\n")])])]),a("p",[t._v("或者通过输入"),a("code",[t._v("git config ")]),t._v(" 或"),a("code",[t._v("git config --get ")]),t._v("来检查 Git 的某一项配置。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" config user.name\nJohn\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--get")]),t._v(" user.email\nJohn@tencent.com\n")])])]),a("h2",{attrs:{id:"_4-获取或创建项目-getting-and-creating-projects"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-获取或创建项目-getting-and-creating-projects"}},[t._v("#")]),t._v(" 4.获取或创建项目(Getting and Creating Projects)")]),t._v(" "),a("h3",{attrs:{id:"git-clone"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-clone"}},[t._v("#")]),t._v(" git clone")]),t._v(" "),a("p",[t._v("git clone 命令用于将远程仓库克隆到本地。这一个操作类似于 SVN 的 check out,只有将远程仓库克隆到本地,才可以通过对本地的代码进行增删改后再提交至远程服务端。")]),t._v(" "),a("p",[t._v("(1)克隆远端仓库到本地。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" clone "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("repository path"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" clone "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--recursive")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("repository path"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v(":")]),t._v(" 给定远端仓库地址进行克隆,同时克隆仓库依赖的子模块。子模块是独立的仓库\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 示例")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" clone https://github.com/dablelv/dablelvweb.git\n")])])]),a("p",[t._v('如果你的仓库地址是在Github,那么你可以在Github的网站查看,点击 "Clone or download" 按钮,具体如下图:')]),t._v(" "),a("img",{attrs:{width:"80%",hegiht:"80%",src:"https://img-blog.csdn.net/20160922114612906"}}),t._v(" "),a("h2",{attrs:{id:"_5-基本快照-basic-snapshotting"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_5-基本快照-basic-snapshotting"}},[t._v("#")]),t._v(" 5.基本快照(Basic Snapshotting)")]),t._v(" "),a("h3",{attrs:{id:"git-add"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-add"}},[t._v("#")]),t._v(" git add")]),t._v(" "),a("p",[t._v("git add 命令用于将工作区的变更添加到暂存区。")]),t._v(" "),a("p",[t._v("(1)批量提交。")]),t._v(" "),a("p",[t._v("在进行修改、删除和新增操作后,需要提交多个文件或文件夹到暂存区,此时不需要一个一个进行"),a("code",[t._v("git add")]),t._v(",这样做的话效率太低,使用"),a("code",[t._v("git add")]),t._v("命令批量提交修改、删除和新增的文件或文件夹。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),t._v(" -A, --all, --no-ignore-removal\n\t添加所有更新的内容,包括修改、新增的和删除的文件\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v(".")]),t._v("\n\t添加新增的和删除的文件,只对当前目录及其子目录有效。2.x 版本开始,可以添加修改的文件\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),t._v(" -u,--update\n\t添加修改和删除的文件,不包括新增文件\n")])])]),a("p",[t._v("(2)查各命令选项的具体含义。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git add -h\n")])])]),a("p",[t._v("(3)其它不常用选项。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git add -n, --dry-run [FILE]\n\t不实际添加文件,仅仅是展示他们是否存在或者将被忽略\ngit add -v, --verbose\n\t冗余模式\ngit add -i, --interactive\n\t交互式\ngit add -f, --force\n\t允许添加其他被忽略的文件\ngit add --ignore-errors\n\t跳过因错误不能被添加的文件\n")])])]),a("h3",{attrs:{id:"git-commit"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-commit"}},[t._v("#")]),t._v(" git commit")]),t._v(" "),a("p",[t._v("git commit 命令用于将工作区或暂存区的变更提交至仓库。")]),t._v(" "),a("p",[t._v("每次使用 git commit 都会在本地版本库通过 SHA1 生成一个40 位的哈希值,这个哈希值也叫 commit-id。commit-id 在版本回退的时候是非常有用的,它相当于一个快照,可以在未来的任何时候通过 git reset 命令回退到指定版本。")]),t._v(" "),a("p",[t._v("(1)提交暂存区的变更到仓库并备注。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git commit -m \n")])])]),a("p",[t._v("(2)将工作区被修改和被删除的文件,以及暂存区的变更提交至版本库并备注。必须要备注,不然无法提交。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git commit (-a | --all) -m \n\n#等同于\ngit add -u\ngit commit -m \n")])])]),a("p",[t._v("注意,新加的文件(即没有被 Git 系统管理的文件)是不能被提交到本地仓库的。建议一般不要使用 -a | --all 参数,正常的提交过程还是先使用 git add 将要改动的文件添加到暂存区,再用 git commit 提交到本地版本库。")]),t._v(" "),a("p",[t._v("(3)使用新的提交记录( commitid 与 comment)覆盖最近一次提交记录。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git commit --amend -m \n")])])]),a("p",[t._v("注意,使用 git push 推送至远端时,需要使用 -f 选项强制推送,不然会提示本地落后于远端,需要先使用 git pull 更新。强制推送时,千万要注意不要把别人的提交给覆盖了。一般在自己的开发分支使用 git push -f 不会有什么问题。")]),t._v(" "),a("p",[t._v("使用 --amend 参数,一般出于两种考虑:\n(a)最近一次提交有 bug 需要修复,但又不想保留最近一次的提交记录;\n(b)减少提交记录的数量,保持提交记录的干净整洁。")]),t._v(" "),a("p",[t._v("(4) 查看帮助,还有许多参数有其他效果,一般来说了解上述三种即可满足我们工作中的日常开发了。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git commit --help\n")])])]),a("h3",{attrs:{id:"git-status"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-status"}},[t._v("#")]),t._v(" git status")]),t._v(" "),a("p",[t._v("git status命令用于显示工作区和暂存区的状态。\n(1)查看工作区与暂存区中文件的变更情况。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git status\n")])])]),a("h3",{attrs:{id:"git-rm"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-rm"}},[t._v("#")]),t._v(" git rm")]),t._v(" "),a("p",[t._v("git rm 命令用于从工作区或暂存区删除文件或目录。注意,git rm无法删除未受版本控制的文件(untracked file)。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git rm [] [--] ...\n -n, --dry-run 用于查看删除之前会删除哪些东西,并不会有实际的影响\n -q, --quiet \t 不列出被删除的文件\n --cached 仅从暂存区删除文件,可用于文件脱离版本控制\n -f, --force 覆盖最新的检查,强制删除\n -r 递归删除,可用于删除目录\n --ignore-unmatch 未匹配到文件不报错\n")])])]),a("h3",{attrs:{id:"git-mv"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-mv"}},[t._v("#")]),t._v(" git mv")]),t._v(" "),a("p",[t._v("git mv 命令用于移动或重命名文件或目录。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git mv [] ... \n\t-v, --verbose 冗长模式执行,输出过程信息\n\t-n, --dry-run 只查看影响的文件或目录,实际不做重命名处理\n\t-f, --force 强制移动或重命名,即使目标文件或目录已经存在\n\t-k 跳过移动或重命名错误\n")])])]),a("h2",{attrs:{id:"_6-分支与合并-branching-and-merging"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_6-分支与合并-branching-and-merging"}},[t._v("#")]),t._v(" 6.分支与合并(Branching and Merging)")]),t._v(" "),a("h3",{attrs:{id:"git-branch"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-branch"}},[t._v("#")]),t._v(" git branch")]),t._v(" "),a("p",[t._v("git branch 用于管理分支,包括查看、创建、删除、重命名和关联。")]),t._v(" "),a("p",[t._v("(1)查看分支。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 查看本地分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 查看远端分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-r")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 查看所有分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-a")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 查看本地分支 commit id 与 commit comment")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch -v"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v("--verbose\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 查看本地分支commit id与commit comment,以及关联的上游分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-vv")]),t._v("\n")])])]),a("p",[t._v("(2)创建分支。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 基于当前分支创建本地分支不切换")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 基于当前分支创建本地分支并切换")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" checkout "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-b")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 或")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" switch "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-c")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("branchName"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 将创建的本地分支推送到远端,远端分支不存在则创建。")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push origin "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("local_branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(":"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("remote_branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n")])])]),a("p",[t._v("(3)更新分支。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 使用远端分支更新本地分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" pull "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("远程仓库名"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("远程分支名"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(":"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("本地分支名"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 使用关联的远端分支更新当前本地分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" pull\n")])])]),a("p",[t._v("(5)合并分支。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 合并某分支到当前分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" merge "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("srcbranch"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n")])])]),a("p",[t._v("(6)删除分支。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 删除本地分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-d "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" --delete"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 强制删除本地分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-D "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-df")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--delete")]),t._v(" --force"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 删除远端分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push origin :"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("remote_branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 或")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push origin "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-d "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" --delete"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 注意,该命令无法删除远端分支,只是删除 git branch -r 列表中的远端追踪分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-dr")]),t._v(" origin/"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n")])])]),a("p",[t._v("(7)本地分支关联远端分支。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 第一种情况,远端分支已经存在。不指定 local_branchname 为当前分支。")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("--set-upstream-to"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("origin/"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-u")]),t._v(" origin/"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("local_branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 第二种情况,远端分支不存在")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 1.将当前本地分支推送至远端并关联(远端分支与本地分支同名)")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-u "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" --set-upstream"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" origin HEAD\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 2.将当前本地分支推送至远端并关联(指定远端分支名)")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-u "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" --set-upstream"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" origin HEAD:"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("remote_branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 3.将本地分支推送至远端并关联(指定本地与远端分支名)")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-u "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" --set-upstream"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" origin "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("local_branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(":"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("remote_branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n")])])]),a("p",[t._v("(8)删除本地分支与远端分支的关联。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch --unset-upstream "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("local_branch"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),a("p",[t._v("(9)重命名本地分支。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 重命名当前分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-m "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" --move"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("newbranch"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 重命名指定分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-m "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--move")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("oldbranch"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("newbranch"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 强制重命名本地分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-M "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-f")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--move")]),t._v(" --force"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("oldbranch"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("newbranch"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n")])])]),a("p",[t._v("(10)重命名远端分支。\nGit 没有直接修改远端分支名的命令,我们可以通过删除重建的方式来间接重命名远端分支。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 先删除远端分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push origin "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("-d")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("branch_name"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 再重命名当前本地分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" branch "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-m "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" --move"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("newbranch"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 将当前本地分支推送至远端并关联")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push origin "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-u "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" --set-upstream"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" HEAD\n")])])]),a("h3",{attrs:{id:"git-checkout"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-checkout"}},[t._v("#")]),t._v(" git checkout")]),t._v(" "),a("p",[t._v("git checkout 主要用于分支切换与工作区文件的恢复。")]),t._v(" "),a("p",[t._v("(1)撤销工作区文件的修改。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git checkout -- \n")])])]),a("p",[t._v("(2)切换分支。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git checkout \n")])])]),a("p",[t._v("(3)切换分支,如果目标分支不存在则新建。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git checkout -b \n")])])]),a("p",[t._v("(4)将远端分支拉取到本地。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git checkout -b origin/\n")])])]),a("p",[t._v("(5)切换当前分支到某个提交,即移动 HEAD 指针指向某个提交。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git checkout \n")])])]),a("h3",{attrs:{id:"git-switch"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-switch"}},[t._v("#")]),t._v(" git switch")]),t._v(" "),a("p",[t._v("(1)简介\ngit switch 从 git 2.23 版本开始引入,是一个比较新的命令,主要用于分支的创建和切换,实现了 git checkout 命令分支创建与切换的功能。git switch 命令的语义更加贴合其作用,更容易理解,建议使用。")]),t._v(" "),a("p",[t._v("(2)格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git switch [] []\n")])])]),a("p",[t._v("(3)选项")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-c \n--create \n\t创建一个新分支然后切换过去\n-C \n--force-create \n\t强制创建一个新分支然后切换过去\n-t\n--track\n\t将远端分支拉取到本地\n")])])]),a("p",[t._v("(4)示例")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git switch dablelv\n\t切换到指定分支\ngit switch -c dablelv_new\n\t基于当前分支创建一个新分支然后切换过去\ngit switch -\n\t切回到之前的分支\ngit switch -t origin/dablelv\n\t将远端分支 dablelv 拉取到本地\n")])])]),a("h3",{attrs:{id:"git-stash"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-stash"}},[t._v("#")]),t._v(" git stash")]),t._v(" "),a("p",[t._v("(1)简介\n当一个分支的开发工作未完成,却要切换到另外一个分支进行开发的时候,除了commit 原分支的代码改动的方法外,可以使用 git stash 来保存当前分支的工作进度。")]),t._v(" "),a("p",[t._v("(2)格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git stash list []\ngit stash show [] []\ngit stash drop [-q|--quiet] []\ngit stash ( pop | apply ) [--index] [-q|--quiet] []\ngit stash branch []\ngit stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n\t [-u|--include-untracked] [-a|--all] [-m|--message ]\n\t [--] […​]]\ngit stash clear\ngit stash create []\ngit stash store [-m|--message ] [-q|--quiet] \n")])])]),a("p",[t._v("(3)示例")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git stash [push]\n保存当前工作进度,会把暂存区和工作区的改动保存起来。执行完这个命令后,在运行git status命令,就会发现当前是一个干净的工作区,没有任何改动。使用 git stash save 'message...' 可以添加一些注释。注意,git stash 是 git stash push 的简写\n\ngit stash list\n显示保存进度的列表。也就意味着,git stash命令可以多次执行。\n\ngit stash pop \n恢复最新的进度到工作区。git默认会把工作区和暂存区的改动都恢复到工作区。\n\ngit stash pop --index \n不仅恢复工作区,还恢复暂存区,即恢复最新的进度到工作区和暂存区。\n\ngit stash pop stash@{stash_id}\n恢复指定的进度到工作区。stash_id是通过git stash list命令得到的。\n\n注意:通过git stash pop命令恢复进度后,会删除当前进度。\n\ngit stash apply --index\n不仅恢复工作区,还恢复暂存区,即恢复最新的进度到工作区和暂存区。不删除当前进度。\n\ngit stash apply stash@{stash_id}\n恢复指定的进度到工作区,不删除当前进度。stash_id是通过git stash list命令得到的。\n\n注意:git stash apply除了不删除恢复的进度之外,其余和git stash pop命令一样。\n\ngit stash drop [stash_id]\n删除一个存储的进度。如果不指定stash_id,则默认删除最新的存储进度。\n\ngit stash clear\n删除所有存储的进度。\n")])])]),a("h3",{attrs:{id:"git-tag"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-tag"}},[t._v("#")]),t._v(" git tag")]),t._v(" "),a("p",[t._v("同大多数 VCS 一样,Git 也可以对某一时间点上的版本打上标签,用于版本的发布管理。一个版本发布时,我们可以为当前版本打上类似于 v.1.0.1、v.1.0.2 这样的 Tag。一个 Tag 指向一个 Commit ID,同时还可以为 Tag 添加备注,如当前的版本功能。")]),t._v(" "),a("ul",[a("li",[t._v("新建标签")])]),t._v(" "),a("p",[t._v("Git 使用的标签有两种类型:轻量级的(lightweight)和含附注的(annotated)。轻量级标签就像是个不会变化的分支,实际上它就是个指向特定提交对象的引用。而含附注标签,实际上是存储在仓库中的一个独立对象,它有自身的校验和信息,包含着标签的名字,电子邮件地址和日期,以及标签说明,标签本身也允许使用 GNU Privacy Guard (GPG) 来签署或验证。一般我们都建议使用含附注型的标签,以便保留相关信息;当然,如果只是临时性加注标签,或者不需要旁注额外信息,用轻量级标签也没问题。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('# 轻量级标签\ngit tag \n\n# 含附注的标签\ngit tag -a -m \n\n# 示例\ngit tag v1.0\ngit tag -a v1.1 -m "my version 1.1"\n')])])]),a("ul",[a("li",[t._v("将本地标签推送到远端")])]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("# 推送本地指定标签\ngit push origin \n\n# 推送本地所有标签\ngit push origin --tags\n")])])]),a("ul",[a("li",[t._v("查看标签")])]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('# 查看所有本地标签\ngit tag\nv1.1.0\nv1.1.1\n\n# 按照创建时间降序排列\ngit tag --sort=-creatordate\n\n# 按照创建时间升序排列\ngit tag --sort=creatordate\n\n# 查看所有远端标签\ngit ls-remote --tags\n\n# 模糊查询标签。支持使用通配符 *\ngit tag -l \n\ngit tag -l "*.1.1"\nv1.1.1\n\n# 查看标签详细信息\ngit show \n')])])]),a("ul",[a("li",[t._v("删除标签")])]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("# 删除本地标签\ngit tag -d \n\n# 删除远端标签\ngit push origin (-d | --delete) \ngit push origin :refs/tags/\n")])])]),a("ul",[a("li",[t._v("重命名标签")])]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("# 无重命名标签选项,只能删除然后新建\ngit tag -d && git tag \n")])])]),a("h3",{attrs:{id:"git-merge"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-merge"}},[t._v("#")]),t._v(" git merge")]),t._v(" "),a("p",[t._v("(1)简介")]),t._v(" "),a("p",[t._v("git merge 用于分支合并。比如当开发分支上的代码达到上线的标准后,此时需要使用 git merge 将开发分支合并到 master 分支。")]),t._v(" "),a("p",[t._v("(2)常见用法")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("# 将原分支合并到当前分支。原分支的历史提交记录会被保留\ngit merge \n\n# 将原分支合并到当前分支。原分支的历史提交记录不会被保留,然后使用 git commit 创建一个新提交,这样会使提交历史干净整洁,推荐使用\ngit merge --squash \n")])])]),a("p",[t._v("(3)git merge 与 git merge --squash 的区别")]),t._v(" "),a("p",[t._v("一图看懂二者的区别。\n"),a("img",{attrs:{src:"https://img-blog.csdnimg.cn/20210713210817629.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0szNDZLMzQ2,size_16,color_FFFFFF,t_70",alt:"在这里插入图片描述"}}),t._v("\n判断是否使用 --squash 选项最根本的标准是,待合并分支上的历史记录是否有意义。如果没有意义,建议使用 --squash 选项将其废弃。")]),t._v(" "),a("h2",{attrs:{id:"_7-分享与更新项目-sharing-and-updating-projects"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_7-分享与更新项目-sharing-and-updating-projects"}},[t._v("#")]),t._v(" 7.分享与更新项目(Sharing and Updating Projects)")]),t._v(" "),a("h3",{attrs:{id:"git-pull"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-pull"}},[t._v("#")]),t._v(" git pull")]),t._v(" "),a("p",[t._v("git pull 命令用于取回远程仓库某个分支的更新与本地指定分支合并。实际上 git pull = git fetch + git merge。其基本用法格式如下:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git pull [] [ […​]]\n")])])]),a("p",[t._v("refspec 为分支名。")]),t._v(" "),a("p",[t._v("(1)例如将远程仓库 origin 的 master 分支拉取过来,与本地的 branchtest 分支合并。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git pull origin master:branchtest\n")])])]),a("p",[t._v("(2)后面的冒号与本地的分支名可以省略,表示与本地当前分支合并。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git pull origin master\n")])])]),a("p",[t._v("(3)远程仓库名和远程分支名均可省略,表示使用与本地当前分支关联的远端分支更新本地分支。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git pull\n")])])]),a("p",[t._v("(4)git push 出现"),a("code",[t._v("error: failed to push some refs to '仓库地址'")]),t._v("的错误,原因是远程仓库中代码版本与本地不一致冲突导致的,解决办法是先"),a("code",[t._v("git pull")]),t._v(",再"),a("code",[t._v("git push")]),t._v("。")]),t._v(" "),a("p",[t._v("(5)git pull 与 git pull --rebase 的区别。\ngit pull --rebase = git fetch + git rebase。使用 --reabase 选项可以使项目提交历史变成直线,没有分叉,非常整洁。git rebase是变基操作,使得本地分支的修改变成在远端最新版本基础上进行,于是少了一步将远端分支的最新版本merge到本地分支的记录,即 git pull --rebase 可以消除"),a("code",[t._v("Merge branch 'master' of ")]),t._v("这种commit 记录。建议使用 -r(--rebase)选项。")]),t._v(" "),a("p",[t._v("git pull --rebase 的过程可以使用如下图表示:\n"),a("img",{attrs:{src:"https://img-blog.csdnimg.cn/20190130144938906.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0szNDZLMzQ2,size_16,color_FFFFFF,t_70",alt:"在这里插入图片描述"}})]),t._v(" "),a("h3",{attrs:{id:"git-push"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-push"}},[t._v("#")]),t._v(" git push")]),t._v(" "),a("p",[t._v("git push 命令用于将本地分支的更新推送到远端分支,命令格式与 git pull 相似。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git push [] [ […​]]\n")])])]),a("p",[t._v("如果命令行没有使用"),a("code",[t._v("")]),t._v("参数指定推送的仓库,则会采用"),a("code",[t._v("branch.*.remote")]),t._v("配置。如果缺少配置,则默认为 origin。")]),t._v(" "),a("p",[t._v("(1)使用将当前本地分支更新关联的远端分支。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push\n")])])]),a("p",[t._v("(2)将本地分支推送至远端并关联。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 将当前分支推送至远端并关联(远端分支与本地分支同名)")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-u "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" --set-upstream"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" origin HEAD\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 将当前分支推送至远端并关联(指定远端分支名)")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-u "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" --set-upstream"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" origin HEAD:"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("remote_branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 将本地分支推送至远端并关联(指定本地与远端分支名)")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-u "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" --set-upstream"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" origin "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("local_branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(":"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("remote_branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n")])])]),a("p",[t._v("(3)使用本地分支更新远端分支。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("仓库名"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("本地分支名"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(":"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("远端分支名"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n")])])]),a("p",[t._v("(4)删除远端分支。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 方式一:推送一个空分支到远端分支")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push origin :"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("remote_branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# 方式二:使用 git push -d")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push origin "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-d "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" --delete"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("branchname"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n")])])]),a("p",[t._v("(5)本地与远端分支版本回退,需要使用 -f, --force 选项。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" reset "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[t._v("--hard")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("commitid"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" push "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("-f "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" --force"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),a("h3",{attrs:{id:"git-remote"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-remote"}},[t._v("#")]),t._v(" git remote")]),t._v(" "),a("p",[t._v("git remote 命令用于管理一组被跟踪的远程代码仓库。")]),t._v(" "),a("p",[t._v("选项说明:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-h\n\t显示帮助信息\n-v, --verbose\n\t查看远端仓库名称与地址。仓库地址在名称的后面,仓库名默认为 origin\n")])])]),a("p",[t._v("子命令说明:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git remote\n\t查看远端仓库名称,默认为 origin\ngit remote rename \n\t修改远程仓库名称,默认为 origin\ngit remote remove \n\t删除与远程仓库的关联\ngit remote add \n\t添加新的远程仓库关联\ngit remote set-head (-a | --auto | -d | --delete | )\n\t设置或删除远程仓库的默认分支。默认分支一般为 master\ngit remote [-v | --verbose] show [-n] \n\t显示远程仓库相关分支信息\ngit remote prune [-n | --dry-run] \n\t清理与远程仓库关联的过时分支。如果使用 --dry-run,则只显示过时分支,不进行清理。使用该命令后,被删除的远程分支将不会出现在 git branch -r 命令结果中\ngit remote [-v | --verbose] update [-p | --prune] [( | )...]\n\t更新远程分支列表\ngit remote set-branches [--add] ...\n\t为远程仓库添加分支列表\ngit remote get-url [--push] [--all] \n\t查看远程仓库地址。如果使用 --push,则查询 push 地址,而非 fetch 地址\ngit remote set-url [--push] []\n\t改变远程仓库地址\ngit remote set-url --add \n\t为远程仓库添加新地址\ngit remote set-url --delete \n\t删除所有远程仓库所有正则匹配 的地址\n")])])]),a("p",[t._v("常用示例:")]),t._v(" "),a("p",[t._v("(1)常看关联的远程仓库名与地址。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git remote -v\norigin\thttp://git.code.oa.com/trpc-cpp/trpc-cpp.git (fetch)\norigin\thttp://git.code.oa.com/trpc-cpp/trpc-cpp.git (push)\n")])])]),a("p",[t._v("(2)将关联的远程仓库名由默认的 origin 更名为 test。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git remote -v rename origin test\n\n# 再次查看,更改成功\ngit remote -v\ntest\thttp://git.code.oa.com/trpc-cpp/trpc-cpp.git (fetch)\ntest\thttp://git.code.oa.com/trpc-cpp/trpc-cpp.git (push)\n")])])]),a("p",[t._v("(3)关联新的远程仓库。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git remote add NewRepo http://git.code.oa.com/dablelv/trpc-cpp.git\n\n# 查看,添加成功\ngit remote -v\nNewRepo\thttp://git.code.oa.com/dablelv/trpc-cpp.git (fetch)\nNewRepo\thttp://git.code.oa.com/dablelv/trpc-cpp.git (push)\ntest\thttp://git.code.oa.com/trpc-cpp/trpc-cpp.git (fetch)\ntest\thttp://git.code.oa.com/trpc-cpp/trpc-cpp.git (push)\n")])])]),a("p",[t._v("成功关联远程仓库后,便可以从其 fetch 或向其 push 代码了。")]),t._v(" "),a("p",[t._v("(4)修改远程仓库地址。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" remote set-url "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("name"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("new_url"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n")])])]),a("h3",{attrs:{id:"git-submodule"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-submodule"}},[t._v("#")]),t._v(" git submodule")]),t._v(" "),a("p",[t._v("(1)更新子模块指针。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git submodule update\n")])])]),a("p",[t._v("将远端仓库子模块指针更新到本地,注意与命令"),a("code",[t._v("git submodule update --remote --merge")]),t._v("的区别。子模块指针指的是子模块的版本号。")]),t._v(" "),a("p",[t._v("(2)更新子模块代码。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git submodule update --remote --merge\n")])])]),a("p",[t._v("将从每个子模块的上游获取最新更改,并将其合并,这相当于在每个子模块中执行 git pull。")]),t._v(" "),a("h2",{attrs:{id:"_8-修补-patching"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_8-修补-patching"}},[t._v("#")]),t._v(" 8.修补(Patching)")]),t._v(" "),a("h3",{attrs:{id:"git-rebase"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-rebase"}},[t._v("#")]),t._v(" git rebase")]),t._v(" "),a("p",[t._v("(1)简介")]),t._v(" "),a("p",[t._v("git rebase 是变基操作,其作用与 git merge 类似,用于将另一个分支合并到当前分支。变基是将一系列提交按照原有次序依次应用到另一分支上,使得提交历史变成一条直线,而合并(git merge)是把最终结果合在一起,提交历史可能会出现分叉,并多出一个 merge 的提交记录。")]),t._v(" "),a("p",[t._v("(2) git rebase 与 git merge 的区别")]),t._v(" "),a("p",[t._v("比如基于 master 分支创建了一个新的分支 experiment,开发任务分叉到两个不同分支,又各自提交了更新,那么提交历史日志如下:\n"),a("img",{attrs:{src:"https://img-blog.csdnimg.cn/20190130110346331.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0szNDZLMzQ2,size_16,color_FFFFFF,t_70",alt:"在这里插入图片描述"}}),t._v("\n现将 experiment 分支合并到 master 分支有两种方式,一是 git rebase,二是 git merge。")]),t._v(" "),a("p",[t._v("(a)git merge 方式")]),t._v(" "),a("p",[t._v("切换到 master 分支,执行合并操作,会将 experiment 分支的最新快照 C3 合并到 master 分支的最新快照 C2 中并生成一个新的快照(并提交)。提交历史将出现分叉,示意如下:\n"),a("img",{attrs:{src:"https://img-blog.csdnimg.cn/20190130111528259.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0szNDZLMzQ2,size_16,color_FFFFFF,t_70",alt:"在这里插入图片描述"}}),t._v("\n操作命令如下:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git checkout master\ngit merge experiment\n")])])]),a("p",[t._v("(b)git rebase 方式")]),t._v(" "),a("p",[t._v("git rebase 实现原理是首先找到两个分支的最近共同祖先 C1,提取 experiment 分支相对于该祖先的历次提交存为临时的差异补丁 patch 文件,存在 .git/rebase 目录下;然后在 master 分支最新提交 C2 的基础上,将保存的 patch 文件中的提交依次应用到 master 分支,并生成新的提交(commit id)。")]),t._v(" "),a("p",[t._v("最后回到 master 分支,进行一次快进合并,即将 experiment 分支合并到 master 分支。\n"),a("img",{attrs:{src:"https://img-blog.csdnimg.cn/20190130113135881.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0szNDZLMzQ2,size_16,color_FFFFFF,t_70",alt:"在这里插入图片描述"}}),t._v("\n操作命令如下:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("# 第一步,变基\ngit checkout experiment\ngit rebase master\n\n# 或者\ngit rebase master experiment\n\n# 第二步,合并\ngit checkout master\ngit merge experiment\n")])])]),a("p",[t._v("(3)变基的风险")]),t._v(" "),a("p",[t._v("变基帮助我们拥有直线提交历史,也并非完美无缺,为避免出错,使用时需要遵守一条准则:"),a("strong",[t._v("不要对已推送至远程仓库的提交进行变基操作")]),t._v("。")]),t._v(" "),a("p",[t._v("变基操作的实质是丢弃一些现有的提交,然后相应地新建一些内容一样但实际上不同的提交。 如果你已经将提交推送至远程仓库,而其他人也已经从该仓库拉取提交并进行了后续工作,此时,如果你用 git rebase 命令重新整理了提交并再次推送,相当于删除之前的提交。你的同伴再次 git pull 时,会将存放在本地的你已经删除的提交再次合并,如果你的同伴将合并后的提交推送到服务器上,实际上是将那些已经被你变基抛弃的提交又恢复了回来,这会令人感到混乱。")]),t._v(" "),a("p",[t._v("(4)变基 vs 合并")]),t._v(" "),a("p",[t._v("变基和合并都可以完成分支合并,到底哪种方式更好?在回答这个问题之前,让我们退后一步,讨论一下提交历史的意义。")]),t._v(" "),a("p",[t._v("有一种观点认为,仓库的提交历史记录实际发生过什么。 它是针对历史的文档,本身就有价值,不能乱改。 从这个角度看来,改变提交历史是一种亵渎,你使用谎言掩盖了实际发生过的事情。 如果由合并产生的提交历史是一团糟怎么办? 既然事实就是如此,那么这些痕迹就应该被保留下来,让后人能够查阅。")]),t._v(" "),a("p",[t._v("另一种观点则正好相反,他们认为提交历史是 项目过程中发生的事。 没人会出版一本书的第一版草稿,软件维护手册也是需要反复修订才能方便使用。 持这一观点的人会使用 rebase 及 filter-branch 等工具来编写故事,怎么方便后来的读者就怎么写。")]),t._v(" "),a("p",[t._v("现在,让我们回到之前的问题上来,到底合并还是变基好?这并没有一个正确的答案。 Git 是一个非常强大的工具,它允许你对提交历史做许多事情,但每个团队、每个项目对此的需求并不相同,按实际需要来选择即可。")]),t._v(" "),a("p",[t._v("个人建议,git merge 足以完成分支合并,易于理解,基于惰性与简明原则,没有必要使用变基。")]),t._v(" "),a("p",[t._v("(5)常用命令选项")]),t._v(" "),a("p",[t._v("git rebase 的基本命令格式如下:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git rebase [-i] [options] [--exec ] [--onto ] [] []\ngit rebase [-i] [options] [--exec ] [--onto ] --root []\ngit rebase --continue | --abort | --skip | --edit-todo\n")])])]),a("p",[t._v("(a)git rebase --onto\n截取特性分支上的另一个特性分支,然后变基到其他分支。比如,假设当前本地仓库提交历史如下:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("A---B---E---F---G master\n \\\n C---D---H---I---J next\n \\\n K---L---M topic\n")])])]),a("p",[t._v("此时topic分支的上游分支是next分支,如果要将topic分支上的提交(K,M,L)跳过next分支,直接放到master分支上,就需要加上--onto参数:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git rebase --onto master next topic\n")])])]),a("p",[t._v("上述命令的意思是:取出topic分支,找出topic和next分支的共同祖先之后的提交,然后放在master分支上,执行后提交历史变为如下:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("A---B---E---F---G master\n \\ \\\n \\ K'---L'---M' topic \n \\ \n C---D---H---I---J next\n")])])]),a("p",[t._v("(b)git rebase –continue/abort/skip\n这三个命令分别表示继续执行变基操作、终止变基、跳过某一文件继续进行。因为在rebase的过程中,有可能会出现文件冲突。这种情况下,首先要解决冲突,解决冲突后可以选择继续执行rebase或者结束rebase,一般的做法为:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git add filename\ngit rebase --continue\n")])])]),a("p",[t._v("或者可以选择终止变基:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git rebase --abort\n")])])]),a("p",[t._v("或者跳过该patch。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git rebase --skip\n")])])]),a("p",[t._v("(c)git rebase -i, --interactive\n该命令相比其他命令,使用频率要高得多。"),a("code",[t._v("git rebase -i ")]),t._v(" 可以进行交互式变基,相比于 "),a("code",[t._v("git rebase ")]),t._v(" 用来变基,它经常用来操作当前分支的提交,git 会将 "),a("code",[t._v("-HEAD")]),t._v(" 之间的提交列在一个变基脚本中,每一笔提交根据用户设置的命令,会进行不同的操作,如修改提交信息、移除指定提交、合并两个提交为一个(压缩提交)、拆分提交等。")]),t._v(" "),a("p",[t._v("如要对最近 4 次提交进行重新操作,则:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git rebase -i HEAD~4\n")])])]),a("p",[t._v("此时将会弹出如下形式的变基脚本:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('1 pick af98479 [Description]:test4\n2 pick 3cc9d66 test3\n3 pick a7e819e usera commit03 branch2\n4 pick efc5b15 usera commit04 branch2\n5 \n6 # Rebase de7b118..efc5b15 onto de7b118 (4 command(s))\n7 #\n8 # Commands:\n9 # p, pick = use commit\n10 # r, reword = use commit, but edit the commit message\n11 # e, edit = use commit, but stop for amending\n12 # s, squash = use commit, but meld into previous commit\n13 # f, fixup = like "squash", but discard this commit\'s log message\n14 # x, exec = run command (the rest of the line) using shell\n15 # d, drop = remove commit\n16 #\n17 # These lines can be re-ordered; they are executed from top to bottom.\n18 #\n19 # If you remove a line here THAT COMMIT WILL BE LOST.\n20 #\n21 # However, if you remove everything, the rebase will be aborted.\n22 #\n23 # Note that empty commits are commented out\n')])])]),a("p",[t._v("这里我们可以修改pick为下面给出的其他命令,比如如果要修改提交信息,就使用r或reword,各指令的含义如下:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("p,pick:直接使用该次提交\nr,reword:使用该次提交,但重新编辑提交信息\ne,edit:停止到该次提交,通过`git commit --amend`追加提交,完毕之后不要忘记使用`git rebase --continue`完成这此rebase\ns,squash:压缩提交,将和上一次提交合并为一个提交\nx,exec:运行命令\nd,drop:移除这次提交\n")])])]),a("h3",{attrs:{id:"git-cherry-pick"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-cherry-pick"}},[t._v("#")]),t._v(" git cherry-pick")]),t._v(" "),a("p",[t._v("(1)简介\ngit cherry-pick 用于应用某些现有提交引入的更改。")]),t._v(" "),a("p",[t._v("比如 master 分支有如下提交记录,A -> B -> C,程序在运行过程中,提交 B 引入的特性存在一个隐藏很深的 bug,现在需要将 B 从分支踢出,但是需要保留提交 C。此时需要将分支回退(reset) 到 A,然后使用 cherry-pick 将 C 的更改应用到 A。这里要注意,cherry-pick 时 C 一定要存在,不然会出错,这就要求我们在回滚 master 分支前,基于 master 先创建一个新的分支来保留提交 C。")]),t._v(" "),a("p",[t._v("(2)用法")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git cherry-pick …​\n")])])]),a("h2",{attrs:{id:"_9-调试-debugging"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_9-调试-debugging"}},[t._v("#")]),t._v(" 9.调试(Debugging)")]),t._v(" "),a("h3",{attrs:{id:"git-blame"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-blame"}},[t._v("#")]),t._v(" git blame")]),t._v(" "),a("p",[t._v("git blame 命令用于查看文件的每一行是谁修改的。")]),t._v(" "),a("div",{staticClass:"language-shell extra-class"},[a("pre",{pre:!0,attrs:{class:"language-shell"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" blame "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("file"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" blame "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("-L n,m"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("file"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\t//指定文件的行范围为n,m\n")])])]),a("h3",{attrs:{id:"git-version"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-version"}},[t._v("#")]),t._v(" git version")]),t._v(" "),a("p",[t._v("git version 用于查看 git 版本。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git version\n")])])]),a("h2",{attrs:{id:"_10-管理-administration"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_10-管理-administration"}},[t._v("#")]),t._v(" 10.管理(Administration)")]),t._v(" "),a("h3",{attrs:{id:"git-clean"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-clean"}},[t._v("#")]),t._v(" git clean")]),t._v(" "),a("p",[t._v("git clean 命令用于删除工作目录所有 untracked 的文件或目录。基本用法如下:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git clean [-d] [-f] [-i] [-n] [-q] [-e ] [-x | -X] [--] ...\n -q, --quiet \t\t\t\t不打印被删除的文件或目录名称\n -n, --dry-run \t\t\t\t查看删除之前会删除哪些东西,并不会有实际的影响\n -f, --force \t\t\t强制删除\n -i, --interactive \t\t\t交互式删除\n -d \t\t\t删除目录\n -e, --exclude 添加到忽略规则中,用于忽略符合规则的文件或目录\n -x \t\t\t\t\t同时可删除被忽略的文件或目录\n -X \t\t\t\t\t只删除被忽略的文件\n")])])]),a("p",[t._v("注意,未指定目录"),a("code",[t._v("")]),t._v("默认为当前目录。一般情况下,git reset --hard 会和 git clean -df 一起使用,让你的工作目录完全回退到最近一次 commit 的时候。")]),t._v(" "),a("h2",{attrs:{id:"_11-检查与比较-inspection-and-comparison"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_11-检查与比较-inspection-and-comparison"}},[t._v("#")]),t._v(" 11.检查与比较(Inspection and Comparison)")]),t._v(" "),a("h3",{attrs:{id:"git-log"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-log"}},[t._v("#")]),t._v(" git log")]),t._v(" "),a("p",[t._v("(1)简介\ngit log 用于看历史提交日志,最近的排在最上方,显示提交对象的哈希值、作者、提交日期和提交说明。如果记录过多,则按 Page Up、Page Down、↓、↑ 键来控制显示,按 q 退出历史记录列表。")]),t._v(" "),a("p",[t._v("(2)命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git log [] [] [[--] …​]\n")])])]),a("p",[t._v("(3)常用选项")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-- …​\n\t显示指定文件的提交日志\n-, -n, --max-count=\n\t显示最近 number 次的提交日志\n--since, --after=\n\t显示指定日期之后的提交日志\n--until, --before=\n\t显示指定日期之前的提交日志\n--author, --committer=\n\t显示指定提交者提交的日志\n--merges\n\t只展示 merge 信息\n--no-merges\n\t不展示 merge 信息\n--abbrev-commit\n\t精简 commit id,只展示 40 个十六进制数字构成的 commit id 的首部\n--graph\n\t以文本字符绘制的“图形”展示\n--pretty[=]\n--format=\n\t以指定格式展示, 可取值 oneline, short, medium, full, fuller, email, raw, format: 和 tformat:,\n\t其中为格式控制字符串。缺省值为 medium。常用的是 oneline\n--oneline\n\t等价于 --pretty=oneline --abbrev-commit\n")])])]),a("p",[t._v("(4)常用示例\n(a)展示提交历史。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git log\n")])])]),a("p",[t._v("(b)单行展示,显示简短 commitid(%h)、提交日期(%cd)、提交者的名字(%cn)和提交说明(%s)。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v('git log --pretty=format:"%h %cd %cn : %s"\n955599561 Tue Mar 10 16:21:51 2020 +0800 tom : 性能优化\n692028af8 Tue Mar 10 10:26:08 2020 +0800 bill : 修改 bug\n11a8e2021 Tue Mar 10 10:26:08 2020 +0800 jerry : 首次提交\n')])])]),a("p",[t._v("(c)以图形方式展示提交历史。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git log --graph\n")])])]),a("p",[t._v("(d)以图形方式展示提交历史,提交信息以单行展示。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git log --graph --oneline\n\n* 2fa056a8c Merge branch 'master' of http://git.code.oa.com/nfa/goserver_proj\n|\\\n| * d336234bc (tag: Tag_20190312_V003) set gopath\n| * b8c3bbd55 (tag: Tag_20190312_V002) fix command.go proto path\n| * 2f6a13fc2 (tag: Tag_20190312_V001) fix proto path\n| * 7a147abe2 fix proto path\n| * 99e295279 (tag: Tag_20190311_B1000) Merge branch 'kbAbOp_eddie' into 'master'\n| |\\\n| | * 809801eb9 add cityhash\n| | * b588a5d40 接口改造\n| * | f1c0ca554 fix\n| |/\n| * 92e4249a9 update conf&log\n| * bd8cf2755 Merge branch 'master' of http://git.code.oa.com/nfa/goserver_proj\n| |\\\n| * | 886fd1ed3 change log\n* | | 0d911b64d 提交新结构\n| |/\n|/|\n* | 8c7eca23a ad\n|/\n* 769b68c61 KbADProxyServer first commit\n* 8cea1f0b4 信息流商业化的所有go服务代码放此项目,方便公用代码\n")])])]),a("h3",{attrs:{id:"git-diff"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-diff"}},[t._v("#")]),t._v(" git diff")]),t._v(" "),a("ul",[a("li",[t._v("简介")])]),t._v(" "),a("p",[t._v("主要用于查看文件之间的区别:\n(1)工作区(working tree)与暂存区(index);\n(2)工作区与版本库(repository);\n(3)暂存区与版本库;\n(4)版本库与版本库的不同版本;\n(5)不同分支;\n(6)磁盘上两个文件之间;\n(7)本地分支与远端分支。")]),t._v(" "),a("ul",[a("li",[t._v("示例")])]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git diff []...\n\t工作区与暂存区比较\ngit diff []...\n\t工作区与版本库比较\ngit diff []...\n\t工作区与分支比较\ngit diff (--staged | --cached) [] []...\n\t暂存区与版本库比较。commit 缺省为 HEAD,即最新提交\ngit diff [commit1] [commit2] []...\n\t版本库与版本库的不同版本比较\ngit diff []...\n\t不同分支最新提交比较\ngit diff --stat\n\t列出发生变更的文件列表以及有多少行产生了改动\ngit diff \n\t两个磁盘文件比较\ngit diff / \n\t本地分支与远端分支\n")])])]),a("p",[t._v("注意:比较的两个对象,第一对象是被比较的对象,给出的差异结果也是第二个对象相对于第一个对象的差异结果。")]),t._v(" "),a("h3",{attrs:{id:"git-show"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-show"}},[t._v("#")]),t._v(" git show")]),t._v(" "),a("p",[t._v("(1)简介\ngit show 用于显示各种类型的对象,包括 blobs、trees、tags 和 commits。")]),t._v(" "),a("p",[t._v("对于 commits,它显示日志消息和文本差异。\n对于 tags,它显示标签消息和引用对象。\n对于 trees,它显示 tree 的名称。\n对于简单的 blobs,它显示了普通的内容。")]),t._v(" "),a("p",[t._v("(2)命令格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git show [] […​]\n")])])]),a("p",[t._v("(3)常用选项")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("…​\n\t待展示的对象,默认为 HEAD\n--pretty[=], --format=\n\t以指定格式展示, 可取值 oneline, short, medium, full, fuller, email, raw, format: 和 tformat:,\n\t其中为格式控制字符串。缺省值为 medium。常用的是 oneline\n--abbrev-commit\n\t精简 commit id,只展示 40 个十六进制数字构成的 commit id 的首部\n--oneline\n\t等价于 --pretty=oneline --abbrev-commit\n--name-only\n\t只显示发生变更的文件名\n")])])]),a("p",[t._v("(4)常用示例\n(a)查看某个 tag 指向的版本信息。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git show v1.0.0\n")])])]),a("p",[t._v("(b)显示某个 tag 指向的版本的目录树。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git show v1.0.0^{tree}\n\n.gitignore\n.orange-ci.yml\nPRJ_ROOT\nREADME.md\nbin/\npkg/\nsrc/\n")])])]),a("p",[t._v("(c)显示某次提交的详细信息,包括文件差异。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git show \n")])])]),a("p",[t._v("(d)只显示某次提交发生变化的文件名。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git show --name-only \n")])])]),a("h2",{attrs:{id:"_12-基本快照-basic-snapshotting"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_12-基本快照-basic-snapshotting"}},[t._v("#")]),t._v(" 12.基本快照(Basic Snapshotting)")]),t._v(" "),a("h3",{attrs:{id:"git-reset"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-reset"}},[t._v("#")]),t._v(" git reset")]),t._v(" "),a("ul",[a("li",[t._v("简介")])]),t._v(" "),a("p",[t._v("git reset 将当前 HEAD 重置为指定状态,即版本回退。")]),t._v(" "),a("p",[t._v("可将分支重设(reset)到指定的"),a("code",[t._v("")]),t._v(",如果不显示指定 commit,默认是 HEAD,即最近一次提交。")]),t._v(" "),a("p",[t._v("比如我们用 Git 时可能在 commit 后,发现这次 commit 的内容是有错误的,那么有两种处理方法:\n(1)修改错误内容,再次 commit;\n(2)使用 git reset 撤销这一次错误的 commit。")]),t._v(" "),a("p",[t._v("第一种方法比较直接,但会多一次 commit 记录,建议使用 git reset 进行版本回退,方便快捷,错误的 commit 记录不会被保留下来。")]),t._v(" "),a("ul",[a("li",[t._v("命令格式")])]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git reset [-q] [] [--] …​\ngit reset (--patch | -p) [] [--] […​]\ngit reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] []\n")])])]),a("ul",[a("li",[t._v("选项说明")])]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-q, --quiet\n\t静默模式,只打印错误信息\n--soft\n\t重置 HEAD,保留暂存区和工作区。版本库的修改会回退到暂存区,工作区的修改保持不动\n--mixed\n\t重置 HEAD 和暂存区,保留工作区。版本库与暂存区的修改都将回退到工作区,即回滚到了所有 git add 和 git commit 的执行之前的状态。为默认模式\n--hard\n\t重置 HEAD、暂存区和工作区。暂存区和工作区的修改都将被丢弃。请谨慎使用,暂存区的修改很难找回,工作区的修改无法找回。\n--merge\n\t重置 HEAD 和暂存区,保留工作区。与 --mixed 不同的是,暂存区的修改不会回退到工作。如果工作区的某个文件与暂存区不同,则命令执行失败。该选项很少使用\n--keep\n\t重置 HEAD 与暂存区,保留工作区。与 --mixed 不同的是,暂存区的修改不会回退到工作。与 --merge 的区别是,如果工作区的某个文件与暂存区不同,则命令不会执行失败。该选项很少使用\n-p, --patch\n\t以 patch 的方式展示出来需要 reset 的代码, git reset -p 和 git add -p 就是一对互为反向的操作,后者是把工作目录下变更的代码以 patch 的方式展示出来,以互动的方式应用到 index 上,前者则是一个反向操作\n-N, --intent-to-add\n\t任何新加入到 HEAD 的文件,再回退到工作区后都将标记为 tracked,即受版本控制\n")])])]),a("p",[t._v("(4)常用示例")]),t._v(" "),a("ul",[a("li",[t._v("放弃当前版本的所有修改。")])]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git reset --hard\ngit reset --hard HEAD\n")])])]),a("ul",[a("li",[t._v("分支版本跳转。")])]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git reset --hard [commit]\ncommit 可取值 HEAD 当前版本,上一个版本 HEAD^(或 HEAD~1),上上一个版本就是 HEAD^^(或 HEAD~2),以此类推。缺省为 HEAD\n")])])]),a("ul",[a("li",[t._v("将暂存区的修改回退到工作区。")])]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git reset ...\ngit reset HEAD ...\ngit reset --mixed ...\ngit reset --mixed HEAD ...\n")])])]),a("h3",{attrs:{id:"git-revert"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-revert"}},[t._v("#")]),t._v(" git revert")]),t._v(" "),a("p",[t._v("(1)简介\ngit revert 用一个新的提交来消除历史提交所做的修改,历史 commit 记录都会保留,并且这次撤销\n操作会产生一次新的提交。")]),t._v(" "),a("p",[t._v("与 git reset 的区别主要有:\n(a)实现的方式不用。git revert 使用一次新的提交来回退到指定版本,不会改变历史的提交历史。git reset 移动 HEAD 指针指向历史某次提交,历史提交记录将被改变。因此,git revert 一般用在公共分支上,git reset 一般用在私有分支上。\n(b)使用的场景不同。git revert 一般只用于版本回退,撤销已经提交的更改,并且要求暂存区与工作区是干净的。git reset 一般用于撤销未提交的修改,比如使用"),a("code",[t._v("git reset --hard")]),t._v("放弃暂存区与工作区的修改。")]),t._v(" "),a("p",[t._v("(2)格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git revert [--[no-]edit] [-n] [-m parent-number] [-s] [-S[]] …​\ngit revert (--continue | --skip | --abort | --quit)\n")])])]),a("p",[t._v("(3)选项")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-e\n--edit\n\t版本回退在提交之前编辑提交消息。如果从终端运行命令,则这是默认设置。\n--no-edit\n\tgit revert 将不会启动提交消息编辑器\n")])])]),a("p",[t._v("(4)示例")]),t._v(" "),a("p",[t._v("(a)回退到上一版本。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git revert HEAD^\n")])])]),a("h3",{attrs:{id:"git-restore"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-restore"}},[t._v("#")]),t._v(" git restore")]),t._v(" "),a("p",[t._v("(1)简介\ngit restore 是从 git 2.23 版本开始引入,是一个比较新的命令,用于恢复暂存区或者工作区中的文件。恢复工作区中的文件,也可以使用"),a("code",[t._v("git checkout -- ")]),t._v("。可见,git restore 实现了 git checkout 命令的文件恢复功能,git restore 命令的语义更加贴合其作用,更容易理解,建议使用。")]),t._v(" "),a("p",[t._v("(2)格式")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v(" git restore [] [--source=] ...\n")])])]),a("p",[t._v("(3)选项")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("-W\n--worktree\n\t恢复工作区指定文件,为缺省选项\n-S\n--staged\n\t将暂存区指定文件回退到工作区\n-s\n--source\n\t指明文件所在的分支,缺省为当前分支\n")])])]),a("p",[t._v("(4)示例\n(a)将暂存区的文件回退到工作区。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git restore -S ...\n")])])]),a("p",[t._v("(b)恢复工作区中的文件。")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git restore ...\n")])])]),a("h2",{attrs:{id:"_13-管理-administration"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_13-管理-administration"}},[t._v("#")]),t._v(" 13.管理(Administration)")]),t._v(" "),a("h3",{attrs:{id:"git-reflog"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-reflog"}},[t._v("#")]),t._v(" git reflog")]),t._v(" "),a("p",[t._v("(1)简介\ngit reflog 用于管理存储在引用日志 reflog 中的记录的信息。用于查看分支版本所有的变更记录,包括因版本回退出现在 HEAD 之后的变更记录。git log 只能查看 HEAD 之前的版本记录,不能查看 HEAD 之后的版本记录。")]),t._v(" "),a("p",[t._v("reflog 可以很好地帮助我们恢复误操作的数据,比如我们错误地 reset 到了一个旧的提交,这个时候我们可以使用 reflog 去查看在误操作之前的信息,并且使用 git reset 恢复到之前的状态。")]),t._v(" "),a("p",[t._v("(2)格式\n该命令采用各种子命令,并根据子命令使用不同的选项:")]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("git reflog [show] [log-options] []\ngit reflog expire [--expire=