2021-7

一. 网址参考

  1. linux >和>>的区别,<号使用

  2. start-stop-daemon 用法

  3. 我可以在Bash中使Tab自动补全不区分大小写吗?

  4. Linux cp命令如何拷贝整个目录下所有文件

  5. linux复制指定目录下的全部文件到另一个目录中,linux cp 文件夹

  6. Shell重定向 &>file、2>&1、1>&2 、/dev/null的区别

  7. Linux 修改时区和时间

  8. OpenWrt开发必备软件模块——系统总线ubus

       9. bash 内建命令与关键字的区别

      10. linux环境下/etc/hosts文件详解

      11. shell学习之三(终端背景字体颜色设置)

  12. Linux中grep查找含有某字符串的所有文件

 

二. 实践

  1. nginx的启动脚本中的start-stop-daemon用法, /etc/init.d/nginx:

# Try to extract nginx pidfile
PID=$(cat /etc/nginx/nginx.conf | grep -Ev '^\s*#' | awk 'BEGIN { RS="[;{}]" } { if ($1 == "pid") print $2 }' | head -n1)
if [ -z "$PID" ]; then
    PID=/run/nginx.pid
fi

if [ -n "$ULIMIT" ]; then
    # Set ulimit if it is set in /etc/default/nginx
    ulimit $ULIMIT
fi

start_nginx() {
    # Start the daemon/service
    #
    # Returns:
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
    start-stop-daemon --start --quiet --pidfile $PID --exec $DAEMON --test > /dev/null \
        || return 1
    start-stop-daemon --start --quiet --pidfile $PID --exec $DAEMON -- \
        $DAEMON_OPTS 2>/dev/null \
        || return 2
}

test_config() {
    # Test the nginx configuration
    $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1
}

stop_nginx() {
    # Stops the daemon/service
    #
    # Return
    #   0 if daemon has been stopped
    #   1 if daemon was already stopped
    #   2 if daemon could not be stopped
    #   other if a failure occurred
    start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PID --name $NAME
    RETVAL="$?"
    sleep 1
    return "$RETVAL"
}

   2. bash补全不区分大小写

  ~/.inputrc文件

  $include /etc/inputrc

  # Case-insensitive tab completion
  set completion-ignore-case on

  3. 查找字符串

--递归查找目录下含有该字符串的所有文件
grep -rn "data_chushou_pay_info" /home/hadoop/nisj/automationDemand/

--查找当前目录下后缀名过滤的文件
grep -Rn "data_chushou_pay_info" *.py

--当前目录及设定子目录下的符合条件的文件
grep -Rn "data_chushou_pay_info" /home/hadoop/nisj/automationDemand/ *.py

--结合find命令过滤目录及文件名后缀
find /home/hadoop/nisj/automationDemand/ -type f -name '*.py'|xargs grep -n 'data_chushou_pay_info'

posted @ 2021-07-05 13:49  shanyu20  阅读(42)  评论(0编辑  收藏  举报