Linux – Remove a directory with all files

In Linux if we need to remove a directory it can be done using command

rmdir dirname

But if directory is not empty then system will through an error.

rmdir scripts

This error comes up:

rmdir: failed to remove `scripts’: Directory not empty

To remove a directory that is full with other files or directories, use the below command.

rm -r directory

Running above command would delete the files and directories inside also, but would require a prompt for each of the files. To not receive a prompt use the command below.

rm -rf scripts

This command will remove scripts directory with all containing directories and files

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.