@devf
Linux Nov 02, 2026

emptying a directory in linux without deleting the folder itself

Want to clear everything inside a logs folder, including hidden files, but keep the folder because a service writes into it. rm -rf folder/* misses the dot files. What's the clean way to do it?
1

Leave A Reply

Log in to post an answer.

1 Answer

alicew Nov 05, 2026
devf
find /path/to/dir -mindepth 1 -delete that keeps the folder and removes everything inside, hidden files included. rm -rf dir/* misses the dotfiles. double-check the path before you hit enter, especially if it's in a variable.