• linux系统中只删除所有文件或只删除所有目录


    1、创建测试数据

    [root@centos7 test2]# touch a.txt b.txt c.txt; mkdir test01 test02 test03
    [root@centos7 test2]# ls
    a.txt  b.txt  c.txt  test01  test02  test03

    2、删除所有文件

    [root@centos7 test2]# ls --file-type
    a.txt  b.txt  c.txt  test01/  test02/  test03/
    [root@centos7 test2]# ls --file-type | grep -v "/$"
    a.txt
    b.txt
    c.txt
    [root@centos7 test2]# ls --file-type | grep -v "/$" | xargs rm -f
    [root@centos7 test2]# ls
    test01  test02  test03

    3、删除所有的目录文件

    [root@centos7 test2]# touch a.txt b.txt c.txt
    [root@centos7 test2]# ls
    a.txt  b.txt  c.txt  test01  test02  test03
    [root@centos7 test2]# ls --file-type
    a.txt  b.txt  c.txt  test01/  test02/  test03/
    [root@centos7 test2]# ls --file-type | grep "/$"
    test01/
    test02/
    test03/
    [root@centos7 test2]# ls --file-type | grep "/$" | xargs rm -rf
    [root@centos7 test2]# ls
    a.txt  b.txt  c.txt
  • 相关阅读:
    leetcode 137
    leetcode 134
    133. Clone Graph
    leetcode 131
    leetcode 130
    mac uwsgi ssl issue handler
    leetcode 85 Maximal Rectangle golang
    leetcode 84 golang
    leetcode 61
    C# 后台实现一次上传多个文件
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14660971.html
Copyright © 2020-2023  润新知