To remove a directory in Linux, you can use the rmdir
command followed by the name of the directory you want to remove. For example:
rmdir directory_to_remove
This will remove the directory called directory_to_remove
if it is empty. If the directory is not empty, you will get an error message saying “Directory not empty”.
To remove a directory and all of its contents, including any subdirectories and files, you can use the rm
command with the -r
option, followed by the name of the directory. For example:
rm -r directory_to_remove
This will recursively delete the directory and all of its contents. Be careful with this command, as it cannot be undone.
You can also use the -f
option to force the removal of the directory, even if it is not empty or if you do not have permission to delete it. For example:
rm -rf directory_to_remove
This will force the removal of the directory and all of its contents, regardless of any errors or permissions issues.
For more information, you can consult the rm
and rmdir
man pages by running man rm
and man rmdir
on the command line.