日期:2014-05-16  浏览次数:20711 次

【汇】linux常用命令集合2

?

ls -l -t为按时间排序显示,默认为新的排在前面,可用下面的命令更改升降序:
ls -lrt 最新的文件排在后面(升序)
ls -lnt 最新的文件排在前面(降序)

?

-------------------- diff


diff -options oldfile/dir newfile/dir


常用的选项有:
-r 比较目录
-u 将差异的文件输出到文件中



??? $diff -ru file_one file_two > file_diff.diff

将file_one和file_two的区别输出到file_diff.diff文件中

?

?

--------------------- 备份数据库

?

cp -a /data/mysql/mysql_3302 /data/mysql/mysql_3302_back20120504 &
#查看是否备份完
jobs
#确认备份大小
du -sh /data/mysql/*

?

?

--------------------- 系统相关:

1.cat /proc/cpuinfo? ???##查看CPU的核数? ?
2.cat /proc/version? ???##查看linux版本? ?
3.ulimit -n??##显示当前文件描述符? ?
4.ulimit -HSn 65536? ???##修改当前用户环境下的文件描述符为65536??
5.getconf LONG_BIT? ???##查看linux系统的位数,是32或还是64, 较实用? ?
6.lsof? ? ##列出当前系统打开文件, 特实用,可grep出你的进程或软件正在操作什么文件? ?
7.ps -eLf | grep java | wc -l? ? ##查看java的线程数,如果是单个java容器,就指这个容器的,多个指所有的总数? ?
8.cat /etc/resolv.conf? ? ##DNS域名解析的配置文件, 内部DNS用得多的系统经常使用? ?
9.cat /etc/hosts? ?? ?##查看host配置??


---------------------? 连接状态:
(1). netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn 或? ?
netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}'??##查看各tcp连接各状态的连接情况? ?
??
(2). netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n30? ???##查找80端口请求连接量最大的前30个IP(常用于查找攻来源,爬虫分析)? ?
??
(3). netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n10? ? ##查找time_wait状态连接量前10??
??
(4). netstat -nat -n | awk -F: '/tcp/{a[$(NF-1)]++}END{for(i in a)if(a>5)print i}'? ?##查询同时连接量大于5个连接的端口和IP


--------------------- 网站日志分析(apache或nginx):
1). cat access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -10? ?#取10,按量的倒序排 或cat access.log|awk '{counts[$(1)]+=1}; END {for(url in counts) print counts[url], url}'??
##获得访问次数前10位的ip地址,具体print出来的第几项,还需要看log_format,那项是$remote_addr? ?

2).cat access.log |awk '{print $10}'|sort|uniq -c|sort -nr|head -10? ???##访问次数最多的文件或页面,取前10 还需要看log_format,第10项为页面? ?

3).cat access.log |awk '{print $1}'|grep 'article.html' sort|uniq -c|sort -nr|head -10? ? ##查询文章页访问次数最多的前个IP? ?

4).awk '($9 ~/404/)' access.log | awk '{print $9,$10}' | sort? ? ##统计404的情况? ?
??
5).cat access.log |awk '($NF > 10){print $NF " "$1" "$10 }'|sort -nr|head -30? ?? ? ##查出前30个访问时间超过10秒的请求, 包括请求时间、IP、页面

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?