尊龙凯时人生就是搏

LinuxÏÂÁî´óÈ«

×¢ÖØ£ºÎªÁËÀû±ã´úÂëÔĶÁ £¬ÎÄÕ´úÂë¿éÀï°ÑÌåÏÖÖÎÀíԱģʽµÄ#¶¼È¥µôÁË¡£Õâ²»Êǹýʧ¡£²»Òª¸ã´í£¡£¡

Ò»¡¢»ù±¾²Ù×÷ÏÂÁî

Ê×ÏÈÏÈÀ´¼¸¸öÈȼü £¬ºÜÊÇÀû±ã £¬Ò»¶¨Òª¼Ç×Å

Tab°´¼ü¡ªÏÂÁî²¹Æ빦Ч

Ctrl+c°´¼ü¡ªÍ£µôÕýÔÚÔËÐеijÌÐò

Ctrl+d°´¼ü¡ªÏ൱ÓÚexit £¬Í˳ö

Ctrl+l°´¼ü¡ªÇåÆÁ

1.1 ¹Ø»úºÍÖØÆô

1.¹Ø»úÏÂÁshutdown

ÔÚlinuxÁìÓòÄÚ´ó¶àÓÃÔÚЧÀÍÆ÷ÉÏ £¬ºÜÉÙÓöµ½¹Ø»úµÄ²Ù×÷¡£ÊÂʵЧÀÍÆ÷ÉÏÅÜÒ»¸öЧÀÍÊÇÓÀÎÞÖ¹¾³µÄ £¬³ý·ÇÌØÊâÇéÐÎÏ £¬²»µÃÒѲŻá¹Ø»ú¡£

׼ȷµÄ¹Ø»úÁ÷³ÌΪ£ºsync > shutdown > reboot > halt

ÀýÈçÄã¿ÉÒÔÔËÐÐÈçÏÂÏÂÁî¹Ø»ú£º

sync ½«Êý¾ÝÓÉÄÚ´æͬ²½µ½Ó²ÅÌÖС£shutdown ¹Ø»úÖ¸Áî£¬Äã¿ÉÒÔman shutdown À´¿´Ò»ÏÂ×ÊÖúÎĵµ¡£ÀýÈçÄã¿ÉÒÔÔËÐÐÈçÏÂÏÂÁî¹Ø»ú£ºshutdown ¨Ch 10 ¡®This server will shutdown after 10 mins¡¯ Õâ¸öÏÂÁî¸æË߸÷ÈË£¬ÅÌËã»ú½«ÔÚ10·ÖÖÓºó¹Ø»ú£¬²¢ÇÒ»áÏÔʾÔÚÉÏ°¶Óû§µÄÄ¿½ñÆÁÄ»ÖС£shutdown ¨Ch now Á¢Âí¹Ø»úshutdown ¨Ch 20:25 ϵͳ»áÔÚ½ñÌì20:25¹Ø»úshutdown ¨Ch +10 Ê®·ÖÖÓºó¹Ø»úshutdown ¨Cr now ϽµµÍ¢ÂíÖØÆôshutdown ¨Cr +10 ϵͳʮ·ÖÖÓºóÖØÆôreboot ¾ÍÊÇÖØÆô£¬µÈͬÓÚ shutdown ¨Cr nowhalt ¹Ø±Õϵͳ£¬µÈͬÓÚshutdown ¨Ch now ºÍ poweroff

µÇ¼ºó¸´ÖÆ

ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄÑùÀý¡£

×÷·Ï׼ʱ¹Ø»úÏÂÁshutdown -c

×îºó×ܽáһϠ£¬²»¹ÜÊÇÖØÆôϵͳÕվɹرÕϵͳ £¬Ê×ÏÈÒªÔËÐÐ sync ÏÂÁî £¬°ÑÄÚ´æÖеÄÊý¾Ýдµ½´ÅÅÌÖС£

¹Ø»úµÄÏÂÁîÓÐ shutdown ¨Ch now halt poweroff ºÍ init 0 , ÖØÆôϵͳµÄÏÂÁîÓÐ shutdown ¨Cr now reboot init 6¡£

2.ÖØÆôÏÂÁreboot

1.2 ×ÊÖúÏÂÁî

¨C-helpÏÂÁî

shutdown --help£ºifconfig --help£ºÉó²éÍø¿¨ÐÅÏ¢

µÇ¼ºó¸´ÖÆ

manÏÂÁÏÂÁî˵Ã÷Ê飩

man shutdown×¢ÖØ£ºman shutdown ·­¿ªÏÂÁî˵Ã÷ÊéÖ®ºó£¬Ê¹Óð´¼üqÍ˳ö

µÇ¼ºó¸´ÖÆ

¶þ¡¢Ä¿Â¼²Ù×÷ÏÂÁî

ÎÒÃÇÖªµÀLinuxµÄĿ¼½á¹¹ÎªÊ÷×´½á¹¹ £¬×¼¶µÄĿ¼Ϊ¸ùĿ¼ /¡£

ÆäËûĿ¼ͨ¹ý¹ÒÔØ¿ÉÒÔ½«ËüÃÇÌí¼Óµ½Ê÷ÖÐ £¬Í¨¹ýɨ³ý¹ÒÔØ¿ÉÒÔÒƳýËüÃÇ¡£

Ê×ÏÈÎÒÃÇÐèÒªÏÈÖªµÀʲôÊǾø¶Ô·¾¶ÓëÏà¶Ô·¾¶¡£

¾ø¶Ô·¾¶£ºÂ·¾¶µÄд·¨ £¬ÓɸùĿ¼ / дÆ𠣬ÀýÈ磺/usr/share/doc Õâ¸öĿ¼¡£

Ïà¶Ô·¾¶£ºÂ·¾¶µÄд·¨ £¬²»ÊÇÓÉ / дÆ𠣬ÀýÈçÓÉ/usr/share/doc Òªµ½ /usr/share/man µ×ÏÂʱ £¬¿ÉÒÔд³É£ºcd ../man Õâ¾ÍÊÇÏà¶Ô·¾¶µÄд·¨À²£¡

2.1 Ŀ¼Çл» cd

ÏÂÁcd Ŀ¼

cdÊÇChange DirectoryµÄËõд £¬ÕâÊÇÓÃÀ´±ä»»ÊÂÇéĿ¼µÄÏÂÁî¡£

cd /        Çл»µ½¸ùĿ¼cd /usr        Çл»µ½¸ùĿ¼ÏµÄusrĿ¼cd ../        Çл»µ½ÉÏÒ»¼¶Ä¿Â¼ »òÕß  cd ..cd ~        Çл»µ½homeĿ¼cd -        Çл»µ½Éϴλá¼ûµÄĿ¼

µÇ¼ºó¸´ÖÆ

2.2 Ŀ¼Éó²é ls [-al]

ÏÂÁls [-al]

Óï·¨£º

ls [-aAdfFhilnrRSt] Ŀ¼Ãû³Æls [--color={never,auto,always}] Ŀ¼Ãû³Æls [--full-time] Ŀ¼Ãû³Æ

µÇ¼ºó¸´ÖÆ

ls Éó²éÄ¿½ñĿ¼ÏµÄËùÓÐĿ¼ºÍÎļþls -a Éó²éÄ¿½ñĿ¼ÏµÄËùÓÐĿ¼ºÍÎļþ£¨°üÀ¨Òþ²ØµÄÎļþ£©ls -l »ò ll ÁбíÉó²éÄ¿½ñĿ¼ÏµÄËùÓÐĿ¼ºÍÎļþ£¨ÁбíÉó²é £¬ÏÔʾ¸ü¶àÐÅÏ¢£©ls /dir Éó²éÖ¸¶¨Ä¿Â¼ÏµÄËùÓÐĿ¼ºÍÎļþ È磺ls /usr

½«¼ÒĿ¼ÏµÄËùÓÐÎļþÁгöÀ´(º¬ÊôÐÔÓëÒþ²Øµµ)

ls -al ~

µÇ¼ºó¸´ÖÆ

2.3 Ŀ¼²Ù×÷¡¾Ôö £¬É¾ £¬¸Ä £¬²é¡¿

2.3.1 ½¨ÉèĿ¼¡¾Ôö¡¿ mkdir

ÈôÊÇÏëÒª½¨ÉèеÄĿ¼µÄ»° £¬ÄÇô¾ÍʹÓÃmkdir (make directory)°É¡£

Óï·¨£º

mkdir [-mp] Ŀ¼Ãû³Æ

µÇ¼ºó¸´ÖÆ

Ñ¡ÏîÓë²ÎÊý£º

-m £ºÉèÖÃÎļþµÄȨÏÞร¡Ö±½ÓÉèÖà £¬²»ÐèÒª¿´Ä¬ÈÏȨÏÞ (umask) µÄÉñÉ«¡«

-p £º×ÊÖúÄãÖ±½Ó½«ËùÐèÒªµÄĿ¼(°üÀ¨ÉÏÒ»¼¶Ä¿Â¼)µÝ¹é½¨ÉèÆðÀ´£¡

ʵÀý£ºÇëµ½/tmpµ×ÏÂʵÑ齨ÉèÊý¸öÐÂĿ¼¿´¿´£º

cd /tmp[root@www tmp] mkdir test    <==½¨ÉèÒ»ÃûΪ test µÄÐÂĿ¼[root@www tmp] mkdir test1/test2/test3/test4mkdir: cannot create directory `test1/test2/test3/test4': No such file or directory       <== û²½·¥Ö±½Ó½¨Éè´ËĿ¼°¡£¡[root@www tmp] mkdir -p test1/test2/test3/test4

µÇ¼ºó¸´ÖÆ

¼ÓÁËÕâ¸ö -p µÄÑ¡Ïî £¬¿ÉÒÔ×ÔÐаïÄ㽨Éè¶à²ãĿ¼£¡

ʵÀý£º½¨ÉèȨÏÞΪ rwx¨Cx¡ªx µÄĿ¼¡£

[root@www tmp] mkdir -m 711 test2[root@www tmp] ls -ldrwxr-xr-x  3 root  root 4096 Jul 18 12:50 testdrwxr-xr-x  3 root  root 4096 Jul 18 12:53 test1drwx--x--x  2 root  root 4096 Jul 18 12:54 test2

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄȨÏÞ²¿·Ö £¬ÈôÊÇûÓмÓÉÏ -m À´Ç¿ÖÆÉèÖÃÊôÐÔ £¬ÏµÍ³»áʹÓÃĬÈÏÊôÐÔ¡£

ÈôÊÇÎÒÃÇʹÓà -m  £¬ÈçÉÏÀýÎÒÃǸøÓè -m 711 À´¸øÓèеÄĿ¼ drwx¨Cx¡ªx µÄȨÏÞ¡£

2.3.2 ɾ³ýĿ¼»òÎļþ¡¾É¾¡¿rm

 rm [-fir] Îļþ»òĿ¼

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

Ñ¡ÏîÓë²ÎÊý£º

-f £º¾ÍÊÇ force µÄÒâ˼ £¬ºöÂÔ²»±£´æµÄÎļþ £¬²»»á·ºÆðÖÒÑÔÐÅÏ¢£»

-i £º»¥¶¯Ä£Ê½ £¬ÔÚɾ³ýÇ°»áѯÎÊʹÓÃÕßÊÇ·ñÐж¯

-r £ºµÝ¹éɾ³ý°¡£¡×î³£ÓÃÔÚĿ¼µÄɾ³ýÁË£¡ÕâÊǺÜÊÇΣÏÕµÄÑ¡Ï£¡£¡

ɾ³ýÎļþ£ºrm Îļþ ɾ³ýÄ¿½ñĿ¼ÏµÄÎļþrm -f Îļþ ɾ³ýÄ¿½ñĿ¼µÄµÄÎļþ£¨²»Ñ¯ÎÊ£©

ɾ³ýĿ¼£ºrm -r aaa µÝ¹éɾ³ýÄ¿½ñĿ¼ÏµÄaaaĿ¼rm -rf aaa µÝ¹éɾ³ýÄ¿½ñĿ¼ÏµÄaaaĿ¼£¨²»Ñ¯ÎÊ£©

ËùÓÐɾ³ý£ºrm -rf ½«Ä¿½ñĿ¼ÏµÄËùÓÐĿ¼ºÍÎļþËùÓÐɾ³ýrm -rf / ¡¾É÷Óã¡É÷Óã¡É÷Óã¡¡¿½«¸ùĿ¼ÏµÄËùÓÐÎļþËùÓÐɾ³ý

×¢ÖØ£ºrm²»µ«¿ÉÒÔɾ³ýĿ¼ £¬Ò²¿ÉÒÔɾ³ýÆäËûÎļþ»òѹËõ°ü £¬ÎªÁËÀû±ã¸÷È˵ÄÓ°Ïó £¬ÎÞÂÛɾ³ýÈκÎĿ¼»òÎļþ £¬¶¼Ö±½ÓʹÓà rm -rf Ŀ¼/Îļþ/ѹËõ°ü

rmdir (ɾ³ý¿ÕµÄĿ¼)

Óï·¨£º

 rmdir [-p] Ŀ¼Ãû³Æ

µÇ¼ºó¸´ÖÆ

Ñ¡ÏîÓë²ÎÊý£º

-p £ºÁ¬Í¬ÉÏÒ»¼¶¡º¿ÕµÄ¡»Ä¿Â¼Ò²Ò»Æðɾ³ý

ɾ³ý runoob Ŀ¼

[root@www tmp] rmdir runoob

µÇ¼ºó¸´ÖÆ

½« mkdir ʵÀýÖн¨ÉèµÄĿ¼(/tmp µ×ÏÂ)ɾ³ýµô£¡

[root@www tmp] ls -l   <==¿´¿´Óм¸¶àĿ¼±£´æ£¿drwxr-xr-x  3 root  root 4096 Jul 18 12:50 testdrwxr-xr-x  3 root  root 4096 Jul 18 12:53 test1drwx--x--x  2 root  root 4096 Jul 18 12:54 test2[root@www tmp] rmdir test   <==¿ÉÖ±½Óɾ³ýµô£¬Ã»ÎÊÌâ[root@www tmp] rmdir test1  <==ÓÉÓÚÉÐÓÐÄÚÈÝ£¬ÒÔÊÇÎÞ·¨É¾³ý£¡rmdir: `test1': Directory not empty[root@www tmp] rmdir -p test1/test2/test3/test4[root@www tmp] ls -l        <==Äú¿´¿´£¬µ×ϵÄÊä³öÖÐtestÓëtest1²»¼ûÁË£¡drwx--x--x  2 root  root 4096 Jul 18 12:54 test2

µÇ¼ºó¸´ÖÆ

ʹÓà -p Õâ¸öÑ¡Ïî £¬Á¬Ã¦¾Í¿ÉÒÔ½« test1/test2/test3/test4 Ò»´Îɾ³ý¡£

²»¹ýҪעÖصÄÊÇ £¬Õâ¸ö rmdir ½öÄÜɾ³ý¿ÕµÄĿ¼ £¬Äã¿ÉÒÔʹÓà rm ÏÂÁîÀ´É¾³ý·Ç¿ÕĿ¼¡£

2.3.3 Ŀ¼Ð޸ġ¾¸Ä¡¿mv ºÍ cp

mv (Òƶ¯ÎļþÓëĿ¼ £¬»òÐÞ¸üÃû³Æ)

Óï·¨£º

[root@www ~] mv [-fiu] source destination[root@www ~] mv [options] source1 source2 source3 .... directory

µÇ¼ºó¸´ÖÆ

Ñ¡ÏîÓë²ÎÊý£º

-f £ºforce Ç¿ÖƵÄÒâ˼ £¬ÈôÊÇÄ¿µÄÎļþÒѾ­±£´æ £¬²»»áѯÎʶøÖ±½ÓÁýÕÖ£»

-i £ºÈôÄ¿µÄÎļþ (destination) ÒѾ­±£´æʱ £¬¾Í»áѯÎÊÊÇ·ñÁýÕÖ£¡

-u £ºÈôÄ¿µÄÎļþÒѾ­±£´æ £¬ÇÒ source ½ÏÁ¿Ð £¬²Å»áÉý¼¶ (update)

cp (¸´ÖÆÎļþ»òĿ¼)

cp ¼´¿½±´ÎļþºÍĿ¼¡£

Óï·¨:

[root@www ~] cp [-adfilprsu] ȪԴµµ(source) Ä¿µÄµµ(destination)[root@www ~] cp [options] source1 source2 source3 .... directory

µÇ¼ºó¸´ÖÆ

Ñ¡ÏîÓë²ÎÊý£º

-a£ºÏàµ±ì¶ -pdr µÄÒâ˼ £¬ÖÁì¶ pdr Çë²Î¿¼ÏÂÁÐ˵Ã÷£»(³£ÓÃ)

-d£ºÈôȪԴµµÎªÁ¬½áµµµÄÊôÐÔ(link file) £¬Ôò¸´ÖÆÁ¬½áµµÊôÐÔ¶ø·ÇÎļþ×Ô¼º£»

-f£ºÎªÇ¿ÖÆ(force)µÄÒâ˼ £¬ÈôÄ¿µÄÎļþÒѾ­±£´æÇÒÎÞ·¨¿ªÆô £¬ÔòÒƳýºóÔÙʵÑéÒ»´Î£»

-i£ºÈôÄ¿µÄµµ(destination)ÒѾ­±£´æʱ £¬ÔÚÁýÕÖʱ»áÏÈѯÎÊÐж¯µÄ¾ÙÐÐ(³£ÓÃ)

-l£º¾ÙÐÐӲʽÁ¬½á(hard link)µÄÁ¬½áµµ½¨Éè £¬¶ø·Ç¸´ÖÆÎļþ×Ô¼º£»

-p£ºÁ¬Í¬ÎļþµÄÊôÐÔÒ»Æð¸´ÖÆÒÑÍù £¬¶ø·ÇʹÓÃĬÈÏÊôÐÔ(±¸·Ý³£ÓÃ)£»

