Ubuntu – Command to delete all files from folders matching name recursivly

bashcommand linerm

I have my base folder (let's call it base).

I have a bunch of folders inside, scattered at various depths within these folders are cache folders.

I want to delete all files from within the cache folders, but not the folders themselves.

I have tried

cd base
#then one of...
sudo rm -rf cache/*
sudo rm -rf *cache/*
sudo rm -rf cache*/*
sudo rm -rf *cache*/*

But really am just guessing, what would be the right command?

Best Answer

In bash, you can enable globstar and use ** to match directories recursively

shopt -s globstar
echo rm -rf ./**/*cache*/*

See Pattern Matching