Linux Delete Folder Using rmdir and rm Command

In Linux, you can delete a folder using either the rmdir or rm command. Here’s how to do it:

Using rmdir command:

  1. Open a terminal window.
  2. Navigate to the parent directory of the folder you want to delete.
  3. Type the following command: rmdir foldername (replace “foldername” with the name of the folder you want to delete).
  4. 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:

  1. Open a terminal window.
  2. Navigate to the parent directory of the folder you want to delete.
  3. Type the following command: rm -r foldername (replace “foldername” with the name of the folder you want to delete).
  4. 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.

Leave a Comment