Linux¹ÜµÀµÄÔÀíÓëÓ¦ÓÃ
Linux ¹ÜµÀµÄÔÀíÓëÓ¦ÓÃ
ÔÚ Linux ϵͳÖУ¬¹ÜµÀ£¨Pipe£©ÊÇÒ»ÖÖºÜÊÇÇ¿Ê¢ÇÒ³£ÓõĿ´·¨£¬ËüÔÊÐí½«Ò»¸öÏÂÁîµÄÊä³ö×÷ΪÁíÒ»¸öÏÂÁîµÄÊäÈ룬´Ó¶øʵÏÖÏÂÁîÖ®¼äµÄÊý¾Ý´«ÊäºÍÐ×÷¡£¹ÜµÀµÄʹÓÃÄܹ»¼«´óµØÌá¸ßÏÂÁîÖ®¼äµÄÎÞаÐÔºÍЧÂÊ£¬ÎªÏµÍ³ÖÎÀíºÍÊý¾Ý´¦ÀíÌṩÁ˱㵱¡£
1. ¹ÜµÀµÄÔÀí
ÔÚ Linux ÖУ¬¹ÜµÀͨ¹ý½¨ÉèÒ»¸öÔÝʱÎļþÐÎò·û£¬Ê¹µÃÒ»¸öÀú³ÌµÄÊä³öÓëÁíÒ»¸öÀú³ÌµÄÊäÈëÏàÅþÁ¬¡£ÏêϸµÄÔÀíÈçÏ£º
ÔÚÏÂÁîÐÐÖÐʹÓÃÊúÏß·ûºÅ¡°|¡±À´ÅþÁ¬Á½¸öÏÂÁ½«Ç°Ò»¸öÏÂÁîµÄ±ê×¼Êä³öÓëºóÒ»¸öÏÂÁîµÄ±ê×¼ÊäÈëÏàÁ¬¡£
¹ÜµÀÊÇ»ùÓÚÄÚºËÖеĻ·Ðλº³åÇøʵÏֵģ¬ËüÔÊÐíÊý¾ÝÔÚ²î±ðÀú³ÌÖ®¼äת´ï£¬¶øÎÞÐèÔÚ´ÅÅÌÉÏ´æ´¢ÖÐÐÄÊý¾Ý¡£
ÿ¸ö¹ÜµÀ¶¼ÓÐÒ»¸ö¶Á¶ËºÍÒ»¸öд¶Ë£¬Ò»¸öÀú³ÌÏò¹ÜµÀµÄд¶ËдÈëÊý¾Ý£¬ÁíÒ»¸öÀú³Ì´Ó¹ÜµÀµÄ¶Á¶Ë¶ÁÈ¡Êý¾Ý¡£
2. ¹ÜµÀµÄÓ¦ÓÃ
2.1 Êý¾Ý´¦Àí
cat data.txt | grep "keyword" | sort | uniq
µÇ¼ºó¸´ÖÆ
ÉÏÃæµÄÏÂÁ¶ÁÈ¡ data.txt ÎļþµÄÄÚÈÝ£¬È»ºóͨ¹ý grep ɸѡ°üÀ¨Ö¸¶¨Òªº¦´ÊµÄÐУ¬ÔÙͨ¹ý sort ¶ÔÐоÙÐÐÅÅÐò£¬×îºóͨ¹ý uniq È¥ÖØ¡£
2.2 Àú³ÌÐ×÷
ps aux | grep "firefox"
µÇ¼ºó¸´ÖÆ
Õâ¸öÀý×ÓÖУ¬ps aux ÏÂÁÁгöÄ¿½ñϵͳÀú³ÌÐÅÏ¢£¬È»ºó½«ÐÅϢת´ï¸ø grep ÏÂÁÓÃÓÚ²éÕÒ°üÀ¨Òªº¦´Ê¡°firefox¡±µÄÀú³Ì¡£
3. ¹ÜµÀµÄ´úÂëʾÀý
ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄʾÀý£¬ÑÝʾÔõÑùÔÚ Shell ¾ç±¾ÖÐʹÓùܵÀ£º
#!/bin/bash # ÌìÉúËæ»úÊý echo "Generating 10 random numbers:" seq 10 | shuf # ´ÓÌìÉúµÄËæ»úÊýÖÐÕÒµ½×î´óÖµ echo "Finding the maximum number:" seq 10 | shuf | sort -nr | head -n 1
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸ö¾ç±¾ÖУ¬Ê×ÏÈʹÓà seq 10 ÌìÉú 1 µ½ 10 µÄÊý×ÖÐòÁУ¬È»ºóͨ¹ý shuf Ëæ»úÅÅÐòÕâЩÊý×Ö¡£½ÓÏÂÀ´£¬ÔÙͨ¹ý sort ¶ÔËæ»úÅÅÐòºóµÄÊý×Ö¾ÙÐе¹ÐòÅÅÐò£¬×îºóʹÓà head ÏÂÁî»ñÈ¡ÅÅÐòºóµÄµÚÒ»¸ö¼´×î´óµÄÊý×Ö¡£
ͨ¹ý¹ÜµÀµÄ·½·¨£¬ÎÒÃÇ¿ÉÒÔʵÏÖ¶ÔÊý¾ÝµÄ´¦ÀíºÍת´ï£¬¼«´óµØÔöÇ¿ÁË Shell ¾ç±¾µÄ¹¦Ð§ºÍÎÞаÐÔ¡£
½áÓï
Linux ¹ÜµÀÊÇÒ»¸öºÜÊÇÇ¿Ê¢µÄ¹¦Ð§£¬¿ÉÒÔ¼«´óµØÌá¸ßÏÂÁîÐвÙ×÷µÄЧÂʺͱ㵱ÐÔ¡£ÕÆÎչܵÀµÄÔÀíºÍÓ¦ÓÿÉÒÔÈÃÄã¸üºÃµØʹÓà Linux ϵͳ¾ÙÐÐÊý¾Ý´¦ÀíºÍ²Ù×÷£¬Ï£Íû±¾ÎĶÔÄãÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇLinux¹ÜµÀµÄÔÀíÓëÓ¦ÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