mdeltree Command in Linux



Linux has many commands to manage files and directories. One such command is mdeltree, which simplifies the process of managing directories. More specifically it is capable of managing files and directories in bulk. It is a helpful tool for deleting folders and their contents recursively, managing symbolic links, and handling access permissions.

Table of Contents

Here is a comprehensive guide to the options available with the mdeltree command −

What is mdeltree Command in Linux?

mdeltree is a command-line utility in Linux that removes directories or files from a directory tree. It lets you quickly delete entire folder structures without removing items one by one. Therefore, this command is particularly useful when managing large or complex file systems where manual deletion would be time-consuming.

Syntax of mdeltree Command

The basic syntax to use this command in Linux is illustrated in the following snippet −

mdeltree [options] dirName

Here, replace the dirName with the actual directory path that you want to remove.

mdeltree Command Options

The mdeltree command belongs to the mtools package. It supports several options that are listed below along with their respective description −

  • -f − It forces the deletion of read-only files.
  • -v − It enables verbose mode to display details of the deletion process.
  • -i − It confirms before deleting each item.
  • -r − It recursively deletes directories and their contents.

You can access the general manual page of the mdeltree command to learn more about its usage −

man mdeltree
mdeltree Command in Linux1

Installation of mdeltree Command in Linux

If mdeltree is not pre-installed, you can install it on most Linux distributions using the appropriate package manager. For example, Debian users can use apt to install mtools package −

sudo apt-get install mtools
mdeltree Command in Linux2

Similarly, we can use yum to install mtools on Red Hat-based systems −

sudo yum install mtools

After installing the mtools package, we can confirm the mdeltree installation by checking its version −

mdeltree --version

It confirms the successful installation of the mdeltree command −

mdeltree Command in Linux3

Examples of mdeltree Command in Linux

Let's learn different use cases of this command in Linux by using the practical examples −

Deleting a Specific Directory

To delete a specific directory, simply type mdeltree followed by the directory name to be deleted −

mdeltree tutorialsDir

Deleting a Directory with Confirmation

To confirm directory deletion before proceeding, use the mdeltree command with the -i option −

mdeltree -i tutorialsDir

Forcing the Deletion of Read-Only Files

We can use the -f option with the mdeltree command to force it to remove the read-only files −

mdeltree -f protectedTutorials

Recursive Deletion Using the mdeltree Command

To apply recursive deletion, use the mdeltree command with the -r option. It deletes a directory, all its subdirectories, and files −

mdeltree -r tutorialsDirectory

It removes tutorialsDirectory and all of its content recursively −

Delete a Directory with Verbose Output

We can execute the mdeltree command with the -v option to show the detailed output about deleted directories and their files −

mdeltree -v tempDirectory

This way, we can use the mdeltree command to manage and clean up directory structures in Linux.

Conclusion

The mdeltree is a useful command in Linux that is used to efficiently manage and clean up directories in Linux. It simplifies handling directory structures by offering options for recursive deletions, managing read-only files, and providing verbose output. It is especially useful when working with large or complex file systems.

With mdeltree command, you can save time and effort in directory management. In this article, we explored mdeltree command, its syntax, options, and its usage in Linux with practical examples.

Advertisements