-r£ºµÝ¹éÒ»Á¬¸´ÖÆ £¬ÓÃì¶Ä¿Â¼µÄ¸´ÖÆÐÐΪ£»(³£ÓÃ)

-s£º¸´ÖƳÉΪ·ûºÅÁ¬½áµµ (symbolic link) £¬Ò༴¡º½Ý¾¶¡»Îļþ£»

-u£ºÈô destination ±È source ¾É²ÅÉý¼¶ destination £¡

Ò»¡¢ÖØÃüÃûĿ¼ÏÂÁmv Ä¿½ñĿ¼ ÐÂĿ¼ÀýÈ磺mv aaa bbb ½«Ä¿Â¼aaa¸ÄΪbbb×¢ÖØ£ºmvµÄÓï·¨²»µ«¿ÉÒÔ¶ÔĿ¼¾ÙÐÐÖØÃüÃû²¢ÇÒÒ²¿ÉÒÔ¶ÔÖÖÖÖÎļþ £¬Ñ¹Ëõ°üµÈ¾ÙÐÐ ÖØÃüÃûµÄ²Ù×÷

¶þ¡¢¼ôÇÐĿ¼ÏÂÁmv Ŀ¼Ãû³Æ Ŀ¼µÄÐÂλÖÃʾÀý£º½«/usr/tmpĿ¼ÏµÄaaaĿ¼¼ôÇе½ /usrĿ¼ÏÂÃæ mv /usr/tmp/aaa /usr×¢ÖØ£ºmvÓï·¨²»µ«¿ÉÒÔ¶ÔĿ¼¾ÙÐмôÇвÙ×÷ £¬¶ÔÎļþºÍѹËõ°üµÈ¶¼¿ÉÖ´ÐмôÇвÙ×÷

Èý¡¢¿½±´Ä¿Â¼ÏÂÁcp -r Ŀ¼Ãû³Æ Ŀ¼¿½±´µÄÄ¿µÄλÖà -r´ú±íµÝ¹éʾÀý£º½«/usr/tmpĿ¼ÏµÄaaaĿ¼¸´ÖƵ½ /usrĿ¼ÏÂÃæ cp /usr/tmp/aaa /usr×¢ÖØ£ºcpÏÂÁî²»µ«¿ÉÒÔ¿½±´Ä¿Â¼»¹¿ÉÒÔ¿½±´Îļþ £¬Ñ¹Ëõ°üµÈ £¬¿½±´ÎļþºÍѹËõ°üʱ²» ÓÃд-rµÝ¹é

2.3.4 ËÑË÷Ŀ¼¡¾²é¡¿find

Linux find ÏÂÁîÓÃÀ´ÔÚÖ¸¶¨Ä¿Â¼Ï²éÕÒÎļþ¡£ÈκÎλÓÚ²ÎÊý֮ǰµÄ×Ö·û´®¶¼½«±»ÊÓΪÓû²éÕÒµÄĿ¼Ãû¡£ÈôÊÇʹÓøÃÏÂÁîʱ £¬²»ÉèÖÃÈκβÎÊý £¬Ôò find ÏÂÁÔÚÄ¿½ñĿ¼Ï²éÕÒ×ÓĿ¼ÓëÎļþ¡£²¢ÇÒ½«²éÕÒµ½µÄ×ÓĿ¼ºÍÎļþËùÓоÙÐÐÏÔʾ¡£

find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} ;

µÇ¼ºó¸´ÖÆ

ÏÂÁfind Ŀ¼ ²ÎÊý ÎļþÃû³Æ

²¿·Ö²ÎÊý£º

find ƾ֤ÏÂÁйæÔòÅÐ¶Ï path ºÍ expression £¬ÔÚÏÂÁîÁÐÉϵÚÒ»¸ö – ( ) , ! ֮ǰµÄ²¿·ÝΪ path £¬Ö®ºóµÄÊÇ expression¡£ÈôÊÇ path ÊÇ¿Õ×Ö´®ÔòʹÓÃÏÖÔÚ·¾¶ £¬ÈôÊÇ expression ÊÇ¿Õ×Ö´®ÔòʹÓà -print ΪԤÉè expression¡£

expression ÖпÉʹÓõÄÑ¡ÏîÓжþÈýÊ®¸öÖ®¶à £¬ÔÚ´ËÖ»ÏÈÈÝ×î³£ÓõIJ¿·Ý¡£

-mount, -xdev : Ö»¼ì²éºÍÖ¸¶¨Ä¿Â¼ÔÚͳһ¸öÎļþϵͳϵÄÎļþ £¬×èÖ¹ÁгöÆäËüÎļþϵͳÖеÄÎļþ

-amin n : ÔÚÒÑÍù n ·ÖÖÓÄÚ±»¶ÁÈ¡¹ý

-anewer file : ±ÈÎļþ file ¸üÍí±»¶ÁÈ¡¹ýµÄÎļþ

-atime n : ÔÚÒÑÍùnÌìÄÚ±»¶ÁÈ¡¹ýµÄÎļþ

-cmin n : ÔÚÒÑÍù n ·ÖÖÓÄÚ±»ÐÞ»Ú¸Ä

-cnewer file :±ÈÎļþ file ¸üеÄÎļþ

-ctime n : ÔÚÒÑÍùnÌìÄÚ±»Ð޻ڸĵÄÎļþ

ʵÀý

½«ÏÖÔÚĿ¼¼°Æä×ÓĿ¼ÏÂËùÓÐÑÓÉìµµÃûÊÇ c µÄÎļþÁгöÀ´¡£

find . -name "*.c"

µÇ¼ºó¸´ÖÆ

½«ÏÖÔÚĿ¼ÆäÆäÏÂ×ÓĿ¼ÖÐËùÓÐÒ»Ñùƽ³£ÎļþÁгö

find . -type f

µÇ¼ºó¸´ÖÆ

½«ÏÖÔÚĿ¼¼°Æä×ÓĿ¼ÏÂËùÓÐ×î½ü 20 ÌìÄÚ¸üйýµÄÎļþÁгö

find . -ctime -20

µÇ¼ºó¸´ÖÆ

2.4 Ä¿½ñĿ¼ÏÔʾ pwd

pwd (ÏÔʾÏÖÔÚËùÔÚµÄĿ¼)

pwd ÊÇ Print Working Directory µÄËõд £¬Ò²¾ÍÊÇÏÔʾÏÖÔÚËùÔÚĿ¼µÄÏÂÁî¡£

[root@www ~] pwd [-P]

µÇ¼ºó¸´ÖÆ

Ñ¡ÏîÓë²ÎÊý£º

-P £ºÏÔʾ³öȷʵµÄ·¾¶ £¬¶ø·ÇʹÓÃÁ¬½á (link) ·¾¶¡£

ʵÀý£º´¿´âÏÔʾ³ÊÏÖÔÚµÄÊÂÇéĿ¼£º

[root@www ~] pwd/root   <== ÏÔʾ³öĿ¼À²¡«

µÇ¼ºó¸´ÖÆ

ʵÀýÏÔʾ³ÊÏÖʵµÄÊÂÇéĿ¼ £¬¶ø·ÇÁ¬½áµµ×Ô¼ºµÄĿ¼Ãû°ÕÁË¡£

[root@www ~] cd /var/mail   <==×¢ÖØ£¬/var/mailÊÇÒ»¸öÁ¬½áµµ[root@www mail] pwd/var/mail         <==ÁгÊÏÖÔÚµÄÊÂÇéĿ¼[root@www mail] pwd -P/var/spool/mail   <==Ôõô»ØÊ£¿ÓÐûÓÐ¼Ó -P ²îÐí¶à¡«[root@www mail] ls -ld /var/maillrwxrwxrwx 1 root root 10 Sep  4 17:54 /var/mail -> spool/mail# ¿´µ½ÕâÀïÓ¦¸ÃÖªµÀΪɶÁË°É£¿ÓÉÓÚ /var/mail ÊÇÁ¬½áµµ£¬Á¬½áµ½ /var/spool/mail # ÒÔÊÇ£¬¼ÓÉÏ pwd -P µÄÑ¡Ïîºó£¬»á²»ÒÔÁ¬½áµµµÄÊý¾ÝÏÔʾ£¬¶øÊÇÏÔʾ׼ȷµÄÍêÕû·¾¶°¡£¡

µÇ¼ºó¸´ÖÆ

Èý¡¢Îļþ²Ù×÷ÏÂÁî

3.1 Îļþ²Ù×÷¡¾Ôö £¬É¾ £¬¸Ä £¬²é¡¿

3.1.1 н¨Îļþ¡¾Ôö¡¿touch

Linux touchÏÂÁîÓÃÓÚÐÞ¸ÄÎļþ»òÕßĿ¼µÄʱ¼äÊôÐÔ £¬°üÀ¨´æȡʱ¼äºÍ¸ü¸Äʱ¼ä¡£ÈôÎļþ²»±£´æ £¬ÏµÍ³»á½¨ÉèÒ»¸öеÄÎļþ¡£

ls -l ¿ÉÒÔÏÔʾµµ°¸µÄʱ¼ä¼Í¼¡£

Óï·¨

touch [-acfm][-d<ÈÕÆÚʱ¼ä>][-r<²Î¿¼Îļþ»òĿ¼>] [-t<ÈÕÆÚʱ¼ä>][--help][--version][Îļþ»òĿ¼¡­]

µÇ¼ºó¸´ÖÆ

²ÎÊý˵Ã÷£º

a ¸Ä±äµµ°¸µÄ¶Áȡʱ¼ä¼Í¼¡£

m ¸Ä±äµµ°¸µÄÐÞ¸Äʱ¼ä¼Í¼¡£

c ÈôÊÇÄ¿µÄµµ°¸²»±£´æ £¬²»»á½¨Éèеĵµ°¸¡£Óë ¡ªno-create µÄЧ¹ûÒ»Ñù¡£

f ²»Ê¹Óà £¬ÊÇΪÁËÓëÆäËû unix ϵͳµÄÏàÈÝÐÔ¶ø±£´æ¡£

r ʹÓòο¼µµµÄʱ¼ä¼Í¼ £¬Óë ¡ªfile µÄЧ¹ûÒ»Ñù¡£

d Éè׼ʱ¼äÓëÈÕÆÚ £¬¿ÉÒÔʹÓÃÖݪֲî±ðµÄÃûÌá£

t É趨µµ°¸µÄʱ¼ä¼Í¼ £¬ÃûÌÃÓë date Ö¸ÁîÏàͬ¡£

¨Cno-create ²»»á½¨Éèеµ°¸¡£

¨Chelp ÁгöÖ¸ÁîÃûÌá£

¨Cversion ÁгöÊ鼮ѶϢ¡£

ʵÀý

ʹÓÃÖ¸Átouch¡±ÐÞ¸ÄÎļþ¡±testfile¡±µÄʱ¼äÊôÐÔΪĿ½ñϵͳʱ¼ä £¬ÊäÈëÈçÏÂÏÂÁ

$ touch testfile                #ÐÞ¸ÄÎļþµÄʱ¼äÊôÐÔ

µÇ¼ºó¸´ÖÆ

Ê×ÏÈ £¬Ê¹ÓÃlsÏÂÁîÉó²étestfileÎļþµÄÊôÐÔ £¬ÈçÏÂËùʾ£º

$ ls -l testfile                #Éó²éÎļþµÄʱ¼äÊôÐÔ  #Ô­À´ÎļþµÄÐÞ¸Äʱ¼äΪ16:09  -rw-r--r-- 1 hdd hdd 55 2011-08-22 16:09 testfile

µÇ¼ºó¸´ÖÆ

Ö´ÐÐÖ¸Átouch¡±ÐÞ¸ÄÎļþÊôÐÔÒÔºó £¬²¢ÔÙ´ÎÉó²é¸ÃÎļþµÄʱ¼äÊôÐÔ £¬ÈçÏÂËùʾ£º

$ touch testfile                #ÐÞ¸ÄÎļþʱ¼äÊôÐÔΪĿ½ñϵͳʱ¼ä  $ ls -l testfile                #Éó²éÎļþµÄʱ¼äÊôÐÔ  #Ð޸ĺóÎļþµÄʱ¼äÊôÐÔΪĿ½ñϵͳʱ¼ä  -rw-r--r-- 1 hdd hdd 55 2011-08-22 19:53 testfile

µÇ¼ºó¸´ÖÆ

ʹÓÃÖ¸Átouch¡±Ê± £¬ÈôÊÇÖ¸¶¨µÄÎļþ²»±£´æ £¬Ôò½«½¨ÉèÒ»¸öеĿÕȱÎļþ¡£ÀýÈç £¬ÔÚÄ¿½ñĿ¼Ï £¬Ê¹ÓøÃÖ¸ÁÉèÒ»¸ö¿ÕȱÎļþ¡±file¡± £¬ÊäÈëÈçÏÂÏÂÁ

$ touch file            #½¨ÉèÒ»¸öÃûΪ¡°file¡±µÄеĿÕȱÎļþ

µÇ¼ºó¸´ÖÆ

3.1.2 ɾ³ýÎļþ ¡¾É¾¡¿ rm

rm (ÒƳýÎļþ»òĿ¼)

Óï·¨£º

 rm [-fir] Îļþ»òĿ¼

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

Ñ¡ÏîÓë²ÎÊý£º

-f £º¾ÍÊÇ force µÄÒâ˼ £¬ºöÂÔ²»±£´æµÄÎļþ £¬²»»á·ºÆðÖÒÑÔÐÅÏ¢£»

-i £º»¥¶¯Ä£Ê½ £¬ÔÚɾ³ýÇ°»áѯÎÊʹÓÃÕßÊÇ·ñÐж¯

-r £ºµÝ¹éɾ³ý°¡£¡×î³£ÓÃÔÚĿ¼µÄɾ³ýÁË£¡ÕâÊǺÜÊÇΣÏÕµÄÑ¡Ï£¡£¡

½«½¨ÉèµÄ bashrc ɾ³ýµô£¡

[root@www tmp]# rm -i bashrcrm: remove regular file `bashrc'? y

µÇ¼ºó¸´ÖÆ

ÈôÊǼÓÉÏ -i µÄÑ¡Ïî¾Í»á×Ô¶¯Ñ¯ÎÊภ£¬×èÖ¹Äãɾ³ýµ½¹ýʧµÄµµÃû£¡

3.1.3 ÐÞ¸ÄÎļþ¡¾¸Ä¡¿ vi»òvim

ÏÈÀ´¸övim¼üÅÌͼ£¡

vi/vim µÄʹÓÃ

»ù±¾ÉÏ vi/vim ¹²·ÖΪÈýÖÖģʽ £¬»®·ÖÊÇÏÂÁîģʽ£¨Command mode£© £¬ÊäÈëģʽ£¨Insert mode£©ºÍ µ×ÏßÏÂÁîģʽ£¨Last line mode£©¡£ÕâÈýÖÖģʽµÄ×÷Óû®·ÖÊÇ£º

3.1.3.1 ÏÂÁîģʽ£º

Óû§¸Õ¸ÕÆô¶¯ vi/vim £¬±ã½øÈëÁËÏÂÁîģʽ¡£

´Ë״̬ÏÂÇû÷¼üÅÌÐж¯»á±»Vimʶ±ðΪÏÂÁî £¬¶ø·ÇÊäÈë×Ö·û¡£ºÃ±ÈÎÒÃÇ´Ëʱ°´ÏÂi £¬²¢²»»áÊäÈëÒ»¸ö×Ö·û £¬i±»¿´³ÉÁËÒ»¸öÏÂÁî¡£

ÒÔÏÂÊdz£Óõļ¸¸öÏÂÁ

i Çл»µ½ÊäÈëģʽ £¬ÒÔÊäÈë×Ö·û¡£

x ɾ³ýÄ¿½ñ¹â±êËùÔÚ´¦µÄ×Ö·û¡£

: Çл»¾¿¾¹ÏßÏÂÁîģʽ £¬ÒÔÔÚ×îµ×Ò»ÐÐÊäÈëÏÂÁî¡£

ÈôÏëÒª±à¼­Îı¾£ºÆô¶¯Vim £¬½øÈëÁËÏÂÁîģʽ £¬°´ÏÂi £¬Çл»µ½ÊäÈëģʽ¡£

ÏÂÁîģʽֻÓÐһЩ×î»ù±¾µÄÏÂÁî £¬Òò´ËÈÔÒªÒÀÀµµ×ÏßÏÂÁîģʽÊäÈë¸ü¶àÏÂÁî¡£

3.1.3.2 ÊäÈëģʽ

ÔÚÏÂÁîģʽÏ°´ÏÂi¾Í½øÈëÁËÊäÈëģʽ¡£

ÔÚÊäÈëģʽÖÐ £¬¿ÉÒÔʹÓÃÒÔÏ°´¼ü£º

×Ö·û°´¼üÒÔ¼°Shift×éºÏ £¬ÊäÈë×Ö·û

ENTER £¬»Ø³µ¼ü £¬»»ÐÐ

BACK SPACE £¬Í˸ñ¼ü £¬É¾³ý¹â±êÇ°Ò»¸ö×Ö·û

DEL £¬É¾³ý¼ü £¬É¾³ý¹â±êºóÒ»¸ö×Ö·û

Æ«Ïò¼ü £¬ÔÚÎı¾ÖÐÒƶ¯¹â±ê

HOME/END £¬Òƶ¯¹â±êµ½ÐÐÊ×/ÐÐβ

Page Up/Page Down £¬ÉÏ/Ï·­Ò³

Insert £¬Çл»¹â±êΪÊäÈë/Ì滻ģʽ £¬¹â±ê½«Äð³ÉÊúÏß/Ï»®Ïß

ESC £¬Í˳öÊäÈëģʽ £¬Çл»µ½ÏÂÁîģʽ

3.1.3.4 µ×ÏßÏÂÁîģʽ

ÔÚÏÂÁîģʽÏ°´ÏÂ:£¨Ó¢ÎÄðºÅ£©¾Í½øÈëÁ˵×ÏßÏÂÁîģʽ¡£

