只是列举些命令片段作为示意

    chmod 权限修改

    1. chmod [-R] $mod $file

    chown 所有者修改

    1. chown $user $file

    useradd 添加用户

    1. useradd $user

    passwd 修改密码

    1. passwd $user

    chgrp 组修改

    1. chgrp $group $user

    ssh

    1. ssh [-p $prot] user@host

    scp

    1. scp -P $port [[user@]host1]:file1 [[user@]host2]:remotePath

    非root访问文件夹,权限不足时赋予rw权限至少

    rsync 断点续传

    init.d 开机自启

    启动脚本的常见方式

    1. 1) 作为程序进程启动
    2. xxxx.sh
    3. 2) 作为控制台模式启动
    4. xxxx.sh run
    5. 3) 作为服务启动
    6. xxxx.sh &

    查看用户

    1. cat /etc/passwd|grep -v nologin|grep -v halt|grep -v shutdown|awk -F":" '{ print $1"|"$3"|"$4 }'|more

    查看活跃用户

    1. w

    查看网卡

    1. ifconfig
    2. 具体信息:ethtool

    查看压缩包的内容

    1. unzip -v xxx.zip
    2. tar -tvf xxxxx.tar

    修改时区与时间

    1. # https://www.cnblogs.com/ljy2013/p/4615149.html
    2. tzselect
    3. # 依次输入 5 9 1 1
    4. # 修改日期,如改为2019.4.9
    5. date -s 04/09/19
    6. # 修改时间,如改为20:00
    7. date -s '20:00'
    8. # 将当前时间和日期写入BIOS,避免重启后失效
    9. hwclock -w

    网络监控

    1. tc

    应用程序端口监听

    1. lsof -i:[port]
    1. port=`lsof -i:8000 | awk '{print $2}' | sed -n '2,$p'`;
    2. echo -e "服务端口为 ====》 ${port}";
    3. if [[ ${port} != "" ]];
    4. then `kill -9 ${port}`;
    5. fi;
    6. #以此解决 allure 命令找不到的错误
    7. source /etc/profile

    网络端口监听

    1. netstat -ant
    2. netstat -nlp

    应用程序监听

    1. ps -ef | grep [port]|[key_name]
    2. ps aux | grep [port]

    内存查看

    1. free

    磁盘查看

    1. df -h
    2. du

    输出执行的指令与结果

    1. echo `[CMD]`
    2. # 例如 echo `ls -al`

    文本相关处理(如编辑、替换等)命令

    1. awk
    2. sed
    3. grep

    定时器

    1. crontab -e

    字符串处理

    shell 字符串截取

    网络资料任意参考,如 http://c.biancheng.net/view/1120.html
    image.png

    变量处理( **$** )

    $0、$?、$!、$$、$*、$#、$@常用语法

    https://blog.csdn.net/a1991520823/article/details/104294882

    • $! Shell最后运行的后台Process的PID
    • $? 最后运行的命令的结束代码(返回值)即执行上一个指令的返回值

    重复执行命令( **!** )
    https://www.bbsmax.com/A/nAJvkRva5r/

    代码片段

    1. ....
    2. ....
    3. file=.......
    4. reports_list=`ls`
    5. crt_date=`date "+%Y-%m-%d"`
    6. for varible in ${reports_list}
    7. do
    8. echo ${varible}
    9. # 字符串截取
    10. file_date=${varible:0-15:10}
    11. # 比较两个字符串。方括号与变量间必须有空格(注意语法)
    12. if [ "${crt_date}" != "${file_date}" ]; then
    13. echo ${WORKSPACE}/*${file_date}.*
    14. echo `mv ${WORKSPACE}/*${file_date}.* ~/history/`
    15. fi
    16. echo "archived files history:"`ls ~/history/`
    17. done

    网络请求命令

    1. wget
    2. curl