linux常用操作整理

1.查找出当前目录下包含有某个文本的文件,并将这些文件移动到指定目录
grep "zyc1729@google.com" /home/admin/web-deploy/asyncfax/ -l |xargs -i mv {} /home/admin/tmp

注:grep 的 -l 表示只输出文件名(只要在文件中找到一个匹配,就输出文件名并终止对这个文件的扫描)

man的原文解释:

 -l, --files-with-matches
              Suppress  normal  output; instead print the name of each input file from which output
              would normally have been printed.  The scanning will stop on the first match.


 

 

2.查找出10天前的文件并删除
find /home/admin/extra_bin/VisitLog/ -type f ! -cmin -14400 |xargs --replace rm {}
或者  rm `find /home/admin/extra_bin/VisitLog/ -type f ! -cmin -14400 ` 
或者  find $rmed_path -name "*.dat*"  -mtime +30 -type f | xargs rm -v 

注:-cmin -10 十分钟内被修改过的文件,   !-cmin -60  一小时未被修改过的文件。

-mtime,-ctime,-atime 分别代表文件最后一次被修改,创建和访问的时间

+N表示 当前时间起 (N*24+24)小时这个时间点之前
-N表示 当前时间向前(N*24)小时 至 当前时间

所以做为特例,-Xtime -1 与-Xtime 0 结果是一致的。


测试方法
先date命令看一下当前时间,再
touch -d "YYYYMMDD mm:ss" filename
touch 几个不同时间点的文件,然后分别
find -mtime {+N|N|-N}
看看结果就知道了

3.ssh到各台机器分别执行(查看多台服务器日志的代码)
for remote in 172.16.131.42 172.16.131.47 172.16.131.61 172.16.131.62 172.16.131.63 172.16.131.64 ;
 do   
    echo $remote;   
    ssh $remote "grep 'sendBatchWWMsg begin sender'  output/logs/user/martini_sales_tool.log"; 
 done 
| more 

远程执行的命令格式为: ssh 远程机 " 命令"


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值