在文件系统中输入数据时,某些文件进入了错误的目录,现在我必须重置具有特定名称的所有文件夹,而无需触摸该子目录的其他文件夹中的文件。由于我要清空的所有目录都具有相同的名称,因此我认为这是可能的,但是不幸的是,我真的不知道该怎么做。
我有以下结构:
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删除任何数据?
您可以使用
rm -fr */folder_I_want_to_empty/* */folder_I_want_to_empty/.??*
请注意,此命令具有很大的破坏性,不会提示,而是以非交互的方式无情地删除。
如果您希望看到要删除的内容,请替换rm -fr
为ls -ld
:
ls -ld */folder_I_want_to_empty/* */folder_I_want_to_empty/.??*
小字体:由于上面使用的模式,很少.
删除仅包含两个字符的文件或文件夹,第一个是点的字符。如果您遇到问题,请在评论中告知我们,我们将调整模式。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句