先 cd 进入该文件夹。 如果N=1000,命令如下:
ls |head -n 1000 |xargs -i cp -r {} /home/xuqiong/data/testimg/nosee/test
原来的包名是 com.xxx.utils,现在要改为 test。有 100 个这样的文件。 使用 sed 命令:
sed -i 's|com.xxx.utils|test|' *.java
df -h
date +%Y-%m-%dT%H:%M:%S
path=$(cd ../abc; pwd) echo $path
path=~/codes echo $path # 输出绝对路径 if [ -d "$path" ]; then echo 'exist codes' fi if [ -d "/Users/plough/codes" ]; then echo 'exist codes' fi # 相对路径是没用的 if [ ! -d "~/codes" ]; then echo 'no exist codes' fi
path=~/codes/test.py if [ -f "$path" ]; then echo 'exist' fi
dir=`dirname $0` script_dir=`readlink -f $dir/`
或者
script_dir=$(cd `dirname $0`; pwd)
sed -i "s#%name#Tom#g" hello.yml
reserve_num=10; ((delete_num=$(ls /var/lib/logs|wc -l) - reserve_num)); if ((delete_num > 0)); then rm -rf $(ls /var/lib/logs|sed \"s:^:/var/lib/logs/:\"|sort|head -n $delete_num); fi;
du -d 1 -h
ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'
根据实际情况,可能存在多个 ip,还要再用 grep 过滤一下。
{ # try command1 && #save your output } || { # catch # save log for exception }
# Array pretending to be a Pythonic dictionary ARRAY=( "cow:moo" "dinosaur:roar" "bird:chirp" "bash:rock" ) for animal in "${ARRAY[@]}" ; do KEY="${animal%%:*}" VALUE="${animal##*:}" printf "%s likes to %s.\n" "$KEY" "$VALUE" done printf "%s is an extinct animal which likes to %s\n" "${ARRAY[1]%%:*}" "${ARRAY[1]##*:}
var="Hello,Word" # 把变量中的第一个字符换成大写 echo ${var^} # 把变量中的所有小写字母,全部替换为大写 echo ${var^^} # 把变量中的第一个字符换成小写 echo ${var,} # 把变量中的所有大写字母,全部替换为小写 echo ${var,,}
#!/bin/bash function is_empty() { if [ -z "$1" ]; then return 1 fi return 0 } function is_empty_ignore_space() { if [ -z "${1// }" ]; then return 1 fi return 0 } is_empty '' echo $? # 1 is_empty_ignore_space '' echo $? # 1 is_empty ' ' echo $? # 0 is_empty_ignore_space ' ' echo $? # 1
kubectl get pods|tail -n +2|awk '{print $1}'
kubectl delete sts `kubectl get sts|tail -n +2|awk '{print $1}'` kubectl delete deployment `kubectl get deployments|tail -n +2|awk '{print $1}'` kubectl delete service `kubectl get services|tail -n +2|awk '{print $1}'`
类似于 ack 的效果。
find . -type f|xargs grep "10.10.25.107"
nc -z <host> <port>,然后检查 $? 的值,为 1 是打开的,为 0 则是关闭的。例如:
if [ !$(nc -z 0.0.0.0 27018) ]; then kubectl port-forward service/mongo --address 0.0.0.0 27018:27018 & fi
find . -name '*.config.js' -exec echo 123{} \; # 查找并删除 find . -name '*Pulished*' -exec rm {} \;