简体   繁体   English

删除所有文件和目录-除非指定

[英]Delete all files and directories - except specified

Been looking for this for a while. 一直在寻找这个。 We have a common directory where everyone has rwx rights. 我们有一个公共目录,每个人都拥有rwx权限。 To keep this from growing out of proportions, I need to clear this once a month. 为了防止这种情况超出范围,我需要每月清除一次。 No problem, except I'm supposed to keep 2 directories - one of which has spaces in its name. 没问题,除了我应该保留2个目录-其中一个目录的名称中带有空格。

I have this find command that lists what should be deleted; 我有这个find命令,其中列出了应删除的内容;

find /COMMON/* | grep -v 'keepthis' | grep -v 'keep this too'

However, I'm at at total loss as to how I could rm or delete the output 但是,我对如何rmdelete输出rm

I've googled an found millions of suggestions but they don't fit - I believe it's because of the spaces in the directory name. 我在Google上搜索了数以百万计的建议,但它们不适合-我相信是因为目录名中的空格。
So: how should the command end in order to work? 那么:命令应该如何结束才能起作用?

Send to xargs and then rm: 发送到xargs然后rm:

find /COMMON/* -maxdepth 0 | grep -v 'keepthis' | grep -v 'keep this too' | xargs -rd '\n' rm -r --

edited after your suggestion :) 根据您的建议进行编辑 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM