How to find and delete directory recursively on Linux or Unix-like system ?

To find and delete a directory recursively on a Linux or Unix-like system, you can use the rm command with the -r (or --recursive) option. For example, to delete the directory /path/to/directory, you would run the following command:

rm -rf /path/to/directory

Note: The -f option (or --force) is used to ignore nonexistent files and suppress warnings. This is particularly useful when deleting a directory that may contain hidden files or other files that are difficult to delete.

It’s important to be cautious when using this command, as there is no way to recover deleted files or directories. Make sure you specify the correct path to the directory you want to delete, and consider using the ls command to verify the contents of the directory before you delete it.

For example, to view the contents of the directory you want to delete, you could run the following command:

ls -l /path/to/directory

This will give you a listing of the files and directories in the directory you want to delete, so you can verify that you have specified the correct path before you use the rm command to delete it.

Leave a Comment