15 49.0138 8.38624 1 0 4000 1 https://www.techpulsetoday.com 300
How to Delete all the Files in a Directory Recursively

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.

touch bspl{0001..0100}.txt

Precaution test

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

find . -name "bspl000*.txt" -type f

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.

find . -name "bspl000*.txt" -type f -delete

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:

find . -name ".svn" -type d -exec rm -r "{}" \;
Share:
Category:Linux
PREVIOUS POST
Flickering and Screen distortion with new Hardware on elementary OS
NEXT POST
How to check the number of protocol connections made in a server
ABOUT
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!

0 Comment

LEAVE A REPLY

This site uses Akismet to reduce spam. Learn how your comment data is processed.