只是我个人经常用到的,不是很全
1、获取管道前面的返回值
echo ${PIPESTATUS[0]}
e.g.
<span style="font-family:Courier New;">root@node2:~# date1 | echo 2
2
No command 'date1' found, did you mean:
Command 'date' from package 'coreutils' (main)
date1: command not found
root@node2:~# echo ${PIPESTATUS[0]}
127</span>
2、查看进程
ps -ef | grep pidname | grep -v grep
注:-v是排除,-ef是ps的参数
e.g.
<span style="font-family:Courier New;">root@node1:~# ps -ef | grep ceph | grep -v grep
root 34880 1 0 11:14 pts/1 00:01:15 /usr/bin/ceph-mon -i node1 --pid-file /var/run/ceph/mon.node1.pid -c /etc/ceph/ceph.conf --cluster ceph
root 37315 1 0 11:17 ? 00:00:38 /usr/bin/ceph-osd -i 0 --pid-file /var/run/ceph/osd.0.pid -c /etc/ceph/ceph.conf --cluster ceph
root 37538 1 0 11:17 ? 00:00:36 /usr/bin/ceph-osd -i 1 --pid-file /var/run/ceph/osd.1.pid -c /etc/ceph/ceph.conf --cluster ceph
root 46838 1 0 11:39 ? 00:00:02 /usr/bin/ceph-mds -i node1 --pid-file /var/run/ceph/mds.node1.pid -c /etc/ceph/ceph.conf --cluster ceph</span>
3、断电
echo b > /proc/sysrq-trigger
4、查看后他运行的脚本,以及转入前台运行
jobs:查看所有后台运行的脚本
fg 1/2..:转入前台运行
脚本后面加个 &,就可以在后台运行了,即使Xshell不小心关了也可以继续运行,如果你要查看在后台运行了那些,或者关掉这些进程,就用上面两个命令转到前台来
5、查看内存使用量和清理内存
查看内存使用量free -m
清内存
echo 3 > /proc/sys/vm/drop_caches释放所有能释放的内存
0 – 不释放
1 – 释放页缓存
2 – 释放dentries和inodes
3 – 释放所有缓存
简单说,清除系统对内存的cache,使用root做下面几步:
1. sync
2. echo 3 > /proc/sys/vm/drop_caches
3. sync
4. echo 0 > /proc/sys/vm/drop_caches
6、调试模式运行脚本并将结果保存到文件
sh -x /script_path > file 2>&1
7、查找目录下的所有文件中是否含有某个字符串
查找目录下的所有文件中是否含有某个字符串
find .|xargs grep -ri "string"
查找目录下的所有文件中是否含有某个字符串,并且只打印出文件名
find .|xargs grep -ri "string" -l
8、设置开机运行或开机不运行某服务
chkconfig --list|grep -i “service name”
chkconfig NetworkManager off|on
e.g
CentOS中有一个服务NetworkManager会和network冲突导致网络启动有问题,解决方法:
(1)查看有无此服务
chkconfig --list|grep -i NetworkManager
(2)关闭此服务
service NetworkManager stop
(3)设置开机不启用该服务
chkconfig NetworkManager off
(4)重启网络
/etc/init.d/network restart
9、ubuntu关闭防火墙
ufw disable
apt-get remove iptables
注:这是卸载了防火墙,比较粗暴,可以试试以下这个
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
e.g
root@node2:/mnt# ufw disable
Firewall stopped and disabled on system startup
root@node2:/mnt# apt-get remove iptables
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libvirt0
Suggested packages:
lvm2
The following packages will be REMOVED:
iptables libvirt-bin ubuntu-standard ubuntu-virt-server ufw
The following packages will be upgraded:
libvirt0
1 upgraded, 0 newly installed, 5 to remove and 75 not upgraded.
Need to get 928 kB of archives.
After this operation, 15.8 MB disk space will be freed.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu/ utopic-proposed/main libvirt0 amd64 1.2.8-0ubuntu11.2 [928 kB]
Fetched 928 kB in 48s (19.3 kB/s)
(Reading database ... 107241 files and directories currently installed.)
Removing ubuntu-virt-server (1.4) ...
Removing libvirt-bin (1.2.8-0ubuntu11) ...
libvirt-bin stop/waiting
Removing libvirt-bin dnsmasq configuration
Removing ufw (0.34~rc-0ubuntu4) ...
Skip stopping firewall: ufw (not enabled)
Removing ubuntu-standard (1.327) ...
Removing iptables (1.4.21-2ubuntu1) ...
Processing triggers for man-db (2.7.0.2-2) ...
Processing triggers for libc-bin (2.19-10ubuntu2) ...
(Reading database ... 106884 files and directories currently installed.)
Preparing to unpack .../libvirt0_1.2.8-0ubuntu11.2_amd64.deb ...
Unpacking libvirt0 (1.2.8-0ubuntu11.2) over (1.2.8-0ubuntu11) ...
root@node2:/mnt#
10、动态查看Log
tail -f /var/log/xx.log