常用命令记录
还是以场景去记忆一些linux命令吧
根据服务名称查看服务pid
ps -ef | grep servername
根据pid查看 pid下面的socket连接信息
lsof -p 3583 -nP | grep TCP //可以帮我们找到这个pid下面的网络socket连接情况,有时候我们需要对进程使用到的资源进行
lsof -i :3306 //查看3306端口被哪个进程占用了,并且这个pid打开的所有 fd
- netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表、实际的网络连接以及每一个网络接口设备的状态信息。
netstat -tan
grep -a //有时候日志文件里面存在二进制数据,直接grep是过滤不了的,得加 -a
grep -E 'a|b' //过滤内容里面有a或有b的
grep -n 显示行号
grep -A 10 -B 10 显示前后上线文的行数
root@iZbp15ildwog86lw08ptpnZ:~# tail -f /var/log/syslog.1 | grep -n -B 10 -A 10 'exited'
1:Jun 21 07:32:31 iZbp15ildwog86lw08ptpnZ supervisord[601]: 2023-06-21 07:32:31,865 INFO exited: slp.rpc.consume.payoff (exit status 2; not expected)
2-Jun 21 07:32:31 iZbp15ildwog86lw08ptpnZ supervisord[601]: 2023-06-21 07:32:31,947 INFO spawned: 'slp.rpc.consume.payoff' with pid 65586
3-Jun 21 07:32:32 iZbp15ildwog86lw08ptpnZ supervisord[601]: 2023-06-21 07:32:32,947 INFO success: slp.rpc.consume.payoff entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
4:Jun 21 07:32:37 iZbp15ildwog86lw08ptpnZ supervisord[601]: 2023-06-21 07:32:37,593 INFO exited: slp.cmd.consume.lottery (exit status 2; not expected)
5-Jun 21 07:32:37 iZbp15ildwog86lw08ptpnZ supervisord[601]: 2023-06-21 07:32:37,797 INFO spawned: 'slp.cmd.consume.lottery' with pid 65601
6-Jun 21 07:32:38 iZbp15ildwog86lw08ptpnZ supervisord[601]: 2023-06-21 07:32:38,849 INFO success: slp.cmd.consume.lottery entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
7-Jun 21 07:32:52 iZbp15ildwog86lw08ptpnZ systemd[1]: Starting Clean php session files...
8-Jun 21 07:32:52 iZbp15ildwog86lw08ptpnZ systemd[1]: Starting Rotate log files...
9-Jun 21 07:32:52 iZbp15ildwog86lw08ptpnZ systemd[1]: Starting Daily man-db regeneration...
10-Jun 21 07:32:52 iZbp15ildwog86lw08ptpnZ sessionclean[65645]: PHP Warning: PHP Startup: Unable to load dynamic library 'phalcon.so' (tried: /usr/lib/php/20190902/phalcon.so (/usr/lib/php/20190902/phalcon.so: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/phalcon.so.so (/usr/lib/php/20190902/phalcon.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
查看目录大小
root@iZbp15ildwog86lw08ptpnZ:/tmp# du -sh * --time | sort -rh
1.6G 2023-06-21 10:26 log
32K 2023-06-21 10:25 gproc
12K 2023-06-21 10:25 gsessions
8.0K 2023-06-20 23:32 systemd-private-9dc65a20779d4132985271b7061e1e9e-systemd-resolved.service-Jdeu9e
8.0K 2023-06-20 23:32 systemd-private-9dc65a20779d4132985271b7061e1e9e-systemd-logind.service-qNPXjf
8.0K 2023-06-20 23:32 systemd-private-9dc65a20779d4132985271b7061e1e9e-redis-server.service-NPmJuf
8.0K 2023-06-20 23:32 systemd-private-9dc65a20779d4132985271b7061e1e9e-chrony.service-GEw22i
4.0K 2023-06-21 10:26 cli_mysql_to_nsq.default.log
0 2023-06-20 23:33 argus.sock
0 2023-06-20 23:33 aliyun_assist_service.sock
0 2023-06-20 23:32 AliyunAssistClientSingleLock.lock
/proc/pid /proc/net
wc -l
awk
curl ipinfo.io
lsof -i:8080 //查看端口占用