zoukankan      html  css  js  c++  java
  • 把扩展名为.XX结尾的文件中内容包含name字符串替换为name1与删除/tmp/xusx/下除passwd以外的其他文件

    1、替换文本内容name为name2

    [root@localhost a]# touch 1.txt 2.txt 3.txt
    [root@localhost a]# echo "ni hao">1.txt
    [root@localhost a]# echo "ni hao">2.txt
    [root@localhost a]# echo "ni hao">3.txt

    [root@localhost a]# find ./ -type f -name "*.txt"|xargs sed 's#ni hao# xiexie#g'
    xiexie
    xiexie
    xiexie

    注意sed -i 是永久改变内容。没加-i是临时查看改变后效果。

    #####################################################################################################

    2、删除/tmp/xusx/下除passwd以外的其他文件:

    方法一:

    [root@localhost xusx]# ls
    1.txt 2.txt 3.txt a passwd passwd1 test.txt xusx.txt
    [root@localhost xusx]# ls |grep -v "passwd"|xargs rm -f    ===>###(不是特别好)
    rm: 无法删除 “a”: 是一个目录
    [root@localhost xusx]# ls
    a passwd passwd1

    方法二:

    [root@localhost a]# ls
    1.sh 1.txt 2.sh 2.txt 3.sh 3.txt passwd passwd1 passwd2
    [root@localhost a]# find ./ -type f ! -name "passwd"|xargs rm -f
    [root@localhost a]# ls
    passwd

  • 相关阅读:
    牛客网 CSL的英语考试
    SDNU 1016.矩形合并
    SDNU 1412.Huffuman树(优先队列)
    HDU
    HDU
    HDU
    SDNU 1504.B.Fibonacci
    Find them, Catch them(种类并查集)
    golang中的net/rpc包
    gRPC
  • 原文地址:https://www.cnblogs.com/xusx/p/6040388.html
Copyright © 2011-2022 走看看