常用的Shell命令汇总

[ruby]  view plain copy print ?
  1. #[cd ~]或者直接[cd]回到自己的Home目录  
  2. #[cd –]回到上一次的目录(比如在/home/aa目录用[cd ../bb]切换到/home/bb。然后反复[cd –]就可在/home/aa和/home/bb来回切换)  
  3. [Jadyer@Jadyer-RHEL63 ~]$ cd /app/code/CucPayTradePortal/  
  4. [Jadyer@Jadyer-RHEL63 CucPayTradePortal]$ cd /app/software/  
  5. [Jadyer@Jadyer-RHEL63 software]$ cd -  
  6. /app/code/CucPayTradePortal  
  7. [Jadyer@Jadyer-RHEL63 CucPayTradePortal]$ cd -  
  8. /app/software  
  9. [Jadyer@Jadyer-RHEL63 software]$ cd ~  
  10. [Jadyer@Jadyer-RHEL63 ~]$ pwd  
  11. /home/Jadyer  
  12. [Jadyer@Jadyer-RHEL63 ~]$ cd ~root  
  13. bash: cd: /root: 权限不够  
  14. [Jadyer@Jadyer-RHEL63 ~]$  
[ruby]  view plain copy print ?
  1. #列出当前目录里最大的10个文件  
  2. [Jadyer@Jadyer-RHEL63 CucPayTradePortalLog]$ du -s * | sort -n | tail  
  3. 4428    autoRecoverOrder.log.20121114  
  4. 5596    autoRecoverOrder.log.20121120  
  5. 6148    autoRecoverOrder.log.20121121  
  6. 6632    autoRecoverOrder.log.20121113  
  7. 12300   autoRecoverOrder.log.20121122  
  8. 12820   autoRecoverOrder.log  
  9. 40344   autoRecoverOrder.log.20121109  
  10. 60460   autoRecoverOrder.log.20121110  
  11. 113652  nohup.log  
  12. 330348  log_bak  
  13. [Jadyer@Jadyer-RHEL63 CucPayTradePortalLog]$  
[ruby]  view plain copy print ?
  1. #[ls -lhS]查询日志文件的大小,并以大小倒序排序(参数大S用于指定排序)  
  2. [Jadyer@Jadyer-RHEL63 CucPayTradePortalLog]$ ls -lhS  
  3. 总用量 2.6G  
  4. -rw-r--r-- 1 wzf  develop 2.1G 11月 23 14:44 nohup.log  
  5. -rw-r--r-- 1 root root    243M 11月 22 23:59 autoRecoverOrder.log.20121122  
  6. -rw-r--r-- 1 root root    162M 11月 23 14:44 autoRecoverOrder.log  
  7. -rw-r--r-- 1 root root     45M 11月 23 14:10 netBankResultNotify.log  
  8. -rw-r--r-- 1 root root     29M 11月 22 23:42 netBankResultNotify.log.20121122  
  9. -rw-r--r-- 1 root root    6.7M 11月 22 23:54 default.log.20121122  
  10. -rw-r--r-- 1 root root    2.0M 11月 22 06:50 orderResultNotify.log.20121122  
  11. -rw-r--r-- 1 root root    1.5M 11月 23 14:43 default.log  
  12. -rw-r--r-- 1 root root    560K 11月 23 06:20 orderResultNotify.log  
  13. [Jadyer@Jadyer-RHEL63 CucPayTradePortalLog]$ ls -lh  
  14. 总用量 2.6G  
  15. -rw-r--r-- 1 root root    162M 11月 23 14:44 autoRecoverOrder.log  
  16. -rw-r--r-- 1 root root    243M 11月 22 23:59 autoRecoverOrder.log.20121122  
  17. -rw-r--r-- 1 root root    1.5M 11月 23 14:43 default.log  
  18. -rw-r--r-- 1 root root    6.7M 11月 22 23:54 default.log.20121122  
  19. -rw-r--r-- 1 root root     45M 11月 23 14:10 netBankResultNotify.log  
  20. -rw-r--r-- 1 root root     29M 11月 22 23:42 netBankResultNotify.log.20121122  
  21. -rw-r--r-- 1 wzf  develop 2.1G 11月 23 14:44 nohup.log  
  22. -rw-r--r-- 1 root root    560K 11月 23 06:20 orderResultNotify.log  
  23. -rw-r--r-- 1 root root    2.0M 11月 22 06:50 orderResultNotify.log.20121122  
  24. [Jadyer@Jadyer-RHEL63 CucPayTradePortalLog]$  
