1¡¢linuxÆô¶¯¹ý³Ì
¡¡¡¡¿ªÆôµçÔ´ --> BIOS¿ª»ú×Ô¼ì --> Òýµ¼³ÌÐòlilo»ògrub --> Äں˵ÄÒýµ¼£¨kernel boot£©--> Ö´ÐÐinit£¨rc.sysinit¡¢rc£©--> mingetty£¨½¨Á¢Öնˣ© --> shell
2¡¢Íø¿¨°ó¶¨¶àIP
# ifconfig eth0:1 192.168.1.99 netmask 255.255.255.0
3¡¢ÉèÖÃDNS¡¢Íø¹Ø
# echo "nameserver 202.16.53.68" ¡·/etc/resolv.conf
# route add default gw 192.168.1.1
4¡¢µ¯³ö¡¢ÊջعâÇý
# eject
# eject -t
5¡¢ÓÃdate²éѯ×òÌìµÄÈÕÆÚ
# date --date=yesterday
6¡¢²éѯfile1ÀïÃæ¿ÕÐеÄËùÔÚÐкÅ
# grep ^$ file
7¡¢²éѯfile1ÒÔabc½áβµÄÐÐ
# grep abc$ file1
8¡¢´òÓ¡³öfile1ÎļþµÚ1µ½µÚÈýÐÐ
# sed -n '1,3p' file1
# head -3 file1
9¡¢Çå¿ÕÎļþ
# true > 1.txt
# echo "" > 1.txt
# > 1.txt
# cat /dev/null > 1.txt
10¡¢É¾³ýËùÓпÕĿ¼
# find /data -type d -empty -exec rm -rf {} \;
11¡¢linuxÏÂÅúÁ¿É¾³ý¿ÕÎļþ£¨´óСµÈÓÚ0µÄÎļþ£©µÄ·½·¨
# find /data -type f -size 0c -exec rm -rf {} \;
# find /data -type f -size 0c|xargs rm -f
12¡¢É¾³ýÎåÌìÇ°µÄÎļþ
# find /data -mtime +5 -type f -exec rm -rf {} \;
13¡¢É¾³ýÁ½¸öÎļþÖظ´µÄ²¿·Ý£¬´òÓ¡ÆäËü
# cat 1.txt 3.txt |sort |uniq
14¡¢¹¥È¡Ô¶³Ì·þÎñÆ÷Ö÷»úÃû
# echo `ssh $IP cat /etc/sysconfig/network|awk -F = '/HOSTNAME/ {print$2}'`
15¡¢ÊµÊ±¼à¿ØÍø¿¨Á÷Á¿£¨°²×°iftop£©
# /usr/local/iftop/sbin/iftop -i eth1 -n
16¡¢²é¿´ÏµÍ³°æ±¾
# lsb_release -a
17¡¢Ç¿ÖÆÌß³öµÇ½Óû§
# pkill -KILL -t pts/1
18¡¢tarÔöÀí±¸·Ý¡¢»¹Ô
# tar -g king -zcvf kerry_full.tar.gz kerry
# tar -g king -zcvf kerry_diff_1.tar.gz kerry
# tar -g king -zcvf kerry_diff_2.tar.gz kerry
# tar -zxvf kerry_full.tar.gz
# tar -zxvf kerry_diff_1.tar.gz
# tar -zxvf kerry_diff_2.tar.gz
19¡¢½«±¾µØ80¶Ë¿ÚµÄÇëÇóת·¢µ½8080¶Ë¿Ú£¬µ±Ç°Ö÷»úÍâÍøIPΪ202.96.85.46
-A PREROUTING -d 202.96.85.46 -p tcp -m tcp --dport 80 -j DNAT--to-destination 192.168.9.10:8080
20¡¢ÔÚ11Ô·ÝÄÚ£¬Ã¿ÌìµÄÔçÉÏ6µãµ½12µãÖУ¬Ã¿¸ô2СʱִÐÐÒ»´Î/usr/bin/httpd.sh
# crontab -e
0 6-12/2 * 11 * /usr/bin/httpd.sh
21¡¢²é¿´Õ¼Óö˿Ú8080µÄ½ø³Ì
# netstat -tnlp | grep 8080
lsof -i:8080
22¡¢ÔÚShell»·¾³Ï£¬ÈçºÎ²é¿´Ô¶³ÌLinuxϵͳÔËÐÐÁ˶àÉÙʱ¼ä£¿
# ssh user@±»¼à¿ØÖ÷»úip "uptime"
23¡¢²é¿´CPUʹÓÃÇé¿öµÄÃüÁî
""ÿ5ÃëË¢ÐÂÒ»´Î£¬×îÓÒ²àÓÐCPUµÄÕ¼ÓÃÂʵÄÊý¾Ý
# vmstat 5
""top È»ºó°´Shift+P£¬°´ÕÕ½ø³Ì´¦ÀíÆ÷Õ¼ÓÃÂÊÅÅÐò
# top
24¡¢²é¿´ÄÚ´æʹÓÃÇé¿öµÄÃüÁî
""ÓÃfreeÃüÁî²é¿´ÄÚ´æʹÓÃÇé¿ö
# free -m
""top È»ºó°´Shift+M, °´ÕÕ½ø³ÌÄÚ´æÕ¼ÓÃÂÊÅÅÐò
# top
25¡¢²é¿´´ÅÅÌi/o
""ÓÃiostat²é¿´´ÅÅÌ/dev/sdc3µÄ´ÅÅÌi/oÇé¿ö£¬Ã¿Á½ÃëË¢ÐÂÒ»´Î
# iostat -d -x /dev/sdc3 2
26¡¢ÐÞ¸´Îļþϵͳ
# fsck -yt ext3 /
-t Ö¸¶¨Îļþϵͳ
-y ¶Ô·¢ÏÖµÄÎÊÌâ×Ô¶¯»Ø´ðyes
27¡¢read ÃüÁî5Ãëºó×Ô¶¯Í˳ö
# read -t 5
28¡¢grep -E -P ÊÇʲôÒâ˼
-E, --extended-regexp ²ÉÓÃÀ©Õ¹Õý¹æ±í´ïʽ¡£
-P£¬--perl-regexp ²ÉÓÃperlÕý¹æ±í´ïʽ
29¡¢vi±à¼Æ÷£¨Éæ¼°µ½Ð޸ģ¬Ìí¼Ó£¬²éÕÒ£©
¡¡¡¡²åÈ루insert£©Ä£Ê½
i¡¡¡¡¡¡¡¡¹â±êÇ°²åÈë
I¡¡¡¡¡¡¡¡¹â±êÐÐÊײåÈë
a¡¡¡¡¡¡¡¡¹â±êºó²åÈë
A¡¡¡¡¡¡¡¡¹â±êÐÐβ²åÈë
o¡¡¡¡¡¡¡¡¹â±êËùÔÚÐÐϲåÈëÒ»ÐУ¬ÐÐÊײåÈë
O¡¡¡¡¡¡¡¡¹â±êËùÔÚÐÐÉϲåÈëÒ»ÐУ¬ÐÐÊײåÈë
G¡¡¡¡¡¡¡¡ÒÆÖÁ×îºóÒ»ÐÐÐÐÊ×
nG¡¡¡¡¡¡¡¡ÒÆÖÁµÚnÐÐÐÐÊ×
n+¡¡¡¡¡¡¡¡ÏÂÒÆnÐУ¬ÐÐÊ×
n-¡¡¡¡¡¡¡¡ÉÏÒÆnÐУ¬ÐÐÊ×
:/str/¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡´Óµ±Ç°ÍùÓÒÒƶ¯µ½ÓÐstrµÄµØ·½
str?¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡´Óµ±Ç°Íù×óÒƶ¯µ½ÓÐstrµÄµØ·½
:s/str1/str2/¡¡¡¡¡¡¡¡¡¡¡¡½«ÕÒµ½µÄµÚÒ»¸östr1Ì滻Ϊstr2
:s/str2/str2/g¡¡¡¡¡¡¡¡¡¡¡¡½«µ±Ç°ÐÐÕÒµ½µÄËùÓÐstr1Ì滻Ϊstr2
:n1,n2s/str1/str2/g¡¡¡¡¡¡¡¡½«´Ón1ÐÐÖÁn2ÐÐÕÒµ½µÄËùÓеÄstr1Ì滻Ϊstr2
:1,.s/str1/str2/g¡¡¡¡¡¡¡¡¡¡¡¡½«´ÓµÚ1ÐÐÖÁµ±Ç°ÐеÄËùÓÐstr1Ì滻Ϊstr2
:.,$s/str1/str2/g¡¡¡¡¡¡¡¡¡¡¡¡½«´Óµ±Ç°ÐÐÖÁ×îºóÒ»ÐеÄËùÓÐstr1Ì滻Ϊstr2
30¡¢linux·þÎñÆ÷Ö®¼äÏ໥¸´ÖÆÎļþ
copy ±¾µØÎļþ1.shµ½Ô¶³Ì192.168.9.10·þÎñÆ÷µÄ/data/Ŀ¼ÏÂ
# scp /etc/1.shking@192.168.9.10:/data/
copyÔ¶³Ì192.168.9.10·þÎñÆ÷/data/2.shÎļþµ½±¾µØ/data/Ŀ¼
# scpking@192.168.9.10:/data/2.sh/data/
31¡¢Ê¹ÓÃsedÃüÁî°Ñtest.txtÎļþµÄµÚ23ÐеÄTEST»»³ÉTSET.
# sed -i '23s/TEST/TSET/' test.txt
# sed -i '23 s/TEST/TSET/' test.txt
32¡¢Ê¹historyÃüÁîÄÜÏÔʾʱ¼ä
# export HISTTIMEFORMAT="%F %T "
33¡¢ÈçºÎ²é¿´Ä¿±êÖ÷»ú192.168.0.1¿ª·ÅÄÇЩ¶Ë¿Ú
# nmap -PS 192.168.0.1
34¡¢ÈçºÎ²é¿´ÍøÂçÁ¬½Ó
# netstat -n | awk '/^tcp/ {++S[$NF]} END {for£¨a in S£© print a,S[a]}'
35¡¢ÈçºÎ²é¿´µ±Ç°ÏµÍ³Ê¹ÓÃÁËÄÇЩ¿âÎļþ
# ldconfig -v
36¡¢ÈçºÎ²é¿´Íø¿¨µÄÇý¶¯°æ±¾
# ethtool -i eth0
37¡¢Ê¹ÓÃtcpdumpÀ´¼àÊÓÖ÷»ú192.168.0.1µÄtcpµÄ80¶Ë¿Ú
# tcpdump tcp port 80 host 192.168.0.1
38¡¢ÈçºÎ¿´ÆäËüÓû§µÄÓʼþÁбí
# mial -u king
39¡¢¶Ô´óÎļþ½øÐÐÇиî
¡¡¡¡°´Ã¿¸öÎļþ1000ÐÐÀ´·Ö¸î
# split -l 1000 httperr8007.log httperr
¡¡¡¡°´ÕÕÿ¸öÎļþ5mÀ´·Ö¸î
# split -b 5m httperr8007.log httperr
40¡¢ºÏ²¢Îļþ
¡¡¡¡È¡³öÁ½¸öÎļþµÄ²¢¼¯£¨Öظ´µÄÐÐÖ»±£ÁôÒ»·Ý£©
# cat file1 file2 | sort | uniq
¡¡¡¡È¡³öÁ½¸öÎļþµÄ½»¼¯£¨Ö»ÁôÏÂͬʱ´æÔÚÓÚÁ½¸öÎļþÖеÄÎļþ£©
# cat file1 file2 | sort | uniq -d
¡¡¡¡É¾³ý½»¼¯£¬ÁôÏÂÆäËûµÄÐÐ
# cat file1 file2 | sort | uniq -u
41¡¢´òÓ¡Îı¾Ä£Ê½ÏÂÔËÐеķþÎñ
# chkconfig --list|awk '$5~/on/{print $1,$5}'
42¡¢É¾³ý0×Ö½ÚÎļþ
# find -type f -size 0 -exec rm -rf {} \;
43¡¢²é¿´½ø³Ì£¬°´ÄÚ´æ´Ó´óµ½Ð¡ÅÅÁÐ
# ps -e -o "%C : %p : %z : %a"|sort -k5 -nr
44¡¢²é¿´httpµÄ²¢·¢ÇëÇóÊý¼°ÆäTCPÁ¬½Ó״̬
# netstat -n | awk '/^tcp/ {++S[$NF]} END {for£¨a in S£© print a,S[a]}'
45¡¢»ñÈ¡IPµØÖ·
# ifconfig eth0|sed -n '2p'|awk '{print $2}'|cut -c 6-30
perlʵÏÖ»ñÈ¡IPµØÖ·£º
# ifconfig -a | perl -ne 'if £¨ m/^\s*inet £¨?:addr:£©?£¨[\d.]+£©.*?cast/ £© { print qq£¨$1 £©; exit 0; }'
46¡¢»ñÈ¡ÄÚ´æ´óС
# free -m |grep "Mem" | awk '{print $2}'
47¡¢²é¿´CPUºËÐÄÊý
# cat /proc/cpuinfo |grep -c processor
48¡¢²é¿´´ÅÅÌʹÓÃÇé¿ö
# df -h
49¡¢²é¿´ÓжàÉÙ¸ö»î¶¯µÄphp-cgi½ø³Ì
# netstat -anp | grep php-cgi | grep ^tcp | wc -l
50¡¢²é¿´Ó²¼þÖÆÔìÉÌ
# dmidecode -s system-product-name
²éѯTCPÁ¬½ÓÇé¿ö£º
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) printa, S[a]}'
1.ɾ³ý0×Ö½ÚÎļþ
find -typef -size 0 -exec rm -rf {} \;
2.²é¿´½ø³Ì°´ÄÚ´æ´Ó´óµ½Ð¡ÅÅÁÐ
ps -e -o"%C : %p : %z : %a"|sort -k5 -nr
3.°´cpuÀûÓÃÂÊ´Ó´óµ½Ð¡ÅÅÁÐ
ps -e -o"%C : %p : %z : %a"|sort -nr
4.´òӡ˵cacheÀïµÄURL
grep -r -ajpg /data/cache/* | strings | grep "http:" | awk -F'http:' '{print"http:"$2;}'
5.²é¿´httpµÄ²¢·¢ÇëÇóÊý¼°ÆäTCPÁ¬½Ó״̬£ºnetstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
6. sed -i'/Root/s/no/yes/' /etc/ssh/sshd_config sedÔÚÕâ¸öÎÄÀïRootµÄÒ»ÐУ¬Æ¥ÅäRootÒ»ÐУ¬½«noÌæ»»³Éyes.
7.ÈçºÎɱµômysql½ø³Ì£º ps aux|grep mysql|grep-v grep|awk '{print $2}'|xargs kill -9 (´ÓÖÐÁ˽⵽awkµÄÓÃ;) killall -TERM mysqld kill -9 `cat/usr/local/apache2/logs/httpd.pid` ÊÔÊÔ²éɱ½ø³ÌPID
8.ÏÔʾÔËÐÐ3¼¶±ð¿ªÆôµÄ·þÎñ: ls /etc/rc3.d/S* |cut-c 15- (´ÓÖÐÁ˽⵽cutµÄÓÃ;£¬½ØÈ¡Êý¾Ý)
9.ÈçºÎÔÚ±àдSHELLÏÔʾ¶à¸öÐÅÏ¢£¬ÓÃEOF cat <
10. for µÄÇÉÓÃ(Èç¸ømysql½¨ÈíÁ´½Ó)
cd/usr/local/mysql/bin for i in * do ln /usr/local/mysql/bin/$i /usr/bin/$i done
11. È¡IPµØÖ·£º ifconfig eth0 |grep "inetaddr:" |awk '{print $2}'|cut -c 6- »òÕß ifconfig |grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'
12.ÄÚ´æµÄ´óС: free -m |grep "Mem" | awk '{print $2}'
13.netstat -an -t | grep ":80" | grep ESTABLISHED | awk '{printf"%s %s\n",$5,$6}' | sort
14.²é¿´ApacheµÄ²¢·¢ÇëÇóÊý¼°ÆäTCPÁ¬½Ó״̬£º
netstat -n| awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
15.ÒòΪͬÊÂҪͳ¼ÆһϷþÎñÆ÷ÏÂÃæËùÓеÄjpgµÄÎļþµÄ´óС,дÁ˸öshell¸øËûÀ´Í³¼Æ.ÔÀ´ÓÃxargsʵÏÖ,µ«ËûÒ»´Î´¦ÀíÒ»²¿·Ö,¸ãµÄÓжà¸ö×ܺÍ....,ÏÂÃæµÄÃüÁî¾ÍÄܽâ¾öÀ². find / -name *.jpg -exec wc -c {} \;|awk '{print$1}'|awk '{a+=$1}END{print a}' CPUµÄÊýÁ¿£¨¶àºËËã¶à¸öCPU£¬cat /proc/cpuinfo |grep -c processor£©Ô½¶à£¬ÏµÍ³¸ºÔØÔ½µÍ£¬Ã¿ÃëÄÜ´¦ÀíµÄÇëÇóÊýÒ²Ô½¶à¡£
16 CPU¸ºÔØ
# cat/proc/loadavg ¼ì²éÇ°Èý¸öÊä³öÖµÊÇ·ñ³¬¹ýÁËϵͳÂß¼CPUµÄ4±¶¡£
18
CPU¸ºÔØ #mpstat 1 1 ¼ì²é%idleÊÇ·ñ¹ýµÍ(±ÈÈçСÓÚ5%)
19 ÄÚ´æ¿Õ¼ä
# free ¼ì²éfreeÖµÊÇ·ñ¹ýµÍ Ò²¿ÉÒÔÓà # cat /proc/meminfo
20 swap¿Õ¼ä
# free ¼ì²éswap usedÖµÊÇ·ñ¹ý¸ß Èç¹ûswap usedÖµ¹ý¸ß£¬½øÒ»²½¼ì²éswap¶¯×÷ÊÇ·ñƵ·±£º # vmstat 1 5 ¹Û²ìsiºÍsoÖµÊÇ·ñ½Ï´ó
21 ´ÅÅÌ¿Õ¼ä
# df -h ¼ì²éÊÇ·ñÓзÖÇøʹÓÃÂÊ(Use%)¹ý¸ß(±ÈÈ糬¹ý90%)Èç·¢ÏÖij¸ö·ÖÇø¿Õ¼ä½Ó½üÓþ¡£¬¿ÉÒÔ½øÈë¸Ã·ÖÇøµÄ¹ÒÔص㣬ÓÃÒÔÏÂÃüÁîÕÒ³öÕ¼Óÿռä×î¶àµÄÎļþ»òĿ¼£º # du-cks * | sort -rn | head -n 10
jlstudent ÓÚ 2013-10-14 12:23:41·¢±í:
¼ÇןöÐèҪʱ¼ä°¡£¡»¹ÊÇÓõ½Ê²Ã´¾Í¼Çʲô°É£¡
zzia0605@163.co ÓÚ 2013-08-26 11:23:45·¢±í:
ÔÝʱ²»¶®
davemac ÓÚ 2013-08-26 06:39:36·¢±í:
ºÜºÃ£¬Ñ§Ï°ÁË¡£
davemac ÓÚ 2013-08-26 06:39:24·¢±í:
ºÜºÃ ѧϰÁË
gjhunique ÓÚ 2013-08-25 15:54:16·¢±í:
ºÜºÃ£¬ÊʺÏÐÂÊÖ
hj5700 ÓÚ 2013-08-23 16:12:14·¢±í:
:0)1
Baron2 ÓÚ 2013-08-23 15:36:22·¢±í:
ѧϰÁË
hwsmail ÓÚ 2013-08-23 09:56:34·¢±í:
ºÜÇ¿´ó
Gpoyinsnbo ÓÚ 2013-08-23 08:50:11·¢±í:
ºÜºÃ£¬Ñ§Ï°ÁË