Linux命令
# 概述
本文记录不常用的Linux命令,大多时候用不到,但对于某些场景下,很实用。
# 详细
# 1.查找进程的启动文件
ps -ef | grep nginx
ll /proc/pid
1
2
2
# 2.修改服务器时间
date -s "2020-1-1 5:20:20"
1
#查看当前的时区
timedatectl
#设置时区
timedatectl set-timezone Asia/Shanghai
1
2
3
4
2
3
4
#查看硬件时间
hwclock
#将操作系统时间同步到硬件时间
hwclock -w
1
2
3
4
2
3
4
# 3.软链接
创建
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
修改
ln -snf /usr/local/nginx/sbin/nginx /usr/bin/nginx
删除软链接和删除普通的文件是一样的,删除都是使用rm来进行操作
1
2
3
4
5
2
3
4
5
# 4.防火墙
firewall-cmd --zone=public --add-port=9930/udp --permanent
firewall-cmd --reload
1
2
2
# 5.端口转发
nc -l -k -p 3410 -c "nc 127.0.0.1 3306"
1
# 6.查看文件内容
cat access.log | tail -n 1000 查看最后的1000行
cat access.log | head -n 1000 查看开始的1000行
1
2
2
grep "%s" -n 显示行号
-C 10 上下行数
-A 10 之后的行数
-B 10 之前的行数
1
2
3
4
2
3
4
awk '/re/ ' log.txt
1
# 7. MySQL时区
查时区:show variables like '%time_zone%'
设置会话时区:set time_zone='+8:00'
设置全局时区:set global time_zone='+8:00
1
2
3
2
3
修改 mysql 的配置文件永久设置时区
[mysqld]
default-time-zone=+08:00
character-set-server=utf8mb4
1
2
3
4
2
3
4
git关闭文件权限校验
# 当前版本库
$ git config core.filemode false
# 所有版本库
$ git config --global core.fileMode false
1
2
3
4
5
6
2
3
4
5
6
上次更新: 2023/10/07