吐血貢獻(xiàn)我常用的shell命令_第1頁
吐血貢獻(xiàn)我常用的shell命令_第2頁
吐血貢獻(xiàn)我常用的shell命令_第3頁
吐血貢獻(xiàn)我常用的shell命令_第4頁
吐血貢獻(xiàn)我常用的shell命令_第5頁
已閱讀5頁,還剩12頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、netstat -n | awk '/tcp/ +S$NF END for(a in S print a, Sa'CLOSED:無連接是活動(dòng)的或正在進(jìn)行LISTEN:服務(wù)器在等待進(jìn)入呼叫SYN_RECV:一個(gè)連接請(qǐng)求已經(jīng)到達(dá),等待確認(rèn)SYN_SENT:應(yīng)用已經(jīng)開始,打開一個(gè)連接ESTABLISHED:正常數(shù)據(jù)傳輸狀態(tài)FIN_WAIT1:應(yīng)用說它已經(jīng)完成FIN_WAIT2:另一邊已同意釋放ITMED_WAIT:等待所有分組死掉CLOSING:兩邊同時(shí)嘗試關(guān)閉TIME_WAIT:另一邊已初始化一個(gè)釋放LAST_ACK:等待所有分組死掉netstat -an | grep -i &q

2、uot;:80" | awk 'print $6' | sort | uniq -c | sort -n 統(tǒng)計(jì)TCP各個(gè)連接狀態(tài)的數(shù)量netstat -na | grep -c ":80"顯示并發(fā)進(jìn)程ls -l按文件大小排序/Data/apps/httpd/bin/apachectl stop/Data/apps/httpd/bin/apachectl start重啟和停止apachenetstat -an|grep ':80'mail收郵件修改郵件路徑可以在/etc/profile里修改hi

