2

I could traverse the directory sizes using pattern in find command:

find . -name "results_*" -exec du -sm '{}' \;

Now I would like to delete the content of those directories, but still retaining those directories themselves (the results_*) to create a placeholder that they existed and could be found in a backup.

How could I do that?

1 Answer 1

5

You can match against the path instead:

find . -path "*/results_*/*" -delete

or, if your find doesn’t support -delete,

find . -path "*/results_*/*" -exec rm -rf {} \; -prune

This finds anything with results_* in its path, excluding the last path component; so all the contents of directories match results_* will be deleted, but the directories themselves will be left alone (unless they are themselves inside a directory matching results_*).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.