博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
17个Linux系统高频率常用命令行和shell小脚本
阅读量:7247 次
发布时间:2019-06-29

本文共 2500 字,大约阅读时间需要 8 分钟。

以下是在部署OpenStack以及使用Linux过程中摘录的一些较为常用的命令行或shell脚本,仅供参考。

1.杀死所有存在的僵尸进程

ps -ef | grep defunc | grep -v grep | awk '{print $3}' | xargs kill -9#pkill dnsmasq

2.去掉配置文件中的#符号和空白行

cat >/root/delsc.sh <

3.CentOS7安装vmtools

# mount /dev/cdrom /mnt/# cp /mnt/VMwareTools-9.4.10-2092844.tar.gz /tmp/# cd /tmp/# tar zxf VMwareTools-9.4.10-2092844.tar.gz# /tmp/vmware-tools-distrib/vmware-install.plyum install open-vm-tools -ysystemctl enable vmtoolsd.servicesystemctl start vmtoolsd.servicesystemctl status vmtoolsd.service

4.修改Linux系统时区

mv /etc/localtime /etc/localtime~ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtimechown -h --reference=/etc/localtime~ /etc/localtimechcon -h --reference=/etc/localtime~ /etc/localtime

5.中国大陆常用时间服务器列表

cat > /etc/ntp.conf <

6.配置时间同步

rpm -qa | grep ntp || yum install -y ntpntpdate -u pool.ntp.org || ntpdate -u time.nist.gov || ntpdate -u time-nw.nist.govdatecat >>/etc/rc.local<
>/etc/cron.daily/ntpdate<

7.对配置文件更改前先备份配置文件

operationfile=/etc/keystone/keystone.confbakoperationfile=$operationfile$(date +-%F-%H-%M-%S)"~"cp $operationfile $bakoperationfilechown -R --reference=$operationfile $bakoperationfilechcon -R --reference=$operationfile $bakoperationfile

8.创建计划任务

(crontab -l -u keystone 2>&1 | grep -q token_flush) || echo '@hourly /usr/bin/keystone-manage token_flush >/var/log/keystone/keystone-tokenflush.log 2>&1' >> /var/spool/cron/keystone

9.不切换用户但以此用户的身份执行命令

su -s /bin/sh -c "glance-manage db_sync" glance

10.获取路由IP

ip=$(ifconfig `route | grep default | awk '{print $8}'` | grep inet | grep -v inet6 | awk '{print $2}')

11.判断CPU是否支持虚拟化

if [[ $(egrep -c '(vmx|svm)' /proc/cpuinfo) == 0 ]];then	defaultnum=`grep -n "^\[libvirt\]$" $operationfile | awk -F ':' '{print $1}'`	sedoperation=$defaultnum"a"	sed -i "$sedoperation  virt_type = qemu" $operationfileelse	defaultnum=`grep -n "^\[libvirt\]$" $operationfile | awk -F ':' '{print $1}'`	sedoperation=$defaultnum"a"	sed -i "$sedoperation  virt_type = kvm" $operationfilefi

12.获取指定网卡名所对应的IP地址

ext_ens=ens160local_ip=$(ifconfig `route | grep $ext_ens | awk '{print $8}'` | grep inet | grep -v inet6 | awk '{print $2}')

13.查找并删除文件

find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f

14.查找并列出文件类型

find . -type f -exec file '{}' \;

15.查找大于1GB以上的文件,并列出

find / -size +1000M -exec ls -alh '{}' \;

16.测试磁盘性能

time dd if=/dev/zero of=/tmp/testfile bs=4k  count=80000

17.find查找文件大小大于10MB的文件,并find排除某些目录

find / -not \( -path /var/lib/docker -prune -o -path /proc -prune \) -type f -size +10M

--end--

转载地址:http://bhjbm.baihongyu.com/

你可能感兴趣的文章
落力在岁月青葱
查看>>
2015年春节往事小记
查看>>
oracle 删除表空间后服务器磁盘空间未释放
查看>>
windows程序员C/C++转向linux程序员时,如何编写、调试linux程序
查看>>
我的友情链接
查看>>
非等宽图片列表的布局
查看>>
【JAVA技术】webservice接口
查看>>
app打包总结 以及 提交app审核过程
查看>>
关于root(其他)用户拒绝登陆mysql的处理方法
查看>>
Linux基本常用命令总结-初级
查看>>
域计算机修改修改本地帐号密码
查看>>
负载均衡集群的实现方式之一LVS
查看>>
公有云产品试用介绍
查看>>
我的友情链接
查看>>
Servlet+JSP+MySQL实现用户管理模块之六、实现用户信息显示
查看>>
软件项目管理
查看>>
3012.脚本作业—l201.10.0编写一个脚本用于检测IP地址(递进版10)
查看>>
rpmbuild SPEC文件
查看>>
心在山水间
查看>>
ionic开发android app步骤
查看>>