How to delete directory in Linux?

Looking for easy commands to remove directory in Linux? Well don’t worry we have got you covered.

Here’s how you remove or delete a directory from the terminal or command line of your server –

You can use the rmdir command. This command will only work if the directory you want to remove is empty.

Here are some examples of how to use the rmdir command:

Ubuntu/Debian:

rmdir /path/to/directory

Fedora/CentOS:

rmdir /path/to/directory

How to remove all directories in a directory?

To remove a directory and all of its contents, you can use the rm -r command. This will remove the directory and all of its files and subdirectories. Be careful when using this command, as it cannot be undone.

Here are some examples of how to use the rm -r command:

Ubuntu/Debian:

rm -r /path/to/directory

Fedora/CentOS:

rm -r /path/to/directory

Again, be careful when using the rm -r command, as it will permanently delete directories and files inside the current directory. To only delete individual files or multiple files follow this post.

Summary
How to delete directory in Linux?
Article Name
How to delete directory in Linux?
Description
Learn the easy steps for deleting a directory in Linux with this helpful tutorial. Whether you're a beginner or an experienced user, you'll find the information you need to safely and effectively remove a directory in Linux.
Author

Leave a Comment