Operating System - HP-UX
1752761 Members
5048 Online
108789 Solutions
New Discussion юеВ

remove directory contents

 
SOLVED
Go to solution
Ron Irving
Trusted Contributor

remove directory contents

Good morning gents, (and ladies.)

How do I remove the contents of a directory without removing the directory itself?

eg,

rm -r /ron/*?

I don't think that's correct.
Should have been an astronaut.
6 REPLIES 6
Steven E. Protter
Exalted Contributor

Re: remove directory contents

Shalom,

rm -rf /ron/

That will do it. Directory and all contents.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Jozef_Novak
Respected Contributor
Solution

Re: remove directory contents

Hi Ron,

That is correct :-)

J.
Pete Randall
Outstanding Contributor

Re: remove directory contents

It may look odd, Ron, but that's the way to do it and still leave the directory itself.


Pete

Pete
Ganesan R
Honored Contributor

Re: remove directory contents

Goto the directory and use rm -r

# cd
#rm -r *
Best wishes,

Ganesh.
James R. Ferguson
Acclaimed Contributor

Re: remove directory contents

Hi:

If you do:

# rm -rf /dir

...you remove the contents AND the directory.

To remove the contents but keep the top directory, do:

# find /dir ! -path /dir -exec rm -rf {} +

Regards!

...JRF...
Ron Irving
Trusted Contributor

Re: remove directory contents

thank you for all your quick reponses...thread closed.
Should have been an astronaut.