Linux的这些命令你需要掌握

查看进程:

查看所有进程:ps -ef

查看指定的进程:
ps -ef|grep pid(进程号)

查看前40个内存占用的进程:
ps auxw|head -1;ps auxw|sort -rn -k4|head -40

服务器编码:

查看服务器编码:locale

修改服务器编码:export LANG=zh_CN.UTF-8

图片

查看服务器本:

cat /etc/redhat-release

服务器时间:

查看服务器时间:date

修改服务器日期:date -s yyyy-MM-dd

修改服务器当天时间:date -s hh:mm:ss

查看服务器已安装字体列表:

fc-list

crontab定时任务:

执行:crontab -e  编辑入以下示例并保存修改,“#”注释则失效

#每分钟执行一次./start.sh脚本,日志输出到crontablog.log
* * * * * /opt/coChainFailDataBackup/./start.sh >> /opt/coChainFailDataBackup/crontablog.log 2>&1;

#在凌晨1、2、3、4、5点,半小时执行一次./start.sh脚本,日志输出到crontablog.log
*/30 1,2,3,4,5 * * * /opt/coChainFailDataBackup/./start.sh >> /opt/coChainFailDataBackup/crontablog.log 2>&1;

grep日志及文本内容检索:

检索日志关键字并输出到xx.log:
grep -a '关键字' xx.log  > xx.log

统计log文件关键字出现的次数:
grep -c "关键字" *.log
cat *.log | grep '关键字' | wc -l

多关键字检索:
grep -E "关键字1|关键字2" *.log
grep -E '关键字1.*关键字2' *.log

zcat *.zip | grep 'einvoice_summary_info_exchange' | wc -l

zgrep日志及文本内容检索:

基本同grep用法
检索zip压缩文件中的关键字日志并输出到xx.log:
zgrep -a '关键字' xx.zip > xx.log

统计zip文件中关键字出现的次数:
zgrep -c "关键字" *.zip

sed日志及文本内容检索:

日志文件内容截取并输出到xx.log:
sed -n '开始行数结束行数'p rizhi.log > xx.log

示例,截取第一行到第一千行的内容: 
sed -n '1,1000'p stdout.log > xx.log

find文件查找:

从根目录开始查找所有扩展名为.log的文件,并找出包含”ERROR”的行:
find / -type f -name "*.log" | xargs grep "ERROR"

从当前目录开始查找所有扩展名为.properties的文件,并找出包含”xxx”的行:
find . -name "*.properties" | xargs grep "xxx"

搜索文件夹:
find / -type d -iname "logstash"

图片

修改ulimit -a的open files值:

设置完需要重启服务器生效设置永久生效:
①vi /etc/profile
加入一行:ulimit  -SHn  65536
生效配置:source /etc/profile

②vim /etc/security/limits.conf
加入:
*     soft     nofile    65536 
*     hard     nofile    65536

后台启动命令nohup:

nohup ./start.sh &

启动并在控制台打印日志内容:
./start.sh | tail -f ./logs/stdout.log

rm常用删除命令:

删除文件夹:rm -rf 目录名

删除文件:rm -f 文件名

防火墙状态相关:

centos6:
查询状态:service iptables status
关闭防火墙:service iptables stop
开启防火墙:service iptables start

centos7:
查询状态:systemctl status firewalld.service
关闭防火墙:systemctl stop firewalld.service  
开启防火墙:systemctl start firewalld.service
posted @ 2022-05-18 10:26  好奇成传奇  阅读(83)  评论(0编辑  收藏  举报