rm *
works fine if your directory doesn't contain subdirectories (see the answer of @kos). However, if you need a recursive solution that also removes all subdirectories, then (as @meesern has pointed out) rm -r *
is not what you want, since it does remove hidden files and subdirectories.
Instead, you can use find
to list and delete non-hidden files and subdirectories (adapted from this answer):
find YOUR_DIRECTORY -not -path '*/\.*' -delete
This will delete all non-hidden files in YOUR_DIRECTORY
and all subdirectories that are empty after the non-hidden files have been removed.
It will not remove content inside a hidden directory (e.g. YOUR_DIRECTORY/.foo/bar/baz
). As a result, you might get some warnings like
find: cannot delete 'some/directory/here': Directory not empty
But you can safely ignore them.