how to delete all the files in a directory, but not the directory

sometimes i come across something so stupidly simple that i need to do, but i don’t know how to do it. today’s task was to delete everything in a directory recursively, but not the directory. i have never done that before and it didn’t seem like it would be that hard to do, but it took me a minute to figure it out.

it’s a little embarrassing, really, but:

delete everything in a directory, including the directory:
rm -rf directory/

delete everything in a directory, excluding the directory:
rm -rf directory/*

simple enough task, but it made me have to think and i don’t like thinking…it hurts my brain.

Leave a Reply

Your email address will not be published.