Linux shell日常使用

运行后台任务

nohup ~/bin/xxx.sh &

运行 SpringBoot 的jar包:
nohup java -jar http_request_tool-0.0.1-SNAPSHOT.jar &
命令格式: nohup <命令> &

定时器

编辑定时器:

crontab -e

范例:

*/20 * * * * /Users/whuanghkl/study/cron/todo.sh

每20分钟执行一次

20 7 * * * /home/whuang/software/auto_start_tomcat.sh

每天的上午7点20分执行脚本

30 18 * * * /home/whuang/software/auto_innerSign.sh
每天的下午6点
每月末执行, 00 23 28-31 * * [ date -d tomorrow +%e -eq 1 ] && /bin/bash youshell.sh

获取命令行参数

if [ x"$1" == x"i" ];then
echo "ignore io0007-0.0.1-SNAPSHOT.jar"
else
cd /Users/whuanghkl/code/mygit/io0007
mvn install
result2=$?
echo $result2
if [ $result2 -ne 0 ];then
echo "error."
exit 4
fi
fi

|格式|含义|

|$1|命令行的第一个参数| |$2|命令行的第二个参数|

创建用户

1,创建用户组
groupadd whuang

2,创建用户
useradd whuang -g whuang
-g 指定用户组

3,设置用户密码
passwd whuang

判断文件是否存在

test -f 判断是否存在

test -f ~/.bash_profile && source ~/.bash_profile

防止别人攻击

查看攻击的ip
linux命令:
grep "authentication failure" /var/log/secure

防止别人尝试登录

/etc/hosts.deny 编辑vim /etc/hosts.deny ,添加: sshd:115.28.240. sshd:89.163.134. sshd:109.74.248. sshd:104.197.46. sshd:43.241.208. sshd:121.42.177. sshd:121.41.108. sshd:112.74.68. sshd:43.250.44. sshd:207.190.196. sshd:121.41.121. sshd:1.82.243. sshd:73.186.113. sshd:138.118.7. sshd:107.184.57. sshd:120.26.106. sshd:123.56.4. sshd:112.74.113. sshd:89.34.24.

搜索文本文件

grep -rn "keyword" --exclude-dir "node_modules" ./
ROLE_SPECIFY是要搜索的关键字
重要参数说明:
--colour:指定搜索的关键字的颜色,取值范围:never',always' or `auto'
--exclude-dir:要排除在外的目录名称,
Note that
-- exclude-dir patterns take priority over --include-dir patterns
-i, --ignore-case:忽略大小写;
-n, --line-number:显示行号 ;
-R, -r, --recursive:递归搜索目录及子目录;
-v, --invert-match:反转,所有不匹配的行;
-w, --word-regexp:作为整个单词来搜索
-E:使用正则表达式:例如:
tail -f ../../logs/catalina.out|grep -E "sameFileName|isEscapestr"
注意:必须是大写的E

转载于:https://my.oschina.net/huangweiindex/blog/2964269

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值