只是列举些命令片段作为示意
chmod 权限修改
chmod [-R] $mod $file
chown 所有者修改
chown $user $file
useradd 添加用户
useradd $user
passwd 修改密码
passwd $user
chgrp 组修改
chgrp $group $user
ssh
ssh [-p $prot] user@host
scp
scp -P $port [[user@]host1]:file1 [[user@]host2]:remotePath
非root访问文件夹,权限不足时赋予rw权限至少
rsync 断点续传
init.d 开机自启
启动脚本的常见方式
1) 作为程序进程启动
xxxx.sh
2) 作为控制台模式启动
xxxx.sh run
3) 作为服务启动
xxxx.sh &
查看用户
cat /etc/passwd|grep -v nologin|grep -v halt|grep -v shutdown|awk -F":" '{ print $1"|"$3"|"$4 }'|more
查看活跃用户
w
查看网卡
ifconfig
具体信息:ethtool
查看压缩包的内容
unzip -v xxx.zip
tar -tvf xxxxx.tar
修改时区与时间
# https://www.cnblogs.com/ljy2013/p/4615149.html
tzselect
# 依次输入 5 9 1 1
# 修改日期,如改为2019.4.9
date -s 04/09/19
# 修改时间,如改为20:00
date -s '20:00'
# 将当前时间和日期写入BIOS,避免重启后失效
hwclock -w
网络监控
tc
应用程序端口监听
lsof -i:[port]
port=`lsof -i:8000 | awk '{print $2}' | sed -n '2,$p'`;
echo -e "服务端口为 ====》 ${port}";
if [[ ${port} != "" ]];
then `kill -9 ${port}`;
fi;
#以此解决 allure 命令找不到的错误
source /etc/profile
网络端口监听
netstat -ant
netstat -nlp
应用程序监听
ps -ef | grep [port]|[key_name]
ps aux | grep [port]
内存查看
free
磁盘查看
df -h
du
输出执行的指令与结果
echo `[CMD]`
# 例如 echo `ls -al`
文本相关处理(如编辑、替换等)命令
awk
sed
grep
定时器
crontab -e
字符串处理
shell 字符串截取
网络资料任意参考,如 http://c.biancheng.net/view/1120.html
变量处理( **$**
)
$0、$?、$!、$$、$*、$#、$@常用语法
https://blog.csdn.net/a1991520823/article/details/104294882
$!
Shell最后运行的后台Process的PID$?
最后运行的命令的结束代码(返回值)即执行上一个指令的返回值
重复执行命令( **!**
)
https://www.bbsmax.com/A/nAJvkRva5r/
代码片段
....
....
file=.......
reports_list=`ls`
crt_date=`date "+%Y-%m-%d"`
for varible in ${reports_list}
do
echo ${varible}
# 字符串截取
file_date=${varible:0-15:10}
# 比较两个字符串。方括号与变量间必须有空格(注意语法)
if [ "${crt_date}" != "${file_date}" ]; then
echo ${WORKSPACE}/*${file_date}.*
echo `mv ${WORKSPACE}/*${file_date}.* ~/history/`
fi
echo "archived files history:"`ls ~/history/`
done
网络请求命令
wget
curl