µ×ÏßÏÂÁîģʽ¿ÉÒÔÊäÈëµ¥¸ö»ò¶à¸ö×Ö·ûµÄÏÂÁî £¬¿ÉÓõÄÏÂÁîºÜÊǶà¡£

ÔÚµ×ÏßÏÂÁîģʽÖÐ £¬»ù±¾µÄÏÂÁîÓУ¨ÒѾ­Ê¡ÂÔÁËðºÅ£©£º

q Í˳ö³ÌÐò

w ÉúÑÄÎļþ

°´ESC¼ü¿ÉËæʱÍ˳öµ×ÏßÏÂÁîģʽ¡£

¼òÆÓµÄ˵ £¬ÎÒÃÇ¿ÉÒÔ½«ÕâÈý¸öģʽÏë³Éµ×ϵÄͼ±êÀ´ÌåÏÖ£º

LinuxÏÂÁî´óÈ«

·­¿ªÎļþ

ÏÂÁvi ÎļþÃûʾÀý£º·­¿ªÄ¿½ñĿ¼ÏµÄaa.txtÎļþ vi aa.txt »òÕß vim aa.txt

×¢ÖØ£ºÊ¹ÓÃvi±à¼­Æ÷·­¿ªÎļþºó £¬²¢²»¿É±à¼­ £¬ÓÉÓÚ´Ëʱ´¦ÓÚÏÂÁîģʽ £¬µã»÷¼üÅÌi/a/o½øÈë±à¼­Ä£Ê½¡£

±à¼­Îļþ

ʹÓÃvi±à¼­Æ÷·­¿ªÎļþºóµã»÷°´¼ü£ºi  £¬a»òÕßo¼´¿É½øÈë±à¼­Ä£Ê½¡£

i:ÔÚ¹â±êËùÔÚ×Ö·ûÇ°×îÏȲåÈëa:ÔÚ¹â±êËùÔÚ×Ö·ûºó×îÏȲåÈëo:ÔÚ¹â±êËùÔÚÐеÄÏÂÃæÁíÆðÒ»ÐÂÐвåÈë

LinuxÏÂÁî´óÈ«

ÉúÑÄ»òÕß×÷·Ï±à¼­

ÉúÑÄÎļþ£º

µÚÒ»²½£ºESC ½øÈëÏÂÁîÐÐģʽµÚ¶þ²½£º: ½øÈëµ×ÐÐģʽµÚÈý²½£ºwq ÉúÑIJ¢Í˳ö±à¼­

×÷·Ï±à¼­£º

µÚÒ»²½£ºESC ½øÈëÏÂÁîÐÐģʽµÚ¶þ²½£º: ½øÈëµ×ÐÐģʽµÚÈý²½£ºq! ×÷·Ï±¾´ÎÐ޸IJ¢Í˳ö±à¼­

3.1.4 ÎļþµÄÉó²é¡¾²é¡¿

LinuxϵͳÖÐʹÓÃÒÔÏÂÏÂÁîÀ´Éó²éÎļþµÄÄÚÈÝ£º

cat ÓɵÚÒ»ÐÐ×îÏÈÏÔʾÎļþÄÚÈÝ

tac ´Ó×îºóÒ»ÐÐ×îÏÈÏÔʾ £¬¿ÉÒÔ¿´³ö tac ÊÇ cat µÄµ¹×Åд£¡

nl ÏÔʾµÄʱ¼ä £¬Ë³Â·Êä³öÐкţ¡

more Ò»Ò³Ò»Ò³µÄÏÔʾÎļþÄÚÈÝ

less Óë more ÀàËÆ £¬¿ÉÊÇ±È more ¸üºÃµÄÊÇ £¬Ëû¿ÉÒÔÍùÇ°·­Ò³£¡

head Ö»¿´Í·¼¸ÐÐ

tail Ö»¿´Î²°Í¼¸ÐÐ

Äã¿ÉÒÔʹÓà man [ÏÂÁî]À´Éó²é¸÷¸öÏÂÁîµÄʹÓÃÎĵµ £¬Èç £ºman cp¡£

3.1.4.1 cat

ÓɵÚÒ»ÐÐ×îÏÈÏÔʾÎļþÄÚÈÝ

Óï·¨£º

cat [-AbEnTv]

µÇ¼ºó¸´ÖÆ

Ñ¡ÏîÓë²ÎÊý£º

-A £ºÏàµ±ì¶ -vET µÄÕûºÏÑ¡Ïî £¬¿ÉÁгöһЩÌØÊâ×Ö·û¶ø²»ÊÇ¿Õȱ°ÕÁË£»

-b £ºÁгöÐкÅ £¬½öÕë¶Ô·Ç¿ÕȱÐÐ×öÐкÅÏÔʾ £¬¿ÕȱÐв»±êÐкţ¡

-E £º½«×îºóµÄ¶ÏÐÐ×Ö½Ú $ ÏÔʾ³öÀ´£»

-n £ºÁÐÓ¡³öÐкÅ £¬Á¬Í¬¿ÕȱÐÐÒ²»áÓÐÐкÅ £¬Óë -b µÄÑ¡Ïî²î±ð£»

-T £º½« [tab] °´¼üÒÔ ^I ÏÔʾ³öÀ´£»

-v £ºÁгöһЩ¿´²»³öÀ´µÄÌØÊâ×Ö·û

¼ì¿´ /etc/issue Õâ¸öÎļþµÄÄÚÈÝ£º

[root@www ~] cat /etc/issueCentOS release 6.4 (Final)Kernel r on an m

µÇ¼ºó¸´ÖÆ

3.1.3.2 tac

tacÓëcatÏÂÁîÇ¡Ç¡Ïà·´ £¬ÎļþÄÚÈÝ´Ó×îºóÒ»ÐÐ×îÏÈÏÔʾ £¬¿ÉÒÔ¿´³ö tac ÊÇ cat µÄµ¹×Åд£¡È磺

[root@www ~] tac /etc/issueKernel r on an mCentOS release 6.4 (Final)

µÇ¼ºó¸´ÖÆ

3.1.3.3 nl

ÏÔʾÐкÅ

Óï·¨£º

nl [-bnw] Îļþ

µÇ¼ºó¸´ÖÆ

Ñ¡ÏîÓë²ÎÊý£º

-b £ºÖ¸¶¨ÐкÅÖ¸¶¨µÄ·½·¨ £¬Ö÷ÒªÓÐÁ½ÖÖ£º-b a £ºÌåÏÖÆñÂÛÊÇ·ñΪ¿ÕÐÐ £¬Ò²Í¬ÑùÁгöÐкÅ(ÀàËÆ cat -n)£»-b t £ºÈôÊÇÓпÕÐÐ £¬¿ÕµÄÄÇÒ»Ðв»ÒªÁгöÐкÅ(ĬÈÏÖµ)£»

-n £ºÁгöÐкÅÌåÏÖµÄÒªÁì £¬Ö÷ÒªÓÐÈýÖÖ£º-n ln £ºÐкÅÔÚÓ«Ä»µÄ×î×ó·½ÏÔʾ£»-n rn £ºÐкÅÔÚ×Ô¼ºÀ¸Î»µÄ×îÓÒ·½ÏÔʾ £¬ÇÒ²»¼Ó 0 £»-n rz £ºÐкÅÔÚ×Ô¼ºÀ¸Î»µÄ×îÓÒ·½ÏÔʾ £¬ÇÒ¼Ó 0 £»

-w £ºÐкÅÀ¸Î»µÄÕ¼ÓõÄλÊý¡£

ʵÀýÒ»£ºÓà nl Áгö /etc/issue µÄÄÚÈÝ

Å£±Æ°¡£¡½Ó˽»î±Ø±¸µÄ N ¸ö¿ªÔ´ÏîÄ¿£¡¸ÏæÕä²Ø°É

µÇ¼ºó¸´ÖÆ

[root@www ~] nl /etc/issue     1  CentOS release 6.4 (Final)     2  Kernel r on an m123

µÇ¼ºó¸´ÖÆ

3.1.3.5 more

Ò»Ò³Ò»Ò³·­¶¯

[root@www ~] more /etc/man_db.config ## Generated automatically from man.conf.in by the# configure script.## man.conf from man-1.6d....(ÖÐÐÄÊ¡ÂÔ)....--More--(28%)  <== ÖصãÔÚÕâÒ»ÐÐร¡ÄãµÄ¹â±êÒ²»áÔÚÕâÀïÆÚ´ýÄãµÄÏÂÁî

µÇ¼ºó¸´ÖÆ

ÔÚ more Õâ¸ö³ÌÐòµÄÔËÐÐÀú³ÌÖÐ £¬ÄãÓм¸¸ö°´¼ü¿ÉÒÔ°´µÄ£º

¿Õȱ¼ü (space)£º´ú±íÏòÏ·­Ò»Ò³£»

Enter £º´ú±íÏòÏ·­¡ºÒ»ÐС»£»

/×Ö´® £º´ú±íÔÚÕâ¸öÏÔʾµÄÄÚÈݵ±ÖÐ £¬ÏòÏÂÕ÷²É¡º×Ö´®¡»Õâ¸öÒªº¦×Ö£»

:f £ºÁ¬Ã¦ÏÔʾ³öµµÃûÒÔ¼°ÏÖÔÚÏÔʾµÄÐÐÊý£»

q £º´ú±íÁ¬Ã¦ÍÑÀë more  £¬²»ÔÙÏÔʾ¸ÃÎļþÄÚÈÝ¡£

b »ò [ctrl]-b £º´ú±íÍù»Ø·­Ò³ £¬²»¹ýÕâÐж¯Ö»¶ÔÎļþÓÐÓà £¬¶Ô¹ÜÏßÎÞÓá£

3.1.3.6 less

Ò»Ò³Ò»Ò³·­¶¯ £¬ÒÔÏÂʵÀýÊä³ö/etc/man.configÎļþµÄÄÚÈÝ£º

[root@www ~] less /etc/man.config## Generated automatically from man.conf.in by the# configure script.## man.conf from man-1.6d....(ÖÐÐÄÊ¡ÂÔ)....:   <== ÕâÀï¿ÉÒÔÆÚ´ýÄãÊäÈëÏÂÁ

µÇ¼ºó¸´ÖÆ

lessÔËÐÐʱ¿ÉÒÔÊäÈëµÄÏÂÁîÓУº

¿Õȱ¼ü £ºÏòÏ·­¶¯Ò»Ò³£»

[pagedown]£ºÏòÏ·­¶¯Ò»Ò³£»

[pageup] £ºÏòÉÏ·­¶¯Ò»Ò³£»

/×Ö´® £ºÏòÏÂÕ÷²É¡º×Ö´®¡»µÄ¹¦Ð§£»

?×Ö´® £ºÏòÉÏÕ÷²É¡º×Ö´®¡»µÄ¹¦Ð§£»

n £ºÖظ´Ç°Ò»¸öÕ÷²É (Óë / »ò ? Óйأ¡)

N £º·´ÏòµÄÖظ´Ç°Ò»¸öÕ÷²É (Óë / »ò ? Óйأ¡)

q £ºÍÑÀë less Õâ¸ö³ÌÐò£»

3.1.3.7 head

È¡³öÎļþÇ°Ã漸ÐÐ

Óï·¨£º

head [-n number] Îļþ

µÇ¼ºó¸´ÖÆ

Ñ¡ÏîÓë²ÎÊý£º

-n £ººóÃæ½ÓÊý×Ö £¬´ú±íÏÔʾ¼¸ÐеÄÒâ˼

[root@www ~] head /etc/man.config

µÇ¼ºó¸´ÖÆ

ĬÈϵÄÇéÐÎÖÐ £¬ÏÔʾǰÃæ 10 ÐУ¡ÈôÒªÏÔʾǰ 20 ÐÐ £¬¾ÍµÃÒªÕâÑù£º

[root@www ~] head -n 20 /etc/man.config

µÇ¼ºó¸´ÖÆ

3.1.3.8 tail

È¡³öÎļþºóÃ漸ÐÐ

Óï·¨£º

tail [-n number] Îļþ

µÇ¼ºó¸´ÖÆ

Ñ¡ÏîÓë²ÎÊý£º

-n £ººóÃæ½ÓÊý×Ö £¬´ú±íÏÔʾ¼¸ÐеÄÒâ˼

-f £ºÌåÏÖÒ»Á¬Õì²âºóÃæËù½ÓµÄµµÃû £¬Òª±È¼°°´ÏÂ[ctrl]-c²Å»á¿¢ÊÂtailµÄÕì²â

[root@www ~] tail /etc/man.config# ĬÈϵÄÇéÐÎÖÐ£¬ÏÔʾ×îºóµÄÊ®ÐУ¡ÈôÒªÏÔʾ×îºóµÄ 20 ÐÐ£¬¾ÍµÃÒªÕâÑù£º[root@www ~] tail -n 20 /etc/man.config

µÇ¼ºó¸´ÖÆ

3.2 ȨÏÞÐÞ¸Ä

Linux/Unix µÄÎļþŲÓÃȨÏÞ·ÖΪÈý¼¶ : ÎļþÓµÓÐÕß¡¢Èº×é¡¢ÆäËû¡£Ê¹Óà chmod ¿ÉÒÔ½åÒÔ¿ØÖÆÎļþÔõÑù±»ËûÈËËùŲÓá£

ʹÓÃȨÏÞ : ËùÓÐʹÓÃÕß

Óï·¨

chmod [-cfvR] [--help] [--version] mode file...

µÇ¼ºó¸´ÖÆ

²ÎÊý˵Ã÷

mode : ȨÏÞÉ趨×Ö´® £¬ÃûÌÃÈçÏ :

[ugoa...][[+-=][rwxX]...][,...]

µÇ¼ºó¸´ÖÆ

ÆäÖУº

u ÌåÏÖ¸ÃÎļþµÄÓµÓÐÕß £¬g ÌåÏÖÓë¸ÃÎļþµÄÓµÓÐÕßÊôÓÚͳһ¸öȺÌå(group)Õß £¬o ÌåÏÖÆäËûÒÔÍâµÄÈË £¬a ÌåÏÖÕâÈýÕß½ÔÊÇ¡£

+ ÌåÏÖÔöÌíȨÏÞ¡¢- ÌåÏÖ×÷·ÏȨÏÞ¡¢= ÌåÏÖΨһÉ趨ȨÏÞ¡£

r ÌåÏֿɶÁÈ¡ £¬w ÌåÏÖ¿ÉдÈë £¬x ÌåÏÖ¿ÉÖ´ÐÐ £¬X ÌåÏÖÖ»Óе±¸ÃÎļþÊǸö×ÓĿ¼»òÕ߸ÃÎļþÒѾ­±»É趨¹ýΪ¿ÉÖ´ÐС£

ÆäËû²ÎÊý˵Ã÷£º

-c : Èô¸ÃÎļþȨÏÞȷʵÒѾ­¸ü¸Ä £¬²ÅÏÔʾÆä¸üתҵ¶¯

-f : Èô¸ÃÎļþȨÏÞÎÞ·¨±»¸ü¸ÄÒ²²»ÒªÏÔʾ¹ýʧѶϢ

-v : ÏÔʾȨÏޱ任µÄÏêϸ×ÊÁÏ

-R : ¶ÔÏÖÔÚĿ¼ÏµÄËùÓÐÎļþÓë×ÓĿ¼¾ÙÐÐÏàͬµÄȨÏޱ任(¼´ÒԵݻصķ½·¨Öð¸ö±ä»»)

¨Chelp : ÏÔʾ¸¨Öú˵Ã÷

¨Cversion : ÏÔʾ°æ±¾

ȨÏÞµÄÉ趨ҪÁìÓÐÁ½ÖÖ £¬ »®·Ö¿ÉÒÔʹÓÃÊý×Ö»òÕßÊÇ·ûºÅÀ´¾ÙÐÐȨÏ޵ı任¡£

Êý×ÖÀàÐ͸ı䵵°¸È¨ÏÞ£º

LinuxÏÂÁî´óÈ«

·ûºÅÀàÐ͸ı䵵°¸È¨ÏÞ£º

LinuxÏÂÁî´óÈ«

ËÄ¡¢Ñ¹ËõÎļþ²Ù×÷

Linux ³£ÓõÄѹËõÓë½âѹËõÏÂÁîÓУºtar¡¢gzip¡¢gunzip¡¢bzip2¡¢bunzip2¡¢compress ¡¢uncompress¡¢ zip¡¢ unzip¡¢rar¡¢unrar µÈ¡£

4.1 ´ò°üºÍѹËõÏ¢Õùѹ

WindowsµÄѹËõÎļþµÄÀ©Õ¹Ãû .zip/.rarlinuxÖеĴò°üÎļþ£ºaa.tarlinuxÖеÄѹËõÎļþ£ºbb.gzlinuxÖдò°ü²¢Ñ¹ËõµÄÎļþ£º.tar.gz

LinuxÖеĴò°üÎļþÒ»Ñùƽ³£ÊÇÒÔ.tar×îºóµÄ £¬Ñ¹ËõµÄÏÂÁîÒ»Ñùƽ³£ÊÇÒÔ.gz×îºóµÄ¡£¶øÒ»Ñùƽ³£ÇéÐÎÏ´ò°üºÍѹËõÊÇÒ»Æð¾ÙÐеÄ £¬´ò°ü²¢Ñ¹ËõºóµÄÎļþµÄºó׺ÃûÒ»Ñùƽ³£.tar.gz¡£

4.1.1 tar

×î³£ÓõĴò°üÏÂÁîÊÇ tar £¬Ê¹Óà tar ³ÌÐò´ò³öÀ´µÄ°üÎÒÃdz£³ÆΪ tar °ü £¬tar °üÎļþµÄÏÂÁîͨ³£¶¼ÊÇÒÔ .tar ×îºóµÄ¡£ÌìÉú tar °üºó £¬¾Í¿ÉÒÔÓÃÆäËüµÄ³ÌÐòÀ´¾ÙÐÐѹËõÁË £¬ÒÔÊÇÊ×ÏȾÍÀ´½²½² tar ÏÂÁîµÄ»ù±¾Ó÷¨¡£

