Learning how to delete a directory in the Linux terminal is an essential skill that makes it easy to manage your file system efficiently.
Delete an Empty Directory
To delete a completely empty directory, you need to use the rm -d command followed by the name of the directory that you want to delete.
rm -d directory_name
Delete a Directory Containing Files
To delete a directory that contains subdirectories and files, you must use the rm -r (recursive) command followed by the name of the directory you want to delete. This will remove the folder and all its contents.
rm -r directory_name
Delete Multiple Directories
And to delete multiple directories containing subdirectories and files at the same time, use the rm -r command followed by the directory names separated by a space.
rm -r directory1 directory2 directory3
Note: Please be very careful when deleting files or directories using the rm command, because once they are deleted from the terminal, they bypass the recycle bin and it is not easy to recover them.