Linux鍩虹鍛戒护
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux鍩虹鍛戒护相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/png' title='png'>png wap ima 鎿嶄綔绯荤粺 鍐呮牳 鏂板缓 min 鎸囧畾 鍒涘缓
鐩綍
鍩虹鍛戒护
甯哥敤鍛戒护
- cd: 杩涘叆鐩綍
- cd ..: 杩斿洖涓婄骇
- cd -: 杩斿洖涓婃鐩綍
- touch: 鏂板缓绌虹櫧鏂囦欢
- mkdir: 鏂板缓鐩綍
- cp/mv/rm: 澶嶅埗/绉诲姩/鍒犻櫎
- cat/more/less/head/tail: 鏌ョ湅鏂囦欢
- cat 1.log |head -100|tail -50
- tar/unrar/unzip: 鍘嬬缉瑙e帇缂?/li>
- shutdown/reboot: 鍏虫満閲嶅惎
ls鍛戒护
鏌ョ湅
- -a: 鏄剧ず闅愯棌鏂囦欢
- -l: 鏄剧ず璇︾粏淇℃伅
- -/d/l/b..: 鏂囦欢绫诲瀷, - 鏅€氭枃浠? d 鐩綍, l 閾炬帴
- rwxrwxrwx: 鐢ㄦ埛/鎵€鍦ㄧ粍/鍏朵粬鐢ㄦ埛鏉冮檺
- 鏁板瓧: 鏂囦欢涓暟
- root: root: 鎵€灞炵敤鎴?鎵€灞炵粍
- 鏁板瓧: 鏂囦欢澶у皬
- 鏃堕棿: 鏈€鍚庝慨鏀规椂闂?/li>
- -h: 鏂囦欢澶у皬浠B, GB鏄剧ず
- -R: 鍒楀嚭瀛愮洰褰曠殑鎵€鏈夋枃浠?/li>
鎺掑簭
- -t: 鎸変慨鏀规椂闂存帓搴?
- -at: 鎸夊垱寤烘椂闂存帓搴?/li>
- -ut: 鎸夎闂椂闂存帓搴?/li>
- -S: 鎸夊ぇ灏忔帓搴?/li>
- -X: 鎸夋墿灞曞悕鎺掑簭
- -r: 鍙嶅悜鎺掑簭
grep鍛戒护
鍖归厤(鍐呭鎼滅储)
- -i : 蹇界暐澶у皬鍐?/li>
- -r: 閫掑綊鍖归厤, 鍖呭惈瀛愮洰褰?/li>
- -v: 鎺掗櫎鍏抽敭瀛?/li>
- -e: 鎸囧畾澶氫釜鍖归厤
- -E: 浣跨敤姝e垯
- grep -E "Exception:\s" rpa/logs
- -F: 涓嶄娇鐢ㄦ鍒?/li>
澶氭枃浠舵悳绱㈡樉绀烘牸寮?
- 榛樿: 鏄剧ず鍖归厤琛屽唴瀹?/li>
- -l: 鏄剧ず鍖归厤鍒扮殑鏂囦欢鍚?/li>
- -c: 鏄剧ず鏂囦欢鍚嶅拰琛屽彿
- -h: 涓嶆樉绀烘枃浠跺悕
find鍛戒护
鏌ユ壘鏂瑰紡
- -name/-iname: 鎸夋枃浠跺悕鏌ユ壘/蹇界暐澶у皬鍐?/li>
- -regex/iregex: 鎸夋鍒欒〃杈惧紡鏌ユ壘/鏃犺澶у皬鍐?/li>
- -type: 鎸夌被鍨嬫煡鎵? f: 鏅€氭枃浠? d: 鐩綍, l: 閾炬帴
- -size: 鎸夊ぇ灏?0k/+10k/-10k 绛変簬/澶т簬/灏忎簬10k
- -mtime/ctime/atime: 鎸変慨鏀?鍙樺寲(鏂囦欢鏉冮檺绛?鏃堕棿/璁块棶鏃堕棿
- -mmin/-cmin/-amin: 鎸夊垎閽? n/-n/+n
- -perm 755: 鎸夋潈闄?/li>
鎵ц鎿嶄綔-ok/-exec
find . -type f -perm 644 -exec ls -l \;
find . -name *.txt -exec cat \; > all.txt
find /var/log -type f -mtime +7 -ok rm \;
閰嶅悎grep鏌ユ壘鍐呭
find / -type f -name 鈥?.log鈥?| xargs grep "Exception"
sort/uniq/wc
sort
- -u: 鍘婚噸
- -r: 鍙嶅悜鎺掑簭
- -n: 鏁板瓧瀛楃鎸夋暟瀛楁帓搴?/li>
uniq
- -i: 蹇界暐澶у皬鍐?/li>
- -c: 缁熻
wc
- -c: 鎸夊瓧绗︾粺璁?/li>
- -w: 鎸夊崟璇嶇粺璁?/li>
- -l: 鎸夎缁熻
绀轰緥:
tail -1000 2019-08-15.log | grep Exception | wc -l
netstat -nat|grep 8080 |awk 'print $6'|sort|uniq -c|sort -rn
sed鍛戒护
鍔ㄤ綔
- p: 鏌ョ湅/鎼滅储
- sed -n 鈥?,7p鈥?main.py 鏌ョ湅
- sed -n 鈥?main/p鈥?main.py 鎼滅储
- i鎴朼: 鎻掑叆/杩藉姞
- sed 鈥榐a@author::hanzhichao鈥?main.py 鍦ㄧ涓€琛屼笅鏂板
- sed 鈥?i@author::hanzhichao鈥?main.py 鎻掑叆
- d: 鍒犻櫎
- sed 鈥?,5d鈥?*.php
- sed 鈥?^$/d鈥?*.php 鍒犻櫎绌鸿
- c鎴杝: 鏇挎崲
- sed 鈥?,5c No 2-5 number鈥?鏇挎崲
- sed 鈥榮/8182/8080/g鈥?*.php
閫夐」
- -i: 鐩存帴灏嗕慨鏀瑰啓鍏ュ師鏂囦欢
- sed 鈥搃 鈥?s/5000/5001/g鈥?main.py
- -e:澶氱偣缂栬緫
- cat /etc/passwd | sed -e 鈥?,$d鈥?-e 鈥榮/bash/blueshell/鈥?/li>
- -n: 瀹夐潤妯″紡
VIM浣跨敤
涓夌妯″紡
- 鍛戒护妯″紡
- 杈撳叆妯″紡
- 搴曠嚎鍛戒护妯″紡
鍛戒护妯″紡甯哥敤鎿嶄綔
绉诲姩鍏夋爣
- 鈫?鈫?鈫?鈫撴垨h/j/k/l:涓婂乏鍙充笅绉诲姩锛宯+h/j/k/l
- n+绌烘牸/n+鍥炶溅
- w銆乄
- 0/$ 琛屽ご灏惧反
- H/M/L/G
- gg/ng/G
缈婚〉
- ctrl+/f/b/d/u
缂栬緫
- 鍒狅細dd/ndd/d1G/dG/d$/d0
- 澶嶅埗: yy/nyy/y1G/yG/y0/y$
- 绮樿创: p/P
- 鍚堝苟: J
- 鎾ら攢/閲嶅仛: u/ctrl+r
- 鎻掑叆: i/I a/A o/O
- 鏇挎崲 r/R
搴曠嚎鍛戒护妯″紡甯哥敤鎿嶄綔
鏌ユ壘
- :/ :锛?鍚戜笅/鍚戜笂鏌ユ壘
n銆丯: 鍚庝竴涓?鍓嶄竴涓?/p>
鏇挎崲
:%s/word1/word2/g
绯荤粺鐩戞帶
鑾峰彇鍩烘湰淇℃伅
- 鏌ョ湅绯荤粺鐗堟湰:
- uname -a
- cat /proc/version
- 绯荤粺杩愯鏃堕棿
- uptime
- CPU淇℃伅
- lscpu
- cat /pro/cpuinfo
- 鍐呭瓨淇℃伅
- cat /proc/meminfo
- 纾佺洏鍗犵敤淇℃伅
- df
- 缃戝崱閰嶇疆淇℃伅
- ifconfig
甯哥敤鐩戞帶鍛戒护
缁煎悎鐩戞帶
- top
- vmstat:鐩戞帶鎿嶄綔绯荤粺鐨勮繘绋嬬姸鎬併€佸唴瀛樸€佽櫄鎷熷唴瀛樸€佺鐩業O銆佷笂涓嬫枃銆丆PU鐨勪俊鎭?/li>
- dstat:鐩戞帶绯荤粺cpu,缃戠粶,纾佺洏,椤甸潰浜ゆ崲, 闇€棰濆
- sar:鍏ㄥ悕鐨勮幏鍙栧埌cpu 銆佽繍琛屻€佺鐩業O銆佽櫄鎷熷唴瀛樸€佸唴瀛樸€佺綉缁滅瓑淇℃伅
CPU鐩戞帶
- uptime:缁熻绯荤粺褰撳墠鐨勮繍琛岀姸鎬?/li>
- tload:鏌ョ湅褰撳墠CPU鐨刲oad锛屾瘡闅?鍒?s鏇存柊涓€娆?/li>
- cat /proc/loadavg
- mpstat:杈撳嚭姣忎釜CPU鐨勮繍琛岀姸鍐碉紝涓哄澶勭悊鍣ㄧ郴缁熶腑鐨凜PU鍒╃敤鐜囨彁渚涚粺璁′俊鎭?/li>
鍐呭瓨鐩戞帶:
- free: 鐩戞帶绯荤粺鍐呭瓨
- -b/k/m/g/--tera 璁惧畾鍗曚綅涓篵/Kb/M/G/T
- -l 鏄剧ず low/high
- -t 鏄剧ずtotal
- -s 鏇存柊鏃堕棿闂撮殧
- -c 鏇存柊娆℃暟
杩涚▼鐩戞帶
- ps
- IO鐩戞帶
- iotop:鍩虹鐨処/O鐩戞帶鍛戒护
- iostat: IO璇诲啓鐩戞帶锛岄渶瀹夎
缃戠粶鐩戞帶
- ifstat:缁熻缃戠粶鎺ュ彛娲诲姩鐘舵€?/li>
- netstat:鏄剧ず鏈満缃戠粶閾炬帴銆佽繍琛岀鍙c€佽矾鐢辫〃绛変俊鎭?/li>
ps鍛戒护-杩涚▼鏌ョ湅
鍙傛暟
- a: 鏄剧ず鎵€鏈夌▼搴?/li>
- u: 浠ョ敤鎴锋牸寮忔樉绀?/li>
- x: 鏄剧ず鎵€鏈夊寘鍚叾浠栫敤鎴风殑绋嬪簭
- f: 鏄剧ず绋嬪簭闆嗙殑鐩镐簰鍏崇郴
甯哥敤鍙傛暟缁勫悎锛?br /> ps 鈥揺f
ps aux
- UID 鐢ㄦ埛ID锛圲ser ID锛?/li>
- PID 杩涚▼ID锛圥rocess ID锛?/li>
- %CPU 杩涚▼鐨凜PU鍗犵敤鐜?/li>
- %MEM 杩涚▼鐨勫唴瀛樺崰鐢ㄧ巼
- VSZ 杩涚▼鎵€浣跨敤鐨勮櫄瀛樼殑澶у皬锛圴irtual Size锛?/li>
- RSS 杩涚▼浣跨敤鐨勫疄闄呭唴瀛樼殑澶у皬锛孠bytes瀛楄妭銆?/li>
- TTY 涓庤繘绋嬪叧鑱旂殑缁堢
- STAT 杩涚▼鐨勭姸鎬?
- R:杩愯, S: 鐫$湢, I: 绌洪棽, Z: 鍍垫, T: 缁堟, P:绛夊緟浜ゆ崲椤? X: 姝绘帀
- START 杩涚▼鍚姩鏃堕棿鍜屾棩鏈?/li>
- TIME 杩涚▼浣跨敤鐨勬€籆PU鏃堕棿
- COMMAND 姝e湪鎵ц鐨勫懡浠よ鍛戒护
top鍛戒护-缁煎悎鐩戞帶
鍙傛暟
- -b 鎵规杩愯
- -d 鍒锋柊鏃堕棿
- -n 杩愯娆℃暟
- -u/U 鐩戞帶鎸囧畾鐢ㄦ埛
- -p 鐩戞帶鎸囧畾杩涚▼
- -H 鏄剧ず绾跨▼
- -i 鏄剧ず绌洪棽鐨勮繘绋?/li>
缁熻淇℃伅:
- 绗?琛? 褰撳墠鏃堕棿 杩愯鏃堕棿 鐧诲綍鐢ㄦ埛鏁?CPU璐熻浇 锛?鍒?5鍒?15鍒嗭級
- 绗?琛? 杩涚▼淇℃伅
- total: 鎬昏繘绋嬫暟
- running: 杩愯涓繘绋嬫暟
- sleeping: 浼戠湢杩涚▼鏁?/li>
- stopped: 鍋滄鐨勮繘绋嬫暟
- zombie: 鍍靛案杩涚▼鏁?/li>
- 绗?琛? CPU淇℃伅
- us: 鐢ㄦ埛杩涚▼鍗犵敤CPU鐧惧垎姣?/li>
- sy: 鍐呮牳(绯荤粺)绌洪棿鍗犵敤CPU鐧惧垎姣?/li>
- ni: 鐢ㄦ埛杩涚▼绌洪棿鍐呮敼鍙樿繃浼樺厛绾х殑杩涚▼鍗犵敤CPU鐧惧垎姣?/li>
- id: 绌洪棽CPU鐧惧垎姣?/li>
- wa :绛夊緟杈撳叆杈撳嚭鐨凜PU鏃堕棿鐧惧垎姣?/li>
- hi :纭欢CPU涓柇鍗犵敤鐧惧垎姣?/li>
- si :杞腑鏂崰鐢ㄧ櫨鍒嗘瘮
- st:铏氭嫙鏈?铏氭嫙鍖栨妧鏈?鍗犵敤鐧惧垎姣?/li>
- 绗?琛? 鍐呭瓨淇℃伅
- total:鐗╃悊鍐呭瓨鎬婚噺
- used: 浣跨敤鍐呭瓨鎬婚噺
- free: 绌洪棽鍐呭瓨鎬荤悊瀹?/li>
- buffers: 鐢ㄤ綔鍐呮牳缂撳瓨鐨勫唴瀛橀噺
- 绗?琛? Swap鍐呭瓨浜ゆ崲鍖猴紙铏氭嫙鍐呭瓨锛?
- total: 浜ゆ崲鍖烘€婚噺
- used: 浣跨敤閲?/li>
- free: 绌洪棽閲?/li>
- cached: 缂撳啿鐨勪氦鎹㈠尯鎬婚噺
灞曠ず鍒?/h4>
- PID: 杩涚▼id
- USER: 杩涚▼鎵€灞炵敤鎴?/li>
- PR:浼樺厛绾?/li>
- NI: Nice鍊?璐熷€艰〃绀洪珮浼樺厛绾?姝e€艰〃绀轰綆浼樺厛绾?/li>
- VIRT: 杩涚▼鐢宠鍐呭瓨
- RES: 杩涚▼瀹為檯浣跨敤鍐呭瓨
- SHR:鍏变韩鍐呭瓨澶у皬锛屽崟浣岾B
- S:杩涚▼鐘舵€?D=涓嶅彲涓柇鐨勭潯鐪犵姸鎬?R=杩愯,S=鐫$湢,T=璺熻釜/鍋滄,Z=鍍靛案杩涚▼)
- %CPU:鑷笂涓€娆op鍒锋柊璇ヨ繘绋嬪崰鐢–PU鐨勬椂闂寸櫨鍒嗘瘮
- %MEM:杩涙秷鑰楀唴瀛樼櫨鍒嗘瘮
- TIME+:鑷繘绋嬪紑濮嬩互鏉ワ紝娑堣€桟PU鏃堕棿锛屽崟浣?/100绉?/li>
- COMMAND: 鎵ц鐨勫懡浠ゅ悕
以上是关于Linux鍩虹鍛戒护的主要内容,如果未能解决你的问题,请参考以下文章