Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I'm in a folder: /var/myfolder.

Inside there are some other folders like: /var/myfolder/A/ /var/myfolder/B/ `/var/myfolder/C/ etc.

Inside each there are some files with random names. How do I remove all the files from all the folders inside /var/myfolder?

The structure (all the directories, eg., A, B, C etc., inside /var/myfolder) should remain intact.

share|improve this question

3 Answers 3

up vote 12 down vote accepted


find /var/myfolder -type f -delete

This gets all the regular files under /var/myfolder and deletes them leaving only the directories.

share|improve this answer
Thanks for the solution. I should have mention that I'm doing this in Solaris 9, so my find dont have the -delete option, but that's a good starting point. – user6554 Aug 21 '12 at 12:27
I was able to came up with a following solution: find /var/myfolder -type f -exec rm -f {} \; – user6554 Aug 21 '12 at 13:17
Sorry. I use Debian or Ubuntu. Your solution is equivalent as far as I know. – StarNamer Aug 21 '12 at 16:08

With zsh, use the . glob qualifier to match only regular files:

rm **/*(.)

This deletes all the regular files in the current directory and its subdirectories recursively.

share|improve this answer
I'm using bash. – user6554 Aug 21 '12 at 12:28
@user6554: ... which neither your question nor the used tags indicate ;) – 0xC0000022L May 4 '14 at 22:58

You can run rm */* in /var/myfolder

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.