Linux Recursive Delete Keeping The First Dir

First question here, I'm usually on StackOverflow.

I need to delete all the contents of a directory, but not the directory itself as I don't have permission to delete that actual directory. This seems simple, but I'm unable to find the command for this. Thanks in advance.


Solution 1:

rm -r /path/to/directory/*

or

rm -rv /path/to/directory/*

if you want to see what is happening.

Solution 2:

Chaos -- You are incorrect in your concern that rm will ever delete ..

I did a quick search and found the man pages to rm from the 7th edition unix manual at http://plan9.bell-labs.com/7thEdMan/vol1/man1.bun where it says:

DIAGNOSTICS

   Generally  self-explanatory.   It  is forbidden to remove the file ..
   merely to avoid the  antisocial  consequences  of  inadvertently  doing
   something like rm -r .

Given that 7th edition unix is the parent of all modern unixes, and was released in 1979, I would say that it is an emphatically safe thing to do. It doesn't do anything, but it causes no harm whatsoever.

Now, there are other programs like chown that will happily "descend" into .. and cause all sorts of chaos if you do wacky things like "chown -Rh user .*" but rm is not chown.