几个有意思的linux系统命令

  • strace

  用法:

   -f :除了跟踪当前进程外,还跟踪其子进程。
  -o file :将输出信息写到文件file中,而不是显示到标准错误输出(stderr)。
  -p pid :绑定到一个由pid对应的正在运行的进程。此参数常用来调试后台进程。

  用处: 查看别的命令或进程都进行了哪些系统调用。比如当前web.py进程号为7393;
      用strace -p 7393 -f   等下一个客户请求过来后就可以看到webserver都干
      了些什么.

  • CP  拷贝指定文件
    情景:一个文件夹有各种文件:sh,log,data,py。我们只想把脚背相关的文件拷贝出来备份。
    解决:cp --parent `find . -type f | grep -vE "data|log"` /target/
    备注:--parent 拷贝后保持原来的树结构
  •  ps  查看线程信息
% ps -Lf 
UID        PID  PPID   LWP  C NLWP STIME TTY          TIME CMD
blaise   22529 28240 22529  0    5 11:31 pts/53   00:00:00 a.out
blaise   22529 28240 22530 99    5 11:31 pts/53   00:01:24 a.out
blaise   22529 28240 22531 99    5 11:31 pts/53   00:01:24 a.out
blaise   22529 28240 22532 99    5 11:31 pts/53   00:01:24 a.out
blaise   22529 28240 22533 99    5 11:31 pts/53   00:01:24 a.out

     注意其中的LWP(light weight)代表线程号,LWP==PID的说明这是线程组组长。C(cpu占用率)

  •  top   H显示线程信息,P按CPU占用率(当前)排序,M按内存占用率排序。 OR : shift+ <,>键自由选择排序的列
  •  sed 添加行怎么样在一行或多行之前,之后增加一行或多行

    sed 可以在匹配的模式之前(i)或之后(a)增加一行或多行;

    [root@vps tmp]# cat a.txt
    1234569
    abcABCabc

    在匹配的模式之前(i):
    [qing.chen@CCSSH2 ~]$ sed -e '/123/ i\solongg' a.txt
    solongg
    1234569
    abcABCabc
    增加两行
    [qing.chen@CCSSH2 ~]$ sed -e '/123/ i\solongg\nso long' a.txt
    solongg
    so long
    1234569
    abcABCabc
    在匹配的模式之后(a)
    增加两行:
    [qing.chen@CCSSH2 ~]$ sed -e '/123/ a\solongg\nso long' a.txt
    1234569
    solonggg
    so long
    abcABCabc

原文地址:https://www.cnblogs.com/tangr206/p/3082524.html