3、story查看歷史的運(yùn)行指令查看訪問80端口的連接ls -al列出當(dāng)前所有檔案(包含隱藏檔及所有的檔案屬性alias lm='ls -al'type ls查看ls是內(nèi)建指令還是非內(nèi)建指令curl -I telnet 11211telnet 25SHOW VARIABLES LIKE 'have_query_cache'通過have_query_cache服務(wù)器系統(tǒng)變量指示查詢緩存是否可用:SHOW VARIABLES LIKE 'query_cache_size'取得查詢緩存大小SET G

4、LOBAL query_cache_size = 40000;FLUSH QUERY CACHE可以使用FLUSH QUERY CACHE語句來清理查詢緩存碎片以提高內(nèi)存使用性能。該語句不從緩存中移出任何查詢。RESET QUERY CACHE從查詢緩存中移出所有查詢/Data/apps/apache/bin/apachectl -t/Data/apps/apache/bin/apachectl -k gracefulError: Table 'xxx' is marked as crashed and should be repairedREPAIR TABLE xxx;ro

5、otpilot bin# /Data/apps/mysql/bin/perror 29OS error code 29: Illegal seek查詢錯(cuò)誤代碼描述信息SELECT name, db FROM c LIMIT 0 , 30;查詢存儲(chǔ)過程列表lsof | grep mysql從哪里看描述符lsof | grep error_logrsync -az -delete -progress /home/www/test /home/www/test2本地同步/usr/bin/rsync -vzrtopg -progress -e ssh root:

6、/etc/hosts /etc/mysqldump -h -uusername -ppass dbname > db.sql導(dǎo)出數(shù)據(jù)庫sftp username連接sftpget /var/www/index.php index.php下載遠(yuǎn)程主機(jī)文件到本地put index.php /home/www/index.php上傳本地文件到遠(yuǎn)程主機(jī)lpwd查看本機(jī)目錄if -s /tmp/php-error.log thenDATE=date +%y%m%dcp /tmp/php-error.log /logs/php_error_log/php-erro

7、r$DATE.logcat /dev/null > /tmp/php-error.loggzip -9 /logs/php_error_log/*.logelseecho okfi= dir=cd /Data/cache;ls | grep ".old"for dirname in $dirdocd /Data/cache;find ./$dirname/ -name '*' -exec rm -rdf ; >/dev/null 2>&1 & donedir = cd /Data/webapps/;ls"for d

8、irname in $dirdoecho dirnamedoneecho md5(uniqid(microtime(;生成唯一標(biāo)識(shí)explorer mysqladmin -h -uroot create 1111 mysqladmin -h -uroot status;mysqladmin -h -uroot drop 1111 mysqladmin -h -uroot processlist; mysqladmin -h -uroot ping mysqladmin -h -uroot

9、 version mysqladmin -h -uroot shutdown 關(guān)閉mysql服務(wù)器svn log urlsvn infosvn lsexplorer e:打開E盤ls | vim -Vim 能從標(biāo)準(zhǔn)輸入讀取文本zfap zo設(shè)置折疊與打開折疊:colo default語法高亮設(shè)置CTRL-Z在vim中把vim先掛起。fg命令:!ls 從vim內(nèi)執(zhí)行單個(gè)shell命令service mysql restart/etc/init.d/mysql start|stop|restart|reload|force-reloadsps -A | grep mysql查看運(yùn)

10、行的mysql進(jìn)程kill后重啟mysqlCan't open file: 'group_lists.MYI' (errno: 145n的解決方案repair table group_listsSELECT benchmark( 100000000, 'select * from group_lists' 檢測(cè)Mysql的性能SELECT * FROM group_lists PROCEDURE ANALYSE ( 分析各個(gè)子段類型大小是否設(shè)置合適ps -ef|grep httpd|wc -l/server-statusap

11、ache信息查看php_flag engine off 對(duì)于不需要php權(quán)限的目錄或者虛擬主機(jī)設(shè)置加上這個(gè)ls -al 查看所有文件包括隱藏文件htpasswd -c /tmp/.htpasswd admin建立一口令文件,文件名為.htpasswd,用戶名為admin.htaccess文件AuthName admin-onlyAuthType BasicAuthUserFile /tmp/.htpasswdrequire user admin/Data/apps/apache/bin/httpd -k restart重啟apachescp /home/scw/group2.sql sunch

12、angwei:/home/sunchangweiSCP的新命令,這個(gè)命令可以在主機(jī)間進(jìn)行大數(shù)據(jù)量的交互。而且在局域網(wǎng)中傳數(shù)據(jù),可以達(dá)到10MB/S.詳細(xì)的命令格式,可以用man scp進(jìn)行查詢gzip壓縮命令mysql -uroot -p tablename < tablename.sql導(dǎo)入數(shù)據(jù)update mysql.db set db ='group2' where user = 'group'll -t按時(shí)間排序ll -S按大小排序awk 'print "space"' /etc/passw

13、dawk 'print' /etc/passwdawk -F":" 'print $1' /etc/passwdawk -F":" 'print "username" $1 "ttuid" $3' /etc/passwdawk /var/'print' /etc/passwd > var.txt會(huì)對(duì)/etc/passwd中的每一行執(zhí)行正則表達(dá)式/var/篩選出來保存到var.txtawk 'print $1' /etc/passw

14、d | tee passwd.txt輸出到文件的同時(shí)也在屏幕上顯示awk 'BEGIN print "Name Beltn-"print $1"t",$4' grade.txtawk '$4 /Brown/' grade.txt打印信息頭Name Belt-M.Tans GreenJ.Lulu greenP.Bunny YellowJ.Troll Brown-3L.Tansl Brown-2awk 'BEGIN print "Namen-"print $1 END print "end

15、-of-report"' grade.txt 打印信息尾awk 'BEGIN print "Namen-"print $1 END "end-of-report"'awk 'if($4 /Brown/ print $1' grade.txt使用操作符和正則例子awk 'gsub(/48317/,6666print $0' grade.txt把記錄中匹配/48317/的替換為6666sed -n '2p' quote.txt 只打印第二行sed -n '1,3p

16、9; quote.txt打印第1到3行sed -n '1,$p' quote.txt 顯示一個(gè)文件的所有行sed -n '1p' quote.txt 打印第一行sed -n '$p' quote.txt 打印最后一行find /Data/logs -type f -mtime +5 -exec rm ;在logs目錄中查找是文件并在5天以前被更改find -type f -print | xargs filefind -name "*.php"在當(dāng)前目錄下查找所有擴(kuò)展名php的文件find /Data/ -type d查找目錄

17、下的所有目錄grep -i -c "usp" data.f在data.f文件中查找usp,不區(qū)分大小寫,只返回匹配的行數(shù)grep -r 'GroupProfileDAO:exist' ./grep -r 'GroupProfileDAO:exist' *.php 只查找php文件grep -n -r 'GroupProfileDAO:exist' *.php加上行號(hào)mysqladmin -uroot ping &>dev/nullmysqladmin -h -uroot -proot proce

18、sslistmysqladmin -h -uroot -proot versionmysqldumpslow -s c -t 5 ment.20080822 > ment.20080822.log -g | grep -v localmysqldumpslow -s c 10.slow.log.20080825 | grep -i notice_message | wc -lmysqldumpslow -s c -t 20 myqlslow.log找出查詢次數(shù)最多的前20條sqlmysqldumpslow -s t -t 20 mysqlslow.log找出查詢時(shí)間最多

19、的前20條sqlecho "That is all right, this is a great job." > test.txthead -n 1 /etc/issue查看操作系統(tǒng)版本df -h 查看各分區(qū)的使用情況last | grep "heiyeluren" | wc -l查看用戶登陸日志ls *0-9*顯示包含數(shù)字的文件名和目錄名mkdir -p /tmp/dir1/dir2創(chuàng)建一個(gè)目錄樹rm -f file1刪除一個(gè)叫做'file1' 的文件'rmdir dir1刪除一個(gè)叫做'dir1' 的目錄&

20、#39;find /dir1/dir2/ -name *.php在此目錄中查找以php結(jié)尾的文件du -sh dirname估算dirname所占用的磁盤空間df -h | grep 50%cat /etc/group查看所有用戶組groupadd group_name 添加一個(gè)用戶組groupdel group_name 刪除一個(gè)用戶組groupmod -n newGroupname oldGroupname 重命名一個(gè)用戶組bzip2 file1壓縮一個(gè)叫file1的文件bunzip2 file1 解壓縮文件gzip file1gunzip file1more /var/log/messa

21、ges查看大文件內(nèi)容grep Aug -R /var/log/*type command查看command指令是內(nèi)建指令還是外建read -p "Please keyin your name: " -t 30 named讀取來自鍵盤輸入的變量,并加上提示,超過30秒沒動(dòng)作自動(dòng)停止a0="apple"a1="orange"a2="banana"for b in $a;doecho $bdoneshell數(shù)組循環(huán)例子echo "empty" >> test1.$basename dir

22、從路徑中分離出文件名cat f1 f2 >> f3把f1和f2的內(nèi)容合并到f3diff f1 f2dirname 跟basename相反file filename 用來確定文件類型logname 顯示當(dāng)前使用的登陸用戶名簡(jiǎn)單的if控制語句=if -d f1 ; thenecho "is dir"elseecho "not dir"fi=function checkUser(name0="admin"name1="test"name2="sysadmin"name3="op&

23、quot;for row in $name;doif $row = $1 ;thenreturn 0fidonereturn 1pass=Nread -p "please input login username:" -t 30 username while $pass = N ;doif checkUser $username;thenecho "username pass"exit 1elseread -p "pass not right,please input again:" -t 30 usernamefi done = 簡(jiǎn)

24、單的用戶驗(yàn)證腳本 if cp myfile myfile.bak;then mysqldump -h -uroot notice > /tmp/notice.sql cd /tmp sftp root get notice.sql rm -fr notice.sql mysql ad1 < /tmp/ad.sql -uroot -p 導(dǎo)入數(shù)據(jù) temph=date | cut -c12-13 截取 date 的第 12 個(gè)和第 13 個(gè)字符 echo -e "03334m qweqwe " RESET QUERY CACHE;

25、 清理查詢緩存 SHOW VARIABLES LIKE 'have_query_cache' INSERT INTO user SELECT * FROM user WHERE user.user = 'group' ON DUPLICATE KEY UPDATE user.user = 'notice' UPDATE user SET PASSWORD = md5( 'notice.tiger' WHERE User = 'notice' 原來 mysql 的 md5 和 password 不一樣 group2

26、INSERT INTO db SELECT * FROM db WHERE db.user = 'group2' ON DUPLICATE KEY UPDATE user.user = 'group2' INSERT INTO mysql.db SELECT * FROM mysql.db WHERE mysql.db.user = 'notice' ON DUPLICATE KEY UPDATE mysql.db.user = 'noticea' 修改數(shù)據(jù)庫權(quán)限后要重啟 mysql 才能生效 /usr/local/bin/con

27、vert lifestyle_logo.gif -resize 90x90 out.gif which php which convert 查找命令的目錄文件 /usr/local/bin/convert -mattecolor "#000000" -frame "3x3" lifestyle_logo.gif remember.gif 為圖片加邊框,邊框顏色是黑色,邊框?qū)挾群透叨榷际?3px /usr/local/bin/convert -fill green -pointsize 40 -draw 'text 10,50 "goog

28、le"' lifestyle_logo.gif fill.gif 為圖片加文字,用 green 顏色字體大小 40,距離左上角 10*50 位置,文字為 google /usr/local/bin/convert animation.gif frmae%02d.gif 把 gif 文件分解為一系列的單個(gè)圖片 - 遠(yuǎn)端登錄 ssh userremote.machine - 遠(yuǎn)端執(zhí)行 ssh userremote.machine 'command .' - 遠(yuǎn)端複制 scp userremote.machine:/remote/path /local/path s

29、cp /local/path userremote.machine:/remote/path id username last df -h 顯示所有磁盤系統(tǒng)的信息 show variables like 'datadir' 顯示 mysql 的數(shù)據(jù)庫目錄 mysqladmin -h -uroot variables 如何修改 mysql 的默認(rèn)帳號(hào) root use mysql; update user set password=password('passowrd' where user='root' flush privil

30、eges; 刷新內(nèi)存中的權(quán)限表 使用 mysqladmin 和 set password,會(huì)自動(dòng)重載該表 mysql>grant all on db.* to 'test''%' identified by 'test' 上例運(yùn)行后的效果是,test 用戶可通過test密碼從任意計(jì)算機(jī)上訪問 db 數(shù)據(jù)庫。%代表任 意字符,_代表一個(gè)任意字符。主機(jī)名部份還可以是 IP 地址 flush logs; ALTER TABLE table_name DISABLE KEYS; 禁用索引 ALTER TABLE table_name ENABLE K

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論