shell相关

echo

echo -e 会打印换行等转义符号

echo "$PATH" 双引号内的变量会自动解析,不需要拼接

read

read -p "提示信息" loginuser
         -r "支持转义信息读取"
         -t 指定多长时间超时

# 如果 loginuser 为空,默认值为admin
if [ -z "${loginuser}" ];then
    loginuser=admin
fi

在read语句之前添加  stty erase '^H'
此时用退格键就没问题了

pgrep

直接查看命令的进程号 pgrep adminservice

取代 ps aux | grep adminservice | grep -v grep | awk -F ' ' '{print $2}'

if

if cmd;then
   # 如果cmd执行成功,那么执行该分支
fi

if ! cmd; then
  # 如果cmd执行失败,那么走该分支
fi

cd /var/www/xxx || exit # 如果打开目录失败,那么退出

for

for i in aaa bbb ccc ddd;do
   echo $i
done

ip=($(/sbin/ip a | grep inet | grep -v 127.0.0.1 | grep -v inet6 | awk -F ' ' '{print $2}'))
for i in  $(seq ${#ip[@]});do
  tmp=$(echo "${ip[i-1]}" | sed 's/\/[[:alnum:]]\{2\}//')
  echo "    网卡编号: $i. $tmp"
done

ss

查看系统socket 统计信息
ss -s

Total: 2148
TCP:   271 (estab 35, closed 214, orphaned 1, timewait 206)

Transport Total     IP        IPv6
RAW       2         0         2        
UDP       32        25        7        
TCP       57        44        13       
INET      91        69        22       
FRAG      0         0         0        

查看当前进程的文件打开数:lsof -p 2324 | wc –l
查看当前端口的文件打开数:lsof -i:80 | wc -l
查看当前所有进程文件打开数:lsof | wc -l

sed 替换

sed -i "1,2s/dest/replace/" file  # 替换第1到2行的dest为replace

axel

axel --help
Usage: axel [options] url1 [url2] [url...]

--max-speed=x           -s x    Specify maximum speed (bytes per second)
--num-connections=x     -n x    Specify maximum number of connections
--max-redirect=x                Specify maximum number of redirections
--output=f              -o f    Specify local output file
--search[=n]            -S[n]   Search for mirrors and download from n servers
--ipv4                  -4      Use the IPv4 protocol
--ipv6                  -6      Use the IPv6 protocol
--header=x              -H x    Add HTTP header string
--user-agent=x          -U x    Set user agent
--no-proxy              -N      Just don't use any proxy server
--insecure              -k      Don't verify the SSL certificate
--no-clobber            -c      Skip download if file already exists
--quiet                 -q      Leave stdout alone
--verbose               -v      More status information
--alternate             -a      Alternate progress indicator
--help                  -h      This information
--timeout=x             -T x    Set I/O and connection timeout
--version               -V      Version information

eg:
axel -n 10 https://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Minimal-2207-02.iso\?spm\=a2c6h.25603864.0.0.34ea6aeaDqg255

你可能感兴趣的:(shell相关)