how to delete directory in linux terminal code example

Example 1: how to remove folder and its contents in linux

rm -rf dirname

Example 2: delete directory linux

rm -rf dir1

Example 3: linux remove folder and all his content

rm -rf /path/to/directory

Example 4: remove directory from linux

rm -r filename

rm -rf filename

this command remove the directory and subdirectory forecefully

Example 5: how to remove folder from linux terminal

To remove an empty directory, use the rmdir command as follows:
$ rmdir foldername

If the directory still contains files or subdirectories, the rmdir command does not remove the directory.
To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r.

$ rm -r foldername

Example 6: remove folder in all sub folders linux command

$ find /start/search/from/this/dir -name "dirname-to-delete" -type d -exec /bin/rm -rf {} +