Operating System - HP-UX
1753511 Members
5129 Online
108795 Solutions
New Discussion юеВ

command to delete all the directories

 
SOLVED
Go to solution
Grayh
Trusted Contributor

command to delete all the directories

Is there a command to delete all the directories and its sub-directories in single shot
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor
Solution

Re: command to delete all the directories

Hi:

# rm -rf /path

...will delete *EVERYTHING*, including the parent '/path' directory.

Be very careful.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: command to delete all the directories

Hi (again):

By the way, if '/path' is a mountpoint, and you want to empty the entire filesystem, it is faster to unmount '/path' and 'newfs' the filesystem than to delete (recursively) all files and directories therein:

# umount /path
# newfs -F vxfs -o largefiles /dev/vgNN/rlvolX

Regards!

...JRF...
Jannik
Honored Contributor

Re: command to delete all the directories

I would guess that you have your answer from James but anyway. If you don't want to delete the files but only directories and sub-directories including files in sub-dirs:

# find /path -type d -maxdepth 1 -exec rm -Rf {} \;

Make a test to see if it correct so you don't delete the wrong things.

# find /path -type d -maxdepth 1 -exec ls -ald {} \;
jaton
Johnson Punniyalingam
Honored Contributor

Re: command to delete all the directories

rm -rf /

Thanks,
Johnson
Problems are common to all, but attitude makes the difference
Suraj K Sankari
Honored Contributor

Re: command to delete all the directories

Hi,

rm -Rf is the right command to delete entire directory and its subdirectories.
rm -rf and rm -Rf both are same

Suraj
Steven Schweda
Honored Contributor

Re: command to delete all the directories

> rm -Rf is the right command [...]

> rm -rf and rm -Rf both are same

If they're the same, what makes one of them
"the right command"?
Suraj K Sankari
Honored Contributor

Re: command to delete all the directories

Hi Steven,
I came to knwo for man rm only please see the below output of man page
-R For each argument that is a directory, this option causes rm
to recursively delete the entire contents of that directory
before removing the directory itself. When used in
conjunction with the -i option, rm asks whether to examine
each directory before interactively removing files in that
directory and again afterward to confirm removing the
directory itself.

The -R option will descend to arbitrary depths in a file
hierarchy and will not fail due to path length limitations
unless the length of file name, file specified by the user
exceeds system limitations.

-r Equivalent to -R.


Suraj
Grayh
Trusted Contributor

Re: command to delete all the directories

Thanks everyone ...