文件差、并、diff操作、pstree、iftop命令使用笔记

数据准备:
inter12@inter12-VirtualBox:/tmp/temp$ more t1
12 hi zhaoming
32 ohoh mingtian
22 jhoh mingtian
2 iehieh tomorrow

inter12@inter12-VirtualBox:/tmp/temp$ more t2
2 iehieh tomorrow
12 hi zhaoming
32 ohoh mingtian
按照第一列排序
inter12@inter12-VirtualBox:/tmp/temp$ sort -n t1
2 iehieh tomorrow
12 hi zhaoming
22 jhoh mingtian
32 ohoh mingtian
或者是:

inter12@inter12-VirtualBox:/tmp/temp$ sort -h t1
2 iehieh tomorrow
12 hi zhaoming
22 jhoh mingtian
32 ohoh mingtian

按照第三列排序:
inter12@inter12-VirtualBox:/tmp/temp$ sort -k3,3 t1
22 ohoh mingtian
32 jhoh mingtian
2 iehieh tomorrow
12 hi zhaoming
先按照第三列排序,若是第三列相同的情况下按照第二类排序

inter12@inter12-VirtualBox:/tmp/temp$ sort -k3,3 t1 | sort -s -k2,2
12 hi zhaoming
2 iehieh tomorrow
32 jhoh mingtian
22 ohoh mingtian

jhoh这个字符串的首字母是在ohoh之前的,所以结果是正确的.
求两个文件的差集,并集,交集
并集:
inter12@inter12-VirtualBox:/tmp/temp$ cat t1 t2 | sort -h | uniq > t3 //按照第一列进行排序后并集

inter12@inter12-VirtualBox:/tmp/temp$ more t3
2 iehieh tomorrow
2 iehieh tomorrow
12 hi zhaoming
22 ohoh mingtian
32 jhoh mingtian
32 ohoh mingtian
交集

inter12@inter12-VirtualBox:/tmp/temp$ cat t1 t2 | sort -h | uniq -d | tee t3

12 hi zhaoming

只有一行是相同的,这个比较工具是按照一行一行的进行比较,只能进行简单的比较
差集

inter12@inter12-VirtualBox:/tmp/temp$ cat t1 t2 | sort | uniq -u | tee t3
22 ohoh mingtian
2 iehieh tomorrow
2 iehieh tomorrow
32 jhoh mingtian
32 ohoh mingtian
注意这里不是简单的 t3 = t1 – t2 , 而是除去了t1,t2中相同的元素后,剩下的元素。上面可以并集只有一个,3(t1)+4(t1) -2(t1+t2) = 5 所以剩下的就是现在这里 .

pstree :将用户的进程以一颗树的形式展开

inter12@inter12-VirtualBox:~$ pstree -ps 2086

init(1)───eclipse4.2.1(2073)───java(2086)─┬─{java}(2087)

├─{java}(2088)

├─{java}(2089)

├─{java}(2090)

├─{java}(2091)

├─{java}(2092)

├─{java}(2093)

├─{java}(2094)

├─{java}(2095)

├─{java}(2096)

├─{java}(2097)

├─{java}(2098)

├─{java}(2099)

├─{java}(2100)

├─{java}(2101)

├─{java}(2104)

├─{java}(2105)

├─{java}(2109)

├─{java}(2161)

├─{java}(2287)

├─{java}(2288)

├─{java}(2289)

├─{java}(2293)

└─{java}(2296)

常见的参数:

-a : 列出启动过程中的参数

-p : 显示PID

-s : 显示父进程ID

若是后面跟的不是PID,而是用户名,那么就会列出这个用户的进程树

inter12@inter12-VirtualBox:~$ pstree -psa inter12

/usr/bin/termin,2203 /usr/bin/terminator

├─(/usr/bin/termin,2209)

├─bash,2210

├─bash,2419

│ └─gedit,2478

│ ├─{gedit},2480

│ └─{gedit},2481

├─bash,2793

│ └─pstree,3276 -psa inter12

├─bash,2872

├─bash,2959

│ └─tail,3038 -f jetty.log

├─bash,3185

│ └─top,3246

├─{/usr/bin/termi},2208

└─{/usr/bin/termi},2211

VBoxClient,1816 –clipboard

└─{VBoxClient},1837

VBoxClient,1824 –display

└─{VBoxClient},1850

VBoxClient,1828 –seamless

└─{VBoxClient},1830

bamfdaemon,1915

└─{bamfdaemon},1991

dbus-daemon,1811 –fork –print-pid 5 –print-address 7 –session

dbus-daemon,1835 –fork –print-pid 8 –print-address 10 –session

dbus-launch,1810 –autolaunch ae29ca89bd7c49cef31124a600000007 –binary-syntax –close-stderr

dbus-launch,1834 –exit-with-session gnome-session –session=ubuntu

dconf-service,1908

├─{dconf-service},1909

└─{dconf-service},1911

eclipse4.2.1,2073

└─java,2086 -Xms40m -Xmx512m -XX:MaxPermSize=256m -jar/home/inter12/install/soft/eclipse4.2.1/eclipse//plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-181

├─{java},2087

├─{java},2088

├─{java},2089

├─{java},2090

。。。。。。。 后面还有很多!这个用户可能还有一个用处就是查看java的线程数量吧:

inter12@inter12-VirtualBox:~$ pstree -p 2086 | grep java | wc -l
24
2086总共开启了24个线程.

iftop:一个查看网络流量的蛮有意思工具

top:

50.0Kb 100Kb 150Kb 200Kb 250Kb

└──────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────

inter12-VirtualBox.local => 192.168.7.41 0b 7.98Kb 4.03Kb

<= 0b 11.3Kb 5.67Kb

……

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

TX: cumm: 628KB peak: 43.6Kb rates: 3.71Kb 2.28Kb 6.09Kb

RX: 620KB 59.5Kb 3.13Kb 1.88Kb 7.39Kb

TOTAL: 1.22MB 103Kb 6.84Kb 4.16Kb 13.5Kb

前面两行代表 从本地流向192.168.7.41这个地址的流量 后面三个数值分别代表 过去2秒,10秒,40秒的平均流量
底部的参数说明:
TX:发送流量
RX:接收流量
TOTAL:总流量
Cumm:运行iftop到目前时间的总流量
peak:流量峰值
rates:分别表示过去 2秒 10秒 40秒 的平均流量

几个常见的参数:
-i设定监测的网卡,如:iftop -i eth0
-n使host信息默认直接都显示IP,如:# iftop -n
-F显示特定网段的进出流量,如# iftop -F 192.168.7.41/24或# iftop -F 10.10.1.0/255.255.255.0

iftop -F 192.168.7.41/24

12.5Kb 25.0Kb 37.5Kb 50.0Kb 62.5Kb

└──────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────

192.168.7.41 => inter12-VirtualBox.local 0b 80b 4.08Kb

<= 0b 74b 2.90Kb
就之显示自己谁设定的IP段
-b使流量图形条默认就显示,比较有用的命令。
-P使host信息及端口信息默认就都显示;

sudo iftop -P

12.5Kb 25.0Kb 37.5Kb 50.0Kb 62.5Kb

└──────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────

192.168.7.41:2181 => inter12-VirtualBox.local:35760 0b 11.3Kb 5.16Kb

<= 0b 7.98Kb 3.66Kb

这样就可以看到端口了。
-B 以bytes为单位显示流量(默认是bits),如:# iftop -B
详细的可以参见 man iftop

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>