锘??xml version="1.0" encoding="utf-8" standalone="yes"?> http://blog.csdn.net/mark_qi/article/details/7919498 棣栧厛鍒涘緩鎴戜滑緇冧範grep鍛戒護鏃墮渶瑕佺敤鍒扮殑demo鏂囦歡demo_file銆?pre>$ cat demo_file grep鐨勫熀紜鐢ㄦ硶鏄涓嬩緥鐨勪粠鎸囧畾鐨勬枃浠朵腑鎼滅儲鐗瑰畾鐨勫瓧涓層?pre>璇硶錛?br>grep "literal_string" filename 鍏堟嫹璐漝emo_file涓篸emo_file1銆俫rep鐨勭粨鏋滃湪絎﹀悎鏉′歡鐨勮鍓嶅皢鍖呮嫭鏂囦歡鍚嶃傚綋鏂囦歡鍚嶅寘鍚厓瀛楃鏃訛紝linux shell浼氬皢鍖歸厤鐨勬墍鏈夋枃浠朵綔涓鴻緭鍏ュ埌grep涓幓銆?pre>$ cp demo_file demo_file1 涔熸槸涓涓熀鏈敤娉曪紝瀵規悳绱㈢殑瀛椾覆蹇界暐澶у皬鍐欙紝鍥犳涓嬩緥涓尮閰嶁渢he鈥? 鈥淭HE鈥?and 鈥淭he鈥濄?pre>$ grep -i "the" demo_file 濡傛灉浣犺兘鏈夋晥鍦板埄鐢ㄦ鍒欒〃杈懼紡錛岃繖鏄釜寰堟湁鐢ㄧ殑鐗圭偣銆傚湪涓嬮潰鐨勪緥瀛愪腑錛屾悳绱㈠叏閮ㄤ互鈥渓ines鈥濆紑濮嬩互鈥渆mpty鈥濈粨鏉熺殑瀛椾覆錛屽鎼滅儲鈥渓ines[涔嬮棿浠繪剰瀛梋empty鈥?錛屽茍涓斿拷鐣ュぇ灝忓啓銆?pre>$ grep -i "lines.*empty" demo_file 姝e垯琛ㄨ揪寮忛伒寰殑鍑犱釜閲嶅鐨勬搷浣?
浣跨敤-w閫夐」鎼滅儲涓涓崟璇嶏紝騫朵笖閬垮厤鎼滅儲鍒拌瘝涓殑閮ㄥ垎瀛椾覆銆?br>涓嬩緥鎼滅儲"is"銆傚鏋滀笉鍔?w閫夐」錛屽皢鏄劇ず鈥渋s鈥? 鈥渉is鈥? 鈥渢his鈥?絳夋墍鏈夊寘鍚渋s鈥濈殑琛屻?pre>$ grep -i "is" demo_file 涓嬩緥浣跨敤浜?w閫夐」錛岃娉ㄦ剰緇撴灉涓笉鍖呭惈 鈥淭his Line Has All Its First Character Of The Word With Upper Case鈥? 铏界劧 鈥淭his鈥濅腑鍖呭惈鈥渋s鈥濄?pre>$ grep -iw "is" demo_file 褰撲嬌鐢╣rep鎼滅儲澶ф枃浠舵椂錛屾樉紺哄尮閰嶈闄勮繎鐨勫琛屾暟鎹槸涓涓緢鏈夌敤鐨勫姛鑳姐?
鍒涘緩濡備笅鏂囦歡 -A 涓嬩緥鏄劇ず鍖歸厤琛屽拰涔嬪悗鐨?琛屾暟鎹?pre>$ grep -A 3 -i "example" demo_text -B 涓嬩緥鏄劇ず鍖歸厤琛屽拰涔嬪墠鐨?琛屾暟鎹?pre>$ grep -B 2 "single WORD" demo_text -C 鏄劇ず涔嬪墠鐨刵琛岋紝涔嬪悗鐨刵琛屾暟鎹? 濡傛灉浣犲笇鏈涙悳绱㈢殑瀛椾覆楂樹寒鏄劇ず鍦ㄧ粨鏋滀腑錛屽彲浠ヨ瘯鐢ㄤ互涓嬬殑鍔炴硶銆?
閫氳繃淇敼GREP_OPTIONS瀵規悳绱㈠瓧涓查珮浜樉紺恒?pre>$ export GREP_OPTIONS='--color=auto' GREP_COLOR='100;8' 濡傛灉鎯蟲煡鎵懼綋鍓嶇洰鍓嶄互鍙婂叾瀛愮洰褰曠殑鍏ㄩ儴鏂囦歡鏃訛紝鍙互浣跨敤 -r 閫夐」銆傚涓嬩緥 鍙互浣跨敤-v閫夐」鏄劇ず涓嶅尮閰嶆悳绱㈠瓧涓茬殑琛屻備笅渚嬫樉紺篸emo_text鏂囦歡涓笉鍖呭惈鈥済o鈥濈殑琛?pre>$ grep -v "go" demo_text 鍒涘緩濡備笅渚嬪瓙鏂囦歡 緇熻涓嶅尮閰嶇殑琛屾暟 緙虹渷鏄劇ず鍖歸厤瀛椾覆鐨勬墍鍦ㄨ錛屽彲浠ヤ嬌鐢?o閫夐」鍙樉紺哄尮閰嶇殑瀛椾覆銆傝繖欏瑰姛鑳藉綋浣跨敤姝e垯琛ㄨ揪寮忔椂姣旇緝鏈夌敤澶勩?
$ grep -o "is.*line" demo_file 娉ㄦ剰: 浠ヤ笂杈撳嚭鏄劇ず鐨勪笉鏄鍐呯殑浣嶇疆錛岃屾槸鏁翠釜鏂囦歡涓殑瀛楄妭byte浣嶇疆
琛屽彿浠?寮濮?pre>$ grep -n "go" demo_text 鐗堟潈鎵鏈夛紝灝婇噸浠栦漢鍔沖姩鎴愭灉錛岃漿杞芥椂璇鋒敞鏄庝綔鑰呭拰鍘熷鍑哄鍙婃湰澹版槑銆?/em> 鍘熸枃鍚嶇О錛氥奡how All Running Processes in Linux銆?/em> 鍘熸枃鍦板潃錛歨ttp://www.cyberciti.biz/faq/show-all-running-processes-in-linux/ 鍦╨inux涓庢牱鏌ョ湅鎵鏈夎繍琛屼腑鐨勮繘紼嬶紵 浣犲彲浠ヤ嬌鐢╬s鍛戒護銆傚畠鑳芥樉紺哄綋鍓嶈繍琛屼腑榪涚▼鐨勭浉鍏充俊鎭紝鍖呮嫭榪涚▼鐨凱ID銆侺inux鍜孶NIX閮芥敮鎸乸s鍛戒護錛屾樉紺烘墍鏈夎繍琛屼腑榪涚▼鐨勭浉鍏充俊鎭俻s鍛戒護鑳芥彁渚涗竴浠藉綋鍓嶈繘紼嬬殑蹇収銆傚鏋滀綘鎯崇姸鎬佸彲浠ヨ嚜鍔ㄥ埛鏂幫紝鍙互浣跨敤top鍛戒護銆? ps鍛戒護 杈撳叆涓嬮潰鐨刾s鍛戒護錛屾樉紺烘墍鏈夎繍琛屼腑鐨勮繘紼嬶細 # ps aux | less 鍏朵腑錛? -A錛氭樉紺烘墍鏈夎繘紼? a錛氭樉紺虹粓绔腑鍖呮嫭鍏跺畠鐢ㄦ埛鐨勬墍鏈夎繘紼? x錛氭樉紺烘棤鎺у埗緇堢鐨勮繘紼? 浠誨姟錛氭煡鐪嬬郴緇熶腑鐨勬瘡涓繘紼嬨? # ps -A # ps -e 浠誨姟錛氭煡鐪嬮潪root榪愯鐨勮繘紼? # ps -U root -u root -N 浠誨姟錛氭煡鐪嬬敤鎴穠ivek榪愯鐨勮繘紼? # ps -u vivek 浠誨姟錛歵op鍛戒護 top鍛戒護鎻愪緵浜嗚繍琛屼腑緋葷粺鐨勫姩鎬佸疄鏃惰鍥俱傚湪鍛戒護鎻愮ず琛屼腑杈撳叆top錛? # top 杈撳嚭錛? 鍥?錛歵op鍛戒護錛氭樉紺篖inux浠誨姟 鎸塹閫鍑猴紝鎸塰榪涘叆甯姪銆? 浠誨姟錛氭樉紺鴻繘紼嬬殑鏍戠姸鍥俱? pstree浠ユ爲鐘舵樉紺烘鍦ㄨ繍琛岀殑榪涚▼銆傛爲鐨勬牴鑺傜偣涓簆id鎴杋nit銆傚鏋滄寚瀹氫簡鐢ㄦ埛鍚嶏紝榪涚▼鏍戝皢浠ョ敤鎴鋒墍鎷ユ湁鐨勮繘紼嬩綔涓烘牴鑺傜偣銆? $ pstree 杈撳嚭紺轟緥錛? 鍥?錛歱stree - 鏄劇ず榪涚▼鐨勬爲鐘跺浘 浠誨姟錛氫嬌鐢╬s鍒楀嵃榪涚▼鏍? # ps -ejH # ps axjf 浠誨姟錛氳幏寰楃嚎紼嬩俊鎭? 杈撳叆涓嬪垪鍛戒護錛? # ps -eLf # ps axms 浠誨姟錛氳幏寰楀畨鍏ㄤ俊鎭? 杈撳叆涓嬪垪鍛戒護錛? # ps -eo euser,ruser,suser,fuser,f,comm,label # ps axZ # ps -eM 浠誨姟錛氬皢榪涚▼蹇収鍌ㄥ瓨鍒版枃浠朵腑 杈撳叆涓嬪垪鍛戒護錛? # top -b -n1 > /tmp/process.log 浣犱篃鍙互灝嗙粨鏋滈氳繃閭歡鍙戠粰鑷繁錛? # top -b -n1 | mail -s 'Process snapshot' you@example.com 浠誨姟錛氭煡鎵捐繘紼? 浣跨敤pgrep鍛戒護銆俻grep鑳芥煡鎵懼綋鍓嶆鍦ㄨ繍琛岀殑榪涚▼騫跺垪鍑虹鍚堟潯浠剁殑榪涚▼ID銆備緥濡傛樉紺篺irefox鐨勮繘紼婭D錛? $ pgrep firefox 涓嬮潰鍛戒護灝嗘樉紺鴻繘紼嬪悕涓簊shd銆佹墍鏈夎呬負root鐨勮繘紼嬨? $ pgrep -u root sshd 鍚慼top鍜宎top璇磆ello htop鏄竴涓被浼紅op鐨勪氦浜掑紡榪涚▼鏌ョ湅宸ュ叿錛屼絾鏄彲浠ュ瀭鐩村拰姘村鉤婊氬姩鏉ユ煡鐪嬫墍鏈夎繘紼嬪拰浠栦滑鐨勫懡浠よ銆傝繘紼嬬殑鐩稿叧鎿嶄綔錛坘illing錛宺enicing錛変笉闇瑕佽緭鍏ID銆傝瀹夎htop杈撳叆鍛戒護錛? # apt-get install htop 鎴? # yum install htop 鍦ㄥ懡浠ゆ彁紺鴻涓緭鍏top錛? # htop 杈撳嚭紺轟緥錛? 鍥?錛歨top - Interactive Linux / UNIX process viewer atop宸ュ叿 atop鏄竴涓敤鏉ユ煡鐪婰inux緋葷粺璐熻澆鐨勪氦浜掑紡鐩戞帶宸ュ叿銆傚畠鑳藉睍鐜扮郴緇熷眰綰х殑鍏抽敭紜歡璧勬簮錛堜粠鎬ц兘瑙掑害錛夌殑浣跨敤鎯呭喌錛屽CPU銆佸唴瀛樸佺‖鐩樺拰緗戠粶銆? 瀹冧篃鍙互鏍規嵁榪涚▼灞傜駭鐨凜PU鍜屽唴瀛樿礋杞芥樉紺哄摢涓繘紼嬮犳垚浜嗙壒瀹氱殑璐熻澆錛涘鏋滃凡緇忓畨瑁呭唴鏍歌ˉ涓佸彲浠ユ樉紺烘瘡涓繘紼嬬殑紜洏鍜岀綉緇滆礋杞姐傝緭鍏ヤ笅闈㈢殑鍛戒護鍚姩atop錛? # atop 杈撳嚭紺轟緥錛? 鍥?錛欰T Computing's System & Process Monitor 鍓嶄袱澶╂湁浜洪棶浜嗕釜鍏充簬Unix鐨刦ork()緋葷粺璋冪敤鐨勯潰璇曢錛岃繖涓姝eソ鏄垜澶х害鍗佸勾鍓嶆壘宸ヤ綔鏃舵煇鍏徃闂垜鐨勪竴涓錛屾垜瑙夊緱姣旇緝鏈夎叮錛屽啓綃囨枃绔犱笌澶у鍒嗕韓涓涓嬨傝繖涓鏄繖鏍風殑錛? 棰樼洰錛氳闂笅闈㈢殑紼嬪簭涓鍏辮緭鍑哄灝戜釜鈥?鈥濓紵 濡傛灉浣犲fork()鐨勬満鍒舵瘮杈冪啛鎮夌殑璇濓紝榪欎釜棰樺茍涓嶉毦錛岃緭鍑哄簲璇ユ槸6涓?鈥濓紝浣嗘槸錛屽疄闄呬笂榪欎釜紼嬪簭浼氬緢tricky鍦拌緭鍑?涓?鈥濄?/p>
瑕佽娓呰繖涓錛屾垜浠鍏堥渶瑕佺煡閬揻ork()緋葷粺璋冪敤鐨勭壒鎬э紝
鎵浠ワ紝涓婇潰鐨勯偅涓▼搴忎負浠涔堜細杈撳叆8涓?鈥濓紝榪欐槸鍥犱負printf(鈥?鈥?;璇彞錛屾垜浠煡閬擄紝Unix涓嬬殑璁懼鏈夆?a >鍧楄澶?/a>鈥濆拰鈥?a >瀛楃璁懼鈥濈殑姒傚康錛屾墍璋撳潡璁懼錛屽氨鏄互涓鍧椾竴鍧楃殑鏁版嵁瀛樺彇鐨勮澶囷紝瀛楃璁懼鏄竴嬈″瓨鍙栦竴涓瓧絎︾殑璁懼銆傜鐩樸佸唴瀛樸佹樉紺哄櫒閮芥槸鍧楄澶囷紝瀛楃璁懼濡傞敭鐩樺拰涓插彛銆?strong>鍧楄澶囦竴鑸兘鏈夌紦瀛橈紝鑰屽瓧絎﹁澶囦竴鑸兘娌℃湁緙撳瓨銆?
鎵浠ワ紝瀵逛簬涓婅堪紼嬪簭錛宲rintf(鈥?鈥?;鎶娾?鈥濇斁鍒頒簡緙撳瓨涓紝騫舵病鏈夌湡姝g殑杈撳嚭錛堝弬鐪嬨?a >C璇█鐨勮糠棰?/a>銆嬩腑鐨勭涓棰橈級錛?strong>鍦╢ork鐨勬椂鍊欙紝緙撳瓨琚鍒跺埌浜嗗瓙榪涚▼絀洪棿錛屾墍浠ワ紝灝卞浜嗕袱涓紝灝辨垚浜?涓紝鑰屼笉鏄?涓?
鎴戜滑濡傛灉淇敼涓涓嬩笂闈㈢殑printf鐨勯偅鏉¤鍙ヤ負錛?
鎴栨槸
灝辨病鏈夐棶棰樹簡錛屽洜涓虹▼搴忛亣鍒扳淺n鈥濇垨鏄疎OF錛屾垨鏄紦涓尯婊★紝鎴栨槸鏂囦歡鎻忚堪絎﹀叧闂紝鎴栨槸涓誨姩flush錛屽氨浼氭妸鏁版嵁鍒峰嚭緙撳啿鍖恒?
鎴戜及璁℃湁浜涙湅鍙嬪彲鑳藉浜巉ork()榪樹笉鏄緢浜嗚В錛岄偅涔堟垜浠妸涓婇潰鐨勭▼搴忔敼鎴愪笅闈㈣繖鏍鳳細 浜庢槸錛屼笂闈㈣繖孌電▼搴忎細杈撳嚭涓嬮潰鐨勭粨鏋滐紝錛堟敞錛氱紪璇戝嚭鐨勫彲鎵ц鐨勭▼搴忓悕涓篺ork錛?
闈㈠榪欐牱鐨勫浘浣犲彲鑳借繕鏄湅涓嶆噦錛屾病浜嬶紝鎴戝ソ浜嬪仛鍒板簳錛岀敾涓浘緇欎綘鐪嬬湅錛?
娉ㄦ剰錛氫笂鍥句腑鐨勬垜鐢ㄤ簡鍑犱釜鑹插僵錛岀浉鍚岄鑹茬殑鏄悓涓涓繘紼嬨備簬鏄紝鎴戜滑鐨刾stree鐨勫浘紺哄氨鍙互鎴愪負涓嬮潰榪欎釜鏍峰瓙錛氾紙涓嬪浘涓殑棰滆壊涓庝笂鍥懼搴旓級
榪欐牱錛屽浜巔rintf(鈥?鈥?;榪欎釜璇彞錛屾垜浠氨鍙互寰堟竻妤氱殑鐭ラ亾錛屽摢涓瓙榪涚▼澶嶅埗浜嗙埗榪涚▼鏍囧噯杈撳嚭緙撲腑鍖洪噷鐨勭殑鍐呭錛岃屽鑷翠簡澶氭杈撳嚭浜嗐傦紙濡備笅鍥炬墍紺猴紝灝辨槸鎴戦槾褰卞茍鍙岃竟妗嗕簡閭d袱涓瓙榪涚▼錛?
鐜板湪浣犳槑鐧戒簡鍚с傦紙鍙︼紝瀵逛簬鍥句腑鐨勬垜鏈漢鎷欏姡鐨勯厤鑹詫紝璇瘋璋?錛?
錛堝叏鏂囧畬錛?
tab=琛ュ叏 鏈嬪弸緇欎簡涓や釜email鏂囦歡錛屼竴涓?00琛屽乏鍙?a.txt)錛屼竴涓笉鍒?000琛?b.txt)銆備袱涓湁寰堝閲嶅鐨別mail錛岃鎵懼嚭b.txt閲岄櫎浜哸.txt涔嬪鐨勬墍鏈夎銆?br />鏍規嵁璇勮錛屽彲浠ヨ繖涔堝仛錛?span style="color: red; ">grep -vxFf a.txt b.txt 浜庢槸灝辨兂鍒頒簡鐩存帴鍒╃敤shell閲岀殑wc錛寀niq錛宻ort絳夈?/p> 鍏跺疄鍍忚繖浜涘懡浠わ紝閫夐」鍙傛暟寰堝錛屽ぇ姒傝鐭ラ亾鏌愪釜鐢ㄦ硶錛屽彲浠ュ疄鐜頒粈涔堬紝鐒跺悗鍐嶆煡涔熶笉榪熴?/p> 鍏堝啓涓嬫垜鐨勬柟娉曪紝鍐嶅垎鏋愶細 cat a.txt > total.txt cat b.txt >> total.txt sort total.txt > total.txt.sort uniq –d total.txt.sort > total.txt.sort.uniq cat b.txt >> total.txt.sort.uniq sort total.txt.sort.uniq > total.txt.sort.uniq.sort uniq –u total.txt.sort.uniq.sort > result.txt 涓棿鐢熸垚浜嗕竴浜涗復鏃舵枃浠訛紝涓嶇煡閬撴庝箞鏍烽氳繃pipe鑳藉噺灝戞暟閲忋?/p> uniq浠嬬粛錛?/strong> uniq [閫夐」] 鏂囦歡 璇存槑錛氳繖涓懡浠よ鍙栬緭鍏ユ枃浠訛紝騫舵瘮杈冪浉閭葷殑琛屻傚湪姝e父鎯呭喌涓嬶紝絎簩涓強浠ュ悗鏇村涓噸澶嶈灝嗚鍒犲幓錛岃姣旇緝鏄牴鎹墍鐢ㄥ瓧絎﹂泦鐨勬帓搴忓簭鍒楄繘琛岀殑銆傝鍛戒護鍔犲伐鍚庣殑緇撴灉鍐欏埌杈撳嚭鏂囦歡涓傝緭鍏ユ枃浠跺拰杈撳嚭鏂囦歡蹇呴』涓嶅悓銆傚鏋滆緭鍏ユ枃浠剁敤“- ”琛ㄧず錛屽垯浠庢爣鍑嗚緭鍏ヨ鍙栥? 璇ュ懡浠ゅ悇閫夐」鍚箟濡備笅錛氥? – c 鏄劇ず杈撳嚭涓紝鍦ㄦ瘡琛岃棣栧姞涓婃湰琛屽湪鏂囦歡涓嚭鐜扮殑嬈℃暟銆傚畠鍙彇浠? u鍜? d閫夐」銆? – d 鍙樉紺洪噸澶嶈銆? – u 鍙樉紺烘枃浠朵腑涓嶉噸澶嶇殑鍚勮銆? – n 鍓峮涓瓧孌典笌姣忎釜瀛楁鍓嶇殑絀虹櫧涓璧瘋蹇界暐銆備竴涓瓧孌墊槸涓涓潪絀烘牸銆侀潪鍒惰〃絎︾殑瀛楃涓詫紝褰兼鐢卞埗琛ㄧ鍜岀┖鏍奸殧寮(瀛楁浠?寮濮嬬紪鍙?銆? +n 鍓峮涓瓧絎﹁蹇界暐錛屼箣鍓嶇殑瀛楃琚煩榪?瀛楃浠?寮濮嬬紪鍙?銆? – f n 涓? n鐩稿悓錛岃繖閲宯鏄瓧孌墊暟銆? – s n 涓?n鐩稿悓錛岃繖閲宯鏄瓧絎︽暟銆? sort浠嬬粛錛?/strong> sort鐨勯夐」鏇村錛屽ぇ姒傛祻瑙堜笅鏈変釜鍗拌薄鐭ラ亾鍙互鍋氫粈涔堝嵆鍙? 璇銆娉曪細sort [-bcdfimMnr][-o<杈撳嚭鏂囦歡>][-t<鍒嗛殧瀛楃>][+<璧峰鏍忎綅>-<緇撴潫鏍忎綅>][--help][--verison][鏂囦歡] http://blog.csdn.net/free_program_1314/article/details/7731073 鎬葷粨涓嬩笁縐嶆柟娉曪細 棣栧厛閮介渶瑕佷嬌鐢╰ime鍑芥暟鑾峰彇鏃墮棿銆?/p>
閮藉湪#include <time.h>閲屽畾涔夈?/p>
鐢ㄥ埌鐨勫嚱鏁板師鍨嬶細 time_t time(time_t *t); char *ctime(const time_t *timep); struct tm *localtime(const time_t *timep); size_t strftime(char *s, size_t max, const char *format, char *asctime(const struct tm *tm); 灝辨垜鐨勬劅瑙夛紝絎簩縐嶆渶涓哄ソ鐢ㄣ傛牸寮忔湁寰堝錛宮an涓涓嬪氨鐪嬪埌浜嗐傛憳鎶勪笅鐢ㄥ埌鐨勶細 %y The year as a decimal number without a century (range 00 to 99). %m The month as a decimal number (range 01 to 12). %d The day of the month as a decimal number (range 01 to 31). %H The hour as a decimal number using a 24-hour clock (range 00 to 23). %M The minute as a decimal number (range 00 to 59). %S The second as a decimal number (range 00 to 60). (The range is up to 60 to allow for occasional leap seconds.) 鍘熷笘鍦板潃錛?a >Classical 10 Examples for learning AWK 寰堜箙涓嶇敤awk浜嗭紝涓鐩磋涓哄涔犵殑鏈浣蟲柟寮忔槸閫氳->瀹炶返->鎬葷粨鐨勮繃紼嬨?/p> 鍘熷笘璁茬殑寰堣緇嗕簡錛屽緢涓嶉敊錛岄兘鏄緢綆鍗曠殑棰樼洰銆傛垜鍦ㄨ繖閲岃褰曚笅鑷繁鍏充簬姣忎釜棰樼洰鐨勬葷粨錛?/p> e1: 1.鈥?-s鈥濇槸宸﹀榻愶紝鈥?s鈥濇槸鍙沖榻愶紝瀵歸綈鏂瑰紡鐢辨璐熷彿琛ㄧず銆?/p> e2: note:grep "Europe" contries涓鏍峰彲浠ヨ揪鍒版晥鏋溿?/p> e5: awk鍙互鐩存帴浠庡懡浠よ璇誨彇鎴栦粠鏂囦歡璇誨彇 awk [options] 'script' var=value file(s) awk [options] -f scriptfile var=value file(s錛?/p> e6: 搴旇榪欎箞鍐欙紵 #!/usr/bin/awk note錛歱rint浼氳嚜鍔ㄦ崲琛岋紝鑰宲rintf涓嶄細銆?/p> e7: FILENAME: 褰撳墠鏂囦歡鍚?/p> OFS:杈撳嚭瀛楁鍒嗛殧絎︼紙榛樿絀烘牸錛?/p> ORS:杈撳嚭璁板綍鍒嗛殧絎︼紙榛樿鍥炶濺錛?/p> 姣斿鍙互榪欎箞閲嶅啓涓嬶細 杈撳嚭緇撴灉錛?/p>
contries-1-Canada-3852-25-North America-$ 鏈榪戠湅鍒癮utomake鐨勫嚑綃囨枃绔狅紝欏轟究閲嶆柊澶嶄範浜嗕笅銆?/p> 鎰熻鏈涓昏鐨勫氨鏄繖寮犲浘浜嗐?/p> 鍏朵腑妞渾褰㈢殑鍛戒護灝辨槸鎴戜滑闇瑕佹墜鍔ㄨ緭鍏ユ垨鑰呬慨鏀圭殑銆?/p> 鏂囩珷鏈夊緢澶氾細 http://m.shnenglu.com/sunrise/archive/2012/06/27/180440.html http://m.shnenglu.com/wc250en007/archive/2012/06/27/180478.aspx 閮芥槸鏈榪戝彂鍦╟pp涓婚〉鐨勩?/p> 浠ョ涓綃囨枃绔犱負渚嬨?/p> 絎?姝ユ湁浜涗笉鏄庣‘ 鎴戝啓鐨勬槸錛?/p> AUTOMAKE_OPTIONS=foreign 榪欐牱鍐欎篃鏄彲浠ョ殑錛岀敓鎴愮殑鍙墽琛屾枃浠跺氨鏄痟elloworld AUTOMAKE_OPTIONS=foreign %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 鍦ㄧ敓鎴怣akefile鏃訛紝榪愯automake --add-missing鍛戒護鍑虹幇浠ヤ笅閿欒錛? configure.in: installing './install-sh': error while making link: 涓嶅厑璁哥殑鎿嶄綔 緇忚繃鍦ㄧ綉涓婃煡鎵撅紝鍙戠幇鏈変竴綃囨枃绔犱篃鍑虹幇浜嗙被浼肩殑鎯呭喌錛屼互涓嬩負榪欑瘒鏂囩珷鐨勫唴瀹癸細 //=========================================================================== fedora 9鑷甫鐨凣lade鏄?.xx鐗堢殑錛岃屼笖Anjuta鏍規湰灝辨病鏈夈傚垹鎺夋崲鎴愭柊鐨凣lade 3.xx鍜孉njuta錛屽噯澶囪瘯璇曞湪linux涓嬪啓gtk+. //========================================================================== 鍒嗘瀽涓涓嬭嚜宸辯殑鍘熷洜錛屾墠鐭ラ亾鍘熸潵鏄洜涓鴻嚜宸辯殑浠g爜鏂囦歡鏀懼湪linux鍜寃indows鐨勫叡浜洰褰曚笅錛屼篃灝辨槸FAT32鍒嗗尯錛屾渶鍚庢妸榪欎簺浠g爜鏂囦歡縐誨埌ext3涓婂氨瑙e喅浜嗭紝鍛靛懙錛屽お璋㈣阿榪欎綅鍝ヤ滑浣犱簡錛? %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 涔嬪墠鐚滄祴鏄湪铏氭嫙鏈簂inux鍜屼富鏈簑in涓嬪叡浜枃浠剁殑鍘熷洜錛岀湅浜嗕笅鎴戠殑鏄疦TFS鐨勶紝鐪嬫潵鍚屾牱涓嶆敮鎸乴ink銆? 鍙﹀鍏充簬automake錛屾劅鍏磋叮鐨勫彲浠ョ湅涓嬭繖閲岋細 http://www.gnu.org/software/automake/manual/automake.html 鍙傝冿細 http://hi.baidu.com/huaan031/blog/item/11849039056fc6c4d5622595.html #include <getopt.h> int getopt_long(int argc, char * const argv[], int getopt_long_only(int argc, char * const argv[], 榪樻槸鐪嬩笅man閲岀殑瑙i噴錛?/strong> The getopt_long() function works like getopt() except that it also accepts long options, started with two dashes. (If the program accepts only long options, then longopts is a pointer to the first element of an array of struct option declared in <getopt.h> as struct option { The meanings of the different fields are: name is the name of the long option. has_arg flag specifies how results are returned for a long option. If flag is NULL, then getopt_long() returns val. (For example, the calling program may set val to val is the value to return, or to load into the variable pointed to by flag. The last element of the array has to be filled with zeros. If longindex is not NULL, it points to a variable which is set to the index of the long option relative to longopts. getopt_long_only() is like getopt_long(), but '-' as well as "--" can indicate a long option. If an option that starts with '-' (not "--") doesn't match a long 鎴戞潵緲昏瘧涓嬶細 鍓嶉潰璇寸殑-h鍙互鐢眊etopt瀹炵幇錛岄偅涔堚攈elp鍒欑敱getopt_long瀹炵幇浜嗐傛墍璋撶殑闀塊夐」鍗砲elp錛岀煭閫夐」灝辨槸h銆?/p> argc錛宎rgv錛宱ptstring閮藉悓鍓嶉潰銆?/p> name:濡傗漢elp鈥?鈥漹ersion鈥濈瓑 has_arg: [絎﹀彿甯擱噺][鏁板糫[鍚箟] no_argument 0 璇ラ夐」娌℃湁鍙傛暟 required_argument 1 閫夐」闇瑕佸弬鏁?/p> optional_argument 2 閫夐」鍙傛暟鍙?/p> int *flag錛?strong>int val: flag鍜寁al鐩鎬簰渚濊禆錛屼富瑕佸垎涓ょ鎯呭喌錛? 錛?錛夈乫lag涓篘ULL錛寁al鍊肩敤浜庣‘瀹氳闀塊夐」錛屾墍浠ラ渶瑕佷負闀塊夐」鎸囧畾鍞竴鐨剉al鍊箋傝繖閲屼篃涓洪暱閫夐」鍜岀煭閫夐」寤虹珛浜嗘ˉ姊併? 錛?錛夈乫lag涓嶄負NULL錛屽垯灝唙al鍊煎瓨鏀懼埌flag鎵鎸囧悜鐨勫瓨鍌ㄧ┖闂達紝鐢ㄤ簬鏍囪瘑璇ラ暱閫夐」鍑虹幇榪囥? 榪斿洖鍊鹼細 紼嬪簭涓嬌鐢ㄧ煭閫夐」錛屽垯榪斿洖鐭夐」瀛楃錛堝鈥榥'錛夛紝褰撻渶瑕佸弬鏁版槸錛屽垯鍦ㄨ繑鍥炰箣鍓嶅皢鍙傛暟瀛樺叆鍒皁ptarg涓? 紼嬪簭涓嬌鐢ㄩ暱閫夐」錛岃繑鍥炲兼牴鎹甪lag鍜寁al紜畾銆傚綋flag涓篘ULL錛屽垯榪斿洖val鍊箋傛墍浠ユ牴鎹畍al鍊煎仛涓嶅悓鐨勫鐞嗭紝榪欎篃璇存槑浜唙al蹇呴』鍞竴銆傚綋val鍊肩瓑浜庣煭閫夐」鍊鹼紝鍒欏彲浠ヤ嬌鐢ㄧ煭閫夐」瑙f瀽鍑芥暟瑙f瀽闀塊夐」錛涘綋flag涓嶄負NULL錛屽垯灝唙al鍊煎瓨鍏lag鎵鎸囧悜鐨勫瓨鍌ㄧ┖闂達紝getopt_long榪斿洖0 鍑虹幇鏈畾涔夌殑闀塊夐」鎴栬呯煭閫夐」錛実etopt_long榪斿洖錛? 瑙f瀽瀹屾瘯錛実etopt_long榪斿洖-1 copy鍙傝冮噷鐨勪竴涓緥瀛愶紝鐣ュ井淇敼浜嗕笅錛?/p> Q: 1.鍙﹀鈥攙ersion錛堝嵆闀塊夐」錛夊悗涓嶇煡閬撳浣曞姞鍙夊弬鏁幫紵璇曚簡涓嬩慨鏀圭▼搴忓悗鈥攄ebug 鈥搗ersion鍚庨兘鏄┖鏍煎姞鍙傛暟鐨勶紝鍙傛暟鐢╫ptarg璇誨彇銆?/p>
2.鏈鍚庝竴涓弬鏁版病鐪嬫噦銆傚弬鑰冮噷璇存槸璋冭瘯鐢ㄣ?/p>
鍙傝冿細 http://www.cnitblog.com/zouzheng/archive/2007/04/02/25034.aspx http://en.wikipedia.org/wiki/Getopt http://blog.csdn.net/lanyan822/article/details/7692013 http://hi.baidu.com/agodliness/blog/item/554a2d516366711b367abeb2.html 棣栧厛man涓嬬湅涓嬪熀鏈殑浠嬬粛錛屾敞鎰忚 $man 3 getopt 鍥犱負getopt涔熸槸shell涓嬬殑涓涓懡浠?/p> 鍩烘湰浠嬬粛錛?/font> 鍘熷瀷錛?/strong> #include <unistd.h> int getopt(int argc, char * const argv[], extern char *optarg; 浣滅敤錛?/p> 鍙互鐢ㄦ潵瑙f瀽鍛戒護琛岄夐」鍙傛暟錛岃屼笉鐢ㄨ嚜宸卞啀鍘誨啓紼嬪簭鍒嗘瀽浜嗐?/p> 鍙傛暟浠嬬粛錛?/strong> 1.argc:鍗充紶鍏ain鍑芥暟鐨刟rgc 2.argv:鍗充紶鍏ain鍑芥暟鐨刟rgv 3.optstring:鎸囧畾棰勬湡鐨勯夐」浠ュ強璇ラ夐」鏄惁瀛樺湪鍙傛暟銆?/p> 鏍煎紡濡備笅錛?/p> 1.鍗曚釜瀛楃錛岃〃紺洪夐」錛屽鈥檟鈥欒〃紺衡?x鈥?br>2.鍗曚釜瀛楃鍚庢帴涓涓啋鍙鳳細琛ㄧず璇ラ夐」鍚庡繀欏昏窡涓涓弬鏁般傚弬鏁扮揣璺熷湪閫夐」鍚庢垨鑰呬互絀烘牸闅斿紑銆傝鍙傛暟鐨勬寚閽堣祴緇檕ptarg銆傚鈥檟:鈥欒〃紺衡?x argument鈥?浣哸rgument鍦ㄨ繖閲屽彲鏈夊彲鏃犮?br>3 鍗曚釜瀛楃鍚庤窡涓や釜鍐掑彿錛岃〃紺鴻閫夐」鍚庡繀欏昏窡涓涓弬鏁般傚弬鏁板繀欏葷揣璺熷湪閫夐」鍚庝笉鑳戒互絀烘牸闅斿紑銆傝鍙傛暟鐨勬寚閽堣祴緇檕ptarg銆傚鈥檟::鈥欒〃紺衡?x argument鈥欙紙榪欎釜鐗規ф槸GNU鐨勬墿寮狅級 涓句釜渚嬪瓙錛? 濡俹ptstring="ab:c::d::",鍛戒護琛屼負getopt.exe -a -b host -ckeke -d haha 鑻辨枃濂界殑鐩存帴鐪嬭繖閲岋紙浠巊etopt.h閲屾妱鐨勶級錛? /* For communication from `getopt' to the caller. extern char *optarg; /* Index in ARGV of the next element to be scanned. On entry to `getopt', zero means this is the first call; initialize. When `getopt' returns -1, this is the index of the first of the Otherwise, `optind' communicates from one call to the next extern int optind; /* Callers store zero here to inhibit the error message `getopt' prints extern int opterr; /* Set to an option character which was unrecognized. */ extern int optopt; 1.extern char* optarg;//閫夐」鐨勫弬鏁版寚閽?/p> 2.extern int optind;//鍌ㄥ瓨璇ヤ綅緗紝涓嬫灝嗕粠璇ヤ綅緗寮濮嬫鏌ラ夐」錛堟鏌ユ椂閬囧埌閫夐」鎴栬呭弬鏁幫紝浣嶇疆+1錛?/p> 3.extern int opterr;//褰搊pterr=0鏃訛紝getopt涓嶅儚stderr杈撳嚭閿欒淇℃伅 4.extern int optopt;//褰撻夐」瀛楃涓嶅湪optstring涓垨鑰呯己灝戝繀瑕佺殑鍙傛暟鏃訛紝璇ラ夐」瀛樺偍鍦╫ptopt錛実etopt榪斿洖鈥?鈥?/p> 璋冪敤涓嬈★紝榪斿洖涓涓夐」銆?/p> 鍦ㄥ懡浠よ閫夐」鍙傛暟鍐嶄篃媯鏌ヤ笉鍒皁ptstring涓寘鍚殑閫夐」鏃訛紝榪斿洖錛?錛屽悓鏃秓ptind鍌ㄥ瓨絎竴涓笉鍖呭惈閫夐」鐨勫懡浠よ鍙傛暟銆?/p> 鍏跺疄鐪嬩釜渚嬪瓙灝辨瘮杈冨鏄撲簡錛?/p> y@y-VirtualBox:~/Training$ ./getopt_l -a -d -b foo 閫愯瑙i噴涓嬭緭鍑猴細 1.-a鍦ㄥ懡浠よ閲屼綅緗負1,涓嬫璇誨彇浣嶇疆涓?錛屽洜姝ptind=2 2-3.optstring閲屾湁a錛屽悓鏃禷鏄笉甯﹀弬鏁扮殑錛屽洜姝ゆ嫻嬪埌-a閫夐」錛屽悓鏃跺弬鏁頒負null 4.optstring閲屾病鏈塪(娉紝榪欓噷鐨勮緭鍑烘椂getopt鏈韓杈撳嚭錛岄氳繃璁劇疆opterr鍙互璁劇疆鏄劇ず榪樻槸涓嶆樉紺? 5.涓嬫浠?浣嶇疆錛屽嵆-b寮濮嬭鍙?/p>
6.optstirng娌℃湁d錛岃繑鍥烇紵錛宱ptopt浼氬瓨鍌ㄩ鏈熶箣澶栫殑涓婁竴涓夐」銆?/p>
7.璇誨彇-b鍚屾椂璇誨彇鍏跺弬鏁癴oo錛屽洜姝や笅涓涓綅緗負5 8optstring閲屾湁b錛岃鍙栨紜茍鎵撳嵃 9.鎵撳嵃b鐨勫弬鏁癴oo錛岃鍙栦笉鍒板叾浠栭鏈熶箣鍐呯殑閫夐」錛屽畬姣曡繑鍥?1 娉ㄦ剰錛?/p>
榛樿鎯呭喌涓媑etopt浼氶噸鏂版帓鍒楀懡浠よ鍙傛暟鐨勯『搴忥紝鎵浠ュ埌鏈鍚庢墍鏈変笉鍖呭惈閫夐」鐨勫懡浠よ鍙傛暟閮芥帓鍒版渶鍚庛?br>濡俫etopt.exe -a ima -b host -ckeke -d haha, 閮芥渶鍚庡懡浠よ鍙傛暟鐨勯『搴忔槸錛?-a -b host -ckeke -d ima haha 鐪嬩釜渚嬪瓙錛?/p> 鎬葷粨錛?/p>
鍑芥暟璇存槑 getopt()鐢ㄦ潵鍒嗘瀽鍛戒護琛屽弬鏁般傚弬鏁癮rgc鍜宎rgv鏄敱main()浼犻掔殑鍙傛暟涓暟鍜屽唴瀹廣傚弬鏁皁ptstring 鍒欎唬琛ㄦ澶勭悊鐨勯夐」瀛楃涓層傛鍑芥暟浼氳繑鍥炲湪argv 涓笅涓涓殑閫夐」瀛楁瘝錛屾瀛楁瘝浼氬搴斿弬鏁皁ptstring 涓殑瀛楁瘝銆傚鏋滈夐」瀛楃涓查噷鐨勫瓧姣嶅悗鎺ョ潃鍐掑彿鈥?鈥濓紝鍒欒〃紺鴻繕鏈夌浉鍏崇殑鍙傛暟錛屽叏鍩熷彉閲弌ptarg 鍗充細鎸囧悜姝ら澶栧弬鏁般傚鏋済etopt()鎵句笉鍒扮鍚堢殑鍙傛暟鍒欎細鍗板嚭閿欎俊鎭紝騫跺皢鍏ㄥ煙鍙橀噺optopt璁句負鈥?鈥濆瓧絎︼紝濡傛灉涓嶅笇鏈沢etopt()鍗板嚭閿欎俊鎭紝鍒欏彧瑕佸皢鍏ㄥ煙鍙橀噺opterr璁句負0鍗沖彲銆?br>榪斿洖鍊?nbsp; 濡傛灉鎵懼埌絎﹀悎鐨勫弬鏁板垯榪斿洖姝ゅ弬鏁板瓧姣嶏紝濡傛灉鍙傛暟涓嶅寘鍚湪鍙傛暟optstring 鐨勯夐」瀛楁瘝鍒欒繑鍥炩?鈥濆瓧絎︼紝鍒嗘瀽緇撴潫鍒欒繑鍥?1銆?
鏈鍚庡疄鎴樹竴涓嬶紝鍋囪鏈変互涓嬮渶姹傦細
1.鍚屽ぇ澶氭暟紼嬪簭涓鏍鳳紝-h杈撳嚭help淇℃伅
2.-c 鎸囧畾鏂囦歡璺緞錛屽鏋滄病鏈夐粯璁や負/tmp/c.conf
3.-d 鎸囧畾鐩爣鏂囦歡錛屽繀欏繪寚瀹氬弬鏁幫紝鍚屾椂璇ラ夐」蹇呴』鎸囧畾銆?
鎴戝疄鐜扮殑錛?pre class="code">/*
* =====================================================================================
* Filename: getopt_l3.c
* Description: -h for help info
* -c set the config file, default is /tmp/c.conf
* -d set destination file, could not be empty.
*
* Version: 1.0
* Created: 06/27/2012 07:12:00 PM
*
* Author: zhy (), izualzhy@163.com
* =====================================================================================
*/
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv)
{
int result;
int hflag = 0, cflag = 0, dflag = 0;
opterr = 0;
char helpinfo[] = "[Usage]: ./a.out \n\
-h, For Help Info\n\
-c, Set the config file, default is /tmp/c.conf\n\
-d, Set the destination file, could not be empty";
while ((result=getopt(argc, argv, "hc::d:")) != -1) {
switch (result) {
case 'h':
hflag = 1;
break;
case 'c':
cflag = 1;
if (NULL != optarg) {
printf("config file set: %s.\n", optarg);
} else {
printf("config file set to default: /tmp/c.conf.\n");
}
break;
case 'd':
dflag = 1;
if (NULL != optarg) {
printf("destination file set to: %s.\n", optarg);
} else {
printf("args could not be empty for -d options.\n");
return;
}
break;
case '?':
printf("unexpected option: %c.\n", optopt);
break;
default:
printf("default, %c", result);
}
}
printf("options(h:%d, c:%d, d:%d)\n", hflag, cflag, dflag);
if (hflag && !cflag && !dflag) {//濡傛灉鍙湁h閫夐」錛屾墦鍗板茍鐩存帴榪斿洖錛屽惁鍒欎笉鎵撳嵃.
printf("%s.\n", helpinfo);
return;
}
if (!dflag) {
printf("-d option must be setted\n");
return;
}
//鍙傛暟媯嫻嬪畬姣曪紝紼嬪簭鐪熸寮濮嬪共媧諱簡......
//
printf("Args Setting Right.\n");
return 0;
}
鍙傝冿細 http://www.cnitblog.com/zouzheng/archive/2007/04/02/25034.aspx http://en.wikipedia.org/wiki/Getopt http://hi.baidu.com/agodliness/blog/item/554a2d516366711b367abeb2.html
#string鐨勯暱搴?/span>
echo ${#string}
#expr鍚屾牱鍙互鑾峰彇闀垮害
#浣嗗湪鏂囦歡閲屾墽琛屼笅闈㈣繖鍙ヤ細鍑洪敊錛屼負浠涔堬紵璇鋒寚鏁?/span>
#expr length ${string}
echo
#鎻愬彇瀛愪覆
#${string:position} 鍦?string涓紝浠庝綅緗?position寮濮嬫彁鍙栧瓙涓?/span>
echo ${string:2}
#${string:poistion:length} 鍦?string涓紝浠庝綅緗?position寮濮嬫彁鍙栭暱搴︿負$length鐨勫瓙涓?/span>
echo ${string:2:5}
echo
#鍒犻櫎鎿嶄綔
#${string#substring} 浠庡彉閲?string鐨勫紑澶達紝鍒犻櫎鏈鐭尮閰?substring鐨勫瓙涓?/span>
#${string##substring} 浠庡彉閲?string鐨勫紑澶達紝鍒犻櫎鏈闀垮尮閰?substring鐨勫瓙涓?/span>
echo ${string#This is a test}
echo ${string#*is}
echo ${string##*is}
echo
#${string%substring} 浠庡彉閲?string鐨勭粨灝撅紝鍒犻櫎鏈鐭尮閰?substring鐨勫瓙涓?/span>
#${string%%substring} 浠庡彉閲?string鐨勭粨灝撅紝鍒犻櫎鏈闀垮尮閰?substring鐨勫瓙涓?/span>
string="i|ban|banana"
echo ${string%ban*}
echo ${string%%ban*}
#鍏充簬#%榪欎釜濡傛灉瑙夊緱闅捐錛屽彲浠ョ湅涓嬮敭鐩?榪欎箞鏉ヨ錛?/span>
# #鍦?鍓嶉潰錛?鍦?鍚庨潰錛?鐨勪綔鐢ㄥ氨鏄彇瀛楃涓?/span>
#浣跨敤涓嬩笂闈粙緇嶈繃鐨勫姛鑳斤紝鐚滀笅杈撳嚭?
string="/etc/init.d/profile"
echo "Dir: " ${string%/*}
echo "File: " ${string##*/}
FileName=${string##*/}
echo "FileName Length: " ${#FileName}
#Note:
#${鍙橀噺鍚?substring姝e垯琛ㄨ揪寮弣 浠庡瓧絎︿覆寮澶村紑濮嬪尮閰峴ubstirng,鍒犻櫎鍖歸厤涓婄殑琛ㄨ揪寮?/span>
#${鍙橀噺鍚?substring姝e垯琛ㄨ揪寮弣 浠庡瓧絎︿覆緇撳熬寮濮嬪尮閰峴ubstring,鍒犻櫎鍖歸厤涓婄殑琛ㄨ揪寮?/span>
#${string/substring/replacement} 浣跨敤$replacement,鏉ヤ唬鏇跨涓涓尮閰嶇殑$substring
#${string//substring/replacement} 浣跨敤$replacement,鏉ヤ唬鏇挎瘡涓涓尮閰嶇殑$substring
string="piapiapia"
echo ${string/pia/ufo}
echo ${string//pia/ufo}
#{string/#substring/replacement} 濡傛灉$stirng鐨勫墠緙鍖歸厤$substring,閭d箞灝辯敤$replacement鏉ヤ唬鏇垮尮閰嶅埌鐨?substring
#{string/%substring/replacement} 濡傛灉$stirng鐨勫悗緙鍖歸厤$substring,閭d箞灝辯敤$replacement鏉ヤ唬鏇垮尮閰嶅埌鐨?substring
string="i hate myself"
echo ${string/#you/ufo}
echo ${string/#i/ufo}
echo ${string/%self/slefish}
string="/etc/init.d/profile"
#鏇存敼絎竴涓枃浠跺す
#褰撴煡鎵懼唴瀹逛腑鍑虹幇浜?,浣跨敤\/杞箟
echo ${string/#\/etc/etc1}
#濡傛灉鏄笅闈㈢殑璇彞鍒欎細杈撳嚭錛?/span>
#/etc/etc1/etc/init.d/profile
#鍥犱負 /#/琚鐞嗘帀,/etc/ect1琚綋浣滀簡$replacement
echo ${string/#/etc/etc1}
]]>
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.
Two lines above this line is empty.
And this is the last line.
1.浠庡崟涓枃浠朵腑鎼滅儲鎸囧畾鐨勫瓧涓?/h5>
$ grep "this" demo_file
this line is the 1st lower case line in this file.
Two lines above this line is empty.
And this is the last line.2. 鍦ㄥ涓枃浠朵腑媯绱㈡寚瀹氱殑瀛椾覆
璇硶錛?br>grep "string" FILE_PATTERN
$ grep "this" demo_*
demo_file:this line is the 1st lower case line in this file.
demo_file:Two lines above this line is empty.
demo_file:And this is the last line.
demo_file1:this line is the 1st lower case line in this file.
demo_file1:Two lines above this line is empty.
demo_file1:And this is the last line.
3. 鐢?grep -i 榪涜澶у皬鍐欐棤鍏崇殑鎼滅儲
璇硶錛?br>grep -i "string" FILE
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.
And this is the last line.
4. 浣跨敤鐢ㄦ鍒欒〃杈懼紡
璇硶錛?br>grep "REGEX" filename
Two lines above this line is empty.
5. 鐢╣rep -w鎼滅儲鏁翠釜璇嶏紝鑰屼笉鏄瘝涓殑閮ㄥ垎瀛椾覆
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.
Two lines above this line is empty.
And this is the last line.
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file.
Two lines above this line is empty.
And this is the last line.
6. 浣跨敤grep -A, -B and -C鏄劇ず涔嬪墠銆佷箣鍚庛佸墠鍚庣殑鍑犺
$ cat demo_text
4. Vim Word Navigation
You may want to do several navigation in relation to the words, such as:
* e - go to the end of the current word.
* E - go to the end of the current WORD.
* b - go to the previous (before) word.
* B - go to the previous (before) WORD.
* w - go to the next word.
* W - go to the next WORD.
WORD - WORD consists of a sequence of non-blank characters, separated with white space.
word - word consists of a sequence of letters, digits and underscores.
Example to show the difference between WORD and word
* 192.168.1.1 - single WORD
* 192.168.1.1 - seven words.6.1 鏄劇ず鍖歸厤琛屼箣鍚庣殑N琛?/h6>
璇硶錛?br>grep -A "string" FILENAME
Example to show the difference between WORD and word
* 192.168.1.1 - single WORD
* 192.168.1.1 - seven words.
6.2鏄劇ず鍖歸厤琛屼箣鍓嶇殑N琛?/h6>
璇硶錛?br>grep -B "string" FILENAME
Example to show the difference between WORD and word
* 192.168.1.1 - single WORD
6.3鏄劇ず鍖歸厤琛屽墠鍚庣殑N琛?/h6>
$ grep -C 2 "Example" demo_text
word - word consists of a sequence of letters, digits and underscores.
Example to show the difference between WORD and word
* 192.168.1.1 - single WORD7.閫氳繃GREP_OPTIONS楂樹寒鏄劇ず鎼滅儲鐨勫瓧涓?/h5>
$ grep this demo_file
this line is the 1st lower case line in this file.
Two lines above this line is empty.
And this is the last line.
8. 鐢╣rep -r閫掑綊鎼滅儲鍏ㄩ儴鐨勬枃浠?/h5>
$ grep -r "ramesh" *
9. 浣跨敤grep -v榪涜涓嶅尮閰?/h5>
4. Vim Word Navigation
You may want to do several navigation in relation to the words, such as:
WORD - WORD consists of a sequence of non-blank characters, separated with white space.
word - word consists of a sequence of letters, digits and underscores.
Example to show the difference between WORD and word
* 192.168.1.1 - single WORD
* 192.168.1.1 - seven words.
10. 鏄劇ず涓嶅尮閰嶅叏閮ㄦā寮忕殑琛?/h5>
璇硶錛?br>grep -v -e "pattern" -e "pattern"
$ cat test-file.txt
a
b
c
d
$ grep -v -e "a" -e "b" -e "c" test-file.txt
d11.鐢╣rep -c 緇熻鍖歸厤鐨勮鏁?/h5>
璇硶錛?br>grep -c "pattern" filename
$ grep -c "go" demo_text
6$ grep -v -c this demo_file
412. 鐢╣rep -l 鍙樉紺烘枃浠跺悕
$ grep -l this demo_*
demo_file
demo_file113. 鍙樉紺哄尮閰嶇殑瀛椾覆
is line is the 1st lower case line
is line
is is the last line14. 鏄劇ず鍖歸厤鐨勪綅緗?/h5>
璇硶錛?br>grep -o -b "pattern" file
$ cat temp-file.txt
12345
12345
$ grep -o -b "3" temp-file.txt
0:3
6:315. 鐢?grep -n 鍦ㄨ緭鍑烘椂鏄劇ず琛屽彿
5: * e - go to the end of the current word.
6: * E - go to the end of the current WORD.
7: * b - go to the previous (before) word.
8: * B - go to the previous (before) WORD.
9: * w - go to the next word.
10: * W - go to the next WORD.
1: #include <stdio.h> 2: 3: #include <sys/types.h> 4: 5: #include <unistd.h> 6: 7: int main(void)
8: 9: { 10: 11: int i;
12: 13: for(i=0; i<2; i++){
14: 15: fork(); 16: 17: printf("-");
18: 19: } 20: 21: return 0;
22: 23: }
printf("-\n");
printf("-");
flush();
1: #include <stdio.h> 2: 3: #include <sys/types.h> 4: 5: #include <unistd.h> 6: 7: int main(void)
8: 9: { 10: 11: int i;
12: 13: for(i=0; i<2; i++){
14: 15: fork(); 16: 17: //娉ㄦ剰錛氫笅闈㈢殑printf鏈夆淺n鈥?/span>
18: 19: printf("ppid=%d, pid=%d, i=%d \n", getppid(), getpid(), i);
20: 21: } 22: 23: sleep(10); //璁╄繘紼嬪仠鐣欏崄縐掞紝榪欐牱鎴戜滑鍙互鐢╬stree鏌ョ湅涓涓嬭繘紼嬫爲
24: 25: return 0;
26: 27: } 28: ppid=8858, pid=8518, i=0
ppid=8858, pid=8518, i=1
ppid=8518, pid=8519, i=0
ppid=8518, pid=8519, i=1
ppid=8518, pid=8520, i=1
ppid=8519, pid=8521, i=1
$ pstree -p | grep fork
|-bash(8858)-+-fork(8518)-+-fork(8519)---fork(8521)
| | `-fork(8520)
ctrl+a=寮濮嬩綅緗?
ctrl+e=鏈鍚庝綅緗?
ctrl+k=鍒犻櫎姝ゅ鑷蟲湯灝炬墍鏈夊唴瀹?
ctrl+u=鍒犻櫎姝ゅ鑷沖紑濮嬫墍鏈夊唴瀹?
ctrl+d=鍒犻櫎褰撳墠瀛楁瘝
ctrl+w=鍒犻櫎姝ゅ鍒板乏杈圭殑鍗曡瘝
ctrl+y=綺樿創鐢眂trl+u錛宑trl+d錛宑trl+w鍒犻櫎鐨勫崟璇?
ctrl+r=姝e湪嫻嬭瘯錛岃繕娌″紕鏄庣櫧錛屽懙鍛點?
ctrl+l=鐩稿綋浜巆lear
ctrl+b=鍚戝洖縐誨姩
ctrl+f=鍚戝墠縐誨姩
ctrl+p=鍚戜笂鏄劇ず緙撳瓨鍛戒護
ctrl+n=鍚戜笅鏄劇ず緙撳瓨鍛戒護
ctrl+d=鍏抽棴緇堢
shift+涓婃垨涓?緇堢涓婁笅婊氬姩
shift+pgup鎴杙gdown=緇堢涓婁笅緲婚〉婊氬姩
ctrl+shift+f=鍏ㄥ睆錛堜粎闄愪簬konsole錛?
ctrl+shift+n=鏂扮粓绔紙terminal鍜宬onsole鏈夋墍涓嶅悓錛?
ctrl+c=緇堟
]]>
琛ュ厖璇存槑錛歴ort鍙拡瀵規枃鏈枃浠剁殑鍐呭錛屼互琛屼負鍗曚綅鏉ユ帓搴忋?br />鍙傘銆鏁幫細
-b 蹇界暐姣忚鍓嶉潰寮濮嬪嚭鐨勭┖鏍煎瓧絎︺?br /> -c 媯鏌ユ枃浠舵槸鍚﹀凡緇忔寜鐓ч『搴忔帓搴忋?br /> -d 鎺掑簭鏃訛紝澶勭悊鑻辨枃瀛楁瘝銆佹暟瀛楀強絀烘牸瀛楃澶栵紝蹇界暐鍏朵粬鐨勫瓧絎︺?br /> -f 鎺掑簭鏃訛紝灝嗗皬鍐欏瓧姣嶈涓哄ぇ鍐欏瓧姣嶃?br /> -i 鎺掑簭鏃訛紝闄や簡040鑷?76涔嬮棿鐨凙SCII瀛楃澶栵紝蹇界暐鍏朵粬鐨勫瓧絎︺?br /> -m 灝嗗嚑涓帓搴忓ソ鐨勬枃浠惰繘琛屽悎騫躲?br /> -M 灝嗗墠闈?涓瓧姣嶄緷鐓ф湀浠界殑緙╁啓榪涜鎺掑簭銆?br /> -n 渚濈収鏁板肩殑澶у皬鎺掑簭銆?br /> -o<杈撳嚭鏂囦歡> 灝嗘帓搴忓悗鐨勭粨鏋滃瓨鍏ユ寚瀹氱殑鏂囦歡銆?br /> -r 浠ョ浉鍙嶇殑欏哄簭鏉ユ帓搴忋?br /> -t<鍒嗛殧瀛楃> 鎸囧畾鎺掑簭鏃舵墍鐢ㄧ殑鏍忎綅鍒嗛殧瀛楃銆?br /> +<璧峰鏍忎綅>-<緇撴潫鏍忎綅> 浠ユ寚瀹氱殑鏍忎綅鏉ユ帓搴忥紝鑼冨洿鐢辮搗濮嬫爮浣嶅埌緇撴潫鏍忎綅鐨勫墠涓鏍忎綅銆?br /> --help 鏄劇ず甯姪銆?br /> --version 鏄劇ず鐗堟湰淇℃伅
]]>/*
* =====================================================================================
* Filename: getCurrentTime.c
* Description: methods of get current time
*
* Version: 1.0
* Created: 07/10/2012 09:50:09 AM
*
* Author: zhy (), izualzhy@163.com
* =====================================================================================
*/
#include <time.h>
#include <stdio.h>
int main()
{
time_t curTime = time(NULL);
char* curDate = ctime(&curTime);
printf("%s\n",curDate);
struct tm* localTime = localtime(&curTime);
char s[50];
char* format = "%y-%m-%d %H:%M:%S";
size_t max_size = 49;
size_t result = strftime(s, max_size, format, localTime);
if (result!=0) {
printf("%s\n",s);
}
char* cTime = asctime(localTime);
printf("%s\n", cTime);
return 0;
}
const struct tm *tm);
]]>
{print $0}#!/usr/bin/awk
BEGIN{FS=":";OFS="-";ORS="$\n"}
{
printf FILENAME OFS\
NR OFS\
$1 OFS\
$2 OFS\
$3 OFS\
$4 OFS\
ORS
}
contries-2-USA-3615-237-North America-$
contries-3-Brazil-3286-134-South America-$
contries-4-England-94-56-Europe-$
contries-5-France-211-55-Europe-$
contries-6-Japan-144-120-Asia-$
contries-7-Mexico-762-78-North America-$
contries-8-China-3705-1032-Asia-$
contries-9-India-1267-746-Asia-$
]]>
bin_PROGRAMS=hello
hello_SOURCES=hello.c
bin_PROGRAMS=helloworld
helloworld_SOURCES=hello.c
]]>
configure.in: installing './mkinstalldirs': error while making link: 涓嶅厑璁哥殑鎿嶄綔
configure.in: installing './missing': error while making link: 涓嶅厑璁哥殑鎿嶄綔
configure.in: installing './depcomp': error while making link: 涓嶅厑璁哥殑鎿嶄綔 Linux涓嬬殑GTK絳夌瓑銆?/a>
menphix 鍙戣〃浜?2008-06-03 21:09:14
緇撴灉榪愯autogen.sh鎬諱篃榪囦笉鍘匯傝涓嶆槸Anjuta鐨勮緭鍑洪珮浜繕鐪熷彂鐜頒笉浜嗚繖鏍風殑閿欒錛?br>configure.ac:6: installing `./install-sh'; error while making link: 涓嶅厑璁哥殑鎿嶄綔
configure.ac:6: installing `./missing'; error while making link: 涓嶅厑璁哥殑鎿嶄綔
src/Makefile.am: installing `./depcomp'; error while making link: 涓嶅厑璁哥殑鎿嶄綔
Makefile.am: installing `./INSTALL'; error while making link: 涓嶅厑璁哥殑鎿嶄綔
浠旂粏鍒嗘瀽鎵嶇煡閬撳師鏉ユ槸鍥犱負鎶婂伐紼嬫斁鍦‵AT32鍒嗗尯涓婁簡錛岃屽畠涓嶆敮鎸乴ink!
鎸埌ext3涓婂氨瑙e喅浜嗐傚懙鍛點?
]]>
const char *optstring,
const struct option *longopts, int *longindex);
const char *optstring,
const struct option *longopts, int *longindex);
optstring should be specified as an empty string (""), not NULL.) Long option names may be abbreviated if the abbreviation is unique or is an exact match for
some defined option. A long option may take a parameter, of the form --arg=param or --arg param.
const char *name;
int has_arg;
int *flag;
int val;
};
is: no_argument (or 0) if the option does not take an argument; required_argument (or 1) if the option requires an argument; or optional_argument (or 2) if
the option takes an optional argument.
the equivalent short option character.) Otherwise, getopt_long() returns 0, and flag points to a variable which is set to val if the option is found, but
left unchanged if the option is not found.
option, but does match a short option, it is parsed as a short option instead./*
* =====================================================================================
* Filename: getopt_long_l.c
* Description: getopt_long() learn notes
*
* Version: 1.0
* Created: 06/27/2012 08:25:20 PM
*
* Author: zhy (), izualzhy@163.com
* =====================================================================================
*/
#include <stdio.h>
#include <getopt.h>
int main(int argc, char* argv[])
{
int result, deb;
struct option opts[] = {{"username", required_argument, NULL, 'n'},
{"version", optional_argument, NULL, 'v'},
{"debug", no_argument, &deb, 2},//flag!=NULL鏃訛紝argument娌℃湁鐢紵
{0,0,0,0}//why?
};
while ((result = getopt_long(argc, argv, "n:v::", opts, NULL))!=-1) {
switch (result) {
case 'n'://-n 鎴栬?-username
printf("username is %s\n", optarg);
break;
case 'v'://-v 鎴栬?--version
printf("version is 1.0.0, %s\n", optarg);
break;
case 0://flag涓嶄負NULL
printf("debug is %d\targs:%s\n", deb, optarg);
break;
case '?'://鏈畾涔夌殑閫夐」
printf("?: %c %c\n", result, optopt);
break;
default:
printf("default: %c\n", result);
break;
}
}
return 0;
}
]]>
const char *optstring);
extern int optind, opterr, optopt;
host鏄痓鐨勫弬鏁幫紝keke鏄痗鐨勫弬鏁般備絾haha騫朵笉鏄痙鐨勫弬鏁幫紝鍥犱負瀹冧滑涓棿鏈夌┖鏍奸殧寮銆?
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
non-option elements that the caller should itself scan.
how much of ARGV has been scanned so far. */
for unrecognized options. *//*
* =====================================================================================
* Filename: getopt_l.c
* Description: getopt learning
*
* Version: 1.0
* Created: 06/26/2012 08:13:49 PM
*
* Author: zhy (), izualzhy@163.com
* =====================================================================================
*/
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int aflag = 0, bflag = 0, cflag = 0;
int ch;
while ((ch = getopt(argc, argv, "ab:c")) != -1) {
printf("optind: %d\n", optind);
switch (ch) {
case 'a':
printf("Have option: -a\n");
aflag = 1;
printf("The argument of -a is %s\n", optarg);
break;
case 'b':
printf("Have option: -b\n");
bflag = 1;
printf("The argument of -b is %s\n", optarg);
break;
case 'c':
printf("Have option: -c\n");
cflag = 1;
break;
case '?':
printf("Unknown option: %c\n", (char)optopt);
break;
}
}
}
鍙互鑷繁鍏堣瘯鐫鍐欎笅杈撳嚭鐨勭粨鏋滐細
optind: 2
Have option: -a
The argument of -a is (null)
./getopt_l: invalid option -- 'd'
optind: 3
Unknown option: d
optind: 5
Have option: -b
The argument of -b is foo
濡傛灉optstring涓殑瀛楃涓蹭互'+'鍔犲彿寮澶存垨鑰呯幆澧冨彉閲廝OSIXLY_CORRE琚緗傞偅涔堜竴閬囧埌涓嶅寘鍚夐」鐨勫懡浠よ鍙傛暟錛実etopt灝變細鍋滄錛岃繑鍥?1銆?
/*
* =====================================================================================
* Filename: getopt_l2.c
* Description:
*
* Version: 1.0
* Created: 06/26/2012 08:37:11 PM
*
* Author: zhy (), izualzhy@163.com
* =====================================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int result;
opterr = 0;//?
while ((result = getopt(argc, argv, "ab:c::")) != -1) {
switch (result) {
case 'a':
printf("option=a, optopt=%c, optarg=%s\n", optopt, optarg);
break;
case 'b':
printf("option=b, optopt=%c, optarg=%s\n", optopt, optarg);
break;
case 'c':
printf("option=c, optopt=%c, optarg=%s\n", optopt, optarg);
break;
case '?':
printf("result=?, optopt=%c, optarg=%s\n", optopt, optarg);
default:
printf("default, result=%c\n", result);
break;
}
printf("argv[%d]=%s\n", optind, argv[optind]);
}
printf("result = -1, optind = %d\n", optind);
for ( result = optind; result<argc; result++)
printf("------ argv[%d] = %s\n", result, argv[result]);
printf("\n");
for ( result = 1; result < argc; result++)
printf("at the end------argv[%d] = %s\n", result, argv[result]);
return 0;
}
]]>
鍦ㄥ仛shell鎵瑰鐞嗙▼搴忔椂鍊欙紝緇忓父浼氭秹鍙婂埌瀛楃涓茬浉鍏蟲搷浣溿傛湁寰堝鍛戒護璇彞錛屽錛歛wk,sed閮藉彲浠ュ仛瀛楃涓插悇縐嶆搷浣溿?鍏跺疄shell鍐呯疆涓緋誨垪鎿嶄綔絎﹀彿錛屽彲浠ヨ揪鍒扮被浼兼晥鏋滐紝澶у鐭ラ亾錛屼嬌鐢ㄥ唴閮ㄦ搷浣滅浼氱渷鐣ュ惎鍔ㄥ閮ㄧ▼搴忕瓑鏃墮棿錛屽洜姝ら熷害浼氶潪甯哥殑蹇?
涓銆佸垽鏂鍙栧瓧絎︿覆鍊?/strong> 琛ㄨ揪寮?br>鍚箟 ${var} ${var-DEFAULT} ${var:-DEFAULT} ${var=DEFAULT} ${var:=DEFAULT} ${var+OTHER} ${var:+OTHER} ${var?ERR_MSG} ${var:?ERR_MSG} ${!varprefix*} ${!varprefix@} 鍔犲叆浜嗏?鈥?nbsp; 涓嶆槸鎰忔濇槸錛?褰撶劧, 濡傛灉鍙橀噺var宸茬粡琚緗殑璇? 閭d箞鍏跺煎氨鏄?var. [chengmo@localhost ~]$ echo ${abc-'ok'} [chengmo@localhost ~]$ echo ${abc='ok'} 濡傛灉abc 娌℃湁澹版槑鈥?" 榪樹細緇檃bc璧嬪箋? [chengmo@localhost ~]$ var1=11;var2=12;var3= ${!varprefix*}涓?{!varprefix@}鐩鎬技錛屽彲浠ラ氳繃鍙橀噺鍚嶅墠緙瀛楃錛屾悳绱㈠凡緇忓畾涔夌殑鍙橀噺,鏃犺鏄惁涓虹┖鍊箋?/p> 浜屻佸瓧絎︿覆鎿嶄綔錛堥暱搴︼紝璇誨彇錛屾浛鎹級 琛ㄨ揪寮?br>鍚箟 ${#string} ${string:position} ${string:position:length} ${string#substring} ${string##substring} ${string%substring} ${string%%substring} ${string/substring/replacement} ${string//substring/replacement} ${string/#substring/replacement} ${string/%substring/replacement} 璇存槑錛?* $substring鈥濆彲浠ユ槸涓涓?em>姝e垯琛ㄨ揪寮?/em>. 1.闀垮害 [web97@salewell97 ~]$ test='I love china' ${#鍙橀噺鍚峿寰楀埌瀛楃涓查暱搴? 2.鎴彇瀛椾覆 [chengmo@localhost ~]$ test='I love china' ${鍙橀噺鍚?璧峰:闀垮害}寰楀埌瀛愬瓧絎︿覆 3.瀛楃涓插垹闄?/strong> [chengmo@localhost ~]$ test='c:/windows/boot.ini' [chengmo@localhost ~]$ echo ${test%/*} ${鍙橀噺鍚?substring姝e垯琛ㄨ揪寮弣浠庡瓧絎︿覆寮澶村紑濮嬮厤澶噑ubstring,鍒犻櫎鍖歸厤涓婄殑琛ㄨ揪寮忋? ${鍙橀噺鍚?substring姝e垯琛ㄨ揪寮弣浠庡瓧絎︿覆緇撳熬寮濮嬮厤澶噑ubstring,鍒犻櫎鍖歸厤涓婄殑琛ㄨ揪寮忋? 娉ㄦ剰錛?{test##*/},${test%/*} 鍒嗗埆鏄緱鍒版枃浠跺悕錛屾垨鑰呯洰褰曞湴鍧鏈綆鍗曟柟娉曘? 4.瀛楃涓叉浛鎹?/strong> [chengmo@localhost ~]$ test='c:/windows/boot.ini' ${鍙橀噺/鏌ユ壘/鏇挎崲鍊紏 涓涓?鈥濊〃紺烘浛鎹㈢涓涓紝鈥?/鈥濊〃紺烘浛鎹㈡墍鏈?褰撴煡鎵句腑鍑虹幇浜嗭細鈥?鈥濊鍔犺漿涔夌鈥漒/鈥濊〃紺恒?/p> 涓夈佹ц兘姣旇緝 鍦╯hell涓紝閫氳繃awk,sed,expr 絳夐兘鍙互瀹炵幇錛屽瓧絎︿覆涓婅堪鎿嶄綔銆備笅闈㈡垜浠繘琛屾ц兘姣旇緝銆? [chengmo@localhost ~]$ test='c:/windows/boot.ini' real 0m0.173s [chengmo@localhost ~]$ time for i in $(seq 10000);do a=$(expr length $test);done; real 0m9.734s 閫熷害鐩稿樊涓婄櫨鍊嶏紝璋冪敤澶栭儴鍛戒護澶勭悊錛屼笌鍐呯疆鎿嶄綔絎︽ц兘鐩稿樊闈炲父澶с傚湪shell緙栫▼涓紝灝介噺鐢ㄥ唴緗搷浣滅鎴栬呭嚱鏁板畬鎴愩備嬌鐢╝wk,sed綾諱技浼氬嚭鐜拌繖鏍風粨鏋溿?/p> 鍒嗙被: linux
鍙橀噺var鐨勫? 涓?var鐩稿悓
濡傛灉var娌℃湁琚0鏄? 閭d箞灝變互$DEFAULT浣滀負鍏跺?*
濡傛灉var娌℃湁琚0鏄? 鎴栬呭叾鍊間負絀? 閭d箞灝變互$DEFAULT浣滀負鍏跺?*
濡傛灉var娌℃湁琚0鏄? 閭d箞灝變互$DEFAULT浣滀負鍏跺?*
濡傛灉var娌℃湁琚0鏄? 鎴栬呭叾鍊間負絀? 閭d箞灝變互$DEFAULT浣滀負鍏跺?*
濡傛灉var澹版槑浜? 閭d箞鍏跺煎氨鏄?OTHER, 鍚﹀垯灝變負null瀛楃涓?
濡傛灉var琚緗簡, 閭d箞鍏跺煎氨鏄?OTHER, 鍚﹀垯灝變負null瀛楃涓?
濡傛灉var娌¤澹版槑, 閭d箞灝辨墦鍗?ERR_MSG *
濡傛灉var娌¤璁劇疆, 閭d箞灝辨墦鍗?ERR_MSG *
鍖歸厤涔嬪墠鎵鏈変互varprefix寮澶磋繘琛屽0鏄庣殑鍙橀噺
鍖歸厤涔嬪墠鎵鏈変互varprefix寮澶磋繘琛屽0鏄庣殑鍙橀噺
ok
[chengmo@localhost ~]$ echo $abc
ok
[chengmo@localhost ~]$ echo $abc
ok
[chengmo@localhost ~]$ echo ${!v@}
var1 var2 var3
[chengmo@localhost ~]$ echo ${!v*}
var1 var2 var3
$string鐨勯暱搴?
鍦?string涓? 浠庝綅緗?position寮濮嬫彁鍙栧瓙涓?
鍦?string涓? 浠庝綅緗?position寮濮嬫彁鍙栭暱搴︿負$length鐨勫瓙涓?
浠庡彉閲?string鐨勫紑澶? 鍒犻櫎鏈鐭尮閰?substring鐨勫瓙涓?
浠庡彉閲?string鐨勫紑澶? 鍒犻櫎鏈闀垮尮閰?substring鐨勫瓙涓?
浠庡彉閲?string鐨勭粨灝? 鍒犻櫎鏈鐭尮閰?substring鐨勫瓙涓?
浠庡彉閲?string鐨勭粨灝? 鍒犻櫎鏈闀垮尮閰?substring鐨勫瓙涓?
浣跨敤$replacement, 鏉ヤ唬鏇跨涓涓尮閰嶇殑$substring
浣跨敤$replacement, 浠f浛鎵鏈?/em>鍖歸厤鐨?substring
濡傛灉$string鐨?em>鍓嶇紑
濡傛灉$string鐨?em>鍚庣紑鍖歸厤$substring, 閭d箞灝辯敤$replacement鏉ヤ唬鏇垮尮閰嶅埌鐨?substring
[web97@salewell97 ~]$ echo ${#test}
12
[chengmo@localhost ~]$ echo ${test:5}
e china
[chengmo@localhost ~]$ echo ${test:5:10}
e china
[chengmo@localhost ~]$ echo ${test#/}
c:/windows/boot.ini
[chengmo@localhost ~]$ echo ${test#*/}
windows/boot.ini
[chengmo@localhost ~]$ echo ${test##*/}
boot.ini
c:/windows
[chengmo@localhost ~]$ echo ${test%%/*}
[chengmo@localhost ~]$ echo ${test/\//\\}
c:\windows/boot.ini
[chengmo@localhost ~]$ echo ${test//\//\\}
c:\windows\boot.ini
[chengmo@localhost ~]$ time for i in $(seq 10000);do a=${#test};done;
user 0m0.139s
sys 0m0.004s
user 0m1.628s
]]>
Wireless Tools For Linux錛?/p>
http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html
鍙互鐪嬪埌鏈鏂扮殑紼沖畾鐗堟湰鏄痸29錛屼笉榪囨垜鍦ㄧ敤鐨勬椂鍊欑粡甯哥鍒拌繖涓敊璇細
[root@y root]# iwlist scanning
lo Interface doesn't support scanning.
usb0 Interface doesn't support scanning.
print_scanning_info: Allocation failed
浜庢槸涓嬭澆浜?9鐨勬簮鐮侊紝閿欒鐨勫嚭澶勶細
realloc: /* (Re)allocate the buffer - realloc(NULL, len) == malloc(len) */ newbuf = realloc(buffer, buflen); if(newbuf == NULL) { if(buffer) free(buffer); fprintf(stderr, "%s: Allocation failed\n", __FUNCTION__); return(-1); } buffer = newbuf; /* Try to read the results */ wrq.u.data.pointer = buffer; wrq.u.data.flags = 0; wrq.u.data.length = buflen; if(iw_get_ext(skfd, ifname, SIOCGIWSCAN, &wrq) < 0) { /* Check if buffer was too small (WE-17 only) */ if((errno == E2BIG) && (range.we_version_compiled > 16)) { /* Some driver may return very large scan results, either * because there are many cells, or because they have many * large elements in cells (like IWEVCUSTOM). Most will * only need the regular sized buffer. We now use a dynamic * allocation of the buffer to satisfy everybody. Of course, * as we don't know in advance the size of the array, we try * various increasing sizes. Jean II */ /* Check if the driver gave us any hints. */ if(wrq.u.data.length > buflen) buflen = wrq.u.data.length; else buflen *= 2; /* Try again */ goto realloc; } E2BIG閿欒鍙戝嚭鍚庯紝浼氫慨鏀硅realloc鐨勫唴瀛樺潡闀垮害
buflen*=2灝卞緢璁╀漢璐硅В浜嗭紝鍔犲叆浜嗕簺鎵撳嵃娑堟伅鍚庣紪璇戜簡涓嬪彂鐜幫紝length=0鏃朵篃浼氬彂鍑篍2BIG鐨別rrno錛屽緢璁╀漢璐硅В錛屼笉榪囦互鑷繁鐩墠鐨勭煡璇嗙Н绱紝娌℃硶緇х畫鐮旂┒涓嬪幓浜嗐?/font>璇曠潃淇敼浜嗕笅錛屼慨鏀圭殑榪囩▼涓紝鍙戠幇浜嗘渶寮濮嬬殑緗戝潃鐨勮繖涔堜竴鍧楋細slightly bigger scan buffer
浜庢槸涓嬭澆浜嗚鐗堟湰鐪嬩簡涓嬶紝鐩稿叧澶勫凡緇忔敼鎴愪簡錛?/font>
realloc: /* (Re)allocate the buffer - realloc(NULL, len) == malloc(len) */ newbuf = realloc(buffer, buflen); if(newbuf == NULL) { if(buffer) free(buffer); fprintf(stderr, "%s: Allocation failed\n", __FUNCTION__); return(-1); } buffer = newbuf; /* Try to read the results */ wrq.u.data.pointer = buffer; wrq.u.data.flags = 0; wrq.u.data.length = buflen; if(iw_get_ext(skfd, ifname, SIOCGIWSCAN, &wrq) < 0) { /* Check if buffer was too small (WE-17 only) */ if((errno == E2BIG) && (range.we_version_compiled > 16) && (buflen < 0xFFFF)) { /* Some driver may return very large scan results, either * because there are many cells, or because they have many * large elements in cells (like IWEVCUSTOM). Most will * only need the regular sized buffer. We now use a dynamic * allocation of the buffer to satisfy everybody. Of course, * as we don't know in advance the size of the array, we try * various increasing sizes. Jean II */ /* Check if the driver gave us any hints. */ if(wrq.u.data.length > buflen) buflen = wrq.u.data.length; else buflen *= 2; /* wrq.u.data.length is 16 bits so max size is 65535 */ if(buflen > 0xFFFF) buflen = 0xFFFF; /* Try again */ goto realloc; }
銆?/p>
涓嶈繃榪欓噷鍑洪敊鏃訛紝鎵寰楃殑buffer鏄┖瀛楃涓詫紝鑰屼笉鏄埅鏂殑瀛楃涓詫紝鎵浠ョ敤澶勪笉澶э紝瀵硅嚜宸辯敤澶勪笉澶с俹(鈺枴鈺?o
鍋氫釜璁板綍錛屾繁鎰熻嚜宸辯殑鐭ヨ瘑縐瘡澶皯錛屽鉤鏃舵病浜嬫嬁榪囪繖縐嶄唬鐮佹潵灝辮瀛︿範涓嬨?/p>
鍏堢湅涓媓elp
# iwconfig -h
Usage: iwconfig [interface]
interface essid {NNN|any|on|off}
interface mode {managed|ad-hoc|master|...}
interface freq N.NNN[k|M|G]
interface channel N
interface bit {N[k|M|G]|auto|fixed}
interface rate {N[k|M|G]|auto|fixed}
interface enc {NNNN-NNNN|off}
interface key {NNNN-NNNN|off}
interface power {period N|timeout N|saving N|off}
interface nickname NNN
interface nwid {NN|on|off}
interface ap {N|off|auto}
interface txpower {NmW|NdBm|off|auto}
interface sens N
interface retry {limit N|lifetime N}
interface rts {N|auto|fixed|off}
interface frag {N|auto|fixed|off}
interface modulation {11g|11a|CCK|OFDMg|...}
interface commit
Check man pages for more details.
鐪嬩簡涓嬫瘮杈冮渶瑕佹敞鎰忕殑涓や釜鍦版柟錛?/font>
1.essid鍗硍ifi鐑偣鍚嶇О錛宨wlist wlan0 scan鍙互鏌ョ湅褰撳墠鎼滅儲鍒扮殑wifi鐐廣傚叾涓瓀lan0鏄綘鐨勬棤綰胯澶囧悕縐般?/p>
[root@kindle /DuoKan]# iwlist
Usage: iwlist [interface] scanning [essid NNN] [last]
[interface] frequency
[interface] channel
[interface] bitrate
[interface] rate
[interface] encryption
[interface] keys
[interface] power
[interface] txpower
[interface] retry
[interface] ap
[interface] accesspoints
[interface] peers
[interface] event
[interface] auth
[interface] wpakeys
[interface] genie
[interface] modulation
2.key鍏抽敭瀛楃殑浣跨敤錛屾暟瀛椾笌ascii鏄笉鍚岀殑銆?br>
杞瘒鏂囩珷錛屽啓鐨勯潪甯歌緇嗭細
iwconfig鏄疞inux Wireless Extensions(LWE)鐨勭敤鎴峰眰閰嶇疆宸ュ叿涔嬩竴銆侺WE鏄疞inux涓嬪鏃犵嚎緗戠粶閰嶇疆鐨勫伐鍏鳳紝鍖呮嫭鍐呮牳鐨勬敮鎸併佺敤鎴峰眰閰嶇疆宸ュ叿鍜岄┍鍔ㄦ帴鍙g殑鏀寔涓夐儴鍒嗐傜洰鍓嶅緢澶氭棤綰跨綉鍗¢兘鏀寔LWE錛岃屼笖涓繪祦鐨凩inux鍙戝竷鐗堟湰錛屾瘮濡俁edhat Linux銆乁buntu Linux閮藉凡緇忓甫浜嗚繖涓厤緗伐鍏楓?
1銆乮wconfig
鐢ㄦ硶: iwconfig interface [essid {NN|on|off}]
[nwid {NN|on|off}]
[mode {managed|ad-hoc|...}
[freq N.NNNN[k|M|G]]
[channel N]
[ap {N|off|auto}]
[sens N]
[nick N]
[rate {N|auto|fixed}]
[rts {N|auto|fixed|off}]
[frag {N|auto|fixed|off}]
[enc {NNNN-NNNN|off}]
[power {period N|timeout N}]
[retry {limit N|lifetime N}]
[txpower N {mW|dBm}]
[commit]
璇存槑錛歩wconfig鏄疞WE鏈涓昏鐨勫伐鍏鳳紝鍙互瀵規棤綰跨綉鍗$殑澶ч儴鍒嗗弬鏁拌繘琛岄厤緗?br>鍙傛暟錛?br>essid錛氳緗棤綰跨綉鍗$殑ESSID(Extension Service Set ID)銆傞氳繃ESSID鏉ュ尯鍒嗕笉鍚岀殑鏃犵嚎緗戠粶錛屾甯告儏鍐典笅鍙湁鐩稿悓ESSID鐨勬棤綰跨珯鐐?br> 鎵嶅彲浠ヤ簰鐩擱氳錛岄櫎闈炴兂鐩戝惉鏃犵嚎緗戠粶銆傚叾鍚庣殑鍙傛暟涓哄弻寮曞彿鎷搗鐨凟SSID瀛楃涓詫紝鎴栬呮槸any/on/off錛屽鏋淓SSID瀛楃涓蹭腑鍖呭惈
any/no/off錛屽垯闇瑕佸湪鍓嶉潰鍔?--"銆?br> 紺轟緥錛?br> #iwconfig eth0 essid any 鍏佽浠諱綍ESSID錛屼篃灝辨槸娣鋒潅妯″紡
#iwconfig eth0 essid "My Network" 璁劇疆ESSID涓?My Network"
#iwconfig eth0 essid -- "ANY" 璁劇疆ESSID涓?ANY"
nwid: Network ID錛屽彧鐢ㄤ簬pre-802.11鐨勬棤綰跨綉鍗★紝802.11緗戝崱鍒╃敤ESSID鍜孉P鐨凪AC鍦板潃鏉ユ浛鎹wid錛岀幇鍦ㄥ熀鏈笂涓嶇敤璁劇疆銆?br> 紺轟緥錛?br> #iwconfig eth0 nwid AB34
#iwconfig eth0 nwid off
nick: Nickname錛屼竴浜涚綉鍗¢渶瑕佽緗鍙傛暟錛屼絾鏄?02.11鍗忚鏍堛丮AC閮芥病鏈夌敤鍒拌鍙傛暟錛屼竴鑸篃涓嶇敤璁劇疆銆?br> 紺轟緥錛?br> #iwconfig eth0 nickname "My Linux Node"
mode錛氳緗棤綰跨綉鍗$殑宸ヤ綔妯″紡錛屽彲浠ユ槸
Ad-hoc錛氫笉甯P鐨勭偣瀵圭偣鏃犵嚎緗戠粶
Managed錛氶氳繃澶氫釜AP緇勬垚鐨勭綉緇滐紝鏃犵嚎璁懼鍙互鍦ㄨ繖涓綉緇滀腑婕父
Master錛氳緗鏃犵嚎緗戝崱涓轟竴涓狝P
Repeater錛氳緗負鏃犵嚎緗戠粶涓戶璁懼錛屽彲浠ヨ漿鍙戠綉緇滃寘
Secondary錛氳緗負澶囦喚鐨凙P/Repeater
Monitor錛氱洃鍚ā寮?br> Auto錛氱敱鏃犵嚎緗戝崱鑷姩閫夋嫨宸ヤ綔妯″紡
紺轟緥錛?br> #iwconfig eth0 mode Managed
#iwconfig eth0 mode Ad-Hoc
freq/channel錛氳緗棤綰跨綉鍗$殑宸ヤ綔棰戠巼鎴栬呴閬擄紝灝忎簬1000鐨勫弬鏁拌璁や負鏄閬擄紝澶т簬10000鐨勫弬鏁拌璁や負鏄鐜囥傞鐜囧崟浣嶄負Hz錛?br> 鍙互鍦ㄦ暟瀛楀悗闈㈤檮甯, M, G鏉ユ敼鍙樻暟閲忕駭錛屾瘮濡?.4G銆傞閬撲粠1寮濮嬨備嬌鐢╨wlist宸ュ叿鍙互鏌ョ湅鏃犵嚎緗戝崱鏀寔鐨勯鐜?br> 鍜岄閬撱傚弬鏁皁ff/auto鎸囩ず鏃犵嚎緗戠粶鑷姩鎸戦夐鐜囥?br> 娉ㄦ剰錛氬鏋滄槸Managed妯″紡錛孉P浼氭寚紺烘棤綰跨綉鍗$殑宸ヤ綔棰戠巼錛屽洜姝よ璁劇疆鐨勫弬鏁頒細琚拷鐣ャ侫d-hoc妯″紡涓嬪彧浣跨敤璇ヨ瀹氱殑棰戠巼
鍒濆鏃犵嚎緗戠粶錛屽鏋滃姞鍏ュ凡緇忓瓨鍦ㄧ殑Ad-hoc緗戠粶鍒欎細蹇界暐璇ヨ緗殑棰戠巼鍙傛暟銆?br> 紺轟緥錛?br> #iwconfig eth0 freq 2422000000
#iwconfig eth0 freq 2.422G
#iwconfig eth0 channel 3
#iwconfig eth0 channel auto
ap錛氳繛鎺ュ埌鎸囧畾鐨凙P鎴栬呮棤綰跨綉緇滐紝鍚庨潰鐨勫弬鏁板彲浠ユ槸AP鐨凪AC鍦板潃錛屼篃鍙互鏄痠wlist scan鍑烘潵鐨勬爣璇嗙銆傚鏋滄槸Ad-hoc錛屽垯榪炴帴鍒?br> 涓涓凡緇忓瓨鍦ㄧ殑Ad-hoc緗戠粶銆備嬌鐢╫ff鍙傛暟璁╂棤綰跨綉鍗′笉鏀瑰彉褰撳墠宸茶繛鎺ョ殑AP涓嬭繘鍏ヨ嚜鍔ㄦā寮忋俛ny/auto鍙傛暟錛屾棤綰跨綉鍗¤嚜鍔ㄩ夋嫨
鏈濂界殑AP銆?br> 娉ㄦ剰錛氬鏋滄棤綰夸俊鍙蜂綆鍒頒竴瀹氱▼搴︼紝鏃犵嚎緗戠粶浼氳繘鍏ヨ嚜鍔ㄩ夋嫨AP妯″紡銆?br> 紺轟緥錛?br> #iwconfig eth0 ap 00:60:1D:01:23:45
#iwconfig eth0 ap any
#iwconfig eth0 ap off
rate/bit錛氬鏋滄棤綰跨綉鍗℃敮鎸佸閫熺巼錛屽垯鍙互閫氳繃璇ュ懡浠よ緗伐浣滅殑閫熺巼銆傚皬浜?000鐨勫弬鏁扮敱鍏蜂綋鐨勬棤綰跨綉鍗¢┍鍔ㄥ畾涔夛紝涓鑸槸浼犺緭閫?br> 鐜囩殑绱㈠紩鍊鹼紝澶т簬1000鐨勪負閫熺巼錛屽崟浣峛ps錛屽彲浠ュ湪鏁板瓧鍚庨潰闄勫甫k, M, G鏉ユ寚瀹氭暟閲忕駭銆俛uto鍙傛暟璁╂棤綰跨綉鍗¤嚜鍔ㄩ夋嫨閫熺巼
fixed鍙傛暟璁╂棤綰跨綉鍗′笉浣跨敤鑷姩閫熺巼妯″紡銆?br> 紺轟緥錛?br> #iwconfig eth0 rate 11M
#iwconfig eth0 rate auto
#iwconfig eth0 rate 5.5M auto //鑷姩閫夋嫨5.5M浠ヤ笅鐨勯熺巼
txpower錛氬鏋滄棤綰跨綉鍗℃敮鎸佸鍙戝皠鍔熺巼璁懼畾錛屽垯浣跨敤璇ュ弬鏁拌瀹氬彂灝勶紝鍗曚綅涓篸Bm錛屽鏋滄寚瀹氫負W錛堟鐡︼級錛屽彧杞崲鍏紡涓猴細
dBm=30+log(W)銆傚弬鏁皁n/off鍙互鎵撳紑鍜屽叧闂彂灝勫崟鍏冿紝auto鍜宖ixed鎸囧畾鏃犵嚎鏄惁鑷姩閫夋嫨鍙戝皠鍔熺巼銆?br> 紺轟緥錛?br> #iwconfig eth0 txpower 15
#iwconfig eth0 txpower 30mW
#iwconfig eth0 txpower auto
#iwconfig eth0 txpower off
sens錛氳緗帴鏀剁伒鏁忓害鐨勪笅闄愶紝鍦ㄨ涓嬮檺涔嬩笅錛屾棤綰跨綉鍗¤涓鴻鏃犵嚎緗戠粶淇″彿澶樊錛屼笉鍚岀殑緗戝崱浼氶噰鍙栦笉鍚岀殑鎺柦錛屼竴浜涚幇浠g殑鏃犵嚎緗戝崱
浼氳嚜鍔ㄩ夋嫨鏂扮殑AP銆傛鐨勫弬鏁頒負raw data錛岀洿鎺ヤ紶緇欐棤綰跨綉鍗¢┍鍔ㄥ鐞嗭紝涓鑸涓烘槸鐧懼垎姣斻傝礋鍊艱〃紺篸Bm鍊箋?br> 紺轟緥錛?br> #iwconfig eth0 sens -80
#iwconfig eth0 sens 2
retry錛氳緗棤綰跨綉鍗$殑閲嶄紶鏈哄埗銆俵imit 鈥榲alue鈥?鎸囧畾鏈澶ч噸浼犳鏁幫紱lifetime 鈥榲alue鈥欐寚瀹氭渶闀塊噸璇曟椂闂達紝鍗曚綅涓虹錛屽彲浠ラ檮甯鍜寀鏉?br> 鎸囧畾鍗曚綅涓烘縐掑拰寰銆傚鏋滄棤綰跨綉鍗℃敮鎸佽嚜鍔ㄦā寮忥紝鍒欏湪limit鍜宭ifetime涔嬪墠榪樺彲浠ラ檮鍔爉in鍜宮ax鏉ユ寚瀹氫笂涓嬮檺鍊箋?br> 紺轟緥錛?br> #iwconfig eth0 retry 16
#iwconfig eth0 retry lifetime 300m
#iwconfig eth0 retry min limit 8
rts錛氭寚瀹歊TS/CTS鎻℃墜鏂瑰紡錛屼嬌鐢≧TS/CTS鎻℃墜浼氬鍔犻澶栧紑閿錛屼絾濡傛灉鏃犵嚎緗戠粶涓湁闅愯棌鏃犵嚎鑺傜偣鎴栬呮湁寰堝鏃犵嚎鑺傜偣鏃跺彲浠ユ彁楂樻ц兘銆?br> 鍚庨潰鐨勫弬鏁版寚瀹氫竴涓嬌鐢ㄨ鏈哄埗鐨勬渶灝忓寘鐨勫ぇ灝忥紝濡傛灉璇ュ肩瓑浜庢渶澶у寘澶у皬錛屽垯鐩稿綋浜庣姝嬌鐢ㄨ鏈哄埗銆傚彲浠ヤ嬌鐢╝uto/off/fixed
鍙傛暟銆?br> 紺轟緥錛?br> #iwconfig eth0 rts 250
#iwconfig eth0 rts off
frag錛氳緗彂閫佹暟鎹寘鐨勫垎鐗囧ぇ灝忋傝緗垎鐗囦細澧炲姞棰濆寮閿錛屼絾鍦ㄥ櫔澹扮幆澧冧笅鍙互鎻愰珮鏁版嵁鍖呯殑鍒拌揪鐜囥備竴鑸儏鍐典笅璇ュ弬鏁板皬浜庢渶澶у寘
澶у皬錛屾湁浜涙敮鎸丅urst妯″紡鐨勬棤綰跨綉鍗″彲浠ヨ緗ぇ浜庢渶澶у寘澶у皬鐨勫兼潵鍏佽Burst妯″紡銆傝繕鍙互浣跨敤auto/fixed/off鍙傛暟銆?br> 紺轟緥錛?br> #iwconfig eth0 frag 512
#iwconfig eth0 frag off
key/enc[ryption]錛氳緗棤綰跨綉鍗′嬌鐢ㄧ殑鍔犲瘑瀵嗛挜錛屾澶勪負璁劇疆WEP妯″紡鐨勫姞瀵唊ey錛屽鏋滆浣跨敤WPA錛岄渶瑕亀pa_supplicant宸ュ叿鍖呫?br> 瀵嗛挜鍙傛暟鍙互鏄?XXXX-XXXX-XXXX-XXXX 鎴栬?XXXXXXXX 鏍煎紡鐨勫崄鍏繘鍒舵暟鍊鹼紝涔熷彲浠ユ槸s:xxxxxx鐨凙SCII瀛楃銆傚鏋滃湪瀵嗛挜鍙傛暟涔嬪墠
鍔犱簡[index]錛屽垯鍙槸璁劇疆璇ョ儲寮曞煎搴旂殑瀵嗛挜錛屽茍涓嶆敼鍙樺綋鍓嶇殑瀵嗛挜銆傜洿鎺ユ寚瀹歔index]鍊煎彲浠ヨ緗綋鍓嶄嬌鐢ㄥ摢涓涓瘑閽ャ傛寚瀹歰n/
off鍙互鎺у埗鏄惁浣跨敤鍔犲瘑妯″紡銆俹pen/restricted鎸囧畾鍔犲瘑妯″紡錛屽彇鍐充簬涓嶅悓鐨勬棤綰跨綉鍗★紝澶у鏁版棤綰跨綉鍗$殑open妯″紡涓嶄嬌鐢ㄥ姞瀵嗕笖
鍏佽鎺ユ敹娌℃湁鍔犲瘑鐨勬暟鎹寘錛宺estricted妯″紡浣跨敤鍔犲瘑銆傚彲浠ヤ嬌鐢ㄥ涓猭ey鍙傛暟錛屼絾鍙湁鏈鍚庝竴涓敓鏁堛?br> WEP瀵嗛挜鍙互鏄?0bit錛岀敤10涓崄鍏繘鍒舵暟瀛楁垨鑰?涓狝SCII瀛楃琛ㄧず錛屼篃鍙互鏄?28bit錛岀敤26涓崄鍏繘鍒舵暟瀛楁垨鑰?3涓狝SCII瀛楃琛?br> 紺恒?
紺轟緥錛?br> #iwconfig eth0 key 0123-4567-89
#iwconfig eth0 key [3] 0123-4567-89
#iwconfig eth0 key s:password [2]
#iwconfig eth0 key [2]
#iwconfig eth0 key open
#iwconfig eth0 key off
#iwconfig eth0 key restricted [3] 0123456789
#iwconfig eth0 key 01-23 key 45-67 [4] key [4]
power錛氳緗棤綰跨綉鍗$殑鐢墊簮綆$悊妯″紡銆俻eriod 鈥榲alue鈥?鎸囧畾鍞ら啋鐨勫懆鏈燂紝timeout 鈥榲alue鈥欐寚瀹氳繘鍏ヤ紤鐪犵殑絳夊緟鏃墮棿錛岃繖涓や釜鍙傛暟涔嬪墠鍙互
鍔爉in鍜宮ax淇グ錛岃繖浜涘肩殑鍗曚綅涓虹錛屽彲浠ラ檮鍔爉鍜寀鏉ユ寚瀹氭縐掑拰寰銆俹ff/on鍙傛暟鎸囧畾鏄惁鍏佽鐢墊簮綆$悊錛宎ll/unicast/multicast
鎸囧畾鍏佽鍞ら啋鐨勬暟鎹寘綾誨瀷銆?br> 紺轟緥錛?br> #iwconfig eth0 power period 2
#iwconfig eth0 power 500m unicast
#iwconfig eth0 power timeout 300u all
#iwconfig eth0 power off
#iwconfig eth0 power min period 2 power max period 4
commit錛氭彁浜ゆ墍鏈夌殑鍙傛暟淇敼緇欐棤綰跨綉鍗¢┍鍔ㄣ傛湁浜涙棤綰跨綉鍗¢┍鍔ㄤ細鍏堢紦瀛樻棤綰跨綉鍗″弬鏁頒慨錛屼嬌鐢ㄨ繖涓懡浠ゆ潵璁╂棤綰跨綉鍗$殑鍙傛暟淇敼鐢熸晥銆備笉榪囦竴
鑸笉闇瑕佷嬌鐢ㄨ鍛戒護錛屽洜涓烘棤綰跨綉鍗¢┍鍔ㄦ渶緇堥兘浼氭槸鍙傛暟鐨勪慨鏀圭敓鏁堬紝涓鑸湪debug鏃朵細鐢ㄥ埌銆?br>2銆佸弬鑰冩枃妗o細
iwconfig(8) 宸ュ叿 Man鎵嬪唽銆?
sudo /etc/init.d/nfs-kernel-server restart
灝卞彲浠ヤ簡錛屽鏋滆繕鏄笉琛岋紝鐢╮pc.mountd璇曚竴涓嬨?/p>
瀵逛簬鍐呮牳鑰岃█錛屾墍鏈夋墦寮鐨勬枃浠墮兘閫氳繃鏂囦歡鎻忚堪絎﹀紩鐢ㄣ備緥濡傚浜嶭inux搴旂敤紼嬪簭鍛樻潵璁詫紝闊抽緙栫▼鎺ュ彛瀹為檯涓婂氨鏄竴緇勯煶棰戣澶囨枃浠訛紝閫氳繃瀹冧滑鍙互浠庡0鍗¤鍙栨暟鎹紝鎴栬呭悜澹板崱鍐欏叆鏁版嵁錛屽茍涓旇兘澶熷澹板崱榪涜鎺у埗錛岃緗噰鏍烽鐜囧拰澹伴亾鏁扮洰絳夌瓑銆?
褰撹鎴栧啓涓涓枃浠舵椂錛屼嬌鐢╫pen鎴朿reate榪斿洖鐨勬枃浠舵弿榪扮鏍囪瘑璇ユ枃浠訛紝灝嗗叾浣滀負鍙傛暟浼犻佺粰read鎴杦rite銆?
UNIX緋葷粺shell浣跨敤鏂囦歡鎻忚堪絎?涓庤繘紼嬬殑鏍囧噯杈撳叆鐩稿叧鑱旓紝鏂囦歡鎻忚堪絎?涓庢爣鍑嗚緭鍑虹浉鍏寵仈錛屾枃浠舵弿榪扮2涓庢爣鍑嗗嚭閿欑浉鍏寵仈銆傚湪渚濅粠POSIX鐨勫簲鐢ㄧ▼搴忎腑錛屽夠鏁?錛?錛?搴斿綋鏇挎崲鎴愬父閲?/p>
/* Standard file descriptors. */
#define STDIN_FILENO 0 /* Standard input. */
#define STDOUT_FILENO 1 /* Standard output. */
#define STDERR_FILENO 2 /* Standard error output. */
//defined in /usr/include/unistd.h銆?/span>
1. open, creat - 鐢ㄦ潵 鎵撳紑鍜屽垱寤?涓涓?鏂囦歡鎴栬澶?
鎻忚堪錛?/p>
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode)
int creat(const char *pathname, mode_t mode);
open() 閫氬父 鐢ㄤ簬 灝?璺緞鍚?杞崲涓?涓涓?鏂囦歡鎻忚堪絎?(涓涓?闈炶礋鐨?灝?鏁存暟, 鍦?read , write 絳?I/O鎿嶄綔涓?灝嗕細琚嬌鐢?. 褰?open() 璋冪敤 鎴愬姛, 瀹冧細 榪斿洖 涓涓?鏂扮殑 鏂囦歡鎻忚堪絎?(姘歌繙鍙?鏈敤 鎻忚堪絎︾殑 鏈灝忓?. 榪欎釜璋冪敤 鍒涘緩 涓涓?鏂扮殑 鎵撳紑鏂囦歡, 鍗?鍒嗛厤 涓涓?鏂扮殑 鐙竴鏃?浜岀殑 鏂囦歡鎻忚堪絎? 涓嶄細涓?榪愯涓殑 浠諱綍 鍏朵粬紼嬪簭 鍏變韓 (浣?鍙互 閫氳繃 fork (2) 緋葷粺璋冪敤 瀹炵幇 鍏變韓). 榪欎釜 鏂扮殑 鏂囦歡鎻忚堪絎?鍦ㄥ叾鍚?瀵?鎵撳紑鏂囦歡鎿嶄綔 鐨勫嚱鏁?涓?浣跨敤.(鍙傝?fcntl(2)). 鏂囦歡鐨?璇誨啓 鎸囬拡 琚?緗簬 鏂囦歡澶村弬鏁?flags 鏄氳繃 O_RDONLY, O_WRONLY 鎴?O_RDWR (鎸囨槑 鏂囦歡 鏄互 鍙 , 鍙啓 鎴?璇誨啓 鏂瑰紡 鎵撳紑鐨? 涓?涓嬮潰鐨?闆朵釜
鎴?澶氫釜 鍙夋ā寮?鎸変綅 -or 鎿嶄綔 寰楀埌鐨勶紙妯″紡寰堝錛屽氨涓嶈創浜嗭紝鐩存帴man鐪嬩笅鍗沖彲錛屼互涓婃弿榪頒篃鏄粠man 2 open閲屽鍒剁殑錛夈?
create鍑芥暟絳夋晥浜?open(pathname, O_WRONLY | O_CREAT | O_TRUNC, mode);
涓や釜鍑芥暟鍦?lt;fcntl.h>閮藉彲浠ユ壘鍒板嚱鏁板0鏄庛?
2. close鍑芥暟鐢ㄦ潵鍏抽棴涓涓枃浠?
鎻忚堪錛?/p>
#include <unistd.h>
int close(int fd);
褰撲竴涓繘紼嬬粓姝㈡椂錛屽唴鏍歌嚜鍔ㄥ叧闂畠鎵鏈夋墦寮鐨勬枃浠躲傚緢澶氱▼搴忓埄鐢ㄤ簡榪欎竴鍔熻兘鑰屼笉鏄懼紡鐨勭敤close鍏抽棴鎵撳紑鏂囦歡銆?
3. lseek錛氳緗枃浠跺亸縐婚噺
鎻忚堪錛?
姣忎釜鎵撳紑鐨勬枃浠墮兘鏈変竴涓笌鍏剁浉鍏寵仈鐨勨滃綋鍓嶆枃浠跺亸縐婚噺鈥?current file offset)銆傚畠閫氬父鏄竴涓潪璐熸暣鏁幫紝鐢ㄤ互搴﹂噺浠庢枃浠跺紑濮嬪璁$畻鐨勫瓧鑺傛暟銆傞氬父錛岃銆佸啓鎿嶄綔閮戒粠鏂囦歡鍋忕Щ閲忓寮濮嬶紝鎵撳紑涓涓枃浠舵椂錛岄櫎闈炴寚瀹歄_APPEND錛屽惁鍒欒鍋忕Щ閲忚緗負0.
#include<unistd.h>
off_t lseek(int fileds, off_t offset, int whence);
SEEK_SET
The offset is set to offset bytes.
SEEK_CUR
The offset is set to its current location plus offset bytes.
SEEK_END
The offset is set to the size of the file plus offset bytes.
鍙互鐢ㄤ笅鍒楁柟寮忕‘瀹氭墦寮鏂囦歡鐨勫綋鍓嶅亸縐婚噺錛?
off_t currpos = lseek(fd, 0, SEEK_CUR);
榪欑鏂規硶涔熷彲浠ョ敤鏉ョ‘瀹氭墍娑夊強鐨勬枃浠舵槸鍚﹀彲浠ヨ緗亸縐婚噺銆傚鏋滄枃浠舵弿榪扮寮曠敤鐨勬槸涓涓閬撱丗IFO鎴栫綉緇滃鎺ュ瓧錛屽垯lseek榪斿洖-1錛屽茍灝唀rrno璁劇疆涓篍SPIPE銆?
lseek浠呭皢褰撳墠鐨勬枃浠跺亸縐婚噺璁板綍鍦ㄥ唴鏍鎬腑錛屽畠騫朵笉寮曡搗浠諱綍IO鎿嶄綔銆傜劧鍚庯紝璇ュ亸縐婚噺鐢ㄤ簬涓嬩竴涓鍐欐搷浣溿?
4. read錛氫粠鎵撳紑鏂囦歡涓鏁版嵁
鎻忚堪錛?
ssize_t read(int fd, void *buf, size_t count);
鎴愬姛榪斿洖璇誨埌鐨勫瓧鑺傛暟錛岃嫢宸插埌鏂囦歡緇撳熬鍒欒繑鍥?錛岃嫢鍑洪敊鍒欒繑鍥?1.
5. write錛氬悜鎵撳紑鐨勬枃浠跺啓鍏ユ暟鎹?
ssize_t write(int fd, const void *buf, size_t count);
浠g爜紺轟緥錛?/b>
浠庢爣鍑嗚緭鍏ヨ鍙栵紝鍐欏埌鏍囧噯杈撳嚭錛?/p>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
const int BUFFSIZE = 4096;
int main()
{
int n;
char buf[BUFFSIZE];
while ((n=read(STDIN_FILENO, buf, BUFFSIZE)) > 0)
if (write(STDOUT_FILENO, buf, n) != n) {
printf("write error\n");
exit(1);
}
if (n < 0) {
printf("read error\n");
exit(1);
}
exit(0);
}
for i in `ls *.cpp`
do
cat $i | grep "$*" && echo $i
done
@desktop:/media/C0FE-F76A/a$ ls
createFile.cpp doubleherit2.cpp doubleherit.cpp myfind.sh test.os test.tt translation濡備綍鍔犱笅鍒掔嚎 鏂版枃浠?br>@desktop:/media/C0FE-F76A/hanvon/a$ myfind void fun_a
virtual void fun_a() {
void fun_a() {
doubleherit2.cpp
void fun_a() {
void fun_a() {
doubleherit.cpp
@desktop:/media/C0FE-F76A/a$