在我的文件系统中输入数据时,某些文件进入了错误的目录,现在我必须使用特定名称重置所有文件夹,而不接触该子目录的其他文件夹中的文件。由于我要清空的所有目录都具有相同的名称,因此我认为这是可能的,不幸的是,我真的不知道该怎么做。
我有以下结构:
dir
subdir1
folder_I_want_to_empty //all of these folders have the same name
file_that_needs_to_be_deleted.txt
folder_I_do_not_want_to_empty
file_that_has_to_remain.txt
subdir2
folder_I_want_to_empty //all of these folders have the same name
file_that_needs_to_be_deleted.txt
folder_I_do_not_want_to_empty
file_that_has_to_remain.txt
subdir3
folder_I_want_to_empty //all of these folders have the same name
file_that_needs_to_be_deleted.txt
folder_I_do_not_want_to_empty
file_that_has_to_remain.txt
如何通过命令提示符清空每个目录中的folder_I_want_to_empty而不删除文件夹或从folder_I_do_not_want_to_empty中删除任何数据?
您可以使用通配
:cd dir
rm */folder_I_want_to_empty/*.txt
第一个星号匹配当前文件夹的所有子目录,第二个星号匹配以.txt
作为文件扩展名的所有文件。您可以通过将第一个星号替换为subdir[1-3]
来进一步限制匹配项