[ruby]  view plain copy print ?
  1. #[less -p "keyword" logfile]根据指定的关键字查询日志(关键字需用双引号括起来,并注意不要出现'>''-'等特殊字符)  
  2. #也可以直接使用[less logfile],然后再键入"/keyword"来按照关键字查询日志  
  3. #当通过keyword找到日志后,就可以使用向上or向下箭头来查看前后的日志,退出日志查看时直接按下Q(大小写均可)键即可  
  4. #其相比[vi logfile]的优点就是:日志载入查询快,它是读一行解析一行的,而不是一次都载入内存,效率自然高些  
  5. [Jadyer@Jadyer-RHEL63 CucPayTradePortalLog]$ less -p "无磁无密" default.log  
  6. [20121121 04:09:52][pool-3-thread-9][NoCardNoPasswordPaymentAction]无磁无密-->检查商户请求参数的有效性,检查结果:[参数有效]  
  7. [20121121 04:09:52][pool-3-thread-9][NoCardNoPasswordPaymentAction]无磁无密-->对商户的请求参数进行验签,验签结果:[验签通过]  
  8. [20121121 04:09:52][pool-3-thread-9][NoCardNoPasswordPaymentAction]无磁无密-->发往支付处理的报文[0002831101520600001201211210409520673308396701248842791`tea`中国`GB18030`GDB_CREDIT`MD5`05_YEEPAY_1`]  
  9. [20121121 04:09:52][pool-3-thread-9][NoCardNoPasswordPaymentAction]无磁无密-->支付处理的响应报文[00015610122502该支付方式只支持信用卡^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@  
  10. ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@201210310000121846512012112104093520121031]  
  11. #另外,补充几个vi的用法  
  12. #vi一个logfile时,[gg]为定位到日志第一行,[G]为定位到日志最后一行,[/keyword]为向下搜索,[?keyword]为向上搜索  
  13. #[n]为向前搜索,[N]为向后搜索(注意这里的措辞:就是说当使用[?]时,[n]就是向上搜索。使用[/]时,[n]就是向下搜索)  
  14. #还有一个[tail]也是比较常用的,用法为[tail -1000f logfile],作用是实时地显示日志的后1000行,达到实时监视的效果  
  15. #参数[-f]会不停地读取最新的内容,使用[Ctrl+c]可以终止日志显示。至于[cat][more]两个命令就不怎么常用了  
[ruby]  view plain copy print ?
  1. #统计keyword在日志中的出现次数  
  2. [Jadyer@Jadyer-RHEL63 CucPayTradePortalLog]$ grep -c "无磁无密" default.log  
  3. 238  
  4. [Jadyer@Jadyer-RHEL63 CucPayTradePortalLog]$  
[ruby]  view plain copy print ?
  1. #[curl ifconfig.me]当你的机器在内网时,可以通过该命令查看其外网的IP  
  2. [Jadyer@Jadyer-RHEL63 ~]$ curl ifconfig.me  
  3. 61.149.24.203  
  4. [Jadyer@Jadyer-RHEL63 ~]$  
[ruby]  view plain copy print ?
  1. #输出最为常用的十条命令,由此甚至可以洞察你是一个什么类型的程序员  
  2. #另外,可以直接使用[history]查看以往执行过的命令,然后使用[!number]执行指定编号的历史命令  
  3. [Jadyer@Jadyer-RHEL63 ~]$ history|awk '{CMD[$2]++;count++;} END {for(a in CMD)print CMD[a]" "CMD[a]/count*100 "% " a}'|grep -v "./"|column -c3 -s " " -t|sort -nr|nl|head -n10  
  4.      1  47  20.0855%   cd  
  5.      2  38  16.2393%   ll  
  6.      3  18  7.69231%   pwd  
  7.      4  12  5.12821%   vi  
  8.      5  12  5.12821%   exit  
  9.      6  12  5.12821%   ab  
  10.      7  8   3.4188%    halt  
  11.      8  8   3.4188%    cat  
  12.      9  7   2.99145%   su  
  13.     10  7   2.99145%   rm  
  14. [Jadyer@Jadyer-RHEL63 ~]$ history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -rn|head -10  
  15.      47 cd  
  16.      38 ll  
  17.      18 pwd  
  18.      12 vi  
  19.      12 exit  
  20.      12 ab  
  21.       8 halt  
  22.       8 cat  
  23.       7 su  
  24.       7 rm  
  25. [Jadyer@Jadyer-RHEL63 ~]$  
[ruby]  view plain copy print ?
  1. #[scp 可选参数 file_source file_target]两个主机间复制文件  
  2. #举例:将本机文件复制到远程主机的指定目录下  
  3. [Jadyer@Jadyer-RHEL63 CucPayTradePortal]$ scp startup.sh wzf@192.168.8.24:/app/wzf/code/  
  4. wzf@192.168.8.24's password:   
  5. startup.sh      100% 1564     1.5KB/s   00:00  
  6. [Jadyer@Jadyer-RHEL63 CucPayTradePortal]$  
  7. #举例:将远程主机文件复制到本机的当前目录下  
  8. [Jadyer@Jadyer-RHEL63 CucPayTradePortal]$ scp wzf@192.168.8.24:/app/wzf/code/startup_824.sh ./  
  9. wzf@192.168.8.24's password:   
  10. startup_824.sh  100% 1564     1.5KB/s   00:00  
  11. [Jadyer@Jadyer-RHEL63 CucPayTradePortal]$  
  12. #补充:使用scp也可以在不同主机间复制目录,只要使用[-r]这个可选参数就行了,示例略。  
[ruby]  view plain copy print ?
  1. #查询指定端口的监听及运行情况  
  2. #其它的诸如[free][top][df -h][ps -ef|grep java][kill -9 PID][nohup ./startup.sh &]等等就不举例了  
  3. [Jadyer@Jadyer-RHEL63 CucPayTradePortalLog]$ netstat -tlanop | grep :80  
  4. tcp        0      0 :::8080                     :::*                        LISTEN      5053/java           off (0.00/0/0)  
  5. tcp        0      0 ::ffff:192.168.8.31:80      :::*                        LISTEN      17608/java          off (0.00/0/0)  
  6. [Jadyer@Jadyer-RHEL63 CucPayTradePortalLog]$ lsof -i:80  
  7. COMMAND   PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME  
  8. java    17608 root  163u  IPv6 29073040      0t0  TCP bjgg-kfvm-31:http (LISTEN)  
  9. [Jadyer@Jadyer-RHEL63 CucPayTradePortalLog]$  
[ruby]  view plain copy print ?
  1. #查看指定年份和月份的日历,及当前时间(使用[cal 2012]则可以直接查看2012的年历)  
  2. [Jadyer@Jadyer-RHEL63 ~]$ cal 11 2012  
  3.      十一月 2012      
  4. 日 一 二 三 四 五 六  
  5.              1  2  3  
  6.  4  5  6  7  8  9 10  
  7. 11 12 13 14 15 16 17  
  8. 18 19 20 21 22 23 24  
  9. 25 26 27 28 29 30  
  10.   
  11. [Jadyer@Jadyer-RHEL63 ~]$ date  
  12. 2012年 11月 23日 星期五 14:36:18 CST  
  13. [Jadyer@Jadyer-RHEL63 ~]$  
[ruby]  view plain copy print ?
  1. #[man ascii]显示ASCII码表(免去了Google时遇到GWF的烦恼)  
  2. [Jadyer@Jadyer-RHEL63 ~]$ man ascii  
  3. DESCRIPTION  
  4.        Oct   Dec   Hex   Char                        Oct   Dec   Hex   Char  
  5.        ------------------------------------------------------------------------  
  6.        000   0     00    NUL '\0'                    100   64    40    @  
  7.        001   1     01    SOH (start of heading)      101   65    41    A  
  8.        002   2     02    STX (start of text)         102   66    42    B  
  9.        003   3     03    ETX (end of text)           103   67    43    C  
  10.        004   4     04    EOT (end of transmission)   104   68    44    D  
  11.        005   5     05    ENQ (enquiry)               105   69    45    E  
  12.        006   6     06    ACK (acknowledge)           106   70    46    F  
  13.        007   7     07    BEL '\a' (bell)             107   71    47    G  
  14.        010   8     08    BS  '\b' (backspace)        110   72    48    H  
  15.        011   9     09    HT  '\t' (horizontal tab)   111   73    49    I  
  16.        012   10    0A    LF  '\n' (new line)         112   74    4A    J  
  17.        013   11    0B    VT  '\v' (vertical tab)     113   75    4B    K  
  18.        014   12    0C    FF  '\f' (form feed)        114   76    4C    L  
  19.        015   13    0D    CR  '\r' (carriage ret)     115   77    4D    M  
  20.        016   14    0E    SO  (shift out)             116   78    4E    N  
  21.        ......  
  22.        ......  
  23.        ......  


http://blog.csdn.net/jadyer/article/details/8217348
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值