tar ÏÂÁîµÄÑ¡ÏîÓÐÐí¶à(Óà man tar ¿ÉÒÔÉó²éµ½) £¬µ«³£ÓõľÍÄÇô¼¸¸öÑ¡Ïî £¬ÏÂÃæÀ´¾ÙÀý˵Ã÷һϣº

 tar -cf all.tar *.jpg

µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽ«ËùÓÐ .jpg µÄÎļþ´ò³ÉÒ»¸öÃûΪ all.tar µÄ°ü¡£-c ÊÇÌåÏÖ±¬·¢Ðµİü £¬-f Ö¸¶¨°üµÄÎļþÃû¡£

 tar -rf all.tar *.gif

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽ«ËùÓÐ .gif µÄÎļþÔöÌíµ½ all.tar µÄ°üÄÚÀïÈ¥ £¬-r ÊÇÌåÏÖÔöÌíÎļþµÄÒâ˼¡£

 tar -uf all.tar logo.gif

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǸüÐÂÔ­À´ tar °ü all.tar ÖÐ logo.gif Îļþ £¬-u ÊÇÌåÏÖ¸üÐÂÎļþµÄÒâ˼¡£

 tar -tf all.tar

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊÇÁгö all.tar °üÖÐËùÓÐÎļþ £¬-t ÊÇÁгöÎļþµÄÒâ˼¡£

 tar -xf all.tar

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽâ³ö all.tar °üÖÐËùÓÐÎļþ £¬-x Êǽ⿪µÄÒâ˼¡£

ÒÔÉϾÍÊÇ tar µÄ×î»ù±¾µÄÓ÷¨¡£ÎªÁËÀû±ãÓû§ÔÚ´ò°ü½â°üµÄͬʱ¿ÉÒÔѹËõ»ò½âѹÎļþ £¬tar ÌṩÁËÒ»ÖÖÌØÊâµÄ¹¦Ð§¡£Õâ¾ÍÊÇ tar ¿ÉÒÔÔÚ´ò°ü»ò½â°üµÄͬʱŲÓÃÆäËüµÄѹËõ³ÌÐò £¬ºÃ±ÈŲÓà gzip¡¢bzip2 µÈ¡£

4.1.1.1 tarŲÓÃ

gzip ÊÇ GNU ×éÖ¯¿ª·¢µÄÒ»¸öѹËõ³ÌÐò £¬.gz ×îºóµÄÎļþ¾ÍÊÇ gzip ѹËõµÄЧ¹û¡£Óë gzip Ïà¶ÔµÄ½âѹ³ÌÐòÊÇ gunzip¡£tar ÖÐʹÓà -z Õâ¸ö²ÎÊýÀ´Å²ÓÃgzip¡£ÏÂÃæÀ´¾ÙÀý˵Ã÷һϣº

 tar -czf all.tar.gz *.jpg

µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽ«ËùÓÐ .jpg µÄÎļþ´ò³ÉÒ»¸ö tar °ü £¬²¢ÇÒ½«ÆäÓà gzip ѹËõ £¬ÌìÉúÒ»¸ö gzip ѹËõ¹ýµÄ°ü £¬°üÃûΪ all.tar.gz¡£

 tar -xzf all.tar.gz

µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽ«ÉÏÃ汬·¢µÄ°ü½â¿ª¡£

4.1.1.2 tar ŲÓà bzip2

bzip2 ÊÇÒ»¸öѹËõÄÜÁ¦¸üÇ¿µÄѹËõ³ÌÐò £¬.bz2 ×îºóµÄÎļþ¾ÍÊÇ bzip2 ѹËõµÄЧ¹û¡£

Óë bzip2 Ïà¶ÔµÄ½âѹ³ÌÐòÊÇ bunzip2¡£tar ÖÐʹÓà -j Õâ¸ö²ÎÊýÀ´Å²Óà gzip¡£ÏÂÃæÀ´¾ÙÀý˵Ã÷һϣº

 tar -cjf all.tar.bz2 *.jpg

µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽ«ËùÓÐ .jpg µÄÎļþ´ò³ÉÒ»¸ö tar °ü £¬²¢ÇÒ½«ÆäÓà bzip2 ѹËõ £¬ÌìÉúÒ»¸ö bzip2 ѹËõ¹ýµÄ°ü £¬°üÃûΪ all.tar.bz2

 tar -xjf all.tar.bz2

µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽ«ÉÏÃ汬·¢µÄ°ü½â¿ª¡£

4.1.1.3 tar ŲÓà compress

compress Ò²ÊÇÒ»¸öѹËõ³ÌÐò £¬¿ÉÊǺÃÏóʹÓà compress µÄÈ˲»Èç gzip ºÍ bzip2 µÄÈ˶à¡£.Z ×îºóµÄÎļþ¾ÍÊÇ bzip2 ѹËõµÄЧ¹û¡£Óë compress Ïà¶ÔµÄ½âѹ³ÌÐòÊÇ uncompress¡£tar ÖÐʹÓà -Z Õâ¸ö²ÎÊýÀ´Å²Óà compress¡£ÏÂÃæÀ´¾ÙÀý˵Ã÷һϣº

 tar -cZf all.tar.Z *.jpg

µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽ«ËùÓÐ .jpg µÄÎļþ´ò³ÉÒ»¸ö tar °ü £¬²¢ÇÒ½«ÆäÓà compress ѹËõ £¬ÌìÉúÒ»¸ö uncompress ѹËõ¹ýµÄ°ü £¬°üÃûΪ all.tar.Z¡£

 tar -xZf all.tar.Z

µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽ«ÉÏÃ汬·¢µÄ°ü½â¿ª¡£

ÓÐÁËÉÏÃæµÄ֪ʶ £¬ÄãÓ¦¸Ã¿ÉÒԽ⿪¶àÖÖѹËõÎļþÁË £¬ÏÂÃæÁÙÓÚ tar ϵÁеÄѹËõÎļþ×÷Ò»¸öС½á£º

1) ¹ØÓÚ.tar×îºóµÄÎļþ

tar -xf all.tar

µÇ¼ºó¸´ÖÆ

2) ¹ØÓÚ .gz ×îºóµÄÎļþ

gzip -d all.gzgunzip all.gz

µÇ¼ºó¸´ÖÆ

3)¹ØÓÚ .tgz »ò .tar.gz ×îºóµÄÎļþ

tar -xzf all.tar.gztar -xzf all.tgz

µÇ¼ºó¸´ÖÆ

4) ¹ØÓÚ .bz2 ×îºóµÄÎļþ

bzip2 -d all.bz2bunzip2 all.bz2

µÇ¼ºó¸´ÖÆ

5) ¹ØÓÚ tar.bz2 ×îºóµÄÎļþ

tar -xjf all.tar.bz2

µÇ¼ºó¸´ÖÆ

6) ¹ØÓÚ .Z ×îºóµÄÎļþ

uncompress all.Z

µÇ¼ºó¸´ÖÆ

7) ¹ØÓÚ .tar.Z ×îºóµÄÎļþ

tar -xZf all.tar.z

µÇ¼ºó¸´ÖÆ

ÁíÍâ¹ØÓÚ Windows ϵij£¼ûѹËõÎļþ .zip ºÍ .rar £¬Linux Ò²ÓÐÏìÓ¦µÄÒªÁìÀ´½âѹËüÃÇ£º

1) ¹ØÓÚ .zip

linux ÏÂÌṩÁË zip ºÍ unzip ³ÌÐò £¬zip ÊÇѹËõ³ÌÐò £¬unzip Êǽâѹ³ÌÐò¡£ËüÃǵIJÎÊýÑ¡ÏîÐí¶à £¬ÕâÀïÖ»×ö¼òÆÓÏÈÈÝ £¬ÒÀ¾É¾ÙÀý˵Ã÷Ò»ÏÂÆäÓ÷¨£º

 zip all.zip *.jpg

µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽ«ËùÓÐ .jpg µÄÎļþѹËõ³ÉÒ»¸ö zip °ü:

 unzip all.zip

µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽ« all.zip ÖеÄËùÓÐÎļþ½âѹ³öÀ´¡£

2) ¹ØÓÚ .rar

ÒªÔÚ linux Ï´¦Àí .rar Îļþ £¬ÐèҪװÖà RAR for Linux¡£ÏÂÔصص㣺http://www.rarsoft.com/download.htm £¬ÏÂÔغó×°Öü´¿É¡£

 tar -xzpvf rarlinux-x64-5.6.b5.tar.gz cd rar  make

µÇ¼ºó¸´ÖÆ

ÕâÑù¾Í×°ÖúÃÁË £¬×°Öúó¾ÍÓÐÁË rar ºÍ unrar ÕâÁ½¸ö³ÌÐò £¬rar ÊÇѹËõ³ÌÐò £¬unrar Êǽâѹ³ÌÐò¡£ËüÃǵIJÎÊýÑ¡ÏîÐí¶à £¬ÕâÀïÖ»×ö¼òÆÓÏÈÈÝ £¬ÒÀ¾É¾ÙÀý˵Ã÷Ò»ÏÂÆäÓ÷¨£º

 rar a all *.jpg

µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽ«ËùÓÐ .jpg µÄÎļþѹËõ³ÉÒ»¸ö rar °ü £¬ÃûΪ all.rar £¬¸Ã³ÌÐò»á½« .rar À©Õ¹Ãû½«×Ô¶¯¸½¼Óµ½°üÃûºó¡£

 unrar e all.rar

µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽ« all.rar ÖеÄËùÓÐÎļþ½âѹ³öÀ´

4.2 À©Õ¹ÄÚÈÝ

tar

-c: ½¨ÉèѹËõµµ°¸ -x£º½âѹ -t£ºÉó²éÄÚÈÝ shell-r£ºÏòѹËõ¹éµµÎļþĩβ׷¼ÓÎļþ -u£º¸üÐÂԭѹËõ°üÖеÄÎļþ

µÇ¼ºó¸´ÖÆ

ÕâÎå¸öÊÇ×ÔÁ¦µÄÏÂÁî £¬Ñ¹Ëõ½âѹ¶¼ÒªÓõ½ÆäÖÐÒ»¸ö £¬¿ÉÒԺͱðµÄÏÂÁîÁ¬Óõ«Ö»ÄÜÓÃÆäÖÐÒ»¸ö¡£ÏÂÃæµÄ²ÎÊýÊÇƾ֤ÐèÒªÔÚѹËõ»ò½âѹµµ°¸Ê±¿ÉÑ¡µÄ¡£

-z£ºÓÐgzipÊôÐ﵀ -j£ºÓÐbz2ÊôÐ﵀ -Z£ºÓÐcompressÊôÐ﵀ -v£ºÏÔʾËùÓÐÀú³Ì -O£º½«Îļþ½â¿ªµ½±ê×¼Êä³ö

µÇ¼ºó¸´ÖÆ

ÏÂÃæµÄ²ÎÊý -f ÊDZØÐèµÄ:

-f: ʹÓõµ°¸Ãû×Ö£¬ÇмÇ£¬Õâ¸ö²ÎÊýÊÇ×îºóÒ»¸ö²ÎÊý£¬ºóÃæÖ»Äܽӵµ°¸Ãû¡£

µÇ¼ºó¸´ÖÆ

# tar -cf all.tar *.jpg

ÕâÌõÏÂÁîÊǽ«ËùÓÐ .jpg µÄÎļþ´ò³ÉÒ»¸öÃûΪ all.tar µÄ°ü¡£-c ÊÇÌåÏÖ±¬·¢Ðµİü £¬-f Ö¸¶¨°üµÄÎļþÃû¡£

 tar -rf all.tar *.gif

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽ«ËùÓÐ .gif µÄÎļþÔöÌíµ½ all.tar µÄ°üÄÚÀïÈ¥¡£-r ÊÇÌåÏÖÔöÌíÎļþµÄÒâ˼¡£

 tar -uf all.tar logo.gif

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǸüÐÂÔ­À´ tar °ü all.tar ÖÐ logo.gif Îļþ £¬-u ÊÇÌåÏÖ¸üÐÂÎļþµÄÒâ˼¡£

 tar -tf all.tar

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊÇÁгö all.tar °üÖÐËùÓÐÎļþ £¬-t ÊÇÁгöÎļþµÄÒâ˼¡£

 tar -xf all.tar

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÕâÌõÏÂÁîÊǽâ³ö all.tar °üÖÐËùÓÐÎļþ £¬-x Êǽ⿪µÄÒâ˼¡£

ѹËõ

tar ¨Ccvf jpg.tar *.jpg       // ½«Ä¿Â¼ÀïËùÓÐjpgÎļþ´ò°ü³É tar.jpg tar ¨Cczf jpg.tar.gz *.jpg    // ½«Ä¿Â¼ÀïËùÓÐjpgÎļþ´ò°ü³É jpg.tar ºó£¬²¢ÇÒ½«ÆäÓà gzip ѹËõ£¬ÌìÉúÒ»¸ö gzip ѹËõ¹ýµÄ°ü£¬ÃüÃûΪ jpg.tar.gz tar ¨Ccjf jpg.tar.bz2 *.jpg   // ½«Ä¿Â¼ÀïËùÓÐjpgÎļþ´ò°ü³É jpg.tar ºó£¬²¢ÇÒ½«ÆäÓà bzip2 ѹËõ£¬ÌìÉúÒ»¸ö bzip2 ѹËõ¹ýµÄ°ü£¬ÃüÃûΪjpg.tar.bz2 tar ¨CcZf jpg.tar.Z *.jpg     // ½«Ä¿Â¼ÀïËùÓÐ jpg Îļþ´ò°ü³É jpg.tar ºó£¬²¢ÇÒ½«ÆäÓà compress ѹËõ£¬ÌìÉúÒ»¸ö umcompress ѹËõ¹ýµÄ°ü£¬ÃüÃûΪjpg.tar.Z rar a jpg.rar *.jpg          // rarÃûÌõÄѹËõ£¬ÐèÒªÏÈÏÂÔØ rar for linux zip jpg.zip *.jpg            // zipÃûÌõÄѹËõ£¬ÐèÒªÏÈÏÂÔØ zip for linux

µÇ¼ºó¸´ÖÆ

½âѹ

tar ¨Cxvf file.tar         // ½âѹ tar °ü tar -xzvf file.tar.gz     // ½âѹ tar.gz tar -xjvf file.tar.bz2    // ½âѹ tar.bz2 tar ¨CxZvf file.tar.Z      // ½âѹ tar.Z unrar e file.rar          // ½âѹ rar unzip file.zip            // ½âѹ zip

µÇ¼ºó¸´ÖÆ

×ܽá

1¡¢*.tar Óà tar ¨Cxvf ½âѹ 2¡¢*.gz Óà gzip -d»òÕßgunzip ½âѹ 3¡¢*.tar.gzºÍ*.tgz Óà tar ¨Cxzf ½âѹ 4¡¢*.bz2 Óà bzip2 -d»òÕßÓÃbunzip2 ½âѹ 5¡¢*.tar.bz2ÓÃtar ¨Cxjf ½âѹ 6¡¢*.Z Óà uncompress ½âѹ 7¡¢*.tar.Z ÓÃtar ¨CxZf ½âѹ 8¡¢*.rar Óà unrar e½âѹ 9¡¢*.zip Óà unzip ½âѹ

µÇ¼ºó¸´ÖÆ

Îå¡¢²éÕÒÏÂÁî

5.1 grep

grepÏÂÁîÊÇÒ»ÖÖÇ¿Ê¢µÄÎı¾ËÑË÷¹¤¾ß

ʹÓÃʵÀý£º

ps -ef | grep sshd  ²éÕÒÖ¸¶¨sshЧÀÍÀú³Ì ps -ef | grep sshd | grep -v grep ²éÕÒÖ¸¶¨Ð§ÀÍÀú³Ì£¬É¨³ýgerpÉí ps -ef | grep sshd -c ²éÕÒÖ¸¶¨Àú³Ì¸öÊý

µÇ¼ºó¸´ÖÆ

´ÓÎļþÄÚÈݲéÕÒÆ¥ÅäÖ¸¶¨×Ö·û´®µÄÐУº

$ grep "±»²éÕÒµÄ×Ö·û´®" ÎļþÃû

µÇ¼ºó¸´ÖÆ

Àý×Ó£ºÔÚÄ¿½ñĿ¼ÀïµÚÒ»¼¶Îļþ¼ÐÖÐÑ°ÕÒ°üÀ¨Ö¸¶¨×Ö·û´®µÄ .in Îļþ

grep "thermcontact" /.in

µÇ¼ºó¸´ÖÆ

´ÓÎļþÄÚÈݲéÕÒÓëÕýÔò±í´ïʽƥÅäµÄÐУº

$ grep ¨Ce "ÕýÔò±í´ïʽ" ÎļþÃû

µÇ¼ºó¸´ÖÆ

²éÕÒʱ²»Çø·Ö¾Þϸд£º

$ grep ¨Ci "±»²éÕÒµÄ×Ö·û´®" ÎļþÃû

µÇ¼ºó¸´ÖÆ

²éÕÒÆ¥ÅäµÄÐÐÊý£º

$ grep -c ¡°±»²éÕÒµÄ×Ö·û´®¡± ÎļþÃû

´ÓÎļþÄÚÈݲéÕÒ²»Æ¥ÅäÖ¸¶¨×Ö·û´®µÄÐУº

$ grep ¨Cv "±»²éÕÒµÄ×Ö·û´®" ÎļþÃû

µÇ¼ºó¸´ÖÆ

5.2 find

findÏÂÁîÔÚĿ¼½á¹¹ÖÐËÑË÷Îļþ £¬²¢¶ÔËÑË÷Ч¹ûÖ´ÐÐÖ¸¶¨µÄ²Ù×÷¡£

