简体   繁体   中英

Delete all files and directories - except specified

Been looking for this for a while. We have a common directory where everyone has rwx rights. 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.

I have this find command that lists what should be deleted;

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

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.
So: how should the command end in order to work?

Send to xargs and then rm:

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

edited after your suggestion :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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