命令
groupadd
groupadd -g 12349 dinstall
useradd
useradd -u 12345 -g dinstall -m -d /home/dmdba -s /bin/bash dmdba
nc
nc -lk 9999
nc 127.0 .0.1 9999
ss
ss -tunap
lsof
lsof -nP -iTCP -sTCP:LISTEN
lsof -nP -iTCP:3306 -sTCP:LISTEN
ip
ip addr add 192.168 .1.1/24 dev eth0
ip addr show eth0
ip addr del 192.168 .1.1 dev eth0
ip route show
ip route get 123.125 .114.144
ip route add default via 192.168 .1.254
ip -s link
ip neigh( 或neighbour)
ip monitor all
ip link set eth0 up
ip link set eth0 down
ps
ps -aux
ps -ef
find
find test/ -name *.txt -type f -user root
scp
scp -P 22 -r test1/ user@host:/test2
rsync
mkfs.ext4
mkfs.ext4 /dev/sdb
hexdump
hexdump -x -s 0 1 .bin
重定向
command > file
command >> file
command 2 > file
command 2 >> file
command > file 2 >&1
command >> file 2 >&1
command << EOF
document
EOF
修改为\r结尾
nano filename.sh
centos查看系统信息
cat /etc/redhat-release
cat /etc/centos-release
cat /etc/centos-release-upstream
uname -a
cat /proc/version
centos切换界面
systemctl get-default
systemctl set-default graphical.target
systemctl set-default multi-user.target
nohup和&
不用nohup和& : 在前台运行(终端不能输入其他命令),关闭当前终端后,进程会停止运行;
只用nohup: 在前台运行,关闭终端后,进程会继续在系统里运行;
只用& : 在后台运行(终端可以输入其他命令),关闭终端后,脚本会继续在系统里运行,但是stdout(标准输出)和stderr(标准错误)的信息会无法查看;
使用nohup 和 & : 在后台运行,关闭运行脚本的终端后,脚本会继续在系统里运行,stdout和stderr里的内容会输出到nohup.out文件中。
jdk配置
export JAVA_HOME = /opt/jdk1.8.0_152
export JRE_HOME = ${JAVA_HOME} /jre
export CLASSPATH = .:${JAVA_HOME} /lib:${JRE_HOME} /lib
export PATH = ${JAVA_HOME} /bin:$PATH
多个命令同时执行
使用 ; 来分隔命令,适合需要按照顺序执行多个命令的情况,不论前一个命令是否成功。 使用 && 来分隔命令,适合需要依赖前一个命令成功才能执行下一个命令的情况。 使用 || 来分隔命令,适合需要依赖前一个命令失败才能执行下一个命令的情况。 使用 & 来分隔命令,适合需要并行执行多个命令的情况,不需要等待前一个命令完成。
脚本
测试某ip是否通畅
ping -c 10 192.168 .1.1 | grep 'packet loss' | awk -F 'packet loss' '{print $1}' | awk '{print $NF}' | sed 's/%//g'
kill某进程
ps -ef | grep -w mysqld | grep -v grep | awk '{print $2}' | xargs kill -9
每隔1s执行命令
watch -n 1 -d "date"
获取监听端口状态
function getListenPortStatus ( ) {
if [ -z $1 ] ; then
echo "0"
return
fi
res = ` ss -tunlp | grep -w LISTEN | grep -w $1`
if [ -n "$res " ] ; then
echo "1"
else
echo "0"
fi
}
获取进程pid
function getProcNum ( ) {
pid = ""
if [ -z $1 ] ; then
echo $pid
return
fi
res = ` ps -ef | grep -v grep | grep -w $1`
if [ -n "$res " ] ; then
pid = ` echo $res | awk '{print $2}' `
fi
echo $pid
}
验证码防止误触发
function confirm ( ) {
randomStr1 = ` echo $RANDOM | md5sum | cut -c 5 -8`
read -p "请输入验证码[$randomStr1 ]:" randomStr2
if [ "$randomStr1 " == "$randomStr2 " ] ; then
echo "1"
else
echo "0"
fi
}
shell基本运算符