find ĬÈÏËÑË÷Ä¿½ñĿ¼¼°Æä×ÓĿ¼ £¬²¢ÇÒ²»¹ýÂËÈκÎЧ¹û£¨Ò²¾ÍÊÇ·µ»ØËùÓÐÎļþ£© £¬½«ËüÃÇÈ«¶¼ÏÔʾÔÚÆÁÄ»ÉÏ¡£ÁíÍâ £¬ËÑË÷ÃñÖںűà³ÌÊÖÒÕȦºǫ́»Ø¸´¡°1024¡± £¬»ñÈ¡Ò»·Ý¾ªÏ²Àñ°ü¡£

ʹÓÃʵÀý£º

find . -name "*.log" -ls  ÔÚÄ¿½ñĿ¼²éÕÒÒÔ.log×îºóµÄÎļþ£¬²¢ÏÔʾÏêϸÐÅÏ¢¡£find /root/ -perm 600   ²éÕÒ/root/Ŀ¼ÏÂȨÏÞΪ600µÄÎļþ find . -type f -name "*.log"  ²éÕÒµ±Ä¿Â¼£¬ÒÔ.log×îºóµÄͨË×Îļþ find . -type d | sort   ²éÕÒÄ¿½ñËùÓÐĿ¼²¢ÅÅÐò find . -size +100M  ²éÕÒÄ¿½ñĿ¼´óÓÚ100MµÄÎļþ

µÇ¼ºó¸´ÖÆ

´Ó¸ùĿ¼×îÏȲéÕÒËùÓÐÀ©Õ¹ÃûΪ .log µÄÎı¾Îļþ £¬²¢ÕÒ³ö°üÀ¨ ¡°ERROR¡± µÄÐУº

$ find / -type f -name "*.log" | xargs grep "ERROR"

µÇ¼ºó¸´ÖÆ

Àý×Ó£º´ÓÄ¿½ñĿ¼×îÏȲéÕÒËùÓÐÀ©Õ¹ÃûΪ .in µÄÎı¾Îļþ £¬²¢ÕÒ³ö°üÀ¨ ¡°thermcontact¡± µÄÐУº

find . -name "*.in" | xargs grep "thermcontact"

µÇ¼ºó¸´ÖÆ

5.3 locate

