• shell 骚操作


    for /L %i in (1,3,200) do ping -n 2 -w 60 192.168.1.%i
    https://www.xuebuyuan.com/730125.html for history show time and user
    https://www.cnblogs.com/xiongzaiqiren/p/11301449.html pkill -kill -t pts/1
    $0     当前脚本的文件名
    $n 传递给脚本或函数的参数。n 是一个数字,表示第几个参数。例如,第一个参数是$1,第二个参数是$2
    $#     传递给脚本或函数的参数个数。
    $*     传递给脚本或函数的所有参数。
    $@     传递给脚本或函数的所有参数。被双引号(" ")包含时,与 $* 稍有不同,下面将会讲到。
    $?     上个命令的退出状态,或函数的返回值。
    $$     当前Shell进程ID。对于 Shell 脚本,就是这些脚本所在的进程ID。
    wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
    shift
    https://blog.csdn.net/weixin_44504987/article/details/86378826

    Example:

    echo “arg1= $1  arg2=$2 arg3=$3”
    shift
    echo “arg1= $1  arg2=$2 arg3=$3”
    shift   
    echo “arg1= $1  arg2=$2 arg3=$3”
    shift  
    echo “arg1= $1  arg2=$2 arg3=$3”
    shift

    The output will be:
    arg1= 1 arg2=2  arg3=3 
    arg1= 2 arg2=3  arg3= 
    arg1= 3 arg2=   arg3=
    arg1=   arg2=   arg3=
    

    shell中条件判断if中的-z到-d的意思
    [ -a FILE ] 如果 FILE 存在则为真。
    [ -b FILE ] 如果 FILE 存在且是一个块特殊文件则为真。
    [ -c FILE ] 如果 FILE 存在且是一个字特殊文件则为真。
    [ -d FILE ] 如果 FILE 存在且是一个目录则为真。
    [ -e FILE ] 如果 FILE 存在则为真。
    [ -f FILE ] 如果 FILE 存在且是一个普通文件则为真。
    [ -g FILE ] 如果 FILE 存在且已经设置了SGID则为真。
    [ -h FILE ] 如果 FILE 存在且是一个符号连接则为真。
    [ -k FILE ] 如果 FILE 存在且已经设置了粘制位则为真。
    [ -p FILE ] 如果 FILE 存在且是一个名字管道(F如果O)则为真。
    [ -r FILE ] 如果 FILE 存在且是可读的则为真。
    [ -s FILE ] 如果 FILE 存在且大小不为0则为真。  
    [ -t FD ] 如果文件描述符 FD 打开且指向一个终端则为真。
    [ -u FILE ] 如果 FILE 存在且设置了SUID (set user ID)则为真。
    [ -w FILE ] 如果 FILE 如果 FILE 存在且是可写的则为真。
    [ -x FILE ] 如果 FILE 存在且是可执行的则为真。
    [ -O FILE ] 如果 FILE 存在且属有效用户ID则为真。
    [ -G FILE ] 如果 FILE 存在且属有效用户组则为真。
    [ -L FILE ] 如果 FILE 存在且是一个符号连接则为真。  
    [ -N FILE ] 如果 FILE 存在 and has been mod如果ied since it was last read则为真。
    [ -S FILE ] 如果 FILE 存在且是一个套接字则为真。  
    [ FILE1 -nt FILE2 ] 如果 FILE1 has been changed more recently than FILE2,or 如果 FILE1 exists and FILE2 does not则为真。  
    [ FILE1 -ot FILE2 ] 如果 FILE1 比 FILE2 要老, 或者 FILE2 存在且 FILE1 不存在则为真。  
    [ FILE1 -ef FILE2 ] 如果 FILE1 和 FILE2 指向相同的设备和节点号则为真。
    [ -o OPTIONNAME ] 如果 shell选项 “OPTIONNAME” 开启则为真。
    [ -z STRING ] “STRING” 的长度为零则为真。  
    [ -n STRING ] or [ STRING ] “STRING” 的长度为非零 non-zero则为真。
    ---------------------  

    0:表示键盘输入(stdin)
    1:表示标准输出(stdout),系统默认是1 
    2:表示错误输出(stderr)

    command >/dev/null 2>&1 &  == command 1>/dev/null 2>&1 &
    1)command:表示shell命令或者为一个可执行程序
    2)>:表示重定向到哪里 
    3)/dev/null:表示Linux的空设备文件 
    4)2:表示标准错误输出
    5)&1:&表示等同于的意思,2>&1,表示2的输出重定向等于于1
    6)&:表示后台执行,即这条指令执行在后台运行1>/dev/null:表示标准输出重定向到空设备文件,也就是不输出任何信息到终端,不显示任何信息。
    2>&1:表示标准错误输出重定向等同于标准输出,因为之前标准输出已经重定向到了空设备文件,所以标准错误输出也重定向到空设
    件。
    这条命令的意思就是在后台执行这个程序,并将错误输出2重定向到标准输出1,然后将标准输出1全部放到/dev/null文件,也就是清空.
    所以可以看出" >/dev/null 2>&1 "常用来避免shell命令或者程序等运行中有内容输出。

    #!/bin/bash

    hgrep()
    {
      sudo find $1 -name "*.h" -o -name "*.hpp" |xargs grep -n $2
    }
    cgrep()
    {
      sudo find $1 -name "*.c" -o -name "*.cpp" |xargs grep -n $2
    }
    cmgrep()
    {
      sudo find $1 -name CMakeList.txt |xargs grep -n $2
    }

    ubuntu@ubuntu:~$ PIP_GET_PIP_URL=${PIP_GET_PIP_URL:-"https://bootstrap.pypa.io/get-pip.py"}
    ubuntu@ubuntu:~$ echo $PIP_GET_PIP_URL
    https://bootstrap.pypa.io/get-pip.py

    function get_versions {
    # FIXME(dhellmann): Deal with multiple python versions here? This
    # is just used for reporting, so maybe not?
    PIP=$(which pip 2>/dev/null || which pip-python 2>/dev/null || true)
    if [[ -n $PIP ]]; then
    PIP_VERSION=$($PIP --version | awk '{ print $2}')
    echo "pip: $PIP_VERSION"
    else
    echo "pip: Not Installed"
    fi
    }
     
    A="helloworld"
    B="low"
    if [[ $A == *$B* ]]
    then
        echo "包含"
    else
        echo "不包含"
    fi

    export OS_IDENTITY_API_VERSION=3
    export OS_AUTH_URL=http://127.0.0.1/identity
    export OS_USERNAME=admin
    export OS_USER_DOMAIN_ID=default
    export OS_PASSWORD=nomoresecret
    export OS_PROJECT_NAME=admin
    export OS_PROJECT_DOMAIN_ID=default
    export OS_REGION_NAME=RegionOne

    关于xargs cp中,如何确定拷贝的源和目的 (copied) 

    Seker:

    find . -name "*" |xargs cp ????
    这里 xargs cp 怎么区分cp源 和 cp目的 
    例如:想把 查询到的文件 都copy到/home/users/中去
            find . -name "*" | xargs cp /home/users/
    cp命令在这里就变成:cp /home/users/ Find_file 

    默认从管道传来的值是放在最后的 这样的话原本想做cp源文件的值和目的目录的参数就颠倒了
    有办法解决一下吗?
    xargs 没有想-exec 那种 {} 的变量吗?

    davistar:

    find . -name "*" | xargs -i cp {}  /home/users/ 

    nuclearxin:

    -i 和{} 什么关系? 

    davistar:

    -i 表示 find 传递给xargs的结果 由{}来代替

    ubuntu show last login
    last | head -n 5

    ubuntu bash show git branch
    .bashrc
    black=$'[e[01;30m]'
    red=$'[e[01;31m]'
    green=$'[e[01;32m]'
    yello=$'[e[01;33m]'
    blue=$'[e[01;34m]'
    magenta=$'[e[01;35m]'
    cyan=$'[e[01;36m]'
    white=$'[e[01;37m]'
    normal=$'[e[m]'
    #. /usr/lib/git-core/git-sh-prompt
    if [ "$color_prompt" = yes ]; then
    PS1="${debian_chroot:+($debian_chroot)}$greenu@h$yellow:$bluew$normal$$red"'$(__git_ps1 " (%s)")'"$normal "
    #PS1='${debian_chroot:+($debian_chroot)}[33[01;32m]u@h[33[00m]:[33[01;34m]w[33[00m]$[33[01;31m]''$(__git_ps1 " (%s)")''$normal '
    else
    PS1='${debian_chroot:+($debian_chroot)}u@h:w$ '
    fi

    /etc/profile
    USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
    if [ "$USER_IP" = "" ]
    then
    USER_IP=`hostname`
    fi
    export HISTTIMEFORMAT="%F %T $USER_IP:`whoami` "
    export HISTSIZE=100000

  • 相关阅读:
    SSH 连接超时解决办法
    alter system switch logfile和alter system archive log current 的区别
    Oracle 删除归档日志脚本
    Oracle 11g 新特性简介
    Oracle sqlplus 常用命令总结
    Oracle 11g 新特性简介
    计算文件的MD5值上传到服务器 下载验证文件是否被篡改
    看不下去的代码放这有机会用手机看。。。
    C++ Primer第一章学习笔记——C++初邂逅
    OpenCV学习笔记(四十七)——VideoWriter生成视频流highgui
  • 原文地址:https://www.cnblogs.com/cjyp/p/10242984.html
Copyright © 2020-2023  润新知