Delete all files in a folder structure in Bash

Written by
Date: 2012-11-21 14:19:32 00:00


If you have a complex folder structure with lots of files in each level of folders. Something like this:

/home/usr/
		|
		|-----/folder1/
		|
		|-----/folder2/
		|		|
		|		|----file1
		|		|----file2
		|
		|-----/folder3/
				|
				|----file3
				|----file4
				|----/folder4/
						|
						|-----file5
						|-----file6

Well you've got the idea. If you want to delete all files from that structure but not folders. You can use find with -type f switch.

find /home/usr/ -type f -delete

That command is going to delete only files and not folders, and you will have an empty structure to work with.