2

I'm working on a bash script in an AWS EC2 instance (RHEL derived) which needs to do the following:

  1. Search for all directories named "_combined" in ${PROJECT_DIR}
  2. Delete all regular files in all those directories - but not the directory itself

What's the best approach to do this?

1
  • @don_crissti - good point. I meant regular files, will amend question. Commented Mar 14, 2017 at 21:15

2 Answers 2

3

So, something like

find "$PROJECT_DIR" -path "*/_combined/*" -type f

And if that seems right:

find "$PROJECT_DIR" -path "*/_combined/*" -type f -delete

Of course that will hit all regular files in the whole tree, not just immediate contents of _combined.

0

This will do what you've described. When you are sure it works, replace the -print clause with -delete:

find "$PROJECT_DIR" -type d -name '_combined' -execdir find '_combined' -maxdepth 1 -type f -print \;

What it does is to search for all directories named _combined underneath $PROJECT_DIR, and in each one it runs the second find snippet which will remove all non-directories in the found directory.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .