linux常用操作整理

来源:互联网 发布:java包有什么用 编辑:程序博客网 时间:2024/04/30 13:49

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 远程机 " 命令"


原创粉丝点击