侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

linux下 rm 删除排除文件的两种方式

2023-12-20 星期三 / 0 评论 / 0 点赞 / 125 阅读 / 877 字

1. 先ls egrep 掉某项,再rm[root@lamp test]$ lltotal 0-rw-r--r--. 1 root root 0 Sep 26 03:21 aa-rw-r--r--.

1. 先ls egrep 掉某项,再rm

[root@lamp test]$ lltotal 0-rw-r--r--. 1 root root 0 Sep 26 03:21 aa-rw-r--r--. 1 root root 0 Sep 26 03:44 aa.txt-rw-r--r--. 1 root root 0 Sep 26 03:44 bb.txt-rw-r--r--. 1 root root 0 Sep 26 03:44 cc.txt[root@lamp test]$ rm -f `ls *|egrep -x -v aa`#先ls egrep 掉某项,再rm[root@lamp test]$ lltotal 0-rw-r--r--. 1 root root 0 Sep 26 03:21 aa

2. 打开extglob,使shell识别叹号排除

[root@lamp test]$ shopt extglobextglob        	off#若extglob为off[root@lamp ~]$ shopt -s extglob#将其打开,开启之后,便可在shell中识别!逻辑非操作,效果如下[root@lamp test]$ lsaa  aa.txt  bb.txt  cc.txt[root@lamp test]$ rm -f !(aa)[root@lamp test]$ lltotal 0-rw-r--r--. 1 root root 0 Sep 26 03:21 aa

广告 广告

评论区