在Linux上的bash,删除具有特定文件扩展名的文件

时间:2021-04-27 15:42:46

I want to delete all files with a specific extension - ".fal", in a folder and its subfolders, except the one named "*Original.fal". The problem is that I want to delete other files that have the same extension:

我想删除所有文件的一个特定的扩展- "。“fal”,在一个文件夹及其子文件夹中,除了一个名为“原创。fal”的文件夹。问题是我想删除其他扩展名相同的文件:

  • *Original.fal.ds
  • * Original.fal.ds
  • *Original.fal.ds.erg
  • * Original.fal.ds.erg
  • *Original.fal.ds.erg.neu
  • * Original.fal.ds.erg.neu

There are other ".fal"s that I want to delete as well, that don't have "Original" in them. Names vary all the time, so I can't delete specific names. The *Original.fal doesn't vary.

还有其他的”。fal也是我想删除的,里面没有“原创”。名字一直在变化,所以我不能删除特定的名字。*原创。歧视不不同。

I can only get up to here:

我只能到这里:

$find /disk_2/people/z183464/DOE-Wellen -name "*.fal" \! -name "*Original.fal" -type f -exec echo rm {} \;

It would be great if the command can delete only in the folder (and it's subfolders) where it has been called (executed)

如果命令只能在被调用(执行)的文件夹(以及子文件夹)中删除,那就太棒了

When I run the code it gives me an error:

当我运行代码时,它会给我一个错误:

  1. /disk_2/people/z183464/DOE-Wellen: is a directory
  2. / disk_2 /人/ z183464 / DOE-Wellen:是一个目录

2 个解决方案

#1


3  

If you do not want find to dive too deep, you can restrict it with -maxdepth.

如果不希望查找太深,可以使用-maxdepth对其进行限制。

#2


0  

You can use a simple for loop for that. This command shows all the files you might want to delete. Change echo with rm to delete them.

你可以用一个简单的for循环。此命令显示您可能要删除的所有文件。使用rm修改echo以删除它们。

cd /disk_2/people/z183464/DOE-Wellen && for I in `find . -name "*.fal" ! -name "*Original.fal"`; do echo $I; done

With "find ... | grep ..." you can use regex too, if you need more flexibility.

与“找到…如果您需要更多的灵活性,您也可以使用regex。

#1


3  

If you do not want find to dive too deep, you can restrict it with -maxdepth.

如果不希望查找太深,可以使用-maxdepth对其进行限制。

#2


0  

You can use a simple for loop for that. This command shows all the files you might want to delete. Change echo with rm to delete them.

你可以用一个简单的for循环。此命令显示您可能要删除的所有文件。使用rm修改echo以删除它们。

cd /disk_2/people/z183464/DOE-Wellen && for I in `find . -name "*.fal" ! -name "*Original.fal"`; do echo $I; done

With "find ... | grep ..." you can use regex too, if you need more flexibility.

与“找到…如果您需要更多的灵活性,您也可以使用regex。