In Linux, you can delete a folder using either the rmdir
or rm
command. Here’s how to do it:
Using rmdir command:
- Open a terminal window.
- Navigate to the parent directory of the folder you want to delete.
- Type the following command:
rmdir foldername
(replace “foldername” with the name of the folder you want to delete). - Press Enter.
The rmdir
command will delete the specified directory, but only if it is empty. If the directory contains any files or subdirectories, you will get an error message and the directory will not be deleted.
Using rm command:
- Open a terminal window.
- Navigate to the parent directory of the folder you want to delete.
- Type the following command:
rm -r foldername
(replace “foldername” with the name of the folder you want to delete). - Press Enter.
The -r
option tells the rm
command to delete the specified directory and all its contents, including any files and subdirectories. Be careful when using the rm
command, as it can permanently delete files and directories without any way to recover them. It’s a good idea to double-check that you’re deleting the correct directory before running this command.