• Linux grep log文件及find命令学习


    最近没有更新博客,遇到国庆终于有时间学习并更新博客了~

    记录一下自己的学习

    Linux一直是我的弱项,由于现在的工作需要用到Linux,决定恶补一下。

    查找文件地址
    find /home/ -name "test*" -type f # type 查找文件类型 -type d 为文件夹, -type f 为文件 >>> /home/learn/test.txt
    查找当前目录下的文件
    find . -name "test*" -type d
    查找当前目录下指定文件并且最后编辑时间为30天以前或者一天内
    find . -name "*01.txt" -type f -mtime +30 find . -name "*01.txt" -type f -mtime -1
    查找并删除文件
    find . -name "*01.txt" -type f -mtime -1 |xargs rm -rf {} ;
    查找并拷贝文件
    find . -name "test.*" -type f -mtime -1 -exec cp -r {} /home/abc ;
    

     grep 命令

    grep -n '2019-10-24 00:01:11' *.log
    从文件内容查找匹配指定字符串的行:
    $ grep "被查找的字符串" 文件名
    例子:在当前目录里第一级文件夹中寻找包含指定字符串的 .in 文件
    grep "thermcontact" /.in
    从文件内容查找与正则表达式匹配的行:
    $ grep –e "正则表达式" 文件名
    
    查找时不区分大小写:
    
    $ grep –i "被查找的字符串" 文件名
    查找匹配的行数:
    $ grep -c "被查找的字符串" 文件名
    从文件内容查找不匹配指定字符串的行:
    $ grep –v "被查找的字符串" 文件名
    从根目录开始查找所有扩展名为 .log 的文本文件,并找出包含 "ERROR" 的行:
    $ find / -type f -name "*.log" | xargs grep "ERROR"
    例子:从当前目录开始查找所有扩展名为 .in 的文本文件,并找出包含 "thermcontact" 的行:
    find . -name "*.in" | xargs grep "thermcontact"
    查看指定程序的进程运行状态,并输出到指定文件中
     ps aux | grep gsd > ps.log
    打印显示输出的文件内容
    cat ps.log
    将文件内容安顺序排列输出到指定文件中
    tr a-z A-Z < test.txt | sort > test01.txt
    

      

     
  • 相关阅读:
    redis学习笔记(5)hash类型
    redis学习笔记(4)set集合
    redis学习笔记(3)list数据类型
    redis学习笔记(7)配置文件说明
    Uipath学习(1):Uipath变量及数据类型
    Novice学Pytest(4)fixture的详细使用
    Novice学Pytest(3)setup和teardown执行顺序
    Novice学Pytest(1)快速入门
    用python3脚本把labelme的json格式文件转png/xml格式文件
    Ubuntu18.04 安装NVIDIA显卡驱动(GTX1060)+CUDA10.1+CUDNNv8+Anaconda3+pytorch+pycharm (最全教程,踩坑)
  • 原文地址:https://www.cnblogs.com/jescs/p/13768728.html
Copyright © 2020-2023  润新知