標籤:blog http os io ar for 檔案 資料 art
http://blog.sina.com.cn/s/blog_79bc8e830101k6m9.html
1、尋找目前的目錄下所有以.tar結尾的檔案然後移動到指定目錄:
find . -name “*.tar” -exec mv {} ./backup/ ;尋找目前的目錄30天以前大於100M的LOG檔案並刪除。find . -name "*.log" –mtime +30 –type f –size +100M |xargs rm –rf {} ;寫一個指令碼尋找最後建立時間是3天前,尾碼是*.log的檔案並刪除。find . -mtime +3 -name "*.log" |xargs rm -rf {} ;寫一個指令碼將某目錄下大於100k的檔案移動至/tmp下。find . -size +100k -exec mv {} /tmp ;2、批量解壓目前的目錄下以.zip結尾的所有檔案到指定目錄:for i in `find . –name “*.zip” –type f `dounzip –d $i /data/www/img/done3、sed常用命收集:test.txt做測試 如何去掉行首的.字元: sed -i ‘s/^.//g‘ test.txt在行首添加一個a字元: sed ‘s/^/a/g‘ test.txt在行尾添加一個a字元: sed ‘s/$/a/‘ tets.txt在特定行後添加一個c字元: sed ‘/wuguangke/ac‘ test.txt在行前加入一個c字元: sed ‘/wuguangke/ic‘ test.txt4、如何判斷某個目錄是否存在,不存在則建立,存在則列印資訊。if[ ! –d /data/backup/ ];thenMkdir –p /data/backup/elseecho "The Directory already exists,please exit"fi註解:if …;then …else ..fi:為if條件陳述式,!歎號表示反義“不存在“,-d代表目錄。 5、監控linux磁碟根分區,如果根分區空間大於等於90%,發送郵件給Linux SA(1)、列印根分區大小df -h |sed -n ‘//$/p‘|awk ‘{print $5}‘|awk –F ”%” ‘{print $1}‘(2)、if條件判斷該大小是否大於90,如果大於90則發送郵件警示while sleep 5mdofor i in `df -h |sed -n ‘//$/p‘ |awk ‘{print $5}‘ |sed ‘s/%//g‘`doecho $iif [ $i -ge 90 ];thenecho “More than 90% Linux of disk space ,Please Linux SA Check Linux Disk !” |mail -s “Warn Linux / Parts is $i%” [email protected]fidonedone6、統計Nginx訪問日誌,訪問量排在前20 的 ip地址:cat access.log |awk ‘{print $1}‘|sort|uniq -c |sort -nr |head -207、sed另外一個用法找到當前行,然後在修改該行後面的參數:sed -i ‘/SELINUX/s/enforcing/disabled/‘ /etc/selinux/configSed冒號方式 sed -i ‘s:/tmp:/tmp/abc/:g’test.txt意思是將/tmp改成/tmp/abc/。11、列印出一個檔案裡面最大和最小值:cat a.txt |sort -nr|awk ‘{}END{print} NR==1′cat a.txt |sort -nr |awk ‘END{print} NR==1′這個才是真正的列印最大最小值:sed ‘s/ / /g’ a.txt |sort -nr|sed -n ’1p;$p’13、修改文本中以jk結尾的替換成yz:sed -e ‘s/jk$/yz/g’ b.txt14、網路抓包:tcpdumptcpdump -nn host 192.168.56.7 and port 80 抓取56.7通過80請求的資料包。tcpdump -nn host 192.168.56.7 or ! host 192.168.0.22 and port 80 排除0.22 80連接埠!16、顯示最常用的20條命令:cat .bash_history |grep -v ^# |awk ‘{print $1}’ |sort |uniq -c |sort -nr |head -2019、寫一個防火牆配置指令碼,只允許遠程主機訪問原生80連接埠。iptables -Fiptables -Xiptables -A INPUT -p tcp --dport 80 -j acceptiptables -A INPUT -p tcp -j REJECT或者iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 20、寫一個指令碼進行nginx日誌統計,得到訪問ip最多的前10個(nginx日誌路徑:/home/logs/nginx/default/access.log)。cd /home/logs.nginx/defaultsort -m -k 4 -o access.logok access.1 access.2 access.3 .....cat access.logok |awk ‘{print $1}‘|sort -n|uniq -c|sort -nr |head -10 21.寫出下列命令的含義(1)MaxKeepAliveRequests 100 串連的最大請求數(2)Options FollowSymLinks 允許192.168.1.1可以列目錄 Order Deny Allow Deny from all Allow from 192.168.1.122.替換檔案中的目錄sed ‘s:/user/local:/tmp:g‘ test.txt或者sed -i ‘s//usr/local//tmp/g‘ test.txt
linux營運常用命令及知識