LKBEN10990: Howto remove a complete directory tree from the command line


This article has not been checked!

LKB | Created: 02/04/2020 | Version: 0 | Language: EN | Rating: 0 | Outdated: False | Marked for deletion: False

Author: Wim Peeters - Keskon GmbH & Co. KG


Symptom

You need to delete a directory tree with all contents

Cause

none

Solution

To remove a directory you can use the rmdir command. To delete a directory, it has to be empty.

The preferred method of removing a directory tree with all its content ist the following command:

rm -rf TheDirectory

Please note the power of this command. I do not like to use these things. I prefer using the mc (= midnight commander) and use the F8 functionality. The  parameter -f stand for force and the -r stand for recursive.

When the directory only contains a few files I use:

rm -ri TheDirectory

Now it asks for every deletion. Even admins need this security from time to time. 

 

About the Author

Wim Peeters is electronics engineer with an additional master in IT and over 30 years of experience including time spent in support, development, consulting, training and database administration. Wim has worked with SQL Server since version 6.5. He has developed in C/C++, Java and C# on Windows and Linux in different European countries and different European languages. He writes knowledge base articles to solve IT problems and publishes them on the Lubby Knowledge Platform where he is one of the most important contributors and the main developer.

Disclaimer:

The information provided in this document is intended for your information only. Lubby makes no claims to the validity of this information. Use of this information is at own risk!