Sunday, April 28, 2024
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 12813  / 2 Years ago, tue, september 20, 2022, 11:12:43

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?


More From » command-line

 Answers
7

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



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


See Pattern Matching


[#36984] Wednesday, September 21, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
calronze

Total Points: 0
Total Questions: 110
Total Answers: 112

Location: Belarus
Member since Thu, Aug 11, 2022
2 Years ago
calronze questions
Sun, Jan 9, 22, 13:41, 2 Years ago
Wed, Feb 15, 23, 01:41, 1 Year ago
Sat, Jul 23, 22, 21:03, 2 Years ago
Sat, Feb 5, 22, 01:57, 2 Years ago
;