0
点赞
收藏
分享

微信扫一扫

Linux 运维指令-基础

1.crontab

1、说明

*         *       *     *       *     cmd
分  时  日  月  周  命令

第1列表示分钟1~59 每分钟用*或者 */1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令

2、示例

#每晚的21:30 重启apache
30 21 * * * /usr/local/etc/rc.d/lighttpd restart
#每月1、10、22日的4 : 45重启apache
45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
#每周六、周日的1 : 10重启apache
10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart
#每天18 : 00至23 : 00之间每隔30分钟重启apache
0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart
#晚上11点到早上7点之间,每隔一小时重启apache
* 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart
#每一小时重启apache
* */1 * * * /usr/local/etc/rc.d/lighttpd restart
#每月的4号与每周一到周三的11点重启apache
0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart
#一月一号的4点重启apache
0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
#每半小时同步一下时间
*/30 * * * * /usr/sbin/ntpdate 210.72.145.44

2.chmod

chmod u+s /sbin/ipset

Linux 运维指令-基础_Linux命令

设置普通用户具有执行ipset的权限

3.namei

namei -om /usr/html

Linux 运维指令-基础_Linux命令_02

显示详细的用户权限

4.curl

4.1.发送GET请求

curl http://status.myj.com.cn

Linux 运维指令-基础_运维_03

4.2.发送POST请求

curl -d 'select * from passwod' http://status.xxx.com.cn

Linux 运维指令-基础_运维_04

4.3.增加Header参数发送POST请求

curl -H "Content-Type:application/json" -X POST -d '{"post_data":"select * from password"}' 'https://status.xxx.com.cn'

5.批量查找替换

sed -i '/ssl on\;/d' `grep -rl "ssl on" ./*.conf`                                             #删除所有.conf文件中的 ssl on;行
sed -i 's/listen 443\;/listen 443 ssl\;/' `grep -rl "listen 443" ./*.conf` #将所有.conf 文件的 listen 443;行替换为 listen 443 ssl;

6.内核更新

​​http://elrepo.org/tiki/tiki-index.php​​

7.Shell相关

7.1.Shell特殊变量

变量

说明

$0

当前脚本名

$[n]

通过命令传递进入的参数,例如$1、$2

$#

通过命令传递进入的参数数量

$*

通过命令传递进入的所有参数

$$

当前shell的进程ID

$?

上个命令的退出状态或返回值

7.2.命令替换

#!/bin/bash​​
​now=`date`​​
​​echo "date now is ${now}"​​

7.3.关系运算

关系运算符只支持数字,返回为真或假

运算符

说明

-eq

2边相等

-ne

不等于

-gt

左边是否大于右边

-lt

左边是否小于右边

-ge

左边是否大于等于右边

-le

左边是否小于等于右边

7.4.字符串运算符

运算符

说明

-Z

字符串长度为0

-n

字符串长度不为0

7.5.文件测试运算符

运算符

说明

-b file

文件是否为块设备

-c file

文件是否为字符设备

-d file

文件是否为目录

-f file

文件是否为普通文件

-p file

文件是否为管道文件

-r file

文件是否可读

-w file 

文件是否可写

-x file

文件是否可执行

-s file

文件是否为空

-e file

文件是否存在

8.查找所有.sh文件并批量授权

find /var -name "*.sh" -exec chmod 755 {} \;
find ./ -not -name “*.bash” -exec chmod o+x {} \;

9.查看 CPU 占用高的前10个进程

ps aux|grep -v PID|sort -nr -k3|head -n10
ps aux|head -n1;ps aux|grep -v PID|sort -nr -k3|head -n10
ps aux|head -n1;ps aux|grep -v PID|sort -nr -k4|head -n10

sort #排序命令
-nr #默认使用字符串排序n代表使用数值进行排序 默认从小到大排序 r代表反向排序
-k3 #以第3列进行排序
grep -v PID #输出的第一行也参与的排序,去除掉
PID:进程的ID
USER:进程所有者
PR:进程的优先级别,越小越优先被执行
NInice:值
VIRT:进程占用的虚拟内存
RES:进程占用的物理内存
SHR:进程使用的共享内存
S:进程的状态。S表示休眠,R表示正在运行,Z表示僵死状态,N表示该进程优先值为负数
%CPU:进程占用CPU的使用率
%MEM:进程使用的物理内存和总内存的百分比
TIME+:该进程启动后占用的总的CPU时间,即占用CPU使用时间的累加值。
COMMAND:进程启动命令名称

举报

相关推荐

0 条评论