aspose file tools*
The moose likes Linux / UNIX and the fly likes Removing a directory in Linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Removing a directory in Linux" Watch "Removing a directory in Linux" New topic
Author

Removing a directory in Linux

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9629
    
    2

Guys,

I have a doubt with the rmdir command. What is the exact difference between rmdir -p and rmdir -R? The documentations says, -R option deletes the files in the directory and the former just deletes the directory. But my question is when a directory is deleted, where will the files be? They would also be deleted/ Or is it that rmdir -p throws an error if there are any files in the directory that we specified?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959


when a directory is deleted, where will the files be


That depends on which command that you use. If you use rmdir -p, you need to ensure the directory is empty (the directory can contain another empty directory and so on) or else you'll get an error. If you use rm -r, it'll delete everything regardless whether the directory is empty or not.

BTW, I don't see any see any option for rmdir -R in my bash, did you mean rm -r?

SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Costi Ciudatu
Ranch Hand

Joined: Oct 24, 2006
Posts: 74
If you use rmdir -p, you need to ensure the directory is empty (the directory can contain another empty directory and so on) or else you'll get an error.

-p deletes empty parent directories, not empty children; rmdir will fail on any non-empty directory (even if that only contains an other empty directory).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Removing a directory in Linux