Linux Delete Directory

To delete a directory you can use the "rmdir", but what if a directory that is not empty. For example:
$ mkdir music
$ rmdir music

will certainly be run successfully, but if
$ mkdir music
$ touch music/filetest

When we want to remove that directory with the command "rmdir", will appear the error
$ rmdir music
rmdir: music/: Directory not empty

To overcome this we can vacate the new directory run "rmdir" or we can use the command "rm" with the option "-rf".
$ rm -rf music

The error will not appear. the option "-r" recursive gave the order to "rm" so that the music directory and all of its contents will be removed, while the option "-f" make "rm" will not bring up the confirm removal and directly delete the music directory with the contents either a file or directory to another.


Click here for Comments