Linux shell命令

一、删除监听指定端口的进程:

lsof -ti: 80 | xargs kill -9

-t: 输出pid

-i:查看指定端口占用情况

二、查看可执行文件动态链接库相关信息 

ldd <可执行文件名>       查看可执行文件链接了哪些  系统动态链接库
nm <可执行文件名>       查看可执行文件里面有哪些符号
strip <可执行文件名>      去除符号表可以给可执行文件瘦身
如果我们想从可执行程序里面提取出来一点什么文本信息的话,还可以用strings命令
strings <可执行文件名>

三、环境变量

env   查看所有环境变量

echo  $PATH  或者 env |grep 'PATH' 或者  env |grep -i path 查看PATH变量

export PATH="$PATH:$JAVA_HOME/bin"  修改环境变量 设置后需要执行source /etc/profile

四、指定CPU

taskset -cp 4 4389#4389号进程运行在4号CPU上

Linux shell命令

五 Top命令

top==》f 列出菜单 ==》j选择显示进程最后运行的cpu ==》enter

Linux shell命令

#显示指定进程的top信息

top -p$(pgrep redis|awk 'BEGIN{ORS=","}{print $0}' |sed 's/.$//')   

Linux shell命令

 六 清理cache

Linux shell命令

  1. Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.
  2. To free pagecache:
  3. * echo 1 > /proc/sys/vm/drop_caches
  4. To free dentries and inodes:
  5. * echo 2 > /proc/sys/vm/drop_caches
  6. To free pagecache, dentries and inodes:
  7. * echo 3 > /proc/sys/vm/drop_caches
  8. As this is a non-destructive operation, and dirty objects are notfreeable, the user should run "sync" first in order to make sure allcached objects are freed.
  9. This tunable was added in 2.6.16.

 七 查看进程连接状态

lsof -i|grep process_name

例如查看ssh

Linux shell命令

 八 查看iptables

Linux shell命令

上述信息表示未开启iptables。

 九、设置网卡IP和路由

 Linux shell命令

Linux shell命令

Linux shell命令