linux常用命令

1.内存使用百分比

1
free -m | sed -n '2p' | awk '{print "used mem is "$3"M,total mem is "$2"M,used percent is "$3/$2*100"%"}'

2.锁定文件

1
2
3
4
5
6
# root用户都无法修改
 
# 锁定/etc/hosts文件
chattr +i /etc/hosts
# 解锁/etc/hosts文件
chattr -i /etc/hosts

3.修改mysql root密码

1.  用SET PASSWORD命令 

1
2
格式:mysql> set password for 用户名@localhost = password('新密码');
例子:mysql> set password for root@localhost = password('123');

2.  用UPDATE直接编辑user表 

1
2
3
mysql> use mysql;
mysql> update user set password=password('123'where user='root' and host='localhost';
mysql> flush privileges;

4.查看本机的IP地址

1
ifconfig | grep "inet"| egrep -v '(192.168.50|127.0.0.1)' | awk -F ' ' '{print $2}'

5.CAT重定向到某个文件

1
2
3
4
cat >> /etc/zabbix/zabbix_agentd.d/userparameter_jar.conf << EOF
# monitor jar tcp status
UserParameter=jar_tcp.status[*],/bin/bash /shell/zabbix/jar_tcp_connection_status.sh $1 $2
EOF

6.压缩文件

1
2
# 如果压缩的时候出现 tar: 从成员名中删除开头的“/”,加参数大写P
tar -zPcf  log.tar.gz start.log

7.拆分打日志

1
2
# 拆分成50M一个文件
split -b 50M stderr.tar.gz stderr_20171209.tar.gz.

8.dos2unix

1
2
3
4
5
6
7
8
由于windows中行结束符和linux中行结束符不同,windows中是\r\n,linux中是\n。
如果shell脚本第一行为#!/bin/bash/^M,最后结束符导致shell编译器不能识别该解释器地址。
linux提供了两种命令转换文件格式: unix2dos和dos2unix。
 
#查看shell文件是否有非打印字符
cat -v 文件名
#转换文件格式
dos2unix 文件名

9.CentOS7 查看本机IP地址

1
hostname -I

10.查看某一进程的启动时间

1
ps -p PID -o lstart #PID是进程的pid
posted @ 2018-03-07 22:24  dion至君  阅读(80)  评论(0编辑  收藏  举报