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


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. 

 

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!

About the Author

Author: Wim Peeters - Keskon GmbH & Co. KG

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. He writes knowledge base articles to solve IT problems and publishes them on the Lubby Knowledge Platform.