文本替换
mac https://www.cnblogs.com/meitian/p/5907562.html https://blog.csdn.net/fengxianger/article/details/64127644
#把test.txt文件中的每一行的11替换成ff# g 一行中所有的11都替换成ff# 不加g,只替换第一行# -i 替换并保存sed -i '' 's/11/ff/g' test.txt
上一条命令是否执行成果
if [ $? -ne 0 ]; thenecho "failed"elseecho "succeed"fi
文件是否存在
if [ -f "/data/filename" ];thenecho "文件存在"elseecho "文件不存在"fi
后缀文件判断
files=$(ls ${local_tmp}/*.war 2> /dev/null | wc -l)if [[ "${files}" != "0" ]] ; thenecho "文件存在"elseusage "war 包不存在"exit 0fi
包含某个字符串
str="this is a string"[[ $str =~ "this" ]] && echo "$str contains this" || echo "$str is missing"
ssh远程执行脚本
#https://www.cnblogs.com/sparkdev/p/6842805.html 参考地址➜ ~ ssh root@192.168.34.23 "ls && cd github && ls "githubSkitch-2.8.1.zipsphinx.osx-x86_64sphinx.osx-x86_64.1xx.zipxx.txt;; 也可以执行多条语句区别&& : 前边失败了后边的不在执行;; : 前边失败了后边继续执行
rsync 远程传输
rsync -avz --delete \--exclude-from=/Users/admin/open/exclude.list \/Users/admin/open/jsp root@1.1.1.1:/root/jsp--delete 删除那些 DST 中 SRC 没有的文件。--exclude-from=FILE 排除 FILE 中指定模式的文件。-a, --archive 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于 -rlptgoD。-v, --verbose 详细模式输出。-r, --recursive 对子目录以递归模式处理。-z, --compress 对备份的文件在传输时进行压缩处理。
scp 日常用
#将本地文件传递到远程文件scp /path/file user@ip:/path/dir#将远程文件同步到本地scp user@ip:/path/file /path/dir
判断远程主机是否存在目录
ssh tomcat@${IP} "[ -d /home/tomcat/xxx ]" >/dev/null 2>&1if [[ $? -ne 0 ]]; thenecho 'xxx 目录不存在,找对应的运维下载xxx. 放到/home/tomcat/xxx目录下'exit 1fi
判断远程目录是否存在2
ssh tomcat@192.168.198.148 "[ -d /home/tomcat/arthas ] && echo good || mkdir -p /home/tomcat/arthas "#如果/home/tomcat/arthas目录不存在则新建目录,否则新建目录
压缩/解压
## 压缩当前目录成xxxzip -r ./xxx.zip ./* -r表示递归## 压缩dir目录zip -r dir.zip dir## 解压到当前目录(这个xxx.zip可以相对/绝对路径)unzip xxx.zip## 解压到指定目录(使用-d参数指定目录)unzip xxx.zip -d /home/root/xxx#解压tar zxvf 文件名.tar.gz#压缩tar zcvf 文件名.tar.gz 待压缩的文件名
查看进程启动时间和运行时长
ps -eo pid,lstart,etime | grep 25699
