Linux工作中常用命令(一)
-
top : 查看进程所占用CPU和内存
-
top -Hp pid : 获取到这个进程下面所有线程,通过%CPU找到最耗费CPU的是线程PID
-
printf ‘%x\n’ PID : 转换成对应的16进制PID
-
free -h : 查看内存使用多少
-
ps aux | grep ** : 查看具体进程信息
-
netstat -lnp : 打印当前系统启动了哪些端口
-
netstat -an : 打印网络连接状况
-
netstat -aon|findstr “49157” : findstr在文件中寻找字符串
-
ls | wc -w : 查看某目录下多少个文件(word count)
-
find / -name “*.log”
-
sed -n ‘/2018-01-08 14:38:51/,/2018-01-08 14:39:51/p’ application.log > test.txt :查找某个时间段的日志,并导入到test.txt文件中
-
tail -n 10 -f test.log : 查询10行之后,实时监控
-
cat -n test.log |grep “debug” 查询关键字的日志
-
cat -n test.log |grep “debug” |more 这样就分页打印了,通过点击空格键翻页
-
pwdx pid : 查看进程的执行路径
-
vim 编辑器 :set hlsearch (高亮) ? /String (查询)
-
cat /etc/redis/6379.conf |grep -A 100 maxclients --color=auto : 查找高亮
-
cat /proc/cpuinfo| grep “physical id”| sort| uniq| wc -l : 查看物理CPU个数
-
cat /proc/cpuinfo| grep “cpu cores”| uniq : 查看每个物理CPU中core的个数(即核数)
-
cut -f 1 test.txt : 取出第一列
cut -d : 指定字段的分隔符,默认的字段分隔符为“TAB”
PS:命令的后面加“-”表示后面跟的是选项