locate ÈÃʹÓÃÕß¿ÉÒԺܿìËÙµÄÕ÷²Éij¸ö·¾¶¡£Ä¬ÈÏÌìÌì×Ô¶¯¸üÐÂÒ»´Î £¬ÒÔÊÇʹÓÃlocate ÏÂÁî²é²»µ½×îб任¹ýµÄÎļþ¡£ÎªÁË×èÖ¹ÕâÖÖÇéÐÎ £¬¿ÉÒÔÔÚʹÓÃlocate֮ǰ £¬ÏÈʹÓÃupdatedbÏÂÁî £¬ÊÖ¶¯¸üÐÂÊý¾Ý¿â¡£ÈôÊÇÊý¾Ý¿âÖÐûÓÐÅÌÎʵÄÊý¾Ý £¬Ôò»á±¨³ölocate: can not stat () `/var/lib/mlocate/mlocate.db¡¯: No such file or directory¸Ã¹ýʧ£¡updatedb¼´¿É£¡

yum -y install mlocate ÈôÊÇÊǾ«¼ò°æCentOSϵͳÐèҪװÖÃlocateÏÂÁî

ʹÓÃʵÀý£º

updatedblocate /etc/sh ËÑË÷etcĿ¼ÏÂËùÓÐÒÔsh¿ªÍ·µÄÎļþ locate pwd ²éÕÒºÍpwdÏà¹ØµÄËùÓÐÎļþ

µÇ¼ºó¸´ÖÆ

5.4 whereis

whereisÏÂÁîÊǶ¨Î»¿ÉÖ´ÐÐÎļþ¡¢Ô´´úÂëÎļþ¡¢×ÊÖúÎļþÔÚÎļþϵͳÖеÄλÖá£ÕâЩÎļþµÄÊôÐÔÓ¦ÊôÓÚԭʼ´úÂë £¬¶þ½øÖÆÎļþ £¬»òÊÇ×ÊÖúÎļþ¡£

ʹÓÃʵÀý£º

whereis ls    ½«ºÍlsÎļþÏà¹ØµÄÎļþ¶¼²éÕÒ³öÀ´

µÇ¼ºó¸´ÖÆ

5.5 which

whichÏÂÁîµÄ×÷ÓÃÊÇÔÚPATH±äÁ¿Ö¸¶¨µÄ·¾¶ÖÐ £¬ËÑË÷ij¸öϵͳÏÂÁîµÄλÖà £¬²¢ÇÒ·µ»ØµÚÒ»¸öËÑË÷Ч¹û¡£

ʹÓÃʵÀý£º

which pwd  ²éÕÒpwdÏÂÁîËùÔÚ·¾¶ which java  ²éÕÒpathÖÐjavaµÄ·¾¶

µÇ¼ºó¸´ÖÆ

Áù¡¢su¡¢sudo

6.1 su

Linux suÏÂÁîÓÃÓڱ任ΪÆäËûʹÓÃÕßµÄÉí·Ý £¬³ý root Íâ £¬ÐèÒª¼üÈë¸ÃʹÓÃÕßµÄÃÜÂë¡£

ʹÓÃȨÏÞ£ºËùÓÐʹÓÃÕß¡£

Óï·¨

su [-fmp] [-c command] [-s shell] [--help] [--version] [-] [USER [ARG]]

µÇ¼ºó¸´ÖÆ

²ÎÊý˵Ã÷£º

-f »ò ¡ªfast ²»±Ø¶ÁÆô¶¯µµ£¨Èç csh.cshrc µÈ£© £¬½öÓÃÓÚ csh »ò tcsh

-m -p »ò ¡ªpreserve-environment Ö´ÐÐ su ʱ²»¸Ä±äÇéÐαäÊý

-c command »ò ¡ªcommand=command ±ä»»ÎªÕʺÅΪ USER µÄʹÓÃÕß²¢Ö´ÐÐÖ¸Ácommand£©ºóÔÙ±ä»ØÔ­À´Ê¹ÓÃÕß

-s shell »ò ¡ªshell=shell Ö¸¶¨ÒªÖ´ÐÐµÄ shell £¨bash csh tcsh µÈ£© £¬Ô¤ÉèֵΪ /etc/passwd ÄڵĸÃʹÓÃÕߣ¨USER£© shell

¨Chelp ÏÔʾ˵Ã÷Îļþ

¨Cversion ÏÔʾ°æ±¾×ÊѶ

– -l »ò ¡ªlogin Õâ¸ö²ÎÊý¼ÓÁËÖ®ºó £¬¾ÍËƺõÊÇÖØРlogin Ϊ¸ÃʹÓÃÕßÒ»Ñù £¬´ó²¿·ÝÇéÐαäÊý£¨HOME SHELL USERµÈµÈ£©¶¼ÊÇÒÔ¸ÃʹÓÃÕߣ¨USER£©ÎªÖ÷ £¬²¢ÇÒÊÂÇéĿ¼Ҳ»á¸Ä±ä £¬ÈôÊÇûÓÐÖ¸¶¨ USER  £¬ÄÚ¶¨ÊÇ root

USER Óû±ä»»µÄʹÓÃÕßÕʺÅ

ARG ´«ÈëÐ嵀 shell ²ÎÊý

ʵÀý

±ä»»ÕʺÅΪ root ²¢ÔÚÖ´ÐÐ ls Ö¸ÁîÍËÈ´³ö±ä»ØԭʹÓÃÕß

su -c ls root

µÇ¼ºó¸´ÖÆ

±ä»»ÕʺÅΪ root ²¢´«Èë -f ²ÎÊý¸øÐÂÖ´ÐÐµÄ shell

su root -f

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

±ä»»ÕʺÅΪ clsung ²¢¸Ä±äÊÂÇéĿ¼ÖÁ clsung µÄ¼ÒĿ¼£¨home dir£©

su - clsung

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

Çл»Óû§

hnlinux@runoob.com:~$ whoami //ÏÔʾĿ½ñÓû§hnlinuxhnlinux@runoob.com:~$ pwd //ÏÔʾĿ½ñĿ¼/home/hnlinuxhnlinux@runoob.com:~$ su root //Çл»µ½rootÓû§ÃÜÂ룺root@runoob.com:/home/hnlinux# whoami rootroot@runoob.com:/home/hnlinux# pwd/home/hnlinux

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

Çл»Óû§ £¬¸Ä±äÇéÐαäÁ¿

hnlinux@runoob.com:~$ whoami //ÏÔʾĿ½ñÓû§hnlinuxhnlinux@runoob.com:~$ pwd //ÏÔʾĿ½ñĿ¼/home/hnlinuxhnlinux@runoob.com:~$ su - root //Çл»µ½rootÓû§ÃÜÂ룺root@runoob.com:/home/hnlinux# whoami rootroot@runoob.com:/home/hnlinux# pwd //ÏÔʾĿ½ñĿ¼/root

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

suÓÃÓÚÓû§Ö®¼äµÄÇл»¡£¿ÉÊÇÇл»Ç°µÄÓû§ÒÀÈ»¼á³ÖµÇ¼״̬¡£ÈôÊÇÊÇroot ÏòͨË×»òÐéÄâÓû§Çл»²»ÐèÒªÃÜÂë £¬·´Ö®Í¨Ë×Óû§Çл»µ½ÆäËüÈκÎÓû§¶¼ÐèÒªÃÜÂëÑéÖ¤¡£

su test:Çл»µ½testÓû§£¬¿ÉÊÇ·¾¶ÕÕ¾É/rootĿ¼su - test : Çл»µ½testÓû§£¬Â·¾¶Äð³ÉÁË/home/testsu : Çл»µ½rootÓû§£¬¿ÉÊÇ·¾¶ÕÕ¾ÉÔ­À´µÄ·¾¶su - : Çл»µ½rootÓû§£¬²¢ÇÒ·¾¶ÊÇ/rootsuȱ·¦£ºÈôÊÇij¸öÓû§ÐèҪʹÓÃrootȨÏÞ¡¢Ôò±ØÐèÒª°ÑrootÃÜÂë¸æËß´ËÓû§¡£Í˳ö·µ»Ø֮ǰµÄÓû§£ºexit

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

6.2 sudo

sudoÊÇΪËùÓÐÏëʹÓÃrootȨÏÞµÄͨË×Óû§Éè¼ÆµÄ¡£¿ÉÒÔÈÃͨË×Óû§¾ßÓÐÔÝʱʹÓÃrootȨÏÞµÄȨÁ¦¡£Ö»ÐèÊäÈë×Ô¼ºÕË»§µÄÃÜÂë¼´¿É¡£

½øÈësudoÉèÖÃÎļþÏÂÁ

vi /etc/sudoer»òÕßvisudo

µÇ¼ºó¸´ÖÆ

°¸Àý£ºÔÊÐíhadoopÓû§ÒÔrootÉí·ÝÖ´ÐÐÖÖÖÖÓ¦ÓÃÏÂÁî £¬ÐèÒªÊäÈëhadoopÓû§µÄÃÜÂë¡£hadoop ALL=(ALL) ALL

°¸Àý£ºÖ»ÔÊÐíhadoopÓû§ÒÔrootÉí·ÝÖ´ÐÐls ¡¢catÏÂÁî £¬²¢ÇÒÖ´ÐÐʱ¼äÃâÊäÈëÃÜÂë¡£ÉèÖÃÎļþÖУºhadoop ALL=NOPASSWD: /bin/ls, /bin/cat

su root -f

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

±ä»»ÕʺÅΪ clsung ²¢¸Ä±äÊÂÇéĿ¼ÖÁ clsung µÄ¼ÒĿ¼£¨home dir£©

su - clsung

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

Çл»Óû§

hnlinux@runoob.com:~$ whoami //ÏÔʾĿ½ñÓû§hnlinuxhnlinux@runoob.com:~$ pwd //ÏÔʾĿ½ñĿ¼/home/hnlinuxhnlinux@runoob.com:~$ su root //Çл»µ½rootÓû§ÃÜÂ룺root@runoob.com:/home/hnlinux# whoami rootroot@runoob.com:/home/hnlinux# pwd/home/hnlinux

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

Çл»Óû§ £¬¸Ä±äÇéÐαäÁ¿

hnlinux@runoob.com:~$ whoami //ÏÔʾĿ½ñÓû§hnlinuxhnlinux@runoob.com:~$ pwd //ÏÔʾĿ½ñĿ¼/home/hnlinuxhnlinux@runoob.com:~$ su - root //Çл»µ½rootÓû§ÃÜÂ룺root@runoob.com:/home/hnlinux# whoami rootroot@runoob.com:/home/hnlinux# pwd //ÏÔʾĿ½ñĿ¼/root

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

suÓÃÓÚÓû§Ö®¼äµÄÇл»¡£¿ÉÊÇÇл»Ç°µÄÓû§ÒÀÈ»¼á³ÖµÇ¼״̬¡£ÈôÊÇÊÇroot ÏòͨË×»òÐéÄâÓû§Çл»²»ÐèÒªÃÜÂë £¬·´Ö®Í¨Ë×Óû§Çл»µ½ÆäËüÈκÎÓû§¶¼ÐèÒªÃÜÂëÑéÖ¤¡£

su test:Çл»µ½testÓû§£¬¿ÉÊÇ·¾¶ÕÕ¾É/rootĿ¼su - test : Çл»µ½testÓû§£¬Â·¾¶Äð³ÉÁË/home/testsu : Çл»µ½rootÓû§£¬¿ÉÊÇ·¾¶ÕÕ¾ÉÔ­À´µÄ·¾¶su - : Çл»µ½rootÓû§£¬²¢ÇÒ·¾¶ÊÇ/rootsuȱ·¦£ºÈôÊÇij¸öÓû§ÐèҪʹÓÃrootȨÏÞ¡¢Ôò±ØÐèÒª°ÑrootÃÜÂë¸æËß´ËÓû§¡£Í˳ö·µ»Ø֮ǰµÄÓû§£ºexit

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

Æß¡¢ÏÂÔØÓë×°Öà yum

yum£¨ Yellow dog Updater, Modified£©ÊÇÒ»¸öÔÚFedoraºÍRedHatÒÔ¼°SUSEÖеÄShellÇ°¶ËÈí¼þ°ü¹ÜÀíÆ÷¡£

»ùì¶RPM°ü¹ÜÀí £¬Äܹ»´ÓÖ¸¶¨µÄЧÀÍÆ÷×Ô¶¯ÏÂÔØRPM°ü²¢ÇÒ×°Öà £¬¿ÉÒÔ×Ô¶¯´¦ÀíÒÀÀµÐÔ¹Øϵ £¬²¢ÇÒÒ»´Î×°ÖÃËùÓÐÒÀÀµµÄÈíÌå°ü £¬ÎÞÐë·±ËöµØÒ»´Î´ÎÏÂÔØ¡¢×°Öá£

yumÌṩÁ˲éÕÒ¡¢×°Öá¢É¾³ýijһ¸ö¡¢Ò»×éÉõÖÁËùÓÐÈí¼þ°üµÄÏÂÁî £¬²¢ÇÒÏÂÁÁ·¶øÓֺüÇ¡£

7.1 yum Óï·¨

yum [options] [command] [package ...]

µÇ¼ºó¸´ÖÆ

options£º¿ÉÑ¡ £¬Ñ¡Ïî°üÀ¨-h£¨×ÊÖú£© £¬-y£¨µ±×°ÖÃÀú³ÌÌáÐÑÑ¡ÔñËùÓÐΪ¡±yes¡±£© £¬-q£¨²»ÏÔʾװÖõÄÀú³Ì£©µÈµÈ¡£

command£ºÒª¾ÙÐеIJÙ×÷¡£

package²Ù×÷µÄ¹¤¾ß¡£

7.2 yum³£ÓÃÏÂÁî

1.ÁгöËùÓпɸüеÄÈí¼þÇåµ¥ÏÂÁyum check-update

2.¸üÐÂËùÓÐÈí¼þÏÂÁyum update

3.½ö×°ÖÃÖ¸¶¨µÄÈí¼þÏÂÁyum install

4.½ö¸üÐÂÖ¸¶¨µÄÈí¼þÏÂÁyum update

5.ÁгöËùÓпɰ²ÑbµÄÈí¼þÇåµ¥ÏÂÁyum list

6.ɾ³ýÈí¼þ°üÏÂÁyum remove

7.²éÕÒÈí¼þ°ü ÏÂÁyum search

8.ɨ³ý»º´æÏÂÁî:

yum clean packages: ɨ³ý»º´æĿ¼ÏµÄÈí¼þ°ü

yum clean headers: ɨ³ý»º´æĿ¼Ï嵀 headers

yum clean oldheaders: ɨ³ý»º´æĿ¼ÏÂ¾ÉµÄ headers

yum clean, yum clean all (= yum clean packages; yum clean oldheaders) :ɨ³ý»º´æĿ¼ÏµÄÈí¼þ°ü¼°¾ÉµÄheaders

ʵÀý 1

×°ÖÃ pam-devel

[root@www ~] yum install pam-develSetting up Install ProcessParsing package install argumentsResolving Dependencies  <==Ïȼì²éÈí¼þµÄÊôÐÔÏàÒÀÎÊÌâ--> Running transaction check---> Package pam-devel.i386 0:0.99.6.2-4.el5 set to be updated--> Processing Dependency: pam = 0.99.6.2-4.el5 for package: pam-devel--> Running transaction check---> Package pam.i386 0:0.99.6.2-4.el5 set to be updatedfilelists.xml.gz          100% |=========================| 1.6 MB    00:05filelists.xml.gz          100% |=========================| 138 kB    00:00-> Finished Dependency Resolution¡­¡­(Ê¡ÂÔ)

µÇ¼ºó¸´ÖÆ

ʵÀý 2

ÒƳý pam-devel

[root@www ~] yum remove pam-develSetting up Remove ProcessResolving Dependencies  <==ͬÑùµÄ£¬ÏȽâ¾öÊôÐÔÏàÒÀµÄÎÊÌâ--> Running transaction check---> Package pam-devel.i386 0:0.99.6.2-4.el5 set to be erased--> Finished Dependency ResolutionDependencies Resolved============================================================================= Package                 Arch       Version          Repository        Size=============================================================================Removing: pam-devel               i386       0.99.6.2-4.el5   installed         495 kTransaction Summary=============================================================================Install      0 Package(s)Update       0 Package(s)Remove       1 Package(s)  <==»¹ºÃ£¬²¢Ã»ÓÐÊôÐÔÏàÒÀµÄÎÊÌâ£¬´¿´âÒƳýÒ»¸öÈí¼þIs this ok [y/N]: yDownloading Packages:Running rpm_check_debugRunning Transaction TestFinished Transaction TestTransaction Test SucceededRunning Transaction  Erasing   : pam-devel                    ######################### [1/1]Removed: pam-devel.i386 0:0.99.6.2-4.el5Complete!

µÇ¼ºó¸´ÖÆ

ʵÀý 3

ʹÓà yum µÄ¹¦Ð§ £¬ÕÒ³öÒÔ pam Ϊ¿ªÍ·µÄÈí¼þÃû³ÆÓÐÄÄЩ£¿

[root@www ~] yum list pam*Installed Packagespam.i386                  0.99.6.2-3.27.el5      installedpam_ccreds.i386           3-5                    installedpam_krb5.i386             2.2.14-1               installedpam_passwdqc.i386         1.0.2-1.2.2            installedpam_pkcs11.i386           0.5.3-23               installedpam_smb.i386              1.1.7-7.2.1            installedAvailable Packages <==µ×ÏÂÔòÊÇ¡º¿ÉÉý¼¶¡»µÄ»ò¡ºÎ´×°ÖỵÄpam.i386                  0.99.6.2-4.el5         basepam-devel.i386            0.99.6.2-4.el5         basepam_krb5.i386             2.2.14-10              base

µÇ¼ºó¸´ÖÆ


7.3 º£ÄÚ yum Ô´

ÍøÒ×£¨163£©yumÔ´ÊǺ£ÄÚ×îºÃµÄyumÔ´Ö®Ò»  £¬ÎÞÂÛÊÇËÙÂÊÕÕ¾ÉÈí¼þ°æ±¾ £¬¶¼ºÜÊǵIJ»´í¡£

½«yumÔ´ÉèÖÃΪ163 yum £¬¿ÉÒÔÌáÉýÈí¼þ°ü×°Öú͸üеÄËÙÂÊ £¬Í¬Ê±×èֹһЩ³£¼ûÈí¼þ°æ±¾ÎÞ·¨ÕÒµ½¡£

×°Öð취

Ê×Ïȱ¸·Ý/etc/yum.repos.d/CentOS-Base.repo

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup1

µÇ¼ºó¸´ÖÆ

ÏÂÔضÔÓ¦°æ±¾ repo Îļþ, ·ÅÈë /etc/yum.repos.d/ (²Ù×÷Ç°Çë×öºÃÏìÓ¦±¸·Ý)

CentOS5 £ºhttp://mirrors.163.com/.help/CentOS5-Base-163.repo

CentOS6 £ºhttp://mirrors.163.com/.help/CentOS6-Base-163.repo

CentOS7 £ºhttp://mirrors.163.com/.help/CentOS7-Base-163.repo

wget http://mirrors.163.com/.help/CentOS6-Base-163.repomv CentOS6-Base-163.repo CentOS-Base.repo

µÇ¼ºó¸´ÖÆ

ÔËÐÐÒÔÏÂÏÂÁîÌìÉú»º´æ

yum clean allyum makecache

µÇ¼ºó¸´ÖÆ

³ýÁËÍøÒ×Ö®Íâ £¬º£ÄÚÉÐÓÐÆäËû²»´íµÄ yum Ô´ £¬ºÃ±ÈÖпƴóºÍËѺü¡£

ÖпƴóµÄ yum Ô´ £¬×°ÖÃÒªÁìÉó²é£ºhttps://lug.ustc.edu.cn/wiki/mirrors/help/centos

sohu µÄ yum Ô´×°ÖÃÒªÁìÉó²é: http://mirrors.sohu.com/help/centos.htm

°Ë. Linux Èý½£¿Í£¨awk £¬sed £¬grep£©

awk¡¢sed¡¢grep¸üÊʺϵÄÆ«Ïò£º

grep ¸üÊʺϴ¿´âµÄ²éÕÒ»òÆ¥ÅäÎı¾

sed ¸üÊʺϱ༭ƥÅäµ½µÄÎı¾

awk ¸üÊʼ°ÃûÌû¯Îı¾ £¬¶ÔÎı¾¾ÙÐнÏÖØѧÃûÌô¦Àí

8.1 awk

AWK ÊÇÒ»ÖÖ´¦ÀíÎı¾ÎļþµÄÓïÑÔ £¬ÊÇÒ»¸öÇ¿Ê¢µÄÎÄÌìÖ°Îö¹¤¾ß¡£

Ö®ÒÔÊǽРAWK ÊÇÓÉÓÚÆäÈ¡ÁËÈýλÊ×´´ÈË Alfred Aho £¬Peter Weinberger, ºÍ Brian Kernighan µÄ Family Name µÄÊ××Ö·û¡£

Óï·¨

awk [Ñ¡Ïî²ÎÊý] 'script' var=value file(s)»òawk [Ñ¡Ïî²ÎÊý] -f scriptfile var=value file(s)

µÇ¼ºó¸´ÖÆ

Ñ¡Ïî²ÎÊý˵Ã÷£º

-F fs or ¡ªfield-separator fsÖ¸¶¨ÊäÈëÎļþÕÛÍÑÀë·û £¬fsÊÇÒ»¸ö×Ö·û´®»òÕßÊÇÒ»¸öÕýÔò±í´ïʽ £¬Èç-F:¡£

-v var=value or ¡ªasign var=value¸³ÖµÒ»¸öÓû§½ç˵±äÁ¿¡£

-f scripfile or ¡ªfile scriptfile´Ó¾ç±¾ÎļþÖжÁÈ¡awkÏÂÁî¡£

-mf nnn and -mr nnn¶ÔnnnÖµÉèÖÃÄÚÔÚÏÞÖÆ £¬-mfÑ¡ÏîÏÞÖÆ·ÖÅɸønnnµÄ×î´ó¿éÊýÄ¿£»-mrÑ¡ÏîÏÞÖƼͼµÄ×î´óÊýÄ¿¡£ÕâÁ½¸ö¹¦Ð§ÊÇBellʵÑéÊÒ°æawkµÄÀ©Õ¹¹¦Ð§ £¬ÔÚ±ê×¼awkÖв»ÊÊÓá£

-W compact or ¡ªcompat, -W traditional or ¡ªtraditionalÔÚ¼æÈÝģʽÏÂÔËÐÐawk¡£ÒÔÊÇgawkµÄÐÐΪºÍ±ê×¼µÄawkÍêÈ«Ò»Ñù £¬ËùÓеÄawkÀ©Õ¹¶¼±»ºöÂÔ¡£

-W copyleft or ¡ªcopyleft, -W copyright or ¡ªcopyright´òÓ¡¼ò¶ÌµÄ°æȨÐÅÏ¢¡£

-W help or ¡ªhelp, -W usage or ¡ªusage´òÓ¡ËùÓÐawkÑ¡ÏîºÍÿ¸öÑ¡ÏîµÄ¼ò¶Ì˵Ã÷¡£

-W lint or ¡ªlint´òÓ¡²»¿ÉÏò¹Å°åunixƽ̨ÒÆÖ²µÄ½á¹¹µÄÖÒÑÔ¡£

-W lint-old or ¡ªlint-old´òÓ¡¹ØÓÚ²»¿ÉÏò¹Å°åunixƽ̨ÒÆÖ²µÄ½á¹¹µÄÖÒÑÔ¡£

-W posix·­¿ª¼æÈÝģʽ¡£µ«ÓÐÒÔÏÂÏÞÖÆ £¬²»Ê¶±ð£º/x¡¢º¯ÊýÒªº¦×Ö¡¢func¡¢»»ÂëÐòÁÐÒÔ¼°µ±fsÊÇÒ»¸ö¿Õ¸ñʱ £¬½«ÐÂÐÐ×÷Ϊһ¸öÓòÍÑÀë·û£»²Ù×÷·û ºÍ =²»¿ÉÈ¡´ú^ ºÍ ^=£»fflushÎÞЧ¡£

-W re-interval or ¡ªre-inervalÔÊÐí¾àÀëÕýÔò±í´ïʽµÄʹÓà £¬²Î¿¼(grepÖеÄPosix×Ö·ûÀà) £¬ÈçÀ¨ºÅ±í´ïʽ[[:alpha:]]¡£

-W source program-text or ¡ªsource program-textʹÓÃprogram-text×÷ΪԴ´úÂë £¬¿ÉÓë-fÏÂÁî»ìÓá£

-W version or ¡ªversion´òÓ¡bug±¨¸æÐÅÏ¢µÄ°æ±¾¡£

»ù±¾Ó÷¨

log.txtÎı¾ÄÚÈÝÈçÏ£º

2 this is a test3 Are you like awkThis's a test10 There are orange,apple,mongo

µÇ¼ºó¸´ÖÆ

Ó÷¨Ò»£º

awk '{[pattern] action}' {filenames}   # ÐÐÆ¥ÅäÓï¾ä awk '' Ö»ÄÜÓõ¥ÒýºÅ

µÇ¼ºó¸´ÖÆ

ʵÀý£º

# ÿÐа´¿Õ¸ñ»òTABÖ§½â£¬Êä³öÎı¾ÖеÄ1¡¢4Ïî $ awk '{print $1,$4}' log.txt --------------------------------------------- 2 a 3 like This's 10 orange,apple,mongo # ÃûÌû¯Êä³ö $ awk '{printf "%-8s %-10sn",$1,$4}' log.txt --------------------------------------------- 2        a 3        like This's 10       orange,apple,mongo

µÇ¼ºó¸´ÖÆ

Ó÷¨¶þ£º

awk -F  #-FÏ൱ÓÚÄÚÖñäÁ¿FS, Ö¸¶¨Ö§½â×Ö·û

µÇ¼ºó¸´ÖÆ

ʵÀý£º

# ʹÓÃ","Ö§½â $  awk -F, '{print $1,$2}'   log.txt --------------------------------------------- 2 this is a test 3 Are you like awk This's a test 10 There are orange apple # »òÕßʹÓÃÄÚ½¨±äÁ¿ $ awk 'BEGIN{FS=","} {print $1,$2}'     log.txt --------------------------------------------- 2 this is a test 3 Are you like awk This's a test 10 There are orange apple # ʹÓöà¸öÍÑÀë·û.ÏÈʹÓÿոñÖ§½â£¬È»ºó¶ÔÖ§½âЧ¹ûÔÙʹÓÃ","Ö§½â $ awk -F '[ ,]'  '{print $1,$2,$5}'   log.txt --------------------------------------------- 2 this test 3 Are awk This's a 10 There apple

µÇ¼ºó¸´ÖÆ

Ó÷¨Èý£º

awk -v  # ÉèÖñäÁ¿

µÇ¼ºó¸´ÖÆ

ʵÀý£º

 $ awk -va=1 '{print $1,$1+a}' log.txt --------------------------------------------- 2 3 3 4 This's 1 10 11 $ awk -va=1 -vb=s '{print $1,$1+a,$1b}' log.txt --------------------------------------------- 2 3 2s 3 4 3s This's 1 This'ss 10 11 10s

µÇ¼ºó¸´ÖÆ

Ó÷¨ËÄ£º

awk -f {awk¾ç±¾} {ÎļþÃû}

µÇ¼ºó¸´ÖÆ

ʵÀý£º

 $ awk -f cal.awk log.txt

µÇ¼ºó¸´ÖÆ

ÔËËã·û

ÔËËã·û ÐÎò
= += -= = /= %= ^= *= ¸³Öµ
?: CÌõ¼þ±í´ïʽ
Âß¼­»ò
&& Âß¼­Óë
~ ºÍ !~ Æ¥ÅäÕýÔò±í´ïʽºÍ²»Æ¥ÅäÕýÔò±í´ïʽ
< <= > >= != == ¹ØϵÔËËã·û
¿Õ¸ñ ÅþÁ¬
+ – ¼Ó £¬¼õ
* / % ³Ë £¬³ýÓëÇóÓà
+ – ! Ò»Ôª¼Ó £¬¼õºÍÂß¼­·Ç
^ * ÇóÃÝ
++ ¨C ÔöÌí»òïÔÌ­ £¬×÷Ϊǰ׺»òºó׺
$ ×Ö¶ÎÒýÓÃ
in Êý×é³ÉÔ±

¹ýÂ˵ÚÒ»ÁдóÓÚ2µÄÐÐ

$ awk '$1>2' log.txt    #ÏÂÁî#Êä³ö3 Are you like awkThis's a test10 There are orange,apple,mongo12345

µÇ¼ºó¸´ÖÆ

¹ýÂ˵ÚÒ»Áм´ÊÇ2µÄÐÐ

$ awk '$1==2 {print $1,$3}' log.txt    #ÏÂÁî#Êä³ö2 is123

µÇ¼ºó¸´ÖÆ

¹ýÂ˵ÚÒ»ÁдóÓÚ2²¢ÇÒµÚ¶þÁм´ÊÇ¡¯Are¡¯µÄÐС£ÁíÍâ £¬ËÑË÷ÃñÖÚºÅJava¼Ü¹¹Ê¦ÊÖÒÕºǫ́»Ø¸´¡°ÃæÊÔÌ⡱ £¬»ñÈ¡Ò»·Ý¾ªÏ²Àñ°ü¡£

$ awk '$1>2 && $2=="Are" {print $1,$2,$3}' log.txt    #ÏÂÁî#Êä³ö3 Are you123

µÇ¼ºó¸´ÖÆ

ÄÚ½¨±äÁ¿

±äÁ¿ ÐÎò
$n Ä¿½ñ¼Í¼µÄµÚn¸ö×ֶΠ£¬×ֶμäÓÉFSÍÑÀë
$0 ÍêÕûµÄÊäÈë¼Í¼
ARGC ÏÂÁîÐвÎÊýµÄÊýÄ¿
ARGIND ÏÂÁîÐÐÖÐÄ¿½ñÎļþµÄλÖÃ(´Ó0×îÏÈËã)
ARGV °üÀ¨ÏÂÁîÐвÎÊýµÄÊý×é
CONVFMT Êý×Öת»»ÃûÌÃ(ĬÈÏֵΪ%.6g)ENVIRONÇéÐαäÁ¿¹ØÁªÊý×é
ERRNO ×îºóÒ»¸öϵͳ¹ýʧµÄÐÎò
FIELDWIDTHS ×ֶοí¶ÈÁбí(Óÿոñ¼üÍÑÀë)
FILENAME Ä¿½ñÎļþÃû
FNR ¸÷Îļþ»®·Ö¼ÆÊýµÄÐкÅ
FS ×Ö¶ÎÍÑÀë·û(ĬÈÏÊÇÈκοոñ)
IGNORECASE ÈôÊÇΪÕæ £¬Ôò¾ÙÐкöÂÔ¾ÞϸдµÄÆ¥Åä
NF Ò»Ìõ¼Í¼µÄ×ֶεÄÊýÄ¿
NR ÒѾ­¶Á³öµÄ¼Í¼Êý £¬¾ÍÊÇÐкÅ £¬´Ó1×îÏÈ
OFMT Êý×ÖµÄÊäÌØÊâʽ(ĬÈÏÖµÊÇ%.6g)
OFS Êä³ö¼Í¼ÍÑÀë·û£¨Êä³ö»»Ðзû£© £¬Êä³öʱÓÃÖ¸¶¨µÄ·ûºÅÈ¡´ú»»Ðзû
ORS Êä³ö¼Í¼ÍÑÀë·û(ĬÈÏÖµÊÇÒ»¸ö»»Ðзû)
RLENGTH ÓÉmatchº¯ÊýËùÆ¥ÅäµÄ×Ö·û´®µÄ³¤¶È
RS ¼Í¼ÍÑÀë·û(ĬÈÏÊÇÒ»¸ö»»Ðзû)
RSTART ÓÉmatchº¯ÊýËùÆ¥ÅäµÄ×Ö·û´®µÄµÚÒ»¸öλÖÃ
SUBSEP Êý×éϱêÍÑÀë·û(ĬÈÏÖµÊÇ/034)
$ awk 'BEGIN{printf "%4s %4s %4s %4s %4s %4s %4s %4s %4sn","FILENAME","ARGC","FNR","FS","NF","NR","OFS","ORS","RS";printf "---------------------------------------------n"} {printf "%4s %4s %4s %4s %4s %4s %4s %4s %4sn",FILENAME,ARGC,FNR,FS,NF,NR,OFS,ORS,RS}'  log.txtFILENAME ARGC  FNR   FS   NF   NR  OFS  ORS   RS---------------------------------------------log.txt    2    1         5    1log.txt    2    2         5    2log.txt    2    3         3    3log.txt    2    4         4    4$ awk -F' 'BEGIN{printf "%4s %4s %4s %4s %4s %4s %4s %4s %4sn","FILENAME","ARGC","FNR","FS","NF","NR","OFS","ORS","RS";printf "---------------------------------------------n"} {printf "%4s %4s %4s %4s %4s %4s %4s %4s %4sn",FILENAME,ARGC,FNR,FS,NF,NR,OFS,ORS,RS}'  log.txtFILENAME ARGC  FNR   FS   NF   NR  OFS  ORS   RS---------------------------------------------log.txt    2    1    '    1    1log.txt    2    2    '    1    2log.txt    2    3    '    2    3log.txt    2    4    '    1    4# Êä³ö˳ÐòºÅ NR, Æ¥ÅäÎı¾ÐкÅ$ awk '{print NR,FNR,$1,$2,$3}' log.txt---------------------------------------------1 1 2 this is2 2 3 Are you3 3 This's a test4 4 10 There are# Ö¸¶¨Êä³öÖ§½â·û$  awk '{print $1,$2,$5}' OFS=" $ "  log.txt---------------------------------------------2 $ this $ test3 $ Are $ awkThis's $ a $10 $ There $

µÇ¼ºó¸´ÖÆ

ʹÓÃÕýÔò £¬×Ö·û´®Æ¥Åä

# Êä³öµÚ¶þÁаüÀ¨ "th"£¬²¢´òÓ¡µÚ¶þÁÐÓëµÚËÄÁÐ$ awk '$2 ~ /th/ {print $2,$4}' log.txt---------------------------------------------this a

µÇ¼ºó¸´ÖÆ

~ ÌåÏÖģʽ×îÏÈ¡£// ÖÐÊÇģʽ¡£

# Êä³ö°üÀ¨ "re" µÄÐÐ$ awk '/re/ ' log.txt---------------------------------------------3 Are you like awk10 There are orange,apple,mongo

µÇ¼ºó¸´ÖÆ


ºöÂÔ¾Þϸд

$ awk 'BEGIN{IGNORECASE=1} /this/' log.txt---------------------------------------------2 this is a testThis's a test

µÇ¼ºó¸´ÖÆ


ģʽȡ·´

$ awk '$2 !~ /th/ {print $2,$4}' log.txt---------------------------------------------Are likeaThere orange,apple,mongo$ awk '!/th/ {print $2,$4}' log.txt---------------------------------------------Are likeaThere orange,apple,mongo

µÇ¼ºó¸´ÖÆ


awk¾ç±¾

¹ØÓÚ awk ¾ç±¾ £¬ÎÒÃÇÐèҪעÖØÁ½¸öÒªº¦´Ê BEGIN ºÍ END¡£

BEGIN{ ÕâÄÚÀï·ÅµÄÊÇÖ´ÐÐÇ°µÄÓï¾ä }

END {ÕâÄÚÀï·ÅµÄÊÇ´¦ÀíÍêËùÓеÄÐкóÒªÖ´ÐеÄÓï¾ä }

{ÕâÄÚÀï·ÅµÄÊÇ´¦ÀíÿһÐÐʱҪִÐеÄÓï¾ä}

¼ÙÉèÓÐÕâôһ¸öÎļþ£¨Ñ§ÉúЧ¹û±í£©£º

$ cat score.txtMarry   2143 78 84 77Jack    2321 66 78 45Tom     2122 48 77 71Mike    2537 87 97 95Bob     2415 40 57 62

µÇ¼ºó¸´ÖÆ

ÎÒÃÇµÄ awk ¾ç±¾ÈçÏ£º

$ cat cal.awk#!/bin/awk -f#ÔËÐÐÇ°BEGIN {    math = 0    english = 0    computer = 0    printf "NAME    NO.   MATH  ENGLISH  COMPUTER   TOTALn"    printf "---------------------------------------------n"}#ÔËÐÐÖÐ{    math+=$3    english+=$4    computer+=$5    printf "%-6s %-6s %4d %8d %8d %8dn", $1, $2, $3,$4,$5, $3+$4+$5}#ÔËÐкóEND {    printf "---------------------------------------------n"    printf "  TOTAL:%10d %8d %8d n", math, english, computer    printf "AVERAGE:%10.2f %8.2f %8.2fn", math/NR, english/NR, computer/NR}123456789101112131415161718192021222324

µÇ¼ºó¸´ÖÆ

ÎÒÃÇÀ´¿´Ò»ÏÂÖ´ÐÐЧ¹û£º

$ awk -f cal.awk score.txtNAME    NO.   MATH  ENGLISH  COMPUTER   TOTAL---------------------------------------------Marry  2143     78       84       77      239Jack   2321     66       78       45      189Tom    2122     48       77       71      196Mike   2537     87       97       95      279Bob    2415     40       57       62      159---------------------------------------------  TOTAL:       319      393      350AVERAGE:     63.80    78.60    70.00

µÇ¼ºó¸´ÖÆ


ÁíÍâһЩʵÀý

AWK µÄ hello world ³ÌÐòΪ£º

BEGIN { print "Hello, world!" }

µÇ¼ºó¸´ÖÆ

ÅÌËãÎļþ¾Þϸ

$ ls -l *.txt | awk '{sum+=$5} END {print sum}'--------------------------------------------------666581

µÇ¼ºó¸´ÖÆ

´ÓÎļþÖÐÕÒ³ö³¤¶È´óÓÚ 80 µÄÐУº

awk 'length>80' log.txt

µÇ¼ºó¸´ÖÆ

´òÓ¡¾Å¾Å³Ë·¨±í

seq 9 | sed 'H;g' | awk -v RS='' '{for(i=1;i<=NF;i++)printf("%dx%d=%d%s", i, NR, i*NR, i==NR?"n":"t")}'

µÇ¼ºó¸´ÖÆ

8.2 sed

Linux sed ÏÂÁîÊÇʹÓýÅÔ­À´´¦ÀíÎı¾Îļþ¡£

sed ¿É×ñÕվ籾µÄÖ¸ÁîÀ´´¦Àí¡¢±à¼­Îı¾Îļþ¡£

Sed Ö÷ÒªÓÃÀ´×Ô¶¯±à¼­Ò»¸ö»ò¶à¸öÎļþ¡¢¼ò»¯¶ÔÎļþµÄÖظ´²Ù×÷¡¢±àдת»»³ÌÐòµÈ¡£

Óï·¨

sed [-hnV][-e<script>][-f<scriptÎļþ>][Îı¾Îļþ]

µÇ¼ºó¸´ÖÆ

²ÎÊý˵Ã÷£º

-e<script>»ò–expression=<script><span style=”outline: 0px;”> </span>ÒÔÑ¡ÏîÖÐÖ¸¶¨µÄscriptÀ´´¦ÀíÊäÈëµÄÎı¾Îļþ¡£</p></li><li style=”margin: 2px 10px;outline: 0px;”><p style=”outline: 0px;”>-f</p><script style=”outline: 0px;”>»ò¨Cfile=<scriptÎļþ style=”outline: 0px;”>ÒÔÑ¡ÏîÖÐÖ¸¶¨µÄscriptÎļþÀ´´¦ÀíÊäÈëµÄÎı¾Îļþ¡£</script>Îļþ>Îļþ>

-h»ò¨Chelp ÏÔʾ×ÊÖú¡£

-n»ò¨Cquiet»ò¨Csilent ½öÏÔʾscript´¦ÀíºóµÄЧ¹û¡£

-V»ò¨Cversion ÏÔʾ°æ±¾ÐÅÏ¢¡£

Ðж¯ËµÃ÷£º

a £ºÐÂÔö £¬ a µÄºóÃæ¿ÉÒÔ½Ó×Ö´® £¬¶øÕâЩ×Ö´®»áÔÚеÄÒ»ÐзºÆð(ÏÖÔÚµÄÏÂÒ»ÐÐ)¡«

c £ºÈ¡´ú £¬ c µÄºóÃæ¿ÉÒÔ½Ó×Ö´® £¬ÕâЩ×Ö´®¿ÉÒÔÈ¡´ú n1,n2 Ö®¼äµÄÐУ¡

d £ºÉ¾³ý £¬ÓÉÓÚÊÇɾ³ý°¡ £¬ÒÔÊÇ d ºóÃæͨ³£²»½ÓÈκÎßËßË£»

i £º²åÈë £¬ i µÄºóÃæ¿ÉÒÔ½Ó×Ö´® £¬¶øÕâЩ×Ö´®»áÔÚеÄÒ»ÐзºÆð(ÏÖÔÚµÄÉÏÒ»ÐÐ)£»

p £º´òÓ¡ £¬Ò༴½«Ä³¸öÑ¡ÔñµÄÊý¾ÝÓ¡³ö¡£Í¨³£ p »áÓë²ÎÊý sed -n Ò»ÆðÔËÐС«

s £ºÈ¡´ú £¬¿ÉÒÔÖ±½Ó¾ÙÐÐÈ¡´úµÄÊÂÇéÁ¨£¡Í¨³£Õâ¸ö s µÄÐж¯¿ÉÒÔ´îÅäÕý¹æÌåÏÖ·¨£¡ÀýÈç 1,20s/old/new/g ¾ÍÊÇÀ²£¡

ʵÀý

ÔÚtestfileÎļþµÄµÚËÄÐкóÌí¼ÓÒ»ÐÐ £¬²¢½«Ð§¹ûÊä³öµ½±ê×¼Êä³ö £¬ÔÚÏÂÁîÐÐÌáÐÑ·ûÏÂÊäÈëÈçÏÂÏÂÁ

sed -e 4anewLine testfile

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

Ê×ÏÈÉó²étestfileÖеÄÄÚÈÝÈçÏ£º

$ cat testfile #Éó²étestfile ÖеÄÄÚÈÝ  HELLO LINUX!  Linux is a free unix-type opterating system.  This is a linux testfile!  Linux test

µÇ¼ºó¸´ÖÆ

ʹÓÃsedÏÂÁîºó £¬Êä³öЧ¹ûÈçÏ£º

$ sed -e 4anewline testfile #ʹÓÃsed ÔÚµÚËÄÐкóÌí¼ÓÐÂ×Ö·û´®  HELLO LINUX! #testfileÎļþÔ­ÓеÄÄÚÈÝ  Linux is a free unix-type opterating system.  This is a linux testfile!  Linux test  newline

µÇ¼ºó¸´ÖÆ

ÒÔÐÐΪµ¥Î»µÄÐÂÔö/ɾ³ý

½« /etc/passwd µÄÄÚÈÝÁгö²¢ÇÒÁÐÓ¡ÐкÅ £¬Í¬Ê± £¬Ç뽫µÚ 2~5 ÐÐɾ³ý£¡

[root@www ~] nl /etc/passwd | sed '2,5d'1 root:x:0:0:root:/root:/bin/bash6 sync:x:5:0:sync:/sbin:/bin/sync7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown.....(ºóÃæÊ¡ÂÔ).....

µÇ¼ºó¸´ÖÆ

sed µÄÐж¯Îª ¡®2,5d¡¯  £¬Ë­ÈË d ¾ÍÊÇɾ³ý£¡ÓÉÓÚ 2-5 ÐиøËûɾ³ýÁË £¬ÒÔÊÇÏÔʾµÄÊý¾Ý¾ÍûÓÐ 2-5 ÐÐÂÞ¡« ÁíÍâ £¬×¢ÖØһϠ£¬Ô­±¾Ó¦¸ÃÊÇҪϴï sed -e ²Å¶Ô £¬Ã»ÓÐ -e Ò²ÐÐÀ²£¡Í¬Ê±Ò²Òª×¢ÖصÄÊÇ £¬ sed ºóÃæ½ÓµÄÐж¯ £¬ÇëÎñ±ØÒÔ ¡®¡¯ Á½¸öµ¥ÒýºÅÀ¨×¡à¸£¡

ֻҪɾ³ýµÚ 2 ÐÐ

nl /etc/passwd | sed '2d'

µÇ¼ºó¸´ÖÆ

Ҫɾ³ýµÚ 3 µ½×îºóÒ»ÐÐ

nl /etc/passwd | sed '3,$d'

µÇ¼ºó¸´ÖÆ

ÔÚµÚ¶þÐкó(Ò༴ÊǼÓÔÚµÚÈýÐÐ)¼ÓÉÏ¡ºdrink tea?¡»×ÖÑù£¡

[root@www ~] nl /etc/passwd | sed '2a drink tea'1 root:x:0:0:root:/root:/bin/bash2 bin:x:1:1:bin:/bin:/sbin/nologindrink tea3 daemon:x:2:2:daemon:/sbin:/sbin/nologin.....(ºóÃæÊ¡ÂÔ).....

µÇ¼ºó¸´ÖÆ

ÄÇÈôÊÇÊÇÒªÔÚµÚ¶þÐÐÇ°

nl /etc/passwd | sed '2i drink tea'

µÇ¼ºó¸´ÖÆ

ÈôÊÇÊÇÒªÔöÌíÁ½ÐÐÒÔÉÏ £¬ÔÚµÚ¶þÐкóÃæ¼ÓÈëÁ½ÐÐ×Ö £¬ÀýÈç Drink tea or ¡­ Óë drink beer?

[root@www ~] nl /etc/passwd | sed '2a Drink tea or ......> drink beer ?'1 root:x:0:0:root:/root:/bin/bash2 bin:x:1:1:bin:/bin:/sbin/nologinDrink tea or ......drink beer ?3 daemon:x:2:2:daemon:/sbin:/sbin/nologin.....(ºóÃæÊ¡ÂÔ).....

µÇ¼ºó¸´ÖÆ

ÿһÐÐÖ®¼ä¶¼±ØÐèÒªÒÔ·´Ð±¸Ü¡º ¡»À´¾ÙÐÐÐÂÐеÄÌí¼Óร¡ÒÔÊÇ £¬ÉÏÃæµÄÀý×ÓÖÐ £¬ÎÒÃÇ¿ÉÒÔ·¢Ã÷ÔÚµÚÒ»ÐеÄ×îºóÃæ¾ÍÓÐ ±£´æ¡£

ÒÔÐÐΪµ¥Î»µÄÌæ»»ÓëÏÔʾ

½«µÚ2-5ÐеÄÄÚÈÝÈ¡´ú³ÉΪ¡ºNo 2-5 number¡»ÄØ£¿

[root@www ~] nl /etc/passwd | sed '2,5c No 2-5 number'1 root:x:0:0:root:/root:/bin/bashNo 2-5 number6 sync:x:5:0:sync:/sbin:/bin/sync.....(ºóÃæÊ¡ÂÔ).....

µÇ¼ºó¸´ÖÆ

͸¹ýÕâ¸öÒªÁìÎÒÃǾÍÄܹ»½«Êý¾ÝÕûÐÐÈ¡´úÁË£¡

½öÁгö /etc/passwd ÎļþÄÚµÄµÚ 5-7 ÐÐ

[root@www ~] nl /etc/passwd | sed -n '5,7p'5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin6 sync:x:5:0:sync:/sbin:/bin/sync7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

µÇ¼ºó¸´ÖÆ

¿ÉÒÔ͸¹ýÕâ¸ö sed µÄÒÔÐÐΪµ¥Î»µÄÏÔʾ¹¦Ð§ £¬ ¾ÍÄܹ»½«Ä³Ò»¸öÎļþÄÚµÄijЩÐкÅÑ¡Ôñ³öÀ´ÏÔʾ¡£

Êý¾ÝµÄÕ÷²É²¢ÏÔʾ

ËÑË÷ /etc/passwdÓÐrootÒªº¦×ÖµÄÐÐ

nl /etc/passwd | sed '/root/p'1  root:x:0:0:root:/root:/bin/bash1  root:x:0:0:root:/root:/bin/bash2  daemon:x:1:1:daemon:/usr/sbin:/bin/sh3  bin:x:2:2:bin:/bin:/bin/sh4  sys:x:3:3:sys:/dev:/bin/sh5  sync:x:4:65534:sync:/bin:/bin/sync....ÏÂÃæºöÂÔ

µÇ¼ºó¸´ÖÆ

ÈôÊÇrootÕÒµ½ £¬³ýÁËÊä³öËùÓÐÐÐ £¬»¹»áÊä³öÆ¥ÅäÐС£

ʹÓÃ-nµÄʱ¼ä½«Ö»´òÓ¡°üÀ¨Ä£°åµÄÐС£

nl /etc/passwd | sed -n '/root/p'1  root:x:0:0:root:/root:/bin/bash

µÇ¼ºó¸´ÖÆ

Êý¾ÝµÄÕ÷²É²¢É¾³ý

ɾ³ý/etc/passwdËùÓаüÀ¨rootµÄÐÐ £¬ÆäËûÐÐÊä³ö

nl /etc/passwd | sed  '/root/d'2  daemon:x:1:1:daemon:/usr/sbin:/bin/sh3  bin:x:2:2:bin:/bin:/bin/sh....ÏÂÃæºöÂÔ#µÚÒ»ÐеÄÆ¥ÅärootÒѾ­É¾³ýÁË

µÇ¼ºó¸´ÖÆ

Êý¾ÝµÄÕ÷²É²¢Ö´ÐÐÏÂÁî

ËÑË÷/etc/passwd,ÕÒµ½root¶ÔÓ¦µÄÐÐ £¬Ö´ÐкóÃ滨À¨ºÅÖеÄÒ»×éÏÂÁî £¬Ã¿¸öÏÂÁîÖ®¼äÓ÷ֺÅÍÑÀë £¬ÕâÀï°ÑbashÌ滻Ϊblueshell £¬ÔÙÊä³öÕâÐУº

nl /etc/passwd | sed -n '/root/{s/bash/blueshell/;p;q}'    1  root:x:0:0:root:/root:/bin/blueshell

µÇ¼ºó¸´ÖÆ

×îºóµÄqÊÇÍ˳ö¡£

Êý¾ÝµÄÕ÷²É²¢Ìæ»»

³ýÁËÕûÐеĴ¦Àíģʽ֮Íâ £¬ sed »¹¿ÉÒÔÓÃÐÐΪµ¥Î»¾ÙÐв¿·ÖÊý¾ÝµÄÕ÷²É²¢È¡´ú¡£»ù±¾ÉÏ sed µÄÕ÷²ÉÓëÌæ»»µÄÓë vi Ï൱µÄÀàËÆ£¡ËûÓеãÏñÕâÑù£º

sed 's/Òª±»È¡´úµÄ×Ö´®/еÄ×Ö´®/g'

µÇ¼ºó¸´ÖÆ

ÏÈÊÓ²ìԭʼÐÅÏ¢ £¬Ê¹Óà /sbin/ifconfig ÅÌÎÊ IP

[root@www ~] /sbin/ifconfig eth0eth0 Link encap:Ethernet HWaddr 00:90:CC:A6:34:84inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0inet6 addr: fe80::290:ccff:fea6:3484/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1.....(ÒÔÏÂÊ¡ÂÔ).....

µÇ¼ºó¸´ÖÆ

±¾»úµÄipÊÇ192.168.1.100¡£

½« IP Ç°ÃæµÄ²¿·ÖÓèÒÔɾ³ý

[root@www ~] /sbin/ifconfig eth0 | grep 'inet addr' | sed 's/^.*addr://g'192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0

µÇ¼ºó¸´ÖÆ

½ÓÏÂÀ´ÔòÊÇɾ³ýºóÐøµÄ²¿·Ö £¬Ò༴£º192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0

½« IP ºóÃæµÄ²¿·ÖÓèÒÔɾ³ý

[root@www ~] /sbin/ifconfig eth0 | grep 'inet addr' | sed 's/^.*addr://g' | sed 's/Bcast.*$//g'192.168.1.100

µÇ¼ºó¸´ÖÆ

¶àµã±à¼­

Ò»ÌõsedÏÂÁî £¬É¾³ý/etc/passwdµÚÈýÐе½Ä©Î²µÄÊý¾Ý £¬²¢°ÑbashÌ滻Ϊblueshell

nl /etc/passwd | sed -e '3,$d' -e 's/bash/blueshell/'1  root:x:0:0:root:/root:/bin/blueshell2  daemon:x:1:1:daemon:/usr/sbin:/bin/sh

µÇ¼ºó¸´ÖÆ

-eÌåÏÖ¶àµã±à¼­ £¬µÚÒ»¸ö±à¼­ÏÂÁîɾ³ý/etc/passwdµÚÈýÐе½Ä©Î²µÄÊý¾Ý £¬µÚ¶þÌõÏÂÁîËÑË÷bashÌ滻Ϊblueshell¡£

Ö±½ÓÐÞ¸ÄÎļþÄÚÈÝ(ΣÏÕÐж¯)

sed ¿ÉÒÔÖ±½ÓÐÞ¸ÄÎļþµÄÄÚÈÝ £¬²»±ØʹÓùܵÀÏÂÁî»òÊý¾ÝÁ÷Öص¼Ïò£¡²»¹ý £¬ÓÉì¶Õâ¸öÐж¯»áÖ±½ÓÐ޸ĵ½Ô­Ê¼µÄÎļþ £¬ÒÔÊÇÇëÄãÍòÍò²»ÒªËæ±ãÄÃϵͳÉèÖÃÀ´²âÊÔ£¡ÎÒÃÇÕÕ¾ÉʹÓÃÎļþ regular_express.txt ÎļþÀ´²âÊÔ¿´¿´°É£¡

regular_express.txt ÎļþÄÚÈÝÈçÏ£º

[root@www ~] cat regular_express.txt runoob.google.taobao.facebook.zhihu-weibo-

µÇ¼ºó¸´ÖÆ

ʹÓà sed ½« regular_express.txt ÄÚÿһÐÐ×îºóÈôΪ . Ôò»»³É !

[root@www ~] sed -i 's/.$/!/g' regular_express.txt[root@www ~] cat regular_express.txt runoob!google!taobao!facebook!zhihu-weibo-

µÇ¼ºó¸´ÖÆ

:q:q

ʹÓà sed Ö±½ÓÔÚ regular_express.txt ×îºóÒ»ÐмÓÈë # This is a test:

[root@www ~] sed -i '$a # This is a test' regular_express.txt[root@www ~] cat regular_express.txt runoob!google!taobao!facebook!zhihu-weibo-# This is a test

µÇ¼ºó¸´ÖÆ

ÓÉì¶ $ ´ú±íµÄÊÇ×îºóÒ»ÐÐ £¬¶ø a µÄÐж¯ÊÇÐÂÔö £¬Òò´Ë¸ÃÎļþ×îºóÐÂÔö # This is a test£¡

sed µÄ -i Ñ¡Ïî¿ÉÒÔÖ±½ÓÐÞ¸ÄÎļþÄÚÈÝ £¬Õ⹦ЧºÜÊÇÓÐ×ÊÖú£¡¾ÙÀýÀ´Ëµ £¬ÈôÊÇÄãÓÐÒ»¸ö 100 ÍòÐеÄÎļþ £¬ÄãÒªÔÚµÚ 100 ÐмÓijЩÎÄ×Ö £¬´ËʱʹÓà vim ¿ÉÄÜ»á·èµô£¡ÓÉÓÚÎļþÌ«´óÁË£¡ÄÇÔõ°ì£¿¾ÍʹÓà sed °¡£¡Í¸¹ý sed Ö±½ÓÐÞ¸Ä/È¡´úµÄ¹¦Ð§ £¬ÄãÉõÖÁ²»ÐèҪʹÓà vim È¥ÐÞ¶©£¡

×·¼ÓÐеÄ˵Ã÷£º

sed -e 4anewLine testfile

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

a Ðж¯ÊÇÔÚÆ¥ÅäµÄÐÐÖ®ºó×·¼Ó×Ö·û´® £¬×·¼ÓµÄ×Ö·û´®ÖпÉÒÔ°üÀ¨»»Ðзû£¨ÊµÏÖ×·¼Ó¶àÐеÄÇéÐΣ©¡£

×·¼ÓÒ»ÐеĻ°Ç°ºó¶¼²»ÐèÒªÌí¼Ó»»Ðзû n £¬Ö»ÓÐ×·¼Ó¶àÐÐʱÔÚÐÐÓëÐÐÖ®¼ä²ÅÐèÒªÌí¼Ó»»Ðзû(×îºóÒ»ÐÐ×îºóÒ²ÎÞÐèÌí¼Ó £¬Ìí¼ÓµÄ»°»á¶à³öÒ»¸ö¿ÕÐÐ)¡£

man sed ÐÅÏ¢£º

Append text, which has each embedded newline preceded by a backslash.

µÇ¼ºó¸´ÖÆ

ÀýÈ磺

4 ÐÐÖ®ºóÌí¼ÓÒ»ÐУº

sed -e '4 a newline' testfile

µÇ¼ºó¸´ÖÆ

4 ÐÐÖ®ºó×·¼Ó 2 ÐУº

sed -e '4 a newlinennewline2' testfile

µÇ¼ºó¸´ÖÆ

4 ÐÐÖ®ºó×·¼Ó 3 ÐÐ(2 ÐÐÎÄ×ÖºÍ 1 ÐпÕÐÐ)

sed -e '4 a newlinennewline2n' testfile

µÇ¼ºó¸´ÖÆ

4 ÐÐÖ®ºó×·¼Ó 1 ÐпÕÐУº

#¹ýʧ£ºsed -e '4 a n' testfilesed -e '4 a  ' testfile ÏÖʵÉÏ

µÇ¼ºó¸´ÖÆ

ÏÖʵÉÏÊDzåÈëÁËÒ»¸öº¬ÓÐÒ»¸ö¿Õ¸ñµÄÐÐ £¬²åÈëÒ»¸öÍêȫΪ¿ÕµÄ¿ÕÐÐûÓÐÕÒµ½ÒªÁ죨²»¹ýÓ¦¸ÃûÓÐÕâ¸öÐèÇó°É £¬¶¼Òª²åÈëÐÐÁ˲åÈë¿ÕÐиÉÂïÄØ£¿£©

Ìí¼Ó¿ÕÐУº

# ¿ÉÒÔÌí¼ÓÒ»¸öÍêȫΪ¿ÕµÄ¿ÕÐÐsed '4 a \'# ¿ÉÒÔÌí¼ÓÁ½¸öÍêȫΪ¿ÕµÄ¿ÕÐÐsed '4 a \n'

µÇ¼ºó¸´ÖÆ

8.3 grep

Linux grep ÏÂÁîÓÃÓÚ²éÕÒÎļþÀïÇкÏÌõ¼þµÄ×Ö·û´®¡£

grep Ö¸ÁîÓÃÓÚ²éÕÒÄÚÈÝ°üÀ¨Ö¸¶¨µÄ·¶±¾ÑùʽµÄÎļþ £¬ÈôÊÇ·¢Ã÷ijÎļþµÄÄÚÈÝÇкÏËùÖ¸¶¨µÄ·¶±¾Ñùʽ £¬Ô¤Éè grep Ö¸Áî»á°Ñº¬Ó綱¾ÑùʽµÄÄÇÒ»ÁÐÏÔʾ³öÀ´¡£Èô²»Ö¸¶¨ÈκÎÎļþÃû³Æ £¬»òÊÇËù¸øÓèµÄÎļþÃûΪ  £¬Ôò grep Ö¸Áî»á´Ó±ê×¼ÊäÈë×°±¸¶ÁÈ¡Êý¾Ý¡£

Óï·¨

grep [-abcEFGhHilLnqrsvVwxy][-A<ÏÔʾÁÐÊý>][-B<ÏÔʾÁÐÊý>][-C<ÏÔʾÁÐÊý>][-d<¾ÙÐÐÐж¯>][-e<·¶±¾Ñùʽ>][-f<·¶±¾Îļþ>][--help][·¶±¾Ñùʽ][Îļþ»òĿ¼...]

µÇ¼ºó¸´ÖÆ

²ÎÊý£º

-a »ò ¡ªtext : ²»ÒªºöÂÔ¶þ½øÖƵÄÊý¾Ý¡£

-A »ò ¡ªafter-context= : ³ýÁËÏÔʾÇкϷ¶±¾ÑùʽµÄÄÇÒ»ÁÐÖ®Íâ £¬²¢ÏÔʾ¸ÃÐÐÖ®ºóµÄÄÚÈÝ¡£

-b »ò ¡ªbyte-offset : ÔÚÏÔʾÇкÏÑùʽµÄÄÇÒ»ÐÐ֮ǰ £¬±êʾ³ö¸ÃÐеÚÒ»¸ö×Ö·ûµÄ±àºÅ¡£

-B »ò ¡ªbefore-context= : ³ýÁËÏÔʾÇкÏÑùʽµÄÄÇÒ»ÐÐÖ®Íâ £¬²¢ÏÔʾ¸ÃÐÐ֮ǰµÄÄÚÈÝ¡£

-c »ò ¡ªcount : ÅÌËãÇкÏÑùʽµÄÁÐÊý¡£

-C »ò ¡ªcontext= »ò- : ³ýÁËÏÔʾÇкÏÑùʽµÄÄÇÒ»ÐÐÖ®Íâ £¬²¢ÏÔʾ¸ÃÐÐ֮ǰºóµÄÄÚÈÝ¡£

-d »ò ¡ªdirectories= : µ±Ö¸¶¨Òª²éÕÒµÄÊÇĿ¼¶ø·ÇÎļþʱ £¬±ØÐèʹÓÃÕâÏî²ÎÊý £¬²»È»grepÖ¸Á»Ø±¨ÐÅÏ¢²¢×èÖ¹Ðж¯¡£

-e »ò ¡ªregexp= : Ö¸¶¨×Ö·û´®×öΪ²éÕÒÎļþÄÚÈݵÄÑùʽ¡£

-E »ò ¡ªextended-regexp : ½«ÑùʽΪÑÓÉìµÄÕýÔò±í´ïʽÀ´Ê¹Óá£

-f »ò ¡ªfile= : Ö¸¶¨¹æÔòÎļþ £¬ÆäÄÚÈݺ¬ÓÐÒ»¸ö»ò¶à¸ö¹æÔòÑùʽ £¬ÈÃgrep²éÕÒÇкϹæÔòÌõ¼þµÄÎļþÄÚÈÝ £¬ÃûÌÃΪÿÐÐÒ»¸ö¹æÔòÑùʽ¡£

-F »ò ¡ªfixed-regexp : ½«ÑùʽÊÓΪÀο¿×Ö·û´®µÄÁбí¡£

-G »ò ¡ªbasic-regexp : ½«ÑùʽÊÓΪͨË×µÄÌåÏÖ·¨À´Ê¹Óá£

-h »ò ¡ªno-filename : ÔÚÏÔʾÇкÏÑùʽµÄÄÇÒ»ÐÐ֮ǰ £¬²»±êʾ¸ÃÐÐËùÊôµÄÎļþÃû³Æ¡£

-H »ò ¡ªwith-filename : ÔÚÏÔʾÇкÏÑùʽµÄÄÇÒ»ÐÐ֮ǰ £¬ÌåÏÖ¸ÃÐÐËùÊôµÄÎļþÃû³Æ¡£

-i »ò ¡ªignore-case : ºöÂÔ×Ö·û¾ÞϸдµÄ²î±ð¡£

-l »ò ¡ªfile-with-matches : ÁгöÎļþÄÚÈÝÇкÏÖ¸¶¨µÄÑùʽµÄÎļþÃû³Æ¡£

-L »ò ¡ªfiles-without-match : ÁгöÎļþÄÚÈݲ»ÇкÏÖ¸¶¨µÄÑùʽµÄÎļþÃû³Æ¡£

-n »ò ¡ªline-number : ÔÚÏÔʾÇкÏÑùʽµÄÄÇÒ»ÐÐ֮ǰ £¬±êʾ³ö¸ÃÐеÄÁÐÊý±àºÅ¡£

-o »ò ¡ªonly-matching : Ö»ÏÔʾƥÅäPATTERN ²¿·Ö¡£

-q »ò ¡ªquiet»ò¨Csilent : ²»ÏÔʾÈκÎÐÅÏ¢¡£

-r »ò ¡ªrecursive : ´Ë²ÎÊýµÄЧ¹ûºÍÖ¸¶¨¡±-d recurse¡±²ÎÊýÏàͬ¡£

-s »ò ¡ªno-messages : ²»ÏÔʾ¹ýʧÐÅÏ¢¡£

-v »ò ¡ªrevert-match : ÏÔʾ²»°üÀ¨Æ¥ÅäÎı¾µÄËùÓÐÐС£

-V »ò ¡ªversion : ÏÔʾ°æ±¾ÐÅÏ¢¡£

-w »ò ¡ªword-regexp : Ö»ÏÔʾȫ×ÖÇкϵÄÁС£

-x ¡ªline-regexp : Ö»ÏÔʾȫÁÐÇкϵÄÁС£

-y : ´Ë²ÎÊýµÄЧ¹ûºÍÖ¸¶¨¡±-i¡±²ÎÊýÏàͬ¡£

ʵÀý

1¡¢ÔÚÄ¿½ñĿ¼ÖÐ £¬²éÕÒºó׺ÓÐ file ×ÖÑùµÄÎļþÖаüÀ¨ test ×Ö·û´®µÄÎļþ £¬²¢´òÓ¡³ö¸Ã×Ö·û´®µÄÐС£´Ëʱ £¬¿ÉÒÔʹÓÃÈçÏÂÏÂÁ

grep test *file

µÇ¼ºó¸´ÖÆ

Ч¹ûÈçÏÂËùʾ£º

$ grep test test* #²éÕÒǰ׺ÓС°test¡±µÄÎļþ°üÀ¨¡°test¡±×Ö·û´®µÄÎļþ  testfile1:This a Linux testfile! #Áгötestfile1 ÎļþÖаüÀ¨test×Ö·ûµÄÐÐ  testfile_2:This is a linux testfile! #Áгötestfile_2 ÎļþÖаüÀ¨test×Ö·ûµÄÐÐ  testfile_2:Linux test #Áгötestfile_2 ÎļþÖаüÀ¨test×Ö·ûµÄÐÐ

µÇ¼ºó¸´ÖÆ

2¡¢ÒԵݹéµÄ·½·¨²éÕÒÇкÏÌõ¼þµÄÎļþ¡£ÀýÈç £¬²éÕÒÖ¸¶¨Ä¿Â¼/etc/acpi ¼°Æä×ÓĿ¼£¨ÈôÊDZ£´æ×ÓĿ¼µÄ»°£©ÏÂËùÓÐÎļþÖаüÀ¨×Ö·û´®¡±update¡±µÄÎļþ £¬²¢´òÓ¡³ö¸Ã×Ö·û´®ËùÔÚÐеÄÄÚÈÝ £¬Ê¹ÓõÄÏÂÁîΪ£º

grep -r update /etc/acpi

µÇ¼ºó¸´ÖÆ

Êä³öЧ¹ûÈçÏ£º

$ grep -r update /etc/acpi #ÒԵݹéµÄ·½·¨²éÕÒ¡°etc/acpi¡±  #Ï°üÀ¨¡°update¡±µÄÎļþ  /etc/acpi/ac.d/85-anacron.sh:# (Things like the slocate updatedb cause a lot of IO.)  Rather than  /etc/acpi/resume.d/85-anacron.sh:# (Things like the slocate updatedb cause a lot of  IO.) Rather than  /etc/acpi/events/thinkpad-cmos:action=/usr/sbin/thinkpad-keys--update

µÇ¼ºó¸´ÖÆ

3¡¢·´Ïò²éÕÒ¡£Ç°Ãæ¸÷¸öÀý×ÓÊDzéÕÒ²¢´òÓ¡³öÇкÏÌõ¼þµÄÐÐ £¬Í¨¹ý¡±-v¡±²ÎÊý¿ÉÒÔ´òÓ¡³ö²»ÇкÏÌõ¼þÐеÄÄÚÈÝ¡£

²éÕÒÎļþÃûÖаüÀ¨ test µÄÎļþÖв»°üÀ¨test µÄÐÐ £¬´Ëʱ £¬Ê¹ÓõÄÏÂÁîΪ£º

grep -v test *test*

µÇ¼ºó¸´ÖÆ

Ч¹ûÈçÏÂËùʾ£º

$ grep-v test* #²éÕÒÎļþÃûÖаüÀ¨test µÄÎļþÖв»°üÀ¨test µÄÐÐ  testfile1:helLinux!  testfile1:Linis a free Unix-type operating system.  testfile1:Lin  testfile_1:HELLO LINUX!  testfile_1:LINUX IS A FREE UNIX-TYPE OPTERATING SYSTEM.  testfile_1:THIS IS A LINUX TESTFILE!  testfile_2:HELLO LINUX!  testfile_2:Linux is a free unix-type opterating system.

µÇ¼ºó¸´ÖÆ

ÒÔÉϾÍÊÇLinuxÏÂÁî´óÈ«µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

13452372176

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