linux常用命令(三)
1.查看cpu信息
[root@ipha-dev71-1 proc]# cat /proc/meminfo MemTotal: 16251672 kB MemFree: 523996 kB MemAvailable: 1058824 kB Buffers: 0 kB Cached: 473528 kB SwapCached: 274264 kB Active: 12841568 kB Inactive: 1854344 kB Active(anon): 12709704 kB Inactive(anon): 1572372 kB Active(file): 131864 kB Inactive(file): 281972 kB Unevictable: 0 kB Mlocked: 0 kB SwapTotal: 16777212 kB SwapFree: 15714656 kB Dirty: 92 kB Writeback: 0 kB AnonPages: 14073736 kB Mapped: 40924 kB Shmem: 59692 kB Slab: 732732 kB SReclaimable: 459264 kB SUnreclaim: 273468 kB
2.查看使用cpu最多的两个进程
ps -aux | sort -k3nr | head -n 10
3.查看是使用内存最多的两个进程
ps -aux | sort -k4nr | head -n 10
4.查看文件末尾5行
[root@ipha-dev71-1 config]# tail -n 5 config.ini 客户端发送理由 : /api/v1/sendChatMessageNoLogin 审方端发送理由 : /api/v1/sendChatMessage 已审查询记录 : /api/v1/queryChatMessage?category=%%s&zoneId=%%s&attachKey=%%s 待审住院获取药嘱信息 : /api/v1/ipt/orderList 已审住院获取药嘱信息 : /api/v1/ipt/all/orderList
5.查看文件前5行
[root@ipha-dev71-1 config]# head -n 5 config.ini [login] address : http://10.1.1.173:9999 username : user1 password : password1 [auditcenter]
6.过滤文件内容中包含ERROR的行
grep "ERROR" filename 或者 cat filename |grep "ERROR"
7.查看端口号所在进程即该进程所在路径
[root@ipha-dev71-1 config]# netstat -pan|grep 8080 tcp6 0 0 :::8080 :::* LISTEN 480/java [root@ipha-dev71-1 config]# pwdx 480 480: /home/jenkins
8.查看进程并杀掉进程
[root@ipha-dev71-1 auditcenter]# ps -ef|grep jenkins root 480 1 0 Aug14 ? 00:09:08 java -jar jenkins.war --httpPort=8080 root 98097 92411 0 12:10 pts/1 00:00:00 grep --color=auto jenkins
[root@ipha-dev71-1 auditcenter]# kill -9 480
9.查看IP地址
ifconfig
10.创建和删除一个多级目录
mkdir -p ./a/b
rm -rf ./a
11.根目录下查找文件config.ini
[root@ipha-dev71-1 chenjl]# find / -name config.ini /root/.jenkins/workspace/python_proj/config/config.ini /root/.jenkins/workspace/python_proj_private/config/config.ini /root/.jenkins/workspace/auditcenter_python_3.x/config/config.ini
12.动态查看日志文件末尾10行
tailf -10 log_file
13.查看当前机器监听的所有端口
[root@ipha-dev71-1 chenjl]# netstat -tlnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 3377/./redis-server tcp 0 0 0.0.0.0:5005 0.0.0.0:* LISTEN 46490/java tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN 94994/nginx: master tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:4369 0.0.0.0:* LISTEN 3495/epmd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1023/sshd tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN 3616/beam.smp tcp 0 0 0.0.0.0:8031 0.0.0.0:* LISTEN 78331/java tcp 0 0 0.0.0.0:9090 0.0.0.0:* LISTEN 94994/nginx: master tcp 0 0 0.0.0.0:4004 0.0.0.0:* LISTEN 46001/java tcp 0 0 0.0.0.0:10278 0.0.0.0:* LISTEN 94994/nginx: master tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 3616/beam.smp
14.linux环境下从大文件日志中快速搜索指定内容
方法一:
vi fun_with_return.sh 默认进入到指令模式
方式二:
-n 会返回行号,-e指定查找的字符串,head返回查询结果的前3条
打开指定行:
12.查找某个文件并删除它
find -name a.txt| xargs rm -rf
踩坑是成长最快的方式