how to delete folders in linux command code example

Example 1: force delete a folder in linux

# To remove non-empty directories and all the files without being prompted, use rm with the -r (recursive) and -f options:
rm -rf dirname

Example 2: 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

Tags:

Misc Example