How to delete files only, but keep the directory structure?
Try this:
find . ! -type d -exec rm '{}' \;
This will delete every single file, excluding directories, below the current working directory. Be extremely careful with this command.
If the version of find
on your machine supports it, you can also use
find . ! -type d -delete
You can use the command find
to locate every file but maintain the directory structure:
$ find /some/dir -type f -exec rm {} +
Per this Unix & Linux Q&A titled: gnu find and masking the {} for some shells - which?, escaping the {}
with single ticks ('
) doesn't appear to be necessary anymore with modern day shells such as Bash.