[英]Delete folders that have numbers in them but don't delete folders that don't have numbers
So there was a bug in our recent code, and instead of creating bunch of numbered folders in a root folder, it created bunch of folders right next to root folder所以我们最近的代码中有一个错误,而不是在根文件夹中创建一堆编号的文件夹,它在根文件夹旁边创建了一堆文件夹
To put it simply, what we wanted was:简单来说,我们想要的是:
customers |-18 |-158 |-405 |-1238 |-1447 ... |-4797
Unfortunately, what we got was:不幸的是,我们得到的是:
customers customers18 customers158 customers405 customers1238 customers1447 .. customers4797
Now, there are about 1000 folders (with their internal sub-folder structure) that we need to delete.现在,我们需要删除大约 1000 个文件夹(及其内部子文件夹结构)。 I tried to look up regex and other filtering method, but it seems like they don't work on rm command.
我试图查找正则表达式和其他过滤方法,但似乎它们不适用于 rm 命令。
What is the command line I need to delete all the "customers[numbers]" folders but NOT the "customers" folder?我需要删除所有“customers [numbers]”文件夹而不是“customers”文件夹的命令行是什么?
Try the following command.试试下面的命令。 It should work -
它应该工作 -
ls | grep -P "customers[0-9]+" | xargs -d"\n" rm -R
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.