2018-09-24 日常操作cheatsheet

[一些变量]

[strace]
strace -T -tt -v -fp <some_pid> 2>&1 #追踪某个pid下所有线程的syacall

[查找历史指令]
ctrl + R,输入字符查找

[切换到上次的目录]
$cd -

[清屏]
ctrl + L, 相当于clear

[暂停当前进程]
ctrl + Z

[恢复暂停的进程]
fg

[列出目录中大小前5的文件]

du -a | sort -n -r | head -n 5 | awk '{print $1/1024,"MB ", $2}'

也可以 watch

watch "du -a | sort -n -r | head -n 5 | awk '{print \$1/1024,\"MB \", \$2}'"

[vim专题]
进入visual mode并高亮选择: v + h/l;
visual mode 按word选择:v + w 高亮光标所在的word

[查看ip]
ip a | grep inet
ifconfig

[查看某进程的所有线程]
$ ps -T -p <pid>

[tcpdump抓某个端口]

  1. tcpdump
    tcpdump -i <eth_x> dst <ip> and port <port_num> -X 打印ascii的数据

[查看某进程占用的内存用量]

  1. ps -e -o 'pid,comm,args,pcpu,rsz,vsz,stime,user,uid' | grep <pid>
  2. expr:
pid  -
comm -   command
args -   run_command_parameter
pcpu -  cpu时间占用百分比
rsz  - 常驻内存大小
vsz  - 虚拟内存用量

ps 的rsz和vsz正好对应top的RES和VIRT.

[grep专题]
或 grep -e "expr1" -e "expr2"
非 grep -v "expr"

[top专题]
cpu:
“1” 查看每个核的详细数据, “1” 回到基本视图

I try to explain  these:
us: is meaning of "user CPU time"
sy: is meaning of "system CPU time"
ni: is meaning of" nice CPU time"
id: is meaning of "idle"
wa: is meaning of "iowait" 
hi:is meaning of "hardware irq"
si : is meaning of "software irq"
st : is meaning of "steal time"
中文翻译为:
us 用户空间占用CPU百分比
sy 内核空间占用CPU百分比
ni 用户进程空间内改变过优先级的进程占用CPU百分比
id 空闲CPU百分比
wa 等待输入输出的CPU时间百分比
hi 硬件中断
si 软件中断 
st: 实时(来源http://bbs.chinaunix.net/thread-1958596-1-1.html)

内存:

  1. virt vs. res vs. shr
项目 含义
VIRT 程序可访问的内存总量
RES 程序的常驻内存总量
SHR 程序可访问内存总量中的共享部分
  • VIRT stands for the virtual size of a process, which is the sum of memory it is actually using, memory it has mapped into itself (for instance the video card’s RAM for the X server), files on disk that have been mapped into it (most notably shared libraries), and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment.
  • RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. (This also corresponds directly to the %MEM column.) This will virtually always be less than the VIRT size, since most programs depend on the C library.
  • SHR indicates how much of the VIRT size is actually sharable (memory or libraries). In the case of libraries, it does not necessarily mean that the entire library is resident. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted in VIRT and SHR, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under RES.
    http://mugurel.sumanariu.ro/linux/the-difference-among-virt-res-and-shr-in-top-output/
  1. 切换内存计量单位
    使内存以MB方式,top -M在top中按E(最上面系统状态中的内存单位会在MiB/GiB等单位切换)

  2. 只看某个进程 top -p <pid>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,490评论 0 10
  • 20170304 今天我儿子要去看牙向我要公交卡,他的没有钱了,他有钱不去充值。我不愿意借公交卡给他,我儿子立马暴...
    慧儿妈阅读 119评论 0 0
  • 最近在学车。天气热皮肤已经被晒得乌黑发亮。对于我这个机器盲来说,学车是一件很痛苦的事情,右倒库的点位经常找不准,学...
    黎明时分的燕子阅读 351评论 0 1
  • 每个人都管好自己 。别人的事别乱逼逼, 别插嘴,别多管闲事,别总以为自己是最对的 瞎几把操心 ,别人也不觉得你对,...
    pinky西西阅读 206评论 0 0