之前被面试被问到过,突然想起来,起初想用类似于编程递归调用实现,感觉很难写,后来翻阅了一些资料,发现就一个指令的事情
1.首先看目录结构
[root@hadoop1]# tree test
test
├── b
│ └── cc.txt
├── bb.csv
└── bb.txt
2.直接执行下边的指令即可
[root@hadoop1]# find test -name '*.txt' -type f |xargs rm -rf
[root@hadoop1]# tree test
test
├── b
└── bb.csv
3.也可以下面这么执行
[root@hadoop1]# find test -name '*.csv' -type f -exec rm -rf {} \;
[root@hadoop1]# tree test
test
└── b