Ubuntu – Delete files and folders with specific name from a certain directory

command line

I have a folder /home/userA/folderA this folder contains many files and folders and subfolders. What I want to do is to delete all files that have certain names data.txt and glass.txt. I also want to delete any folder named match with all its contents. I'd be thankful for any advice in how to do this.

Best Answer

You can delete the files and folders in the subdirectories of folderA.

To remove the files, run:

find /home/userA/folderA/* -type f \( -name "data.txt" -or -name "glass.txt" \) -delete 

and to remove the folders match:

find /home/userA/folderA/* -depth -name "match" -type d -exec rm -rf "{}" \;