How to Delete all the Files in a Directory Recursively

Linux deletes all the files in a directory 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.

Recursively delete all files with a specific extension (e.g. .txt) from current directory and all subfolders, use the find command.

I’m able to use the following to remove the target directory and recursively all of its subdirectories and contents. Before deleting, make a sure the list of files, first run this below command.

Create dummy files

For testing this command, Just create dummy text files by using this below command.

Precaution test

Before deleting, make a sure the list of files, first run this below command.

Delete all files from directory and all subfolders

If you want to delete a file with start from bspl1000*.txt or delete all files with a specific extension (e.g. .txt) from current directory and all subfolders, use the find command, you can safely delete.

Make sure that -delete is the last argument in your command.

Delete all files from directory and all subfolders

Delete Folder Recursively

You can also tell find to just find directories named .svn by adding a -type d check:

Vijayan J

Thanks for stopping by guys! I’m Vijayan and Techpulse is my beloved brainchild.
Currently working as a PHP developer in a digital marketing start-up, I’m overly passionate about not just learning new things but also putting those into practice. I swear by a quote I once came across…
‘What separates successful people from unsuccessful people is the former’s ability to execute’.
Feel free to reach out to me if you have any questions, suggestions or feedback. Hoping to see more of you here!