暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Linux批量替换目录下文件内容字符串【测试成功】

巴韭特锁螺丝 2024-11-05
43

一、批量查找当前文件夹包含字符串的.sh文件

    grep -rl 'sort -nr' --include='*.sh' .

二、批量查找并显示文件信息

    grep -rl 'sort -Vr' --include='*.sh' . | xargs ls -l

    [zz@0001 tomp]$ grep -rl 'sort -Vr' --include='*.sh' . | xargs ls -l
    -rwxr-xr-x 1 zz zz 661 8月 16 15:40 ./tomp-dm/start-tomp-dm.sh
    -rwxr-xr-x 1 zz zz 446 822 09:54 ./tomp-dm/stop-tomp-dm.sh
    -rwxr-xr-x 1 zz zz 684 821 21:24 ./tomp-web-autoschedule/start-tomp-web-autoschedule.sh
    -rwxr-xr-x 1 zz zz 466 822 09:54 ./tomp-web-autoschedule/stop-tomp-web-autoschedule.sh
    -rwxr-xr-x 1 zz zz 722 822 09:54 ./tomp-web-cm/start-tomp-web-cm.sh
    -rwxr-xr-x 1 zz zz 671 821 18:39 ./tomp-web-hdm/start-tomp-web-hdm.sh
    -rwxr-xr-x 1 zz zz 454 822 09:54 ./tomp-web-hdm/stop-tomp-web-hdm.sh
    -rwxr-xr-x 1 zz zz 676 822 09:54 ./tomp-web-ra/start-tomp-web-ra.sh
    -rwxr-xr-x 1 zz zz 726 822 09:54 ./tomp-web-report/start-tomp-web-report.sh
    -rwxr-xr-x 1 zz zz 508 822 09:54 ./tomp-web-report/stop-tomp-web-report.sh
    -rwxr-x--- 1 zz zz 733 8月 22 09:54 ./tomp-web-staffuser/start-tomp-web-staffuser.sh
    -rwxrwxrwx 1 zz zz 670 822 09:54 ./tomp-web-topo/start-tomp-web-topo.sh
    -rwxrwxrwx 1 zz zz 452 822 09:54 ./tomp-web-topo/stop-tomp-web-topo.sh
    -rwxr-xr-x 1 zz zz 676 822 09:48 ./tomp-web-tsdn/start-tomp-web-tsdn.sh

    三、批量查找并替换

        grep -rl 'sort -nr' --include='*.sh' . | xargs sed -i 's/sort -nr/sort -Vr/g'


    文章转载自巴韭特锁螺丝,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

    评论