aaron note linux shell command


使用開源工具來作運維監控,如nagios報警,munin/cacti監控,puppet配置php

watch -n 2 'ss -s'html

wc -l /proc/net/tcpjava


命令行製造cpu壓力 cat /dev/urandom | md5summysql


查看nginx編譯參數:/usr/local/nginx/sbin/nginx -Vlinux

查看php編譯參數:/usr/local/php/bin/php -i | grep configureios


拷貝目錄, 忽略大圖片目錄nginx

rsync -rt --exclude="static/p_w_picpaths/upload" web/ web-testweb


指定內容出如今文件中的總行數正則表達式

cat all.log |grep 'data size:' | wc -lsql

含子目錄查找 grep oldWord `find ./ -name "*.sh"` grep -ir oldWord *.sh(not work anymore)

批量文件替換 sed -i 's|oldWord|newWord|g' *.sh

含子目錄替換 sed -i 's|oldString|newString|g' `find ./ -name "*.sh" -type f`


查找三個月沒有更新的文件(!!!若是沒有結果, 則會列出全部文件)

ls -lhtr `find /logs/ -iname '*.log' -type f -not -mtime -90`

刪除三個月沒有更新的文件

find /logs/ -iname '*.log' -type f -not -mtime -90 -exec rm -f {} \;

 

刪除當前目錄的子目錄中的文件, 但保留每一個子目錄修改時間最新的兩個文件

for dd in `dir -d *` ; do cd $dd; rm -f `ls -t |sed 1,2d |tr '\n' ' '`; cd ..; done

 

搜索當前目錄的子目錄大小爲1M-1023M之間, 從大到小排列, 取前20個, 刪除這些子目錄中的最後修改時間爲48小時以前的.log文件並進行刪除

要先執行du -h --max-depth=1 |grep M |sort -nr |head -n 20查看確保第一列不是當前目錄./

find `du -h --max-depth=1 |grep M |sort -nr |head -n 20 |awk '{print $2}' |tr '\n' ' '` -iname '*.log' -type f -not -mtime -2 -exec rm -f {} \;

 

設置用戶的默認umask

umask 0022 增長到.bashrc

遞歸設置文件權限爲644

find /path -type f -exec chmod 644 {} \;

遞歸設置目錄權限爲755

find /path -type d -exec chmod 755 {} \;

 

當前目錄下全部文件, 不含子目錄和子目錄中的文件, 兩種方式輸出的格式不同

ll |grep -v ^d 或 find ./ -maxdepth 1 -iname '*' -type f

 

rm後能夠接多個文件, 文件名能夠用正則表達式

通常用rm -fr (force, recursive)


ls --help |more

man ls


chown; chgrp

chmod u+x myStart.sh







free -m

top

du -h --max-depth

du -h --max-depth=1 |grep G |sort -n

du -h --max-depth=1 |grep M |sort -nr |head

 

ps aux | grep java

強行結束 kill -9

結束全部 killall

重啓程序 kill -HUP


wget http://members.3322.org/dyndns/getip


ipcs -a


fuser -mv /usr

ps -fp "PID1 PID2"


sqlplus '' /as sysdba ''

nohup curl "" > output.txt

nohup curl "" > /dev/null

crontab -l

crontab -e

>/dev/null  2>&1  &


mysqld_safe --bind-address=127.0.0.1

memcached -d -m 512 -u user -l 127.0.0.1 -p 11211 -P /tmp/memcached.pid

telnet 127.0.0.1 11211





which mysql

whereis php

find / -name 'java'


yum check-update

yum update kernel kernel-source

 

yum install xmms-mp3

yum remove licq

 

yum list mozilla*

yum list updates

yum list installed


view or find installed software:

rpm -ivh [file_name]

rpm -qa |more

rpm -q software_name (rpm -q ftp) (rpm -q apache)(rpm -qa | grep httpd)

uninstall: rpm -e or rpm -ev







linux調優:

http://www.phpchina.com/download/handbook/linux-html/type17.html


vi /etc/inittab

change 'id:5:initdefault:' to 'id:3:initdefault:'


(change linux to English)

temporary:

#export LC_ALL=POSIX

persistent:

編輯/etc/sysconfig/目錄下的i18n文件,將LC_ALL=POSIX





/etc/samba/smb.conf

1.hosts allow = 192.168.0.

security = share

2.[share_name]

comment = #comment

path = /home/share

browseable = 

writable = 

guest ok = 

3.

id nobody

uid=99(nobody) gid=99(nobody) groups=99(nobody)

chown -R nobody:nobody /home/share

4. ;service iptables stop

service network restart

service smb start


zip -r -9 products.zip products/ good_products.xml bad_products.xml

tar -czf

tar -xjf filename.tar.bz2

tar cf blog.tar blog --exclude blog/static/p_w_picpaths/upload

c: create; x: extract; z: gzip format; j: bz2 format


scp -rCp user@IP:source destination

scp -rCp source user@IP:destination


vimdiff scp://user@IP:port/~/blog/static/js/common.js ~/Documents/www/blog/static/js/common.js

diff -r <(md5 ~/Documents/workspace/proj-blog/target/proj-blog-0.0.1-SNAPSHOT.jar) <(ssh -p port user@IP 'md5sum /usr/local/tomcat/proj-web/webapps/proj-web-0.0.1-SNAPSHOT/WEB-INF/lib/proj-blog-0.0.1-SNAPSHOT.jar')

相關文章
相關標籤/搜索