my dog learned polymorphism
The moose likes Linux / UNIX and the fly likes Removing Non Empty Directories Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Removing Non Empty Directories" Watch "Removing Non Empty Directories" New topic

Removing Non Empty Directories

Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
Please whats the syntax to use in removing non empty directories
Sanjaya Sugiarto
Ranch Hand

Joined: Mar 25, 2004
Posts: 229
rm -R <directory_name>
-R switch means recursive deletation.

<a href="" target="_blank" rel="nofollow">Business Information Technology - Hochschule Furtwangen University, Germany</a>
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

I use "rm -rf" (recursive, force). I think plain '-R' fails if there are non-directory files in the tree you're trying to remove.

An IDE is no substitute for an Intelligent Developer.
Jay Suttiruttana
Ranch Hand

Joined: Aug 17, 2006
Posts: 36
Here's some explanation for -r, -R, or -f and combination of -rf

The following options are supported for /usr/bin/rm and

-r Recursively removes directories and subdirectories in
the argument list. The directory will be emptied of
files and removed. The user is normally prompted for
removal of any write-protected files which the direc-
tory contains. The write-protected files are removed
without prompting, however, if the -f option is used,
or if the standard input is not a terminal and the -i
option is not used.

Symbolic links that are encountered with this option
will not be traversed.

If the removal of a non-empty, write-protected direc-
tory is attempted, the utility will always fail (even
if the -f option is used), resulting in an error mes-

-R Same as -r option

-f Removes all files (whether write-protected or not) in
a directory without prompting the user. In a write-
protected directory, however, files are never removed
(whatever their permissions are), but no messages are
displayed. If the removal of a write-protected direc-
tory is attempted, this option will not suppress an
error message.
I agree. Here's the link:
subject: Removing Non Empty Directories
It's not a secret anymore!