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