[英]How to delete all files apart from a set of directories using rm command inlinux?
I want to delete all the files in a folder apart from my LOG directory and my reports directory. 我想删除除我的LOG目录和报告目录之外的文件夹中的所有文件。 Is there a way to do that in Linux terminal using rm command ?
有没有一种方法可以在Linux终端中使用rm命令执行此操作?
I want to delete all the files in a folder apart from my LOG directory and my reports directory.
我想删除除我的LOG目录和报告目录之外的文件夹中的所有文件。
rm -rf !(LOG|reports)
Make sure that you have extglob
option enabled: 确保已启用
extglob
选项:
shopt -s extglob
$rm -rf [your directory path to delete]
此命令将删除所选目录以及其中的所有文件和文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.