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

  • 相关阅读:
    MongoDB的基本操作
    Python 进阶 之 协程
    sublime text3 3143 注册码
    git add 文档
    Corosync 配置描述
    Centos 7 设置 DNS
    2017百度春招<度度熊买帽子的问题>
    leetcode 160. Intersection of Two Linked Lists
    leetcode 155. Min Stack
    leetcode 141 142. Linked List Cycle
  • 原文地址:https://www.cnblogs.com/xusx/p/6040388.html
Copyright © 2011-2022 走看看