≡ Menu

Linux Delete Folder Recursively

How do I delete folder recursively under Linux operating systems using a bash command line options?

You need to use the rm command to remove files or directories (also known as folders) recursively. The rmdir command removes only empty directories. So you need to use rm command.

rm command syntax to delete directories recursively

The syntax is as follows:
rm -r dirName


rm -r folderName


rm -rf folderName


In this example, recursively delete data folder:

rm -r /home/vivek/data/

The specified /home/vivek/data/ will first be emptied of any subdirectories including their subdirectories and files and then data directory removed. The user is prompted for removal of any write-protected files in the directories unless the -f (force) option is given on command line:

rm -rf dirname-here


rm -r -f /path/to/folder/

To remove a folder whose name starts with a -, for example '--dsaatia', use one of these commands:

rm -rf -- --dsaatia


rm -rf ./--dsaatia

See Linux rm(1) command man page or rm command example page for more information.

Share this tutorial on:

Like this? Follow us on Twitter OR support us by using Patreon

{ 5 comments… add one }
  • Thota Madhu Sudhan March 11, 2013, 6:11 pm

    What is the significance of -r in the code ?
    rm -r dirname
    what is the difference in using -rf and -r ?

    • K-hole March 18, 2014, 2:34 pm
      • -r :recursive
      • -f :force (no prompt)
  • tuunga July 9, 2013, 1:42 pm

    # rm -r dirName
    on centos ask every file to be deleted

  • Miloslav Havrda January 22, 2016, 11:54 am

    Thank you very much.

  • Dima February 10, 2016, 1:21 am

    Thanks. Great article.
    I have a question. How can I delete all subfolders /wp-content/cache/* in all folders in /home/ directory?